cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r265706 - in /cocoon: blocks/portal/trunk/java/org/apache/cocoon/portlet/ trunk/ trunk/src/java/org/apache/cocoon/bean/ trunk/src/java/org/apache/cocoon/core/ trunk/src/java/org/apache/cocoon/servlet/ trunk/src/test/org/apache/cocoon/test/c...
Date Thu, 01 Sep 2005 12:20:32 GMT
Author: cziegeler
Date: Thu Sep  1 05:20:21 2005
New Revision: 265706

URL: http://svn.apache.org/viewcvs?rev=265706&view=rev
Log:
Read several (block related) property files and update status file

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java
    cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
    cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java
    cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
    cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java
    cocoon/trunk/status.xml

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java (original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portlet/CocoonPortlet.java Thu Sep 
1 05:20:21 2005
@@ -885,13 +885,6 @@
         }
 
         /**
-         * @see org.apache.cocoon.core.BootstrapEnvironment#getInputStream(java.lang.String)
-         */
-        public InputStream getInputStream(String path) {
-            return this.config.getPortletContext().getResourceAsStream(path);
-        }
-
-        /**
          * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.cocoon.core.MutableSettings)
          */
         public void configure(MutableSettings settings) {

Modified: cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/bean/CocoonWrapper.java Thu Sep  1 05:20:21 2005
@@ -719,21 +719,6 @@
         }
 
         /**
-         * @see org.apache.cocoon.core.BootstrapEnvironment#getInputStream(java.lang.String)
-         */
-        public InputStream getInputStream(String path) {
-            final File f = new File(this.contextDirectory, path);
-            if ( f.exists() ) {
-                try {
-                    return new FileInputStream(f);
-                } catch (FileNotFoundException fnfe) {
-                    // this can't occure as we checked it already
-                }
-            }
-            return null;
-        }
-
-        /**
          * @see org.apache.cocoon.core.BootstrapEnvironment#log(java.lang.String, java.lang.Throwable)
          */
         public void log(String message, Throwable error) {

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/BootstrapEnvironment.java Thu Sep  1 05:20:21
2005
@@ -17,7 +17,6 @@
 package org.apache.cocoon.core;
 
 import java.io.File;
-import java.io.InputStream;
 import java.net.URL;
 
 import org.apache.avalon.framework.context.DefaultContext;
@@ -79,6 +78,7 @@
             return this.name;
         }
     }
+
     /**
      * Get the bootstrap logger.
      * @param logLevel The log level to use according to the {@link Logger} interface.
@@ -105,8 +105,6 @@
      */
     void setLogger(Logger rootLogger);
 
