XslServletBean.java.

Graphic Java
Create XML files using JSP
David Geary
Listing 6. XslServletBean.java.


package com.companyName.beans.xsl;

import java.io.*;
import java.net.URL;
import javax.servlet.*;
import javax.servlet.http.*;

import com.jclark.xsl.sax.*;
import org.xml.sax.*;

public class XslServletBean implements Serializable {
	private XSLProcessor processor = new XSLProcessorImpl();

	public XslServletBean() {}

	public void process(File inputFile, URL xslFile,
						HttpServletRequest req,
						HttpServletResponse res)
						  	throws IOException, ServletException {
		loadProcessor(xslFile);
		setOutputMethodHandler(processor, res);

		try {
			processor.parse(fileInputSource(inputFile));
		}
		catch(SAXException e) {
			throw new ServletException(e);
		}
	}
	protected void setOutputMethodHandler(XSLProcessor p,
									HttpServletResponse res) {
	    OutputMethodHandlerImpl outputMethodHandler =
                new OutputMethodHandlerImpl(processor);

        processor.setOutputMethodHandler(outputMethodHandler);
        outputMethodHandler.setDestination(
                                 new ServletDestination(res));
	}
	// Listing truncated: see www.javareport.com for a full listing.
}

About the Author

David Geary was the lead engineer for the Java Management API GUI toolkit, and is now an independent Java consultant. David is the author of Graphic Java—Mastering the JFC. He can be contacted at sabreware@tri-lakesonline.net.

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.