package com.whump.course.realworld;

import java.io.*;
import org.apache.xalan.xslt.*;
import org.xml.sax.SAXException;

/** transform
 * <p>The transform class takes an input stream
 * applies an XSLT style sheet, and returns the output
 * </p>
 *
 * @author Bill Humphries
 */
public class transformer
{

    org.apache.xalan.xslt.XSLTProcessor processor;
    org.apache.xalan.xslt.StylesheetRoot style;
    org.apache.xalan.xslt.XSLTInputSource xmlSource;
    org.apache.xalan.xslt.XSLTResultTarget xmlTarget;
    
    public transformer(String sheet) throws org.xml.sax.SAXException, java.io.FileNotFoundException 
    {
        // Use XSLTProcessorFactory to instantiate an XSLTProcessor.
        processor =
         org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor();

        style = processor.processStylesheet(new XSLTInputSource(sheet));
                                       
        processor.setStylesheet(style); // Good form!
    }
    
    public void setSource(InputStreamReader source)
    {
        xmlSource = new XSLTInputSource(source);
    }
    
    public void setTarget(PrintWriter target)
    {
        xmlTarget = new XSLTResultTarget(target);
    }
    
    public void process() throws java.io.FileNotFoundException, java.io.IOException, 
                                    java.net.MalformedURLException, org.xml.sax.SAXException
    {
        style.process(xmlSource, xmlTarget);
    }
 
}
