You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2005/09/22 23:56:47 UTC

svn commit: r291023 - in /cocoon/trunk: src/java/ src/java/org/apache/cocoon/core/osgi/ src/osgi-servlet/ src/osgi-servlet/org/apache/cocoon/service/servlet/impl/ src/webapp/WEB-INF/ tools/targets/

Author: danielf
Date: Thu Sep 22 14:56:34 2005
New Revision: 291023

URL: http://svn.apache.org/viewcvs?rev=291023&view=rev
Log:
Need to rewrite part of the CocoonServlet for blocks. Start by copy it to osgi-servlet and modify package export and import.

Added:
    cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java   (with props)
    cocoon/trunk/src/webapp/WEB-INF/block.xml   (with props)
Modified:
    cocoon/trunk/src/java/Manifest.mf
    cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java   (contents, props changed)
    cocoon/trunk/src/osgi-servlet/Manifest.mf
    cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java
    cocoon/trunk/tools/targets/osgi-build.xml

Modified: cocoon/trunk/src/java/Manifest.mf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/Manifest.mf?rev=291023&r1=291022&r2=291023&view=diff
==============================================================================
--- cocoon/trunk/src/java/Manifest.mf (original)
+++ cocoon/trunk/src/java/Manifest.mf Thu Sep 22 14:56:34 2005
@@ -10,21 +10,47 @@
 Bundle-DocURL: http://cocoon.apache.org
 Bundle-ContactAddress: http://cocoon.apache.org
 Bundle-Category: library
-Bundle-Classpath: .,avalon-framework-api-4.3.jar,avalon-framework-impl
- -4.3.jar,commons-cli-1.0.jar,commons-collections-3.1.jar,commons-http
- client-2.0.2.jar,commons-jci-r159148.jar,commons-jexl-1.0.jar,commons
- -jxpath-1.2.jar,commons-lang-2.1.jar,commons-logging-1.0.4.jar,ehcach
- e-1.1.jar,excalibur-i18n-1.1.jar,excalibur-instrument-2.1.jar,excalib
- ur-io-1.1.jar,excalibur-logger-2.1.jar,excalibur-naming-1.0.jar,excal
- ibur-pool-api-2.1.jar,excalibur-pool-impl-2.1.jar,excalibur-pool-inst
- rumented-2.1.jar,excalibur-sourceresolve-2.1.jar,excalibur-store-2.1.
- jar,excalibur-xmlutil-2.1.jar,jcs-1.2.5-dev-20050313.jar,log4j-1.2.12
- .jar,logkit-1.2.2.jar,rhino-1.6R1.jar,servlet-2_3.jar,util.concurrent
- -1.3.4.jar,xml-commons-resolver-1.1.jar,xmlbeans-1.0.3.jar,jakarta-bc
- el-20040329.jar,jakarta-regexp-1.4.jar,xalan-2.7.0.jar,xercesImpl-2.7
- .1.jar,xml-apis-1.3.02.jar
-Export-Package: javax.servlet,
+Bundle-Classpath: 
+ .,
+ avalon-framework-api-4.3.jar,
+ avalon-framework-impl-4.3.jar,
+ avalon-logkit-2.1.jar,
+ commons-cli-1.0.jar,
+ commons-collections-3.1.jar,
+ commons-httpclient-2.0.2.jar,
+ commons-jci-r159148.jar,
+ commons-jexl-1.0.jar,
+ commons-jxpath-1.2.jar,
+ commons-lang-2.1.jar,
+ commons-logging-1.0.4.jar,
+ ehcache-1.1.jar,
+ excalibur-i18n-1.1.jar,
+ excalibur-instrument-api-2.1.jar,
+ excalibur-io-1.1.jar,
+ excalibur-logger-2.1.jar,
+ excalibur-naming-1.0.jar,
+ excalibur-pool-api-2.1.jar,
+ excalibur-pool-impl-2.1.jar,
+ excalibur-pool-instrumented-2.1.jar,
+ excalibur-sourceresolve-2.1.jar,
+ excalibur-store-2.1.jar,
+ excalibur-xmlutil-2.1.jar,
+ jcs-1.2.5-dev-20050313.jar,
+ log4j-1.2.12.jar,
+ rhino-1.6R1.jar,
+ servlet-2_3.jar,
+ util.concurrent-1.3.4.jar,
+ xml-commons-resolver-1.1.jar,
+ xmlbeans-1.0.3.jar,
+ jakarta-bcel-20040329.jar,
+ jakarta-regexp-1.4.jar,
+ xalan-2.7.0.jar,
+ xercesImpl-2.7.1.jar,
+ xml-apis-1.3.02.jar
+Export-Package: 
+ javax.servlet,
  javax.servlet.http,
+ org.apache.avalon.excalibur.logger,
  org.apache.avalon.framework.context,
  org.apache.avalon.framework.logger,
  org.apache.avalon.framework.service,
@@ -32,45 +58,65 @@
  org.apache.avalon.framework.thread,
  org.apache.avalon.framework.configuration,
  org.apache.cocoon,
+ org.apache.cocoon.acting,
  org.apache.cocoon.caching,
+ org.apache.cocoon.caching.impl,
  org.apache.cocoon.components.blocks,
  org.apache.cocoon.components.classloader,
  org.apache.cocoon.components.fam,
+ org.apache.cocoon.components.flow,
+ org.apache.cocoon.components.flow.javascript.fom,
  org.apache.cocoon.components.modules.input,
+ org.apache.cocoon.components.modules.output,
+ org.apache.cocoon.components.notification,
  org.apache.cocoon.components.pipeline.impl,
+ org.apache.cocoon.components.resolver,
+ org.apache.cocoon.components.sax,
  org.apache.cocoon.components.source,
  org.apache.cocoon.components.source.impl,
+ org.apache.cocoon.components.store.impl,
+ org.apache.cocoon.components.thread,
  org.apache.cocoon.components.treeprocessor,
  org.apache.cocoon.components.treeprocessor.sitemap,
  org.apache.cocoon.core,
  org.apache.cocoon.core.container,
+ org.apache.cocoon.core.osgi,
  org.apache.cocoon.environment,
+ org.apache.cocoon.environment.http,
  org.apache.cocoon.environment.impl,
  org.apache.cocoon.generation,
+ org.apache.cocoon.i18n,
  org.apache.cocoon.matching,
  org.apache.cocoon.reading,
  org.apache.cocoon.serialization,
  org.apache.cocoon.servlet,
+ org.apache.cocoon.servlet.multipart,
+ org.apache.cocoon.sitemap,
  org.apache.cocoon.transformation,
+ org.apache.cocoon.transformation.helpers,
+ org.apache.cocoon.transformation.pagination,
+ org.apache.cocoon.reading,
+ org.apache.cocoon.selection,
+ org.apache.cocoon.serialization,
  org.apache.cocoon.util,
  org.apache.cocoon.util.log,
  org.apache.cocoon.xml,
  org.apache.cocoon.xml.dom,
- org.apache.avalon.excalibur.logger,
+ org.apache.commons.jxpath,
+ org.apache.commons.lang,
+ org.apache.commons.lang.time,
  org.apache.excalibur.source,
  org.apache.excalibur.source.impl,
+ org.apache.excalibur.store,
  org.apache.excalibur.xml.impl,
  org.apache.excalibur.xml.sax,   
