Package webEditor.util

Source Code of webEditor.util.xsl_transform

/*  $Id: xsl_transform.java,v 1.4 2001/01/17 22:40:03 agarcia3 Exp $
    webEditor. The new way in content management
    Copyright (C) 2001  Alfredo Garcia

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/

package webEditor.util;

import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;


/**
* Direct access to the Xalan XSL formating capabilities
*
* @author <a href="mailto:agarcia@mundofree.com">Alfredo Garcia</a>
*/
public class xsl_transform
{
   public xsl_transform ()
   {
   }
  
   /**
    * Transformation method; We expect to improve this method soon.
    * Given a xml stream and an XSL template, it returns a string with
    * the document transformation;
    * @param input    Content of the XML file
    * @param templateName  Name of the template
    * @return String    Output of the transformation
    */
   public String process (String input, String templateName)
   throws java.io.IOException,
          java.net.MalformedURLException

   {
     StringReader readerInput = new StringReader (input);
     XSLTInputSource XSLinput = new XSLTInputSource (readerInput);

  StringWriter outBuffer = new StringWriter();
  XSLTResultTarget XSLoutput = new XSLTResultTarget(outBuffer)
try {
  XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
  processor.process(XSLinput, new XSLTInputSource(templateName),
                          XSLoutput);
} catch (Exception e) {
  e.printStackTrace();
}
  String result = XSLoutput.getCharacterStream().toString();
  //System.out.println (result);
     return (result);
   }

    /**
    * Transformation method; We expect to improve this method soon
    * In this case, the input source is a DOM tree.
    * @param input    DOM tree of the document
    * @param templateName  Name of the template
    * @return String    XSL output
    */
   public String processDOM (Document input, String templateName)
   throws java.io.IOException,
          java.net.MalformedURLException

   {
     XSLTInputSource XSLinput = new XSLTInputSource (input);

  StringWriter outBuffer = new StringWriter();
  XSLTResultTarget XSLoutput = new XSLTResultTarget(outBuffer)
try {
  // Set up the XSLTProcessor to use XercesLiaison.
  XSLTProcessor processor = XSLTProcessorFactory.getProcessor
                                  (new org.apache.xalan.xpath.xdom.XercesLiaison());

  processor.process(XSLinput, new XSLTInputSource(templateName),
                          XSLoutput);
} catch (Exception e) {
  e.printStackTrace();
}
  String result = XSLoutput.getCharacterStream().toString();
     return (result);
   }

}
TOP

Related Classes of webEditor.util.xsl_transform

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.