cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Lamb" <p...@redfork.com>
Subject fixes to allow relative cocoon.properties
Date Fri, 28 Apr 2000 15:17:49 GMT
Below are some minor changes for the 1.7.3-dev track that allow you to
define a "propertiesURI" in web.xml instead of "properties" so that the
cocoon.properties file can be accessed thru the servlet engine as opposed to
direct file system access. It only works for a 2.1 or greater container.

I'm still getting used to cvs so let me know if I didn't do the diff's
correctly.

Paul Lamb


Index: web.xml
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/WEB-INF/web.xml,v
retrieving revision 1.1
diff -u -r1.1 web.xml
--- web.xml 1999/12/16 11:41:44 1.1
+++ web.xml 2000/04/28 14:57:04
@@ -15,6 +15,12 @@
   <servlet-name>org.apache.cocoon.Cocoon</servlet-name>
   <servlet-class>org.apache.cocoon.Cocoon</servlet-class>
   <init-param>
+   <!--  propertiesURI will take precedence over properties in
+         servlet containers that are at least 2.1 compatible -->
+   <param-name>propertiesURI</param-name>
+   <param-value>/conf/cocoon.properties</param-value>
+  </init-param>
+  <init-param>
    <param-name>properties</param-name>
    <param-value>[path-to-cocoon]/conf/cocoon.properties</param-value>
   </init-param>


Index: Cocoon.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.13
diff -u -r1.13 Cocoon.java
--- Cocoon.java 2000/04/04 11:10:10 1.13
+++ Cocoon.java 2000/04/28 15:05:52
@@ -74,10 +74,13 @@
     Exception exception = null;
     Configurations confs = null;
     String confsName = null;
+    String confsURI = null;
     String server = null;
     String statusURL = null;
     boolean errorsInternally = false;
     boolean showStatus = false;
+    int containerMajorVersion = 0;
+    int containerMinorVersion = 0;

     /**
      * Returns the version signature of Cocoon
@@ -96,11 +99,14 @@
         server = config.getServletContext().getServerInfo();

         // Get the initialization argument
-        confsName = config.getInitParameter(INIT_ARG);
+        confsName = config.getInitParameter(INIT_ARG_PROPS);
+        confsURI = config.getInitParameter(INIT_ARG_PROPS_URI);
+ containerMajorVersion = this.getContainerMajorVersion();
+ containerMinorVersion = this.getContainerMinorVersion();

-        if (confsName == null) {
+        if (confsURI == null && confsName == null) {
             exception = null;
-            message = "<p>The servlet initialization argument <i>\"" +
INIT_ARG + "\"</i> was not found. " +
+            message = "<p>The servlet initialization argument <i>\"" +
INIT_ARG_PROPS_URI + "\"</i> or <i>\"" + INIT_ARG_PROPS + "\"</i> was not
found. " +
                 "Please, make sure Cocoon is able to find its
configurations or it won't be able to execute correctly.</p>" +
                 "<p>A template for such configurations may be found in the
file \"/conf/cocoon.properties\" in the distribution.</p>";
             return;
@@ -108,7 +114,21 @@

         try {
             // Create the configuration object
-            confs = new Configurations(confsName);
+  // if we are using a servlet container that is 2.1 or higher then we
+  // can use container based resources instead of files
+  if(confsURI != null && (containerMajorVersion >= 2) &&
(containerMinorVersion > 0) ) {
+   try {
+           URL resource = config.getServletContext().getResource(confsURI);
+              InputStream confsStream =
resource.openConnection().getInputStream();
+              confs = new Configurations(confsStream);
+       confsStream.close();
+   } catch( Exception ex ) {
+    exception = ex;
+    message = "Unable to open resource: " + confsURI;
+   }
+  } else {
+   confs = new Configurations(confsName);
+  }

             // Save servlet configurations
             showStatus = ((String) confs.get(SHOW_STATUS,
"false")).toLowerCase().equals("true");
@@ -167,7 +187,12 @@
         Runtime jvm = Runtime.getRuntime();
         Hashtable table = new Hashtable();
         table.put("Servlet Engine", server);
-        table.put("Configurations", confsName);
+ table.put("Servlet Version", Integer.toString(containerMajorVersion) + "."
+ Integer.toString(containerMinorVersion));
+ if( confsURI != null && (containerMajorVersion >= 2) &&
(containerMinorVersion > 0) ) {
+  table.put("ConfigurationsURI", confsURI);
+ } else {
+  table.put("Configurations", confsName);
+ }
         table.put("Free Memory", new Long(jvm.freeMemory()));
         table.put("Total Memory", new Long(jvm.totalMemory()));
         return table;
@@ -252,5 +277,25 @@
         if (f.canRead()) return f.toString();

         throw new Exception("The property file could not be found.");
+    }
+
+    private int getContainerMajorVersion() {
+     int v;
+     try {
+      v = getServletConfig().getServletContext().getMajorVersion();
+     } catch( NoSuchMethodError e ) {
+   v = 2;   // using pre 2.1 servlet container
+     }
+     return v;
+    }
+
+    private int getContainerMinorVersion() {
+     int v;
+     try {
+      v = getServletConfig().getServletContext().getMinorVersion();
+     } catch( NoSuchMethodError e ) {
+     v = 0; // using pre 2.1 servlet container
+     }
+     return v;
     }
 }

Index: Defaults.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/Defaults.java,v
retrieving revision 1.11
diff -u -r1.11 Defaults.java
--- Defaults.java 2000/03/17 16:46:58 1.11
+++ Defaults.java 2000/04/28 15:06:54
@@ -63,7 +63,8 @@
     public static final String VERSION = "@version@";
     public static final String YEAR = "@year@";

-    public static final String INIT_ARG = "properties";
+    public static final String INIT_ARG_PROPS = "properties";
+    public static final String INIT_ARG_PROPS_URI = "propertiesURI";
     public static final String PROPERTIES = "cocoon.properties";
     public static final String INTERNAL_PROPERTIES = "org/apache/cocoon/" +
PROPERTIES;


Index: Configurations.java
===================================================================
RCS file:
/home/cvspublic/xml-cocoon/src/org/apache/cocoon/framework/Configurations.ja
va,v
retrieving revision 1.6
diff -u -r1.6 Configurations.java
--- Configurations.java 2000/02/13 18:29:22 1.6
+++ Configurations.java 2000/04/28 15:08:30
@@ -78,6 +78,13 @@
     }

     /**
+     * Create the class from a the InputStream
+     */
+    public Configurations(InputStream stream) throws Exception {
+        this(stream, null);
+    }
+
+    /**
      * Create the class with given defaults and from the file
      */
     public Configurations(String file, Configurations defaults) throws
Exception {
@@ -89,6 +96,17 @@
         InputStream input = new FileInputStream(file);
         properties.load(input);
         input.close();
+    }
+    /**
+     * Create the class with given defaults and from the URL resource
+     */
+    public Configurations(InputStream stream, Configurations defaults)
throws Exception {
+ if (defaults != null) {
+  properties = new Properties(defaults.properties);
+ } else {
+  properties = new Properties();
+ }
+        properties.load(stream);
     }

     /**



Mime
View raw message