+ org.apache.excalibur.xml.xpath,
  org.apache.excalibur.xml.xslt,
  org.apache.excalibur.xmlizer,
  org.apache.log,
- org.xml.sax,
- org.apache.commons.lang,
- org.apache.excalibur.store,
- org.apache.cocoon.components.source,
- org.apache.cocoon.components.flow,
- org.apache.commons.jxpath
+ org.xml.sax
 Import-Package: 
- org.osgi.framework
+ org.osgi.framework,
+ org.osgi.service.log
 DynamicImport-Package: org.apache.cocoon.*
 Bundle-UUID: org.apache.cocoon:cocoon:1.0.0:all

Modified: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java?rev=291023&r1=291022&r2=291023&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java Thu Sep 22 14:56:34 2005
@@ -1,246 +1,250 @@
-/*
- * Copyright 1999-2005 The Apache Software Foundation.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cocoon.core.osgi;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.cocoon.core.BootstrapEnvironment;
-import org.apache.cocoon.core.MutableSettings;
-import org.apache.cocoon.core.Settings;
-import org.apache.cocoon.environment.Context;
-import org.apache.cocoon.environment.impl.AbstractContext;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.log.LogService;
-
-public class OSGiBootstrapEnvironment
-    implements BootstrapEnvironment {
-    
-    private final String configuration = "/WEB-INF/block.xconf";
-    private final ClassLoader classLoader;
-    public Logger logger = null;
-    private final String contextPath;
-    private final Context environmentContext;
-
-    public OSGiBootstrapEnvironment(ClassLoader classLoader, BundleContext bc)
-	throws IOException {
-        this.classLoader = classLoader;
-
-        // Create a logger manager that delegates to OSGi
-        // FIXME: have the maximum level as a property of the bundle
-        LoggerManager logManager = new OSGiLoggerManager(bc, LogService.LOG_DEBUG);
-        this.logger = logManager.getDefaultLogger();
-
-	Bundle bundle = getSitemapBundle(bc, this.logger); //bc.getBundle();
-	// Try to figure out the path of the root from that of /WEB-INF/block.xconf
-        String path = bundle.getResource(this.configuration).toString();
-	if (path == null)
-	    throw new FileNotFoundException("Unable to get resource '/WEB-INF/block.xconf'.");
-	path = path.substring(0, path.length() - this.configuration.length() - 1);
-        this.contextPath = path;
-
-        this.environmentContext = new OSGiContext(bundle);
-    }
-
-    /**
-     * @see org.apache.cocoon.core.BootstrapEnvironment#getBootstrapLogger(org.apache.cocoon.core.BootstrapEnvironment.LogLevel)
-     */
-    public Logger getBootstrapLogger(LogLevel logLevel) {
-        return this.logger;
-    }
-
-    /** Log a message during bootstrapping. This is used to log
-     * information before the logging system is setup.
-     * @param message A message.
-     */
-    public void log(String message) {
-        this.logger.info(message);
-    }
-
-    /** Log a message during bootstrapping. This is used to log
-     * information before the logging system is setup.
-     * @param message A message.
-     * @param error   An error.
-     */
-    public void log(String message, Throwable error) {
-        this.logger.info(message, error);
-    }
-
-    /**
-     * Pass the root logger back to the environment. As soon as the
-     * logging system is set up, this method is called.
-     * @param rootLogger The root logger.
-     */
-    public void setLogger(Logger rootLogger) {
-        this.logger = rootLogger;
-    }
-
-    /**
-     * 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
-     */
-    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);
-    }
-
-    public void configureLoggingContext(DefaultContext context) {
-        // simply do nothing
-    }
-
-    public void configure(DefaultContext context) {
-    }
-
-    public ClassLoader getInitClassLoader() {
-        return this.classLoader;
-    }
-
-    public Context getEnvironmentContext() {
-        return this.environmentContext;
-    }
-    
-    /**
-     * Returns the URL to the application context.
-     */
-    public String getContextURL() {
-        return this.contextPath;
-    }
-
-    /**
-     * Returns a file to the application context.
-     * @return A file pointing to the context or null if the context is not
-     *         writeable.
-     */
-    public File getContextForWriting() {
-        return null;
-    }
-
-    /**
-     * Set the ConfigFile for the Cocoon object.
-     *
-     * @param configFileName The file location for the cocoon.xconf
-     *
-     * @throws Exception
-     */
-    public URL getConfigFile(String configFileName) throws Exception {
-        return new URL(this.contextPath + configFileName);
-    }
-
-    public String getClassPath(Settings settings) {
-        return null;
-    }
-
-    private Bundle getSitemapBundle(BundleContext bc, Logger log) {
-	String SITEMAP = "sitemap";
-        Bundle[] bundles = bc.getBundles();
-        for (int i = 0; i < bundles.length; i++) {
-            Bundle bundle = bundles[i];
-            try {
-                log.info("checking bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME) + " category=" + bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
-                if ((bundle.getState() == Bundle.INSTALLED ||
-                     bundle.getState() == Bundle.RESOLVED ||
-                     bundle.getState() == Bundle.ACTIVE)) {
-                    log.info("ok state");
-                    if (SITEMAP.equals(bundle.getHeaders().get(Constants.BUNDLE_CATEGORY))) {
-                        log.info("sitemap");
-                        return bundle;
-                    }
-                }
-            } catch (NullPointerException e) {
-                // BUNDLE_CATEGORY not present in the headers of the
-                // bundle, nothing to do.
-            }
-        }
-        return null;
-    }
-
-    public class OSGiContext extends AbstractContext {
-
-	Bundle bundle;
-	private Hashtable attributes = new Hashtable();
-	private Hashtable initparameters = new Hashtable();
-
-	public OSGiContext(Bundle bundle) {
-	    this.bundle = bundle;
-            this.initparameters.put("init-classloader", "true");
-            this.initparameters.put("work-directory", "work");
-	}
-
-	public Object getAttribute(String name) {
-	    return attributes.get(name);
-	}
-
-	public void setAttribute(String name, Object value) {
-	    attributes.put(name, value);
-	}
-
-	public void removeAttribute(String name) {
-	    attributes.remove(name);
-	}
-
-	public Enumeration getAttributeNames() {
-	    return attributes.keys();
-	}
-
-	public URL getResource(String path) throws MalformedURLException {
-	    return this.bundle.getResource(path);
-	}
-
-	public String getRealPath(String path) {
-	    try {
-		return getResource(path).toString();
-	    } catch (MalformedURLException me) {
-		// Will not happen, Bundle getResource does not throw MalformedURLException
-		return null;
-	    }
-	}
-
-	public String getMimeType(String file) {
-	    return null;
-	}
-
-	public String getInitParameter(String name) {
-	    return (String)initparameters.get(name);
-	}
-
-	public InputStream getResourceAsStream(String path) {
-	    return null;
-	}
-    }
-}
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.osgi;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.core.BootstrapEnvironment;
+import org.apache.cocoon.core.MutableSettings;
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.impl.AbstractContext;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogService;
+
+public class OSGiBootstrapEnvironment
+    implements BootstrapEnvironment {
+    
+    private final String configuration = "/WEB-INF/block.xml";
+    private final ClassLoader classLoader;
+    public Logger logger = null;
+    private final String contextPath;
+    private final Context environmentContext;
+
+    public OSGiBootstrapEnvironment(ClassLoader classLoader, BundleContext bc)
+        throws Exception {
+        this.classLoader = classLoader;
+
+        // Create a logger manager that delegates to OSGi
+        // FIXME: have the maximum level as a property of the bundle
+        LoggerManager logManager = new OSGiLoggerManager(bc, LogService.LOG_DEBUG);
+        this.logger = logManager.getDefaultLogger();
+
+        Bundle bundle = getSitemapBundle(bc, this.logger); //bc.getBundle();
+        if (bundle == null)
+            throw new Exception("No sitemap bundle");
+        // Try to figure out the path of the root from that of /WEB-INF/block.xml
+        URL pathURL = bundle.getResource(this.configuration);
+        if (pathURL == null)
+            throw new FileNotFoundException("Unable to get resource '/WEB-INF/block.xml' from bundle ." + bundle);
+        String path = pathURL.toString();
+        path = path.substring(0, path.length() - this.configuration.length() - 1);
+        this.contextPath = path;
+
+        this.environmentContext = new OSGiContext(bundle);
+    }
+
+    /**
+     * @see org.apache.cocoon.core.BootstrapEnvironment#getBootstrapLogger(org.apache.cocoon.core.BootstrapEnvironment.LogLevel)
+     */
+    public Logger getBootstrapLogger(LogLevel logLevel) {
+        return this.logger;
+    }
+
+    /** Log a message during bootstrapping. This is used to log
+     * information before the logging system is setup.
+     * @param message A message.
+     */
+    public void log(String message) {
+        this.logger.info(message);
+    }
+
+    /** Log a message during bootstrapping. This is used to log
+     * information before the logging system is setup.
+     * @param message A message.
+     * @param error   An error.
+     */
+    public void log(String message, Throwable error) {
+        this.logger.info(message, error);
+    }
+
+    /**
+     * Pass the root logger back to the environment. As soon as the
+     * logging system is set up, this method is called.
+     * @param rootLogger The root logger.
+     */
+    public void setLogger(Logger rootLogger) {
+        this.logger = rootLogger;
+    }
+
+    /**
+     * 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
+     */
+    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);
+    }
+
+    public void configureLoggingContext(DefaultContext context) {
+        // simply do nothing
+    }
+
+    public void configure(DefaultContext context) {
+    }
+
+    public ClassLoader getInitClassLoader() {
+        return this.classLoader;
+    }
+
+    public Context getEnvironmentContext() {
+        return this.environmentContext;
+    }
+    
+    /**
+     * Returns the URL to the application context.
+     */
+    public String getContextURL() {
+        return this.contextPath;
+    }
+
+    /**
+     * Returns a file to the application context.
+     * @return A file pointing to the context or null if the context is not
+     *         writeable.
+     */
+    public File getContextForWriting() {
+        return null;
+    }
+
+    /**
+     * Set the ConfigFile for the Cocoon object.
+     *
+     * @param configFileName The file location for the cocoon.xconf
+     *
+     * @throws Exception
+     */
+    public URL getConfigFile(String configFileName) throws Exception {
+        return new URL(this.contextPath + configFileName);
+    }
+
+    public String getClassPath(Settings settings) {
+        return null;
+    }
+
+    private Bundle getSitemapBundle(BundleContext bc, Logger log) {
+        String SITEMAP = "sitemap";
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            Bundle bundle = bundles[i];
+            try {
+                log.info("checking bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME) + " category=" + bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
+                if ((bundle.getState() == Bundle.INSTALLED ||
+                     bundle.getState() == Bundle.RESOLVED ||
+                     bundle.getState() == Bundle.ACTIVE)) {
+                    log.info("ok state");
+                    if (SITEMAP.equals(bundle.getHeaders().get(Constants.BUNDLE_CATEGORY))) {
+                        log.info("sitemap");
+                        return bundle;
+                    }
+                }
+            } catch (NullPointerException e) {
+                // BUNDLE_CATEGORY not present in the headers of the
+                // bundle, nothing to do.
+            }
+        }
+        return null;
+    }
+
+    public class OSGiContext extends AbstractContext {
+
+        Bundle bundle;
+        private Hashtable attributes = new Hashtable();
+        private Hashtable initparameters = new Hashtable();
+
+        public OSGiContext(Bundle bundle) {
+            this.bundle = bundle;
+            this.initparameters.put("init-classloader", "true");
+            this.initparameters.put("work-directory", "work");
+        }
+
+        public Object getAttribute(String name) {
+            return attributes.get(name);
+        }
+
+        public void setAttribute(String name, Object value) {
+            attributes.put(name, value);
+        }
+
+        public void removeAttribute(String name) {
+            attributes.remove(name);
+        }
+
+        public Enumeration getAttributeNames() {
+            return attributes.keys();
+        }
+
+        public URL getResource(String path) throws MalformedURLException {
+            return this.bundle.getResource(path);
+        }
+
+        public String getRealPath(String path) {
+            try {
+                URL pathURL = getResource(path);
+                return pathURL == null ? null : pathURL.toString();
+            } catch (MalformedURLException me) {
+                // Will not happen, Bundle getResource does not throw MalformedURLException
+                return null;
+            }
+        }
+
+        public String getMimeType(String file) {
+            return null;
+        }
+
+        public String getInitParameter(String name) {
+            return (String)initparameters.get(name);
+        }
+
+        public InputStream getResourceAsStream(String path) {
+            return null;
+        }
+    }
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/core/osgi/OSGiBootstrapEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/src/osgi-servlet/Manifest.mf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/osgi-servlet/Manifest.mf?rev=291023&r1=291022&r2=291023&view=diff
==============================================================================
--- cocoon/trunk/src/osgi-servlet/Manifest.mf (original)
+++ cocoon/trunk/src/osgi-servlet/Manifest.mf Thu Sep 22 14:56:34 2005
@@ -13,11 +13,30 @@
 Import-Package: 
  javax.servlet,
  javax.servlet.http,
