FileDocCategorySizeDatePackage
Transform.javaAPI DocApache log4j 1.2.157221Sat Aug 25 00:09:36 BST 2007org.apache.log4j.xml

Transform

public class Transform extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    PropertyConfigurator.disableAll();
    PropertyConfigurator.configure("x.lcf");

    // I. Instantiate  a stylesheet processor.
    Processor processor = Processor.newInstance("xslt");

    // II. Process the stylesheet. producing a Templates object.

    // Get the XMLReader.
    XMLReader reader = XMLReaderFactory.createXMLReader();

    // Set the ContentHandler.
    TemplatesBuilder templatesBuilder = processor.getTemplatesBuilder();
    reader.setContentHandler(templatesBuilder);

    // Set the ContentHandler to also function as a LexicalHandler, which
    // includes "lexical" (e.g., comments and CDATA) events. The Xalan
    // TemplatesBuilder -- org.apache.xalan.processor.StylesheetHandler -- is
    // also a LexicalHandler).
    if(templatesBuilder instanceof LexicalHandler) {
       reader.setProperty("http://xml.org/sax/properties/lexical-handler", 
                           templatesBuilder);
    }

    // Parse the stylesheet.                       
    reader.parse(args[0]);

    //Get the Templates object from the ContentHandler.
    Templates templates = templatesBuilder.getTemplates();

    // III. Use the Templates object to instantiate a Transformer.
    Transformer transformer = templates.newTransformer();

    // IV. Perform the transformation.

    // Set up the ContentHandler for the output.
	FileOutputStream fos = new FileOutputStream(args[2]);
    Result result = new Result(fos);
    Serializer serializer = SerializerFactory.getSerializer("xml");
    serializer.setOutputStream(fos);

    transformer.setContentHandler(serializer.asContentHandler());

    // Set up the ContentHandler for the input.
    org.xml.sax.ContentHandler chandler = transformer.getInputContentHandler();
    DC dc = new DC(chandler);
    reader.setContentHandler(dc);
    if(chandler instanceof LexicalHandler) {
       reader.setProperty("http://xml.org/sax/properties/lexical-handler", 
			  chandler);
    } else {
       reader.setProperty("http://xml.org/sax/properties/lexical-handler", 
			  null);
    }

    // Parse the XML input document. The input ContentHandler and
    // output ContentHandler work in separate threads to optimize
    // performance.
    reader.parse(args[1]);