-    InputStream getInputStream(String path);
-    
     /**
      * This callback can be used by the environment to add environment specific
      * settings. For example the servlet environment parsed the web.xml and adjusts

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/CoreUtil.java Thu Sep  1 05:20:21 2005
@@ -109,18 +109,8 @@
 
     protected void init()
     throws Exception {
-        // create settings
-        this.settings = this.createSettings();
-
-        if (this.settings.isInitClassloader()) {
-            // Force context classloader so that JAXP can work correctly
-            // (see javax.xml.parsers.FactoryFinder.findClassLoader())
-            try {
-                Thread.currentThread().setContextClassLoader(this.env.getInitClassLoader());
-            } catch (Exception e) {
-                // ignore this
-            }
-        }
+        // first let's set up the appContext with some values to make
+        // the simple source resolver work
 
         // add root url
         try {
@@ -137,6 +127,19 @@
         // now add environment specific information
         this.env.configure(appContext);
 
+        // create settings
+        this.settings = this.createSettings();
+
+        if (this.settings.isInitClassloader()) {
+            // Force context classloader so that JAXP can work correctly
+            // (see javax.xml.parsers.FactoryFinder.findClassLoader())
+            try {
+                Thread.currentThread().setContextClassLoader(this.env.getInitClassLoader());
+            } catch (Exception e) {
+                // ignore this
+            }
+        }
+
         // first init the work-directory for the logger.
         // this is required if we are running inside a war file!
         final String workDirParam = this.settings.getWorkDirectory();
@@ -337,23 +340,57 @@
         // create an empty settings objects
         final MutableSettings s = new MutableSettings();
 
+        // we need our own resolver
+        final SourceResolver resolver = this.createSourceResolver(new LoggerWrapper(this.env));
+
         String additionalPropertyFile = System.getProperty(Settings.PROPERTY_USER_SETTINGS);
 
         // read cocoon-settings.properties - if available
-        InputStream propsIS = env.getInputStream("cocoon-settings.properties");
-        if ( propsIS != null ) {
-            env.log("Reading settings from 'cocoon-settings.properties'");
-            final Properties p = new Properties();
-            try {
+        Source source = null;
+        try {
+            source = resolver.resolveURI("context://WEB-INF/cocoon-settings.properties");
+            if ( source.exists() ) {
+                final InputStream propsIS = source.getInputStream();
+                env.log("Reading settings from '" + source.getURI() + "'");
+                final Properties p = new Properties();
                 p.load(propsIS);
                 propsIS.close();
                 s.fill(p);
-                additionalPropertyFile = p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
-            } catch (IOException ignore) {
-                env.log("Unable to read 'cocoon-settings.properties'.", ignore);
-                env.log("Continuing initialization.");
+                additionalPropertyFile = p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
               
+            }
+        } catch (IOException ignore) {
+            env.log("Unable to read 'WEB-INF/cocoon-settings.properties'.", ignore);
+            env.log("Continuing initialization.");            
+        } finally {
+            resolver.release(source);
+        }
+
+        // now read all properties from the properties directory
+        Source directory = null;
+        try {
+            directory = resolver.resolveURI("context://WEB-INF/properties", null, CONTEXT_PARAMETERS);
+            if (directory.exists() && directory instanceof TraversableSource) {
+                final Iterator c = ((TraversableSource) directory).getChildren().iterator();
+                while (c.hasNext()) {
+                    final Source src = (Source) c.next();
+                    if ( src.getURI().endsWith(".properties") ) {
+                        final InputStream propsIS = src.getInputStream();
+                        env.log("Reading settings from '" + src.getURI() + "'.");
+                        final Properties p = new Properties();
+                        p.load(propsIS);
+                        propsIS.close();
+                        s.fill(p);
+                        additionalPropertyFile = p.getProperty(Settings.PROPERTY_USER_SETTINGS,
additionalPropertyFile);                
+                    }
+                }
             }
+        } catch (IOException ignore) {
+            env.log("Unable to read from directory 'WEB-INF/properties'.", ignore);
+            env.log("Continuing initialization.");            
+        } finally {
+            resolver.release(directory);
         }
+
         // fill from the environment configuration, like web.xml etc.
         env.configure(s);
 
@@ -401,6 +438,22 @@
         }
     }
 
+    /**
+     * Create a simple source resolver.
+     */
+    protected SourceResolver createSourceResolver(Logger logger) {
+        // Create our own resolver
+        final SimpleSourceResolver resolver = new SimpleSourceResolver();
+        resolver.enableLogging(logger);
+        try {
+            resolver.contextualize(this.appContext);
+        } catch (ContextException ce) {
+            throw new CascadingRuntimeException(
+                    "Cannot setup source resolver.", ce);
+        }
+        return resolver;        
+    }
+
     protected void initLogger() {
         String logLevel = settings.getBootstrapLogLevel();
         if (logLevel == null) {
@@ -417,14 +470,8 @@
         final Logger bootstrapLogger = this.env.getBootstrapLogger(level);
 
         // Create our own resolver
-        final SimpleSourceResolver resolver = new SimpleSourceResolver();
-        resolver.enableLogging(bootstrapLogger);
-        try {
-            resolver.contextualize(this.appContext);
-        } catch (ContextException ce) {
-            throw new CascadingRuntimeException(
-                    "Cannot setup source resolver.", ce);
-        }
+        final SourceResolver resolver = this.createSourceResolver(bootstrapLogger);
+
         // create an own service manager for the logger manager
         final ServiceManager loggerManagerServiceManager = new SingleComponentServiceManager(
                  null, resolver, SourceResolver.ROLE);
@@ -834,4 +881,83 @@
         return "";
     }
 
+    protected static final class LoggerWrapper implements Logger {
+        private final BootstrapEnvironment env;
+
+        public LoggerWrapper(BootstrapEnvironment env) {
+            this.env = env;
+        }
+
+        protected void text(String arg0, Throwable arg1) {
+            if ( arg1 != null ) {
+                this.env.log(arg0, arg1);
+            } else {
+                this.env.log(arg0);
+            }
+        }
+
+        public void debug(String arg0, Throwable arg1) {
+            // we ignore debug
+        }
+
+        public void debug(String arg0) {
+            // we ignore debug
+        }
+
+        public void error(String arg0, Throwable arg1) {
+            this.text(arg0, arg1);
+        }
+
+        public void error(String arg0) {
+            this.text(arg0, null);
+        }
+
+        public void fatalError(String arg0, Throwable arg1) {
+            this.text(arg0, arg1);
+        }
+
+        public void fatalError(String arg0) {
+            this.text(arg0, null);
+        }
+
+        public Logger getChildLogger(String arg0) {
+            return this;
+        }
+
+        public void info(String arg0, Throwable arg1) {
+            // we ignore info
+        }
+
+        public void info(String arg0) {
+            // we ignore info
+        }
+
+        public boolean isDebugEnabled() {
+            return false;
+        }
+
+        public boolean isErrorEnabled() {
+            return true;
+        }
+
+        public boolean isFatalErrorEnabled() {
+            return true;
+        }
+
+        public boolean isInfoEnabled() {
+            return false;
+        }
+
+        public boolean isWarnEnabled() {
+            return false;
+        }
+
+        public void warn(String arg0, Throwable arg1) {
+            // we ignore warn
+        }
+
+        public void warn(String arg0) {
+            // we ignore warn
+        }
+    }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Thu Sep  1 05:20:21
2005
@@ -685,13 +685,6 @@
         }
 
         /**
-         * @see org.apache.cocoon.core.BootstrapEnvironment#getInputStream(java.lang.String)
-         */
-        public InputStream getInputStream(String path) {
-            return this.config.getServletContext().getResourceAsStream(path);
-        }
-
-        /**
          * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.cocoon.core.MutableSettings)
          */
         public void configure(MutableSettings settings) {

Modified: cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java (original)
+++ cocoon/trunk/src/test/org/apache/cocoon/test/core/TestBootstrapEnvironment.java Thu Sep
 1 05:20:21 2005
@@ -83,24 +83,12 @@
     }
 
     /**
-     * Get the input stream from a resource at the given
-     * path. Only paths relative to the bootstrap context are
-     * supported. Returns null if no resource exists at the
-     * specified path
+     * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.cocoon.core.MutableSettings)
      */
