cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott_B...@lotus.com
Subject Re: [C2] Short TODO list [was CLI almost there]
Date Mon, 02 Oct 2000 16:13:02 GMT

> Hmmm, I'd like to use the Cocoon configurations instead (you never know
> if you'll be able to set the system properties in a servlet sandboxed
> servlet environment), Scott, is the trax processor factory configurable
> from the external?

I'm pretty unhappy with what's there now.  We try to load from the system,
then, if we fail, we load from a .properties file, and set the system
properties.  I think we might take better advantage of using
getResourceAsStream without setting the system properties (I think SAX uses
the system props, though).

Suggestions are welcome.  I can think of a number of ways the current code
could be improved, but I would like to get input first from you Cocoon
folks.

  /**
   * Obtain a new instance of a Processor object.
   * @return Concrete instance of an Processor object.
   */
  public static Processor newInstance(String type)
    throws ProcessorFactoryException
  {
    Processor factory = null;
    try
    {
      String factoryKey = "trax.processor."+type;
      String factoryName = System.getProperty(factoryKey);

      if(null == factoryName)
      {
        loadPropertyFileToSystem(XSLT_PROPERTIES) ;
        factoryName = System.getProperty(factoryKey);
      }

      if(null == factoryName)
        factoryName = platformDefaultFactoryName;

      if(null == factoryName)
        throw new ProcessorFactoryException("Can't find system property: "
+factoryKey, null);

      Class factoryClass = Class.forName(factoryName);
      factory = (Processor)factoryClass.newInstance();
    }
    catch(java.lang.IllegalAccessException iae)
    {
      throw new ProcessorFactoryException("Transformation Processor can not
be accessed!", iae);
    }
    catch(java.lang.InstantiationException ie)
    {
      throw new ProcessorFactoryException("Not able to create
Transformation Processor!", ie);
    }
    catch(java.lang.ClassNotFoundException cnfe)
    {
      throw new ProcessorFactoryException("Transformation Processor not
found!", cnfe);
    }

    return factory;
  }

  // TODO: This needs changing to some vendor neutral location.
  public static String XSLT_PROPERTIES
= "/org/apache/xalan/res/XSLTInfo.properties";

  /*
  * Retrieve a propery bundle from a specified file and load it
  * int the System properties.
  * @param file The string name of the property file.
  */
  private static void loadPropertyFileToSystem(String file)
  {
    InputStream is;
    try
    {
      Properties props = new Properties();
      is = Process.class.getResourceAsStream(file);
      // get a buffered version
      BufferedInputStream bis = new BufferedInputStream (is);
      props.load (bis);                                     // and load up
the property bag from this
      bis.close ();                                          // close out
after reading
      // OK, now we only want to set system properties that
      // are not already set.
      Properties systemProps = System.getProperties();
      Enumeration propEnum = props.propertyNames();
      while(propEnum.hasMoreElements())
      {
        String prop = (String)propEnum.nextElement();
        if(!systemProps.containsKey(prop))
          systemProps.put(prop, props.getProperty(prop));
      }
      System.setProperties(systemProps);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }



-scott




                                                                                         
                         
                    Stefano                                                              
                         
                    Mazzocchi            To:     cocoon-dev@xml.apache.org, Scott_Boag/CAM/Lotus
                  
                    <stefano@apac        <Scott_Boag/CAM/Lotus@lotus.com>       
                                  
                    he.org>              cc:                                          
                            
                                         Subject:     Re: [C2] Short TODO list [was CLI almost
there]              
                    10/02/00                                                             
                         
                    09:22 AM                                                             
                         
                                                                                         
                         
                                                                                         
                         



Davanum Srinivas wrote:
>
> According to the docs, trax.Processor can pick up "plugged" Processors
using System Properties.
> (like org.xml.trax.Processor.xslt should point to the factory that can
instantiate an XSLT
> Processor). More info at
http://xml.apache.org/xalan-j/apidocs/trax/Processor.html
>
> Is this good enough for moving forward?

Hmmm, I'd like to use the Cocoon configurations instead (you never know
if you'll be able to set the system properties in a servlet sandboxed
servlet environment), Scott, is the trax processor factory configurable
from the external?

--
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<stefano@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------





Mime
View raw message