You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/04/07 17:51:09 UTC

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

henning     2003/04/07 08:51:09

  Modified:    src/java/org/apache/turbine/services/xslt
                        TurbineXSLTService.java
  Log:
  - Some cleanups
  - Hashtable -> Map/HashMap
  - factored out configuration object
  -
  
  Revision  Changes    Path
  1.7       +25 -21    jakarta-turbine-2/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java
  
  Index: TurbineXSLTService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/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	9 Mar 2003 03:06:35 -0000	1.6
  +++ TurbineXSLTService.java	7 Apr 2003 15:51:09 -0000	1.7
  @@ -58,7 +58,10 @@
   import java.io.Reader;
   import java.io.StringWriter;
   import java.io.Writer;
  -import java.util.Hashtable;
  +
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import javax.xml.transform.Result;
   import javax.xml.transform.Source;
   import javax.xml.transform.Templates;
  @@ -68,10 +71,16 @@
   import javax.xml.transform.stream.StreamResult;
   import javax.xml.transform.stream.StreamSource;
   
  -import org.apache.turbine.services.TurbineBaseService;
  +import org.apache.commons.configuration.Configuration;
  +
  +import org.apache.commons.lang.StringUtils;
  +
  +xoimport org.apache.turbine.services.TurbineBaseService;
   import org.apache.turbine.services.TurbineServices;
   import org.apache.turbine.services.servlet.TurbineServlet;
   
  +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,7 +108,7 @@
       /**
        * Cache of compiled StyleSheetRoots.
        */
  -    protected Hashtable cache = new Hashtable();
  +    protected Map cache = new HashMap();
   
       /**
        * Factory for producing templates and null transformers
  @@ -111,26 +120,21 @@
        * xsl files and initiates the cache.
        */
       public void init()
  +        throws InitializationException
       {
  -        if (getInit())
  -        {
  -            return;
  -        }
  -
  -        path = getConfiguration().getString(
  -                TurbineServices.SERVICE_PREFIX +
  -                XSLTService.SERVICE_NAME + ".path");
  +        Configuration conf = getConfiguration();
   
  -        path = TurbineServlet.getRealPath(path);
  +        path = TurbineServlet.getRealPath(conf.getString(STYLESHEET_PATH, null));
   
  -        if (!path.endsWith("/") && !path.endsWith("\\"))
  +        if (StringUtils.isNotEmpty(path))
           {
  -            path = path + File.separator;
  +            if (!path.endsWith("/") && !path.endsWith ("\\"))
  +            {
  +                path=path + File.separator;
  +            }
           }
   
  -        caching = getConfiguration().getBoolean(
  -                TurbineServices.SERVICE_PREFIX +
  -                XSLTService.SERVICE_NAME + ".cache");
  +        caching = conf.getBoolean(STYLESHEET_CACHING);
   
           tfactory = TransformerFactory.newInstance();
   
  @@ -264,8 +268,8 @@
       /**
        * Execute an xslt
        */
  -    public void transform(String xslName, org.w3c.dom.Node in, Writer out)
  -            throws Exception
  +    public void transform (String xslName, Node in, Writer out)
  +        throws Exception
       {
           Source xmlin = new DOMSource(in);
           Result xmlout = new StreamResult(out);
  @@ -276,8 +280,8 @@
       /**
        * Execute an xslt
        */
  -    public String transform(String xslName, org.w3c.dom.Node in)
  -            throws Exception
  +    public String transform (String xslName, Node in)
  +        throws Exception
       {
           StringWriter sw = new StringWriter();
           transform(xslName, in, sw);
  
  
  

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