+ org.apache.avalon.excalibur.logger,
+ org.apache.avalon.framework.context,
+ org.apache.avalon.framework.logger,
+ org.apache.cocoon,
+ org.apache.cocoon.core,
+ org.apache.cocoon.core.osgi,
+ org.apache.cocoon.components.notification,
+ org.apache.cocoon.environment,
+ org.apache.cocoon.environment.http,
  org.apache.cocoon.servlet,
+ org.apache.cocoon.servlet.multipart,
+ org.apache.cocoon.util,
+ org.apache.commons.lang,
+ org.apache.commons.lang.time,
+ org.apache.excalibur.source.impl,
+ org.apache.excalibur.xml.impl,
+ org.apache.excalibur.xml.xpath,
+ org.apache.excalibur.xml.xslt,
+ org.apache.excalibur.xmlizer,
  org.osgi.framework,
  org.osgi.service.http,
  org.osgi.service.log,
  org.osgi.util.tracker
+DynamicImport-Package: org.apache.cocoon.*
 Bundle-UUID: org.apache.cocoon:cocoon_servlet:1.0.0:impl
 Built-From: C:\cygwin\usr\local\svn\cocoon\osgi\bundles\cocoon_servlet
 Build-Date: Fri July 15 2005, 22:46:00

Modified: cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java?rev=291023&r1=291022&r2=291023&view=diff
==============================================================================
--- cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java (original)
+++ cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/Activator.java Thu Sep 22 14:56:34 2005
@@ -17,11 +17,15 @@
 
 import java.util.Hashtable;
 import java.net.URL;
