You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by le...@apache.org on 2001/04/26 10:44:52 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/services/xslt XSLTService.java TurbineXSLTService.java TurbineXSLT.java

leonm       01/04/26 01:44:52

  Modified:    src/java/org/apache/turbine/services/xslt XSLTService.java
                        TurbineXSLTService.java TurbineXSLT.java
  Log:
  1.  I added support for transformation of DOM nodes.
  2.  The xsl path is now a relative path.
  
  Revision  Changes    Path
  1.5       +21 -0     jakarta-turbine/src/java/org/apache/turbine/services/xslt/XSLTService.java
  
  Index: XSLTService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xslt/XSLTService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XSLTService.java	2001/04/08 16:41:11	1.4
  +++ XSLTService.java	2001/04/26 08:44:50	1.5
  @@ -62,6 +62,8 @@
   import org.apache.turbine.util.*;
   import org.apache.turbine.modules.*;
   
  +// Xalan Classes
  +import org.w3c.dom.Node;
   /**
    * The Turbine XSLT Service is used to transform xml with a xsl stylesheet.
    * The service makes use of the Xalan xslt engine available from apache.
  @@ -92,4 +94,23 @@
        * @param in The reader that passes the xml to be transformed
        */
       public String transform (String xslName, Reader in) throws Exception;
  +    
  +    /**
  +     * Uses an xsl file to transform xml input from a DOM note and writes the
  +     * output to a writer.
  +     *
  +     * @param xslName The name of the file that contains the xsl stylesheet.
  +     * @param in The DOM Node to be transformed
  +     * @param out The writer for the transformed output
  +     */
  +    public void transform (String xslName, org.w3c.dom.Node in, Writer out) throws Exception;
  +    
  +    /**
  +     * Uses an xsl file to transform xml input from a DOM note and returns a
  +     * string containing the transformed output.
  +     *
  +     * @param xslName The name of the file that contains the xsl stylesheet.
  +     * @param out The writer for the transformed output
  +     */
  +    public String transform (String xslName, org.w3c.dom.Node in) throws Exception;
   }
  
  
  
  1.7       +45 -11    jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java
  
  Index: TurbineXSLTService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TurbineXSLTService.java	2001/04/11 14:29:31	1.6
  +++ TurbineXSLTService.java	2001/04/26 08:44:50	1.7
  @@ -62,14 +62,15 @@
   //import org.apache.turbine.services.Service;
   import org.apache.turbine.services.*;
   import org.apache.turbine.services.resources.TurbineResources;
  +import org.apache.turbine.services.servlet.TurbineServlet;
   import org.apache.turbine.util.*;
   import org.apache.turbine.modules.*;
   
   // Xalan classes
   import org.xml.sax.SAXException;
   import org.apache.xalan.xslt.*;
  +import org.w3c.dom.Node;
   
  -
   /**
    * Implementation of the Turbine XSLT Service.  It transforms xml with a given
    * xsl file.  XSL stylesheets are compiled and cached (if the property in 
  @@ -99,6 +100,8 @@
           path = TurbineResources.getString (TurbineServices.SERVICE_PREFIX+
                                              XSLTService.SERVICE_NAME+
                                              ".path");
  +
  +        path = TurbineServlet.getRealPath (path);
                                              
           if (!path.endsWith("/") && !path.endsWith ("\\"))
           {
  @@ -200,23 +203,17 @@
           
       }
       
  -    /**
  -     * Execute an xslt
  -     */
  -    public void transform (String xslName, Reader in, Writer out) throws Exception
  +
  +    protected void transform (String xslName, XSLTProcessor processor, XSLTInputSource xmlin, XSLTResultTarget xmlout) throws Exception
       {
  -        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
  -        XSLTInputSource xmlin = new XSLTInputSource(in);
  -        XSLTResultTarget xmlout = new XSLTResultTarget(out);
  -        
           StylesheetRoot sr = getStylesheetRoot(xslName);
           
           // If there is no stylesheet we just echo the xml
           if (sr == null)
           {
               String line;
  -            BufferedReader br = new BufferedReader (in);
  -            BufferedWriter bw = new BufferedWriter (out);
  +            BufferedReader br = new BufferedReader (xmlin.getCharacterStream());
  +            BufferedWriter bw = new BufferedWriter (xmlout.getCharacterStream());
               line = br.readLine();
               while (line != null)
               {
  @@ -236,9 +233,24 @@
               processor.setStylesheet (sr);
               processor.process(xmlin, null, xmlout);
           }
  +    }
  +    
  +
  +    /**
  +     * Execute an xslt
  +     */
  +    public void transform (String xslName, Reader in, Writer out) throws Exception
  +    {
  +        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
  +        XSLTInputSource xmlin = new XSLTInputSource(in);
  +        XSLTResultTarget xmlout = new XSLTResultTarget(out);
           
  +        transform (xslName,processor,xmlin,xmlout);        
       }
       
  +    /**
  +     * Execute an xslt
  +     */
       public String transform (String xslName, Reader in) throws Exception
       {
           StringWriter sw = new StringWriter();
  @@ -246,5 +258,27 @@
           return sw.toString();
       }
       
  +
  +    /**
  +     * Execute an xslt
  +     */
  +    public void transform (String xslName, org.w3c.dom.Node in, Writer out) throws Exception
  +    {
  +        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
  +        XSLTInputSource xmlin = new XSLTInputSource(in);
  +        XSLTResultTarget xmlout = new XSLTResultTarget(out);
  +        
  +        transform (xslName,processor,xmlin,xmlout);        
  +    }
  +    
  +    /**
  +     * Execute an xslt
  +     */
  +    public String transform (String xslName, org.w3c.dom.Node in) throws Exception
  +    {
  +        StringWriter sw = new StringWriter();
  +        transform (xslName,in,sw);
  +        return sw.toString();
  +    }
       
   }
  
  
  
  1.7       +15 -0     jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLT.java
  
  Index: TurbineXSLT.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLT.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TurbineXSLT.java	2001/04/05 05:41:33	1.6
  +++ TurbineXSLT.java	2001/04/26 08:44:50	1.7
  @@ -99,4 +99,19 @@
       {
           return getService().transform (xslName,in);
       }
  +
  +    public void transform (String xslName, org.w3c.dom.Node in, Writer out)
  +        throws Exception
  +    {
  +        getService().transform (xslName,in,out);
  +    }
  +     
  +    
  +    public String transform (String xslName, org.w3c.dom.Node in)
  +        throws Exception
  +    {
  +        return getService().transform (xslName,in);
  +    }
  +    
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org