-    public InputStream getInputStream(String path) {
-        try {
-            return (new URL(this.contextPath + path)).openStream();
-        } catch (IOException e) {
-            this.log("Couldn't open " + this.contextPath + path);
-            return null;
-        }
-    }
-    
     public void configure(MutableSettings settings) {
         settings.setConfiguration(this.configuration);
         settings.setWorkDirectory("work");
-	settings.setInitClassloader(true);
+        settings.setInitClassloader(true);
     }
 
     public void configureLoggingContext(DefaultContext context) {

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=265706&r1=265705&r2=265706&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Thu Sep  1 05:20:21 2005
@@ -197,6 +197,16 @@
 
   <changes>
   <release version="@version@" date="@date@">
+    <action dev="CZ" type="add">
+      Add property mechanism for Cocoon configuration. All settings for Cocoon can now
+      be configured using properties instead of putting them in web.xml.
+    </action>
+    <action dev="CZ" type="add">
+      Allow the use of property replacements in logging, xconf and sitemap configurations.
+    </action>
+    <action dev="CZ" type="add">
+      Use includes for logkit configurations and for sitemap components.
+    </action>
     <action dev="AN" type="fix">
       XSP block: Move AttributeImpl in xsp.xsl to class scope.
       That allows top-level xsp:logic to define markup generating methods.



Mime
View raw message