-import java.io.InputStream;
+import java.io.IOException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.cocoon.servlet.CocoonServlet;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.core.BootstrapEnvironment;
+import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.osgi.OSGiBootstrapEnvironment;
+import org.apache.cocoon.environment.Context;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -32,8 +36,6 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.HttpService;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * Activator which register a Cocoon servlet
@@ -42,23 +44,37 @@
 public class Activator implements BundleActivator {
 
     static BundleContext bc;
-    static ServiceTracker logTracker;
     static final String  SERVLET_ALIAS = "/";     // the http server root
     static final String  SITEMAP = "sitemap";
 
     private Hashtable registrations = new Hashtable();
     private Bundle sitemapBundle;
-    
+    private ClassLoader classLoader = getClass().getClassLoader();;
+    private String contextURL;
+    private Context environmentContext;
+    private Logger logger;
+    private CoreUtil coreUtil;
+
     public void start(BundleContext bc) throws BundleException {
 
         this.bc  = bc;
-        this.logTracker = new ServiceTracker(bc, LogService.class.getName(), null);
-        this.logTracker.open();
+        try {
+            BootstrapEnvironment env = new OSGiBootstrapEnvironment(this.classLoader, this.bc);
+            env.log("OSGiBootstrapEnvironment created");
+            this.coreUtil = new CoreUtil(env);
+            env.log("CoreUtil created");
+            this.contextURL = env.getContextURL();
+            this.environmentContext = env.getEnvironmentContext();
+            this.logger = env.getBootstrapLogger(null);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new BundleException("Failed to create core util", e);
+        }
 
         // FIXME: Add a BundleListener to detect if a sitemap bundle
         // is installed, updated or uninstalled.
         this.sitemapBundle = getSitemapBundle();
-        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "set sitemap bundle " + this.sitemapBundle);
+        this.logger.info("set sitemap bundle " + this.sitemapBundle);
 
         ServiceListener listener = new ServiceListener() {
                 public void serviceChanged(ServiceEvent ev) {
@@ -86,8 +102,7 @@
                                                          srl[i]));
             }
         } catch (Exception e) {
-            ((LogService)this.logTracker.getService()).log(LogService.LOG_ERROR,
-                                                           "Failed to set up listener for http service", e);
+            this.logger.info("Failed to set up listener for http service", e);
         }
     }
   
@@ -99,13 +114,13 @@
         for (int i = 0; i < bundles.length; i++) {
             Bundle bundle = bundles[i];
             try {
-                ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "checking bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME) + " category=" + bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
+                this.logger.info("checking bundle " + bundle + " name=" + bundle.getHeaders().get(Constants.BUNDLE_NAME) + " category=" + bundle.getHeaders().get(Constants.BUNDLE_CATEGORY) + " state=" + bundle.getState());
                 if ((bundle.getState() == Bundle.INSTALLED ||
                      bundle.getState() == Bundle.RESOLVED ||
                      bundle.getState() == Bundle.ACTIVE)) {
-                    ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "ok state");
+                    this.logger.info("ok state");
                     if (SITEMAP.equals(bundle.getHeaders().get(Constants.BUNDLE_CATEGORY))) {
-                        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "sitemap");
+                        this.logger.info("sitemap");
                         return bundle;
                     }
                 }
@@ -123,14 +138,14 @@
             return; // already done
         }
         
-        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "set root for " + sr);
+        this.logger.info("set root for " + sr);
 
         HttpService http = (HttpService)bc.getService(sr);
 
         HttpContext context = new HttpContext() {
                 public boolean handleSecurity(HttpServletRequest  request,
                                               HttpServletResponse response) 
-                    throws java.io.IOException {
+                    throws IOException {
                     return true;
                 }
         
@@ -151,12 +166,19 @@
             Hashtable parameters = new Hashtable();
             parameters.put("init-classloader", "true");
             parameters.put("work-directory", "work");
-            http.registerServlet(SERVLET_ALIAS, new CocoonServlet(), parameters, context);
+            http.registerServlet(SERVLET_ALIAS,
+                                 new BlocksServlet(),
+//                                   new CocoonServlet(this.classLoader,
+//                                                     this.contextURL,
+//                                                     this.environmentContext,
+//                                                     this.logger,
+//                                                     this.coreUtil),
+                                 parameters,
+                                 context);
 
             registrations.put(sr, context);
         } catch (Exception e) {
-            ((LogService)this.logTracker.getService()).log(LogService.LOG_ERROR,
-                                                           "Failed to register resource", e);
+            this.logger.info("Failed to register resource", e);
         }
     } 
 
@@ -165,7 +187,7 @@
             return; // nothing to do
         }
 
-        ((LogService)this.logTracker.getService()).log(LogService.LOG_INFO, "unset root for " + sr);
+        this.logger.info("unset root for " + sr);
     
         HttpService http = (HttpService)bc.getService(sr);
     
@@ -175,5 +197,4 @@
         }
         registrations.remove(sr);
     }
-
 }

Added: cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java?rev=291023&view=auto
==============================================================================
--- cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java (added)
+++ cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java Thu Sep 22 14:56:34 2005
@@ -0,0 +1,954 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.service.servlet.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.SocketException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.excalibur.logger.ServletLogger;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.Cocoon;
+import org.apache.cocoon.ConnectionResetException;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
+import org.apache.cocoon.components.notification.Notifier;
+import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.core.BootstrapEnvironment;
+import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.MutableSettings;
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.http.HttpContext;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.servlet.SettingsHelper;
+import org.apache.cocoon.servlet.multipart.MultipartHttpServletRequest;
+import org.apache.cocoon.servlet.multipart.RequestFactory;
+import org.apache.cocoon.util.IOUtils;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.time.StopWatch;
+
+/**
+ * This is the entry point for Cocoon execution as an HTTP Servlet.
+ *
+ * @version $Id$
+ */
+public class BlocksServlet extends HttpServlet {
+
+    /**
+     * Application <code>Context</code> Key for the servlet configuration
+     * @since 2.1.3
+     */
+    public static final String CONTEXT_SERVLET_CONFIG = "servlet-config";
+
+    // Processing time message
+    protected static final String PROCESSED_BY = "Processed by "
+            + Constants.COMPLETE_NAME + " in ";
+
+    // Used by "show-time"
+    static final float SECOND = 1000;
+    static final float MINUTE = 60 * SECOND;
+    static final float HOUR   = 60 * MINUTE;
+
+    /**
+     * The <code>Cocoon</code> instance
+     */
+    protected Cocoon cocoon;
+
+    /**
+     * Holds exception happened during initialization (if any)
+     */
+    protected Exception exception;
+
+    private String containerEncoding;
+
+    protected ServletContext servletContext;
+
+    /** The classloader that will be set as the context classloader if init-classloader is true */
+    protected ClassLoader classLoader = getClass().getClassLoader();
+
+    /**
+     * This is the path to the servlet context (or the result
+     * of calling getRealPath('/') on the ServletContext.
+     * Note, that this can be null.
+     */
+    protected String servletContextPath;
+
+    /**
+     * This is the url to the servlet context directory
+     */
+    protected String servletContextURL;
+
+    /**
+     * The RequestFactory is responsible for wrapping multipart-encoded
+     * forms and for handing the file payload of incoming requests
+     */
+    protected RequestFactory requestFactory;
+
+    /** CoreUtil */
+    protected CoreUtil coreUtil;
+
+    /** The logger */
+    protected Logger log;
+
+    protected Context environmentContext;
+
+    /**
+     * Initialize this <code>BlocksServlet</code> instance.  You will
+     * notice that I have broken the init into sub methods to make it
+     * easier to maintain (BL).  The context is passed to a couple of
+     * the subroutines.  This is also because it is better to explicitly
+     * pass variables than implicitely.  It is both more maintainable,
+     * and more elegant.
+     *
+     * @param conf The ServletConfig object from the servlet engine.
+     *
+     * @throws ServletException
+     */
+    public void init(ServletConfig conf)
+    throws ServletException {
+        this.servletContext = conf.getServletContext();
+        this.servletContext.log("Initializing Apache Cocoon " + Constants.VERSION);
+
+        super.init(conf);
+
+        this.servletContextPath = this.servletContext.getRealPath("/");
+        String path = this.servletContextPath;
+        // these two variables are just for debugging. We can't log at this point
+        // as the logger isn't initialized yet.
+        String debugPathOne = null, debugPathTwo = null;
+        if (path == null) {
+            // Try to figure out the path of the root from that of WEB-INF/web.xml
+            try {
+                path = this.servletContext.getResource("/WEB-INF/web.xml").toString();
+            } catch (MalformedURLException me) {
+                throw new ServletException("Unable to get resource 'WEB-INF/web.xml'.", me);
+            }
+            debugPathOne = path;
+            path = path.substring(0, path.length() - "WEB-INF/web.xml".length());
+            debugPathTwo = path;
+        }
+        try {
+            if (path.indexOf(':') > 1) {
+                this.servletContextURL = path;
+            } else {
+                this.servletContextURL = new File(path).toURL().toExternalForm();
+            }
+        } catch (MalformedURLException me) {
+            // VG: Novell has absolute file names starting with the
+            // volume name which is easily more then one letter.
+            // Examples: sys:/apache/cocoon or sys:\apache\cocoon
+            try {
+                this.servletContextURL = new File(path).toURL().toExternalForm();
+            } catch (MalformedURLException ignored) {
+                throw new ServletException("Unable to determine servlet context URL.", me);
+            }
+        }
+
+        try {
+            // FIXME (VG): We shouldn't have to specify these. Need to override
+            // jaxp implementation of weblogic before initializing logger.
+            // This piece of code is also required in the Cocoon class.
+            String value = System.getProperty("javax.xml.parsers.SAXParserFactory");
+            if (value != null && value.startsWith("weblogic")) {
+                System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
+                System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+            }
+        } catch (Exception e) {
+            // Ignore security exception
+            this.servletContext.log("BlocksServlet: Could not check system properties, got: " + e);
+        }
+
+        // initialize settings
+        ServletBootstrapEnvironment env = new ServletBootstrapEnvironment(conf, this.classLoader, this.servletContextPath, this.servletContextURL);
+
+        try {
+            this.coreUtil = new CoreUtil(env);
+            this.environmentContext = env.getEnvironmentContext();
+            this.log = env.logger;
+        } catch (Exception e) {
+            if ( e instanceof ServletException ) {
+                throw (ServletException)e;
+            }
+            throw new ServletException(e);
+        }
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug(this.coreUtil.getSettings().toString());
+            getLogger().debug("getRealPath for /: " + this.servletContextPath);
+            if (this.servletContextPath == null) {
+                getLogger().debug("getResource for /WEB-INF: " + debugPathOne);
+                getLogger().debug("Path for Root: " + debugPathTwo);
+            }
+        }
+
+        this.containerEncoding = this.getInitParameter("container-encoding", "ISO-8859-1");
+        this.requestFactory = new RequestFactory(coreUtil.getSettings().isAutosaveUploads(),
+                                                 new File(coreUtil.getCore().getSettings().getUploadDirectory()),
+                                                 coreUtil.getSettings().isAllowOverwrite(),
+                                                 coreUtil.getSettings().isSilentlyRename(),
+                                                 coreUtil.getSettings().getMaxUploadSize(),
+                                                 this.containerEncoding);
+
+        try {
+            this.exception = null;
+            this.cocoon = this.coreUtil.createCocoon();
+        } catch (Exception e) {
+            this.exception = e;
+        }
+        if (this.exception == null) {
+            this.servletContext.log("Apache Cocoon " + Constants.VERSION + " is up and ready.");
+        } else {
+            final String message = "Errors during initializing Apache Cocoon " + Constants.VERSION + " : " + this.exception.getMessage();
+            this.servletContext.log(message, this.exception);
+        }
+    }
+
+    /**
+     * Dispose Cocoon when servlet is destroyed
+     */
+    public void destroy() {
+        this.servletContext.log("Destroying Cocoon Servlet.");
+        if (this.coreUtil != null) {
+            this.coreUtil.destroy();
+            this.coreUtil = null;
+            // coreUtil will dispose it.
+            this.cocoon = null;
+        }
+
+        this.requestFactory = null;
+        this.servletContext = null;
+        this.environmentContext = null;
+        this.classLoader = null;
+        this.log = null;
+        super.destroy();
+    }
+
+    /**
+     * Process the specified <code>HttpServletRequest</code> producing output
+     * on the specified <code>HttpServletResponse</code>.
+     */
+    public void service(HttpServletRequest req, HttpServletResponse res)
+    throws ServletException, IOException {
+
+        /* HACK for reducing class loader problems.                                     */
+        /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
+        if (this.coreUtil.getSettings().isInitClassloader()) {
+            try {
+                Thread.currentThread().setContextClassLoader(this.classLoader);
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        // used for timing the processing
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start();
+
+        // add the cocoon header timestamp
+        if (this.coreUtil.getSettings().isShowCocoonVersion()) {
+            res.addHeader("X-Cocoon-Version", Constants.VERSION);
+        }
+
+        // get the request (wrapped if contains multipart-form data)
+        HttpServletRequest request;
+        try{
+            if (this.coreUtil.getSettings().isEnableUploads()) {
+                request = requestFactory.getServletRequest(req);
+            } else {
+                request = req;
+            }
+        } catch (Exception e) {
+            if (getLogger().isErrorEnabled()) {
+                getLogger().error("Problem with Cocoon servlet", e);
+            }
+
+            manageException(req, res, null, null,
+                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "Problem in creating the Request", null, null, e);
+            return;
+        }
+
+        // Get the cocoon engine instance
+        try {
+            this.exception = null;
+            this.cocoon = this.coreUtil.getCocoon(request.getPathInfo(), request.getParameter(Constants.RELOAD_PARAM));
+        } catch (Exception e) {
+            this.exception = e;
+        }
+
+        // Check if cocoon was initialized
+        if (this.cocoon == null) {
+            manageException(request, res, null, null,
+                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "Initialization Problem",
+                            null /* "Cocoon was not initialized" */,
+                            null /* "Cocoon was not initialized, cannot process request" */,
+                            this.exception);
+            return;
+        }
+
+        // We got it... Process the request
+        String uri = request.getServletPath();
+        if (uri == null) {
+            uri = "";
+        }
+        String pathInfo = request.getPathInfo();
+        if (pathInfo != null) {
+            // VG: WebLogic fix: Both uri and pathInfo starts with '/'
+            // This problem exists only in WL6.1sp2, not in WL6.0sp2 or WL7.0b.
+            if (uri.length() > 0 && uri.charAt(0) == '/') {
+                uri = uri.substring(1);
+            }
+            uri += pathInfo;
+        }
+
+        if (uri.length() == 0) {
+            /* empty relative URI
+                 -> HTTP-redirect from /cocoon to /cocoon/ to avoid
+                    StringIndexOutOfBoundsException when calling
+                    "".charAt(0)
+               else process URI normally
+            */
+            String prefix = request.getRequestURI();
+            if (prefix == null) {
+                prefix = "";
+            }
+
+            res.sendRedirect(res.encodeRedirectURL(prefix + "/"));
+            return;
+        }
+
+        String contentType = null;
+        Object handle = null;
+
+        Environment env;
+        try{
+            if (uri.charAt(0) == '/') {
+                uri = uri.substring(1);
+            }
+            // Pass uri into environment without URLDecoding, as it is already decoded.
+            env = getEnvironment(uri, request, res);
+        } catch (Exception e) {
+            if (getLogger().isErrorEnabled()) {
+                getLogger().error("Problem with Cocoon servlet", e);
+            }
+
+            manageException(request, res, null, uri,
+                            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                            "Problem in creating the Environment", null, null, e);
+            return;
+        }
+
+        try {
+            try {
+                handle = this.coreUtil.initializeRequest(env);
+
+                if (this.cocoon.process(env)) {
+                    contentType = env.getContentType();
+                } else {
+                    // We reach this when there is nothing in the processing change that matches
+                    // the request. For example, no matcher matches.
+                    getLogger().fatalError("The Cocoon engine failed to process the request.");
+                    manageException(request, res, env, uri,
+                                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                                    "Request Processing Failed",
+                                    "Cocoon engine failed in process the request",
+                                    "The processing engine failed to process the request. This could be due to lack of matching or bugs in the pipeline engine.",
+                                    null);
+                    return;
+                }
+            } catch (ResourceNotFoundException e) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().warn(e.getMessage(), e);
+                } else if (getLogger().isWarnEnabled()) {
+                    getLogger().warn(e.getMessage());
+                }
+
+                manageException(request, res, env, uri,
+                                HttpServletResponse.SC_NOT_FOUND,
+                                "Resource Not Found",
+                                "Resource Not Found",
+                                "The requested resource \"" + request.getRequestURI() + "\" could not be found",
+                                e);
+                return;
+
+            } catch (ConnectionResetException e) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug(e.toString(), e);
+                } else if (getLogger().isWarnEnabled()) {
+                    getLogger().warn(e.toString());
+                }
+
+            } catch (IOException e) {
+                // Tomcat5 wraps SocketException into ClientAbortException which extends IOException.
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug(e.toString(), e);
+                } else if (getLogger().isWarnEnabled()) {
+                    getLogger().warn(e.toString());
+                }
+
+            } catch (Exception e) {
+                if (getLogger().isErrorEnabled()) {
+                    getLogger().error("Internal Cocoon Problem", e);
+                }
+
+                manageException(request, res, env, uri,
+                                HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                                "Internal Server Error", null, null, e);
+                return;
+            }
+
+            stopWatch.stop();
+            String timeString = null;
+            if (getLogger().isInfoEnabled()) {
+                timeString = processTime(stopWatch.getTime());
+                getLogger().info("'" + uri + "' " + timeString);
+            }
+
+            if (contentType != null && contentType.equals("text/html")) {
+                String showTime = request.getParameter(Constants.SHOWTIME_PARAM);
+                boolean show = this.coreUtil.getSettings().isShowTime();
+                if (showTime != null) {
+                    show = !showTime.equalsIgnoreCase("no");
+                }
+                if (show) {
+                    if ( timeString == null ) {
+                        timeString = processTime(stopWatch.getTime());
+                    }
+                    boolean hide = this.coreUtil.getSettings().isHideShowTime();
+                    if (showTime != null) {
+                        hide = showTime.equalsIgnoreCase("hide");
+                    }
+                    ServletOutputStream out = res.getOutputStream();
+                    out.print((hide) ? "<!-- " : "<p>");
+                    out.print(timeString);
+                    out.println((hide) ? " -->" : "</p>");
+                }
+            }
+        } finally {
+            this.coreUtil.cleanUpRequest(handle);
+
+            try {
+                if (request instanceof MultipartHttpServletRequest) {
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("Deleting uploaded file(s).");
+                    }
+                    ((MultipartHttpServletRequest) request).cleanup();
+                }
+            } catch (IOException e) {
+                getLogger().error("Cocoon got an Exception while trying to cleanup the uploaded files.", e);
+            }
+
+            try {
+                OutputStream out = res.getOutputStream();
+                out.flush();
+                out.close();
+            } catch (SocketException se) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("SocketException while trying to close stream.", se);
+                } else if (getLogger().isWarnEnabled()) {
+                    getLogger().warn("SocketException while trying to close stream.");
+                }
+            } catch (IOException e) {
+                // See: http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=107489037219505
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("IOException while trying to close stream.", e);
+                }
+            } catch (Exception e) {
+                getLogger().error("Exception while trying to close stream.", e);
+            }
+        }
+    }
+
+    protected void manageException(HttpServletRequest req, HttpServletResponse res, Environment env,
+                                   String uri, int errorStatus,
+                                   String title, String message, String description,
+                                   Exception e)
+    throws IOException {
+        if (this.coreUtil.getSettings().isManageExceptions()) {
+            if (env != null) {
+                env.tryResetResponse();
+            } else {
+                res.reset();
+            }
+
+            String type = Notifying.FATAL_NOTIFICATION;
+            HashMap extraDescriptions = null;
+
+            if (errorStatus == HttpServletResponse.SC_NOT_FOUND) {
+                type = "resource-not-found";
+                // Do not show the exception stacktrace for such common errors.
+                e = null;
+            } else {
+                extraDescriptions = new HashMap(2);
+                extraDescriptions.put(Notifying.EXTRA_REQUESTURI, req.getRequestURI());
+                if (uri != null) {
+                     extraDescriptions.put("Request URI", uri);
+                }
+
+                // Do not show exception stack trace when log level is WARN or above. Show only message.
+                if (!getLogger().isInfoEnabled()) {
+                    Throwable t = DefaultNotifyingBuilder.getRootCause(e);
+                    if (t != null) extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage());
+                    e = null;
+                }
+            }
+
+            Notifying n = new DefaultNotifyingBuilder().build(this,
+                                                              e,
+                                                              type,
+                                                              title,
+                                                              "Cocoon Servlet",
+                                                              message,
+                                                              description,
+                                                              extraDescriptions);
+
+            res.setContentType("text/html");
+            res.setStatus(errorStatus);
+            Notifier.notify(n, res.getOutputStream(), "text/html");
+        } else {
+            res.sendError(errorStatus, title);
+            res.flushBuffer();
+        }
+    }
+
+    /**
+     * Create the environment for the request
+     */
+    protected Environment getEnvironment(String uri,
+                                         HttpServletRequest req,
+                                         HttpServletResponse res)
+    throws Exception {
+        HttpEnvironment env;
+
+        String formEncoding = req.getParameter("cocoon-form-encoding");
+        if (formEncoding == null) {
+            formEncoding = this.coreUtil.getSettings().getFormEncoding();
+        }
+        env = new HttpEnvironment(uri,
+                                  this.servletContextURL,
+                                  req,
+                                  res,
+                                  this.servletContext,
+                                  this.environmentContext,
+                                  this.containerEncoding,
+                                  formEncoding);
+        env.enableLogging(getLogger());
+        return env;
+    }
+
+    private String processTime(long time) {
+        StringBuffer out = new StringBuffer(PROCESSED_BY);
+        if (time <= SECOND) {
+            out.append(time);
+            out.append(" milliseconds.");
+        } else if (time <= MINUTE) {
+            out.append(time / SECOND);
+            out.append(" seconds.");
+        } else if (time <= HOUR) {
+            out.append(time / MINUTE);
+            out.append(" minutes.");
+        } else {
+            out.append(time / HOUR);
+            out.append(" hours.");
+        }
+        return out.toString();
+    }
+
+    /**
+     * Get an initialisation parameter. The value is trimmed, and null is returned if the trimmed value
+     * is empty.
+     */
+    public String getInitParameter(String name) {
+        String result = super.getInitParameter(name);
+        if (result != null) {
+            result = result.trim();
+            if (result.length() == 0) {
+                result = null;
+            }
+        }
+
+        return result;
+    }
+
+    /** Convenience method to access servlet parameters */
+    protected String getInitParameter(String name, String defaultValue) {
+        String result = getInitParameter(name);
+        if (result == null) {
+            if (getLogger() != null && getLogger().isDebugEnabled()) {
+                getLogger().debug(name + " was not set - defaulting to '" + defaultValue + "'");
+            }
+            return defaultValue;
+        }
+        return result;
+    }
+
+    protected Logger getLogger() {
+        return this.log;
+    }
+
+    protected static final class ServletBootstrapEnvironment
+    implements BootstrapEnvironment {
+
+        private final ServletConfig config;
+        private final ClassLoader   classLoader;
+        private final File          writeableContextPath;
+        private final String        contextPath;
+        public Logger logger;
+        private final HttpContext   environmentContext;
+
+        public ServletBootstrapEnvironment(ServletConfig config,
+                                           ClassLoader   cl,
+                                           String        writeablePath,
+                                           String        path) {
+            this.config = config;
+            this.classLoader = cl;
+            if ( writeablePath == null ) {
+                this.writeableContextPath = null;
+            } else {
+                this.writeableContextPath = new File(writeablePath);
+            }
+            this.contextPath = path;
+            this.environmentContext = new HttpContext(this.config.getServletContext());
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getBootstrapLogger(org.apache.cocoon.core.BootstrapEnvironment.LogLevel)
+         */
+        public Logger getBootstrapLogger(BootstrapEnvironment.LogLevel logLevel) {
+            return new ServletLogger(this.config, logLevel.getLevel());
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#log(java.lang.String)
+         */
+        public void log(String message) {
+            this.config.getServletContext().log(message);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#log(java.lang.String, java.lang.Throwable)
+         */
+        public void log(String message, Throwable error) {
+            this.config.getServletContext().log(message, error);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#setLogger(org.apache.avalon.framework.logger.Logger)
+         */
+        public void setLogger(Logger rootLogger) {
+            this.logger = rootLogger;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.cocoon.core.MutableSettings)
+         */
+        public void configure(MutableSettings settings) {
+            // fill from the servlet parameters
+            SettingsHelper.fill(settings, this.config);
+            if ( settings.getWorkDirectory() == null ) {
+                final File workDir = (File)this.config.getServletContext().getAttribute("javax.servlet.context.tempdir");
+                settings.setWorkDirectory(workDir.getAbsolutePath());
+            }
+            if ( settings.getLoggingConfiguration() == null ) {
+                settings.setLoggingConfiguration("/WEB-INF/logkit.xconf");
+            }
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getInitClassLoader()
+         */
+        public ClassLoader getInitClassLoader() {
+            return this.classLoader;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getEnvironmentContext()
+         */
+        public Context getEnvironmentContext() {
+            return this.environmentContext;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getContextURL()
+         */
+        public String getContextURL() {
+            return this.contextPath;
+        }
+
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getContextForWriting()
+         */
+        public File getContextForWriting() {
+            return this.writeableContextPath;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configureLoggingContext(org.apache.avalon.framework.context.DefaultContext)
+         */
+        public void configureLoggingContext(DefaultContext context) {
+            context.put("servlet-context", this.config.getServletContext());
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.avalon.framework.context.DefaultContext)
+         */
+        public void configure(DefaultContext context) {
+            context.put(CONTEXT_SERVLET_CONFIG, this.config);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getConfigFile(java.lang.String)
+         */
+        public URL getConfigFile(final String configFileName)
+        throws Exception {
+            final String usedFileName;
+
+            if (configFileName == null) {
+                if (this.logger.isWarnEnabled()) {
+                    this.logger.warn("Servlet initialization argument 'configurations' not specified, attempting to use '/WEB-INF/cocoon.xconf'");
+                }
+                usedFileName = "/WEB-INF/cocoon.xconf";
+            } else {
+                usedFileName = configFileName;
+            }
+
+            if (this.logger.isDebugEnabled()) {
+                this.logger.debug("Using configuration file: " + usedFileName);
+            }
+
+            URL result;
+            try {
+                // test if this is a qualified url
+                if (usedFileName.indexOf(':') == -1) {
+                    result = this.config.getServletContext().getResource(usedFileName);
+                } else {
+                    result = new URL(usedFileName);
+                }
+            } catch (Exception mue) {
+                String msg = "Init parameter 'configurations' is invalid : " + usedFileName;
+                this.logger.error(msg, mue);
+                throw new ServletException(msg, mue);
+            }
+
+            if (result == null) {
+                File resultFile = new File(usedFileName);
+                if (resultFile.isFile()) {
+                    try {
+                        result = resultFile.getCanonicalFile().toURL();
+                    } catch (Exception e) {
+                        String msg = "Init parameter 'configurations' is invalid : " + usedFileName;
+                        this.logger.error(msg, e);
+                        throw new ServletException(msg, e);
+                    }
+                }
+            }
+
+            if (result == null) {
+                String msg = "Init parameter 'configuration' doesn't name an existing resource : " + usedFileName;
+                this.logger.error(msg);
+                throw new ServletException(msg);
+            }
+            return result;
+        }
+
+        /**
+         * This builds the important ClassPath used by this Servlet.  It
+         * does so in a Servlet Engine neutral way.  It uses the
+         * <code>ServletContext</code>'s <code>getRealPath</code> method
+         * to get the Servlet 2.2 identified classes and lib directories.
+         * It iterates in alphabetical order through every file in the
+         * lib directory and adds it to the classpath.
+         *
+         * Also, we add the files to the ClassLoader for the Cocoon system.
+         * In order to protect ourselves from skitzofrantic classloaders,
+         * we need to work with a known one.
+         *
+         * We need to get this to work properly when Cocoon is in a war.
+         *
+         */
+        public String getClassPath(Settings settings) {
+            StringBuffer buildClassPath = new StringBuffer();
+
+            File root = null;
+            if (this.getContextForWriting() != null) {
+                // Old method.  There *MUST* be a better method than this...
+
+                String classDir = this.config.getServletContext().getRealPath("/WEB-INF/classes");
+                String libDir = this.config.getServletContext().getRealPath("/WEB-INF/lib");
+
+                if (libDir != null) {
+                    root = new File(libDir);
+                }
+
+                if (classDir != null) {
+                    buildClassPath.append(classDir);
+                }
+            } else {
+                // New(ish) method for war'd deployments
+                URL classDirURL = null;
+                URL libDirURL = null;
+
+                try {
+                    classDirURL = this.config.getServletContext().getResource("/WEB-INF/classes");
+                } catch (MalformedURLException me) {
+                    this.logger.warn("Unable to add WEB-INF/classes to the classpath", me);
+                }
+
+                try {
+                    libDirURL = this.config.getServletContext().getResource("/WEB-INF/lib");
+                } catch (MalformedURLException me) {
+                    this.logger.warn("Unable to add WEB-INF/lib to the classpath", me);
+                }
+
+                if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:")) {
+                    root = new File(libDirURL.toExternalForm().substring("file:".length()));
+                }
+
+                if (classDirURL != null) {
+                    buildClassPath.append(classDirURL.toExternalForm());
+                }
+            }
+
+            // Unable to find lib directory. Going the hard way.
+            if (root == null) {
+                root = this.extractLibraries(settings);
+            }
+
+            if (root != null && root.isDirectory()) {
+                File[] libraries = root.listFiles();
+                Arrays.sort(libraries);
+                for (int i = 0; i < libraries.length; i++) {
+                    String fullName = IOUtils.getFullFilename(libraries[i]);
+                    buildClassPath.append(File.pathSeparatorChar).append(fullName);
+                }
+            }
+
+            buildClassPath.append(File.pathSeparatorChar)
+                          .append(SystemUtils.JAVA_CLASS_PATH);
+
+            return buildClassPath.toString();
+        }
+
+        private File extractLibraries(Settings settings) {
+            try {
+                URL manifestURL = this.config.getServletContext().getResource("/META-INF/MANIFEST.MF");
+                if (manifestURL == null) {
+                    this.logger.fatalError("Unable to get Manifest");
+                    return null;
+                }
+
+                Manifest mf = new Manifest(manifestURL.openStream());
+                Attributes attr = mf.getMainAttributes();
+                String libValue = attr.getValue("Cocoon-Libs");
+                if (libValue == null) {
+                    this.logger.fatalError("Unable to get 'Cocoon-Libs' attribute from the Manifest");
+                    return null;
+                }
+
+                List libList = new ArrayList();
+                for (StringTokenizer st = new StringTokenizer(libValue, " "); st.hasMoreTokens();) {
+                    libList.add(st.nextToken());
+                }
+
+                File root = new File(settings.getWorkDirectory(), "lib");
+                root.mkdirs();
+
+                File[] oldLibs = root.listFiles();
+                for (int i = 0; i < oldLibs.length; i++) {
+                    String oldLib = oldLibs[i].getName();
+                    if (!libList.contains(oldLib)) {
+                        this.logger.debug("Removing old library " + oldLibs[i]);
+                        oldLibs[i].delete();
+                    }
+                }
+
+                this.logger.warn("Extracting libraries into " + root);
+                byte[] buffer = new byte[65536];
+                for (Iterator i = libList.iterator(); i.hasNext();) {
+                    String libName = (String) i.next();
+
+                    long lastModified = -1;
+                    try {
+                        lastModified = Long.parseLong(attr.getValue("Cocoon-Lib-" + libName.replace('.', '_')));
+                    } catch (Exception e) {
+                        this.logger.debug("Failed to parse lastModified: " + attr.getValue("Cocoon-Lib-" + libName.replace('.', '_')));
+                    }
+
+                    File lib = new File(root, libName);
+                    if (lib.exists() && lib.lastModified() != lastModified) {
+                        this.logger.debug("Removing modified library " + lib);
+                        lib.delete();
+                    }
+
+                    InputStream is = this.config.getServletContext().getResourceAsStream("/WEB-INF/lib/" + libName);
+                    if (is == null) {
+                        this.logger.warn("Skipping " + libName);
+                    } else {
+                        this.logger.debug("Extracting " + libName);
+                        OutputStream os = null;
+                        try {
+                            os = new FileOutputStream(lib);
+                            int count;
+                            while ((count = is.read(buffer)) > 0) {
+                                os.write(buffer, 0, count);
+                            }
+                        } finally {
+                            if (is != null) is.close();
+                            if (os != null) os.close();
+                        }
+                    }
+
+                    if (lastModified != -1) {
+                        lib.setLastModified(lastModified);
+                    }
+                }
+
+                return root;
+            } catch (IOException e) {
+                this.logger.fatalError("Exception while processing Manifest file", e);
+                return null;
+            }
+        }
+
+    }
+}

Propchange: cocoon/trunk/src/osgi-servlet/org/apache/cocoon/service/servlet/impl/BlocksServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/trunk/src/webapp/WEB-INF/block.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/block.xml?rev=291023&view=auto
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/block.xml (added)
+++ cocoon/trunk/src/webapp/WEB-INF/block.xml Thu Sep 22 14:56:34 2005
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. 
+-->
+<block xmlns="http://apache.org/cocoon/blocks/cob/1.0"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+       xsi:schemaLocation="http://apache.org/cocoon/blocks/cob/1.0 cob-schema-1.0.xsd"
+       id="http://cocoon.apache.org/blocks/webapp/1.0">
+  <name>webapp</name>
+  <description href="http://cocoon.apache.org/blocks/webapp/1.0">
+    Cocoon core samples
+  </description>
+  <state href="http://cocoon.apache.org/blocks/wbapp/1.0/state.html" 
+         community="supported" 
+         interfaces="unstable" 
+         implementation="unstable"/>
+  <license href="http://www.apache.org/licenses/">Apache License 2.0</license>
+  <author href="http://cocoon.apache.org">Apache Cocoon community</author>
+  <sitemap src="sitemap.xmap"/>
+</block>

Propchange: cocoon/trunk/src/webapp/WEB-INF/block.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/tools/targets/osgi-build.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/tools/targets/osgi-build.xml?rev=291023&r1=291022&r2=291023&view=diff
==============================================================================
--- cocoon/trunk/tools/targets/osgi-build.xml (original)
+++ cocoon/trunk/tools/targets/osgi-build.xml Thu Sep 22 14:56:34 2005
@@ -53,11 +53,15 @@
   
   <target name="osgi.compile-osgi-servlet" depends="osgi.init, compile-core">
     <path id="osgi.osgi-servlet.classpath">
-      <fileset dir="./lib/core">
+      <fileset dir="${lib.core}">
         <include name="knopflerfish-*.jar"/>
       </fileset>      
       <!-- include Cocoon core -->
       <dirset dir="${build.dest}"/>
+      <pathelement location="${lib.core}/avalon-framework-api-4.3.jar"/>
+      <pathelement location="${lib.core}/avalon-framework-impl-4.3.jar"/>
+      <pathelement location="${lib.core}/commons-lang-2.1.jar"/>
+      <pathelement location="${lib.core}/excalibur-logger-2.1.jar"/>
       <pathelement location="${lib.core}/servlet-2_3.jar"/>
     </path>