cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [36/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,639 @@
+/* 
+ * Copyright 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.components.xslt;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TemplatesHandler;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.AggregatedValidity;
+import org.apache.excalibur.store.Store;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.apache.excalibur.xml.xslt.XSLTProcessor;
+import org.apache.excalibur.xml.xslt.XSLTProcessorException;
+import org.apache.excalibur.xmlizer.XMLizer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
+
+/**
+ * Adaptation of Excalibur's XSLTProcessor implementation to allow for better
+ * error reporting.
+ * 
+ * @version $Id: TraxProcessor.java 326713 2005-10-19 21:19:29Z sylvain $
+ * @since 2.1.8
+ */
+
+public class TraxProcessor extends AbstractLogEnabled implements XSLTProcessor, Serviceable, Initializable, Disposable, Parameterizable,
+        Recyclable, URIResolver {
+    /** The store service instance */
+    protected Store m_store;
+
+    /** The configured transformer factory to use */
+    protected String m_transformerFactory;
+
+    /** The trax TransformerFactory this component uses */
+    protected SAXTransformerFactory m_factory;
+
+    /** The default TransformerFactory used by this component */
+    protected SAXTransformerFactory m_defaultFactory;
+
+    /** Is the store turned on? (default is off) */
+    protected boolean m_useStore;
+
+    /** Is incremental processing turned on? (default for Xalan: no) */
+    protected boolean m_incrementalProcessing;
+
+    /** Resolver used to resolve XSLT document() calls, imports and includes */
+    protected SourceResolver m_resolver;
+
+    /** Check included stylesheets */
+    protected boolean m_checkIncludes;
+
+    /** Map of pairs of System ID's / validities of the included stylesheets */
+    protected Map m_includesMap = new HashMap();
+
+    protected XMLizer m_xmlizer;
+
+    /** The ServiceManager */
+    protected ServiceManager m_manager;
+
+    /**
+     * Compose. Try to get the store
+     * 
+     * @avalon.service interface="XMLizer"
+     * @avalon.service interface="SourceResolver"
+     * @avalon.service interface="Store/TransientStore" optional="true"
+     */
+    public void service(final ServiceManager manager) throws ServiceException {
+        m_manager = manager;
+        m_xmlizer = (XMLizer) m_manager.lookup(XMLizer.ROLE);
+        m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
+
+        if (m_manager.hasService(Store.TRANSIENT_STORE)) {
+            m_store = (Store) m_manager.lookup(Store.TRANSIENT_STORE);
+        }
+    }
+
+    /**
+     * Initialize
+     */
+    public void initialize() throws Exception {
+        m_factory = getTransformerFactory(m_transformerFactory);
+        m_defaultFactory = m_factory;
+    }
+
+    /**
+     * Disposable
+     */
+    public void dispose() {
+        if (null != m_manager) {
+            m_manager.release(m_store);
+            m_manager.release(m_resolver);
+            m_manager.release(m_xmlizer);
+            m_manager = null;
+        }
+        m_xmlizer = null;
+        m_store = null;
+        m_resolver = null;
+    }
+
+    /**
+     * Configure the component
+     */
+    public void parameterize(final Parameters params) throws ParameterException {
+        m_useStore = params.getParameterAsBoolean("use-store", this.m_useStore);
+        m_incrementalProcessing = params.getParameterAsBoolean("incremental-processing", this.m_incrementalProcessing);
+        m_transformerFactory = params.getParameter("transformer-factory", null);
+        m_checkIncludes = params.getParameterAsBoolean("check-includes", true);
+        if (!m_useStore) {
+            // release the store, if we don't need it anymore
+            m_manager.release(m_store);
+            m_store = null;
+        } else if (null == m_store) {
+            final String message = "XSLTProcessor: use-store is set to true, " + "but unable to aquire the Store.";
+            throw new ParameterException(message);
+        }
+    }
+
+    /**
+     * Set the transformer factory used by this component
+     */
+    public void setTransformerFactory(final String classname) {
+        m_factory = getTransformerFactory(classname);
+    }
+
+    /**
+     * @see org.apache.excalibur.xml.xslt.XSLTProcessor#getTransformerHandler(org.apache.excalibur.source.Source)
+     */
+    public TransformerHandler getTransformerHandler(final Source stylesheet) throws XSLTProcessorException {
+        return getTransformerHandler(stylesheet, null);
+    }
+
+    /**
+     * @see org.apache.excalibur.xml.xslt.XSLTProcessor#getTransformerHandler(org.apache.excalibur.source.Source,
+     *      org.xml.sax.XMLFilter)
+     */
+    public TransformerHandler getTransformerHandler(final Source stylesheet, final XMLFilter filter) throws XSLTProcessorException {
+        final XSLTProcessor.TransformerHandlerAndValidity validity = getTransformerHandlerAndValidity(stylesheet, filter);
+        return validity.getTransfomerHandler();
+    }
+
+    public TransformerHandlerAndValidity getTransformerHandlerAndValidity(final Source stylesheet) throws XSLTProcessorException {
+        return getTransformerHandlerAndValidity(stylesheet, null);
+    }
+
+    public TransformerHandlerAndValidity getTransformerHandlerAndValidity(Source stylesheet, XMLFilter filter) throws XSLTProcessorException {
+
+        final String id = stylesheet.getURI();
+        TransformerHandlerAndValidity handlerAndValidity;
+
+        try {
+            handlerAndValidity = getTemplates(stylesheet, id);
+            if (handlerAndValidity != null) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Reusing Templates for " + id);
+                }
+                return handlerAndValidity;
+            }
+        } catch(Exception e) {
+            throw new XSLTProcessorException("Error retrieving template", e);
+        }
+        
+        TraxErrorListener errorListener = new TraxErrorListener(getLogger(), stylesheet.getURI());
+        try{
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Creating new Templates for " + id);
+            }
+
+            m_factory.setErrorListener(errorListener);
+
+            // Create a Templates ContentHandler to handle parsing of the
+            // stylesheet.
+            TemplatesHandler templatesHandler = m_factory.newTemplatesHandler();
+
+            // Set the system ID for the template handler since some
+            // TrAX implementations (XSLTC) rely on this in order to obtain
+            // a meaningful identifier for the Templates instances.
+            templatesHandler.setSystemId(id);
+            if (filter != null) {
+                filter.setContentHandler(templatesHandler);
+            }
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Source = " + stylesheet + ", templatesHandler = " + templatesHandler);
+            }
+
+            // Initialize List for included validities
+            SourceValidity validity = stylesheet.getValidity();
+            if (validity != null && m_checkIncludes) {
+                m_includesMap.put(id, new ArrayList());
+            }
+
+            try {
+                // Process the stylesheet.
+                sourceToSAX(stylesheet, filter != null ? (ContentHandler) filter : (ContentHandler) templatesHandler);
+
+                // Get the Templates object (generated during the parsing of
+                // the stylesheet) from the TemplatesHandler.
+                final Templates template = templatesHandler.getTemplates();
+
+                if (null == template) {
+                    throw new XSLTProcessorException("Unable to create templates for stylesheet: " + stylesheet.getURI());
+                }
+
+                putTemplates(template, stylesheet, id);
+
+                // Create transformer handler
+                final TransformerHandler handler = m_factory.newTransformerHandler(template);
+                handler.getTransformer().setErrorListener(new TraxErrorListener(getLogger(), stylesheet.getURI()));
+                handler.getTransformer().setURIResolver(this);
+
+                // Create aggregated validity
+                AggregatedValidity aggregated = null;
+                if (validity != null && m_checkIncludes) {
+                    List includes = (List) m_includesMap.get(id);
+                    if (includes != null) {
+                        aggregated = new AggregatedValidity();
+                        aggregated.add(validity);
+                        for (int i = includes.size() - 1; i >= 0; i--) {
+                            aggregated.add((SourceValidity) ((Object[]) includes.get(i))[1]);
+                        }
+                        validity = aggregated;
+                    }
+                }
+
+                // Create result
+                handlerAndValidity = new MyTransformerHandlerAndValidity(handler, validity);
+            } finally {
+                if (m_checkIncludes)
+                    m_includesMap.remove(id);
+            }
+
+            return handlerAndValidity;
+        } catch (Exception e) {
+            Throwable realEx = errorListener.getThrowable();
+            if (realEx == null) realEx = e;
+            
+            if (realEx instanceof RuntimeException) {
+                throw (RuntimeException)realEx;
+            }
+            
+            if (realEx instanceof XSLTProcessorException) {
+                throw (XSLTProcessorException)realEx;
+            }
+            
+            throw new XSLTProcessorException("Exception when creating Transformer from " + stylesheet.getURI(), realEx);
+        }
+    }
+
+    private void sourceToSAX(Source source, ContentHandler handler) throws SAXException, IOException, SourceException {
+        if (source instanceof XMLizable) {
+            ((XMLizable) source).toSAX(handler);
+        } else {
+            final InputStream inputStream = source.getInputStream();
+            final String mimeType = source.getMimeType();
+            final String systemId = source.getURI();
+            m_xmlizer.toSAX(inputStream, mimeType, systemId, handler);
+        }
+    }
+
+    public void transform(final Source source, final Source stylesheet, final Parameters params, final Result result) throws XSLTProcessorException {
+        try {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug(
+                        "Transform source = " + source + ", stylesheet = " + stylesheet + ", parameters = " + params + ", result = " + result);
+            }
+            final TransformerHandler handler = getTransformerHandler(stylesheet);
+            if (params != null) {
+                final Transformer transformer = handler.getTransformer();
+                transformer.clearParameters();
+                String[] names = params.getNames();
+                for (int i = names.length - 1; i >= 0; i--) {
+                    transformer.setParameter(names[i], params.getParameter(names[i]));
+                }
+            }
+
+            handler.setResult(result);
+            sourceToSAX(source, handler);
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Transform done");
+            }
+        } catch (SAXException e) {
+            // Unwrapping the exception will "remove" the real cause with
+            // never Xalan versions and makes the exception message unusable
+            final String message = "Error in running Transformation";
+            throw new XSLTProcessorException(message, e);
+            /*
+             * if( e.getException() == null ) { final String message = "Error in
+             * running Transformation"; throw new XSLTProcessorException(
+             * message, e ); } else { final String message = "Got SAXException.
+             * Rethrowing cause exception."; getLogger().debug( message, e );
+             * throw new XSLTProcessorException( "Error in running
+             * Transformation", e.getException() ); }
+             */
+        } catch (Exception e) {
+            final String message = "Error in running Transformation";
+            throw new XSLTProcessorException(message, e);
+        }
+    }
+
+    /**
+     * Get the TransformerFactory associated with the given classname. If the
+     * class can't be found or the given class doesn't implement the required
+     * interface, the default factory is returned.
+     */
+    private SAXTransformerFactory getTransformerFactory(String factoryName) {
+        SAXTransformerFactory _factory;
+
+        if (null == factoryName) {
+            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+        } else {
+            try {
+                ClassLoader loader = Thread.currentThread().getContextClassLoader();
+                if (loader == null) {
+                    loader = getClass().getClassLoader();
+                }
+                _factory = (SAXTransformerFactory) loader.loadClass(factoryName).newInstance();
+            } catch (ClassNotFoundException cnfe) {
+                getLogger().error("Cannot find the requested TrAX factory '" + factoryName + "'. Using default TrAX Transformer Factory instead.");
+                if (m_factory != null)
+                    return m_factory;
+                _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+            } catch (ClassCastException cce) {
+                getLogger().error(
+                        "The indicated class '" + factoryName
+                                + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead.");
+                if (m_factory != null)
+                    return m_factory;
+                _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+            } catch (Exception e) {
+                getLogger().error(
+                        "Error found loading the requested TrAX Transformer Factory '" + factoryName
+                                + "'. Using default TrAX Transformer Factory instead.");
+                if (m_factory != null)
+                    return m_factory;
+                _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+            }
+        }
+
+        _factory.setErrorListener(new TraxErrorListener(getLogger(), null));
+        _factory.setURIResolver(this);
+
+        // FIXME (SM): implementation-specific parameter passing should be
+        // made more extensible.
+        if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) {
+            _factory.setAttribute("http://xml.apache.org/xalan/features/incremental", new Boolean(m_incrementalProcessing));
+        }
+
+        return _factory;
+    }
+
+    private TransformerHandlerAndValidity getTemplates(Source stylesheet, String id) throws IOException, TransformerException {
+        if (!m_useStore) {
+            return null;
+        }
+
+        // we must augment the template ID with the factory classname since one
+        // transformer implementation cannot handle the instances of a
+        // template created by another one.
+        String key = "XSLTTemplate: " + id + '(' + m_factory.getClass().getName() + ')';
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("getTemplates: stylesheet " + id);
+        }
+
+        SourceValidity newValidity = stylesheet.getValidity();
+
+        // Only stylesheets with validity are stored
+        if (newValidity == null) {
+            // Remove an old template
+            m_store.remove(key);
+            return null;
+        }
+
+        // Stored is an array of the templates and the caching time and list of
+        // includes
+        Object[] templateAndValidityAndIncludes = (Object[]) m_store.get(key);
+        if (templateAndValidityAndIncludes == null) {
+            // Templates not found in cache
+            return null;
+        }
+
+        // Check template modification time
+        SourceValidity storedValidity = (SourceValidity) templateAndValidityAndIncludes[1];
+        int valid = storedValidity.isValid();
+        boolean isValid;
+        if (valid == 0) {
+            valid = storedValidity.isValid(newValidity);
+            isValid = (valid == 1);
+        } else {
+            isValid = (valid == 1);
+        }
+        if (!isValid) {
+            m_store.remove(key);
+            return null;
+        }
+
+        // Check includes
+        if (m_checkIncludes) {
+            AggregatedValidity aggregated = null;
+            List includes = (List) templateAndValidityAndIncludes[2];
+            if (includes != null) {
+                aggregated = new AggregatedValidity();
+                aggregated.add(storedValidity);
+
+                for (int i = includes.size() - 1; i >= 0; i--) {
+                    // Every include stored as pair of source ID and validity
+                    Object[] pair = (Object[]) includes.get(i);
+                    storedValidity = (SourceValidity) pair[1];
+                    aggregated.add(storedValidity);
+
+                    valid = storedValidity.isValid();
+                    isValid = false;
+                    if (valid == 0) {
+                        Source includedSource = null;
+                        try {
+                            includedSource = m_resolver.resolveURI((String) pair[0]);
+                            SourceValidity included = includedSource.getValidity();
+                            if (included != null) {
+                                valid = storedValidity.isValid(included);
+                                isValid = (valid == 1);
+                            }
+                        } finally {
+                            m_resolver.release(includedSource);
+                        }
+                    } else {
+                        isValid = (valid == 1);
+                    }
+                    if (!isValid) {
+                        m_store.remove(key);
+                        return null;
+                    }
+                }
+                storedValidity = aggregated;
+            }
+        }
+
+        TransformerHandler handler = m_factory.newTransformerHandler((Templates) templateAndValidityAndIncludes[0]);
+        handler.getTransformer().setErrorListener(new TraxErrorListener(getLogger(), stylesheet.getURI()));
+        handler.getTransformer().setURIResolver(this);
+        return new MyTransformerHandlerAndValidity(handler, storedValidity);
+    }
+
+    private void putTemplates(Templates templates, Source stylesheet, String id) throws IOException {
+        if (!m_useStore)
+            return;
+
+        // we must augment the template ID with the factory classname since one
+        // transformer implementation cannot handle the instances of a
+        // template created by another one.
+        String key = "XSLTTemplate: " + id + '(' + m_factory.getClass().getName() + ')';
+
+        // only stylesheets with a last modification date are stored
+        SourceValidity validity = stylesheet.getValidity();
+        if (null != validity) {
+            // Stored is an array of the template and the current time
+            Object[] templateAndValidityAndIncludes = new Object[3];
+            templateAndValidityAndIncludes[0] = templates;
+            templateAndValidityAndIncludes[1] = validity;
+            if (m_checkIncludes) {
+                templateAndValidityAndIncludes[2] = m_includesMap.get(id);
+            }
+            m_store.store(key, templateAndValidityAndIncludes);
+        }
+    }
+
+    /**
+     * Called by the processor when it encounters an xsl:include, xsl:import, or
+     * document() function.
+     * 
+     * @param href
+     *            An href attribute, which may be relative or absolute.
+     * @param base
+     *            The base URI in effect when the href attribute was
+     *            encountered.
+     * 
+     * @return A Source object, or null if the href cannot be resolved, and the
+     *         processor should try to resolve the URI itself.
+     * 
+     * @throws TransformerException
+     *             if an error occurs when trying to resolve the URI.
+     */
+    public javax.xml.transform.Source resolve(String href, String base) throws TransformerException {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("resolve(href = " + href + ", base = " + base + "); resolver = " + m_resolver);
+        }
+
+        Source xslSource = null;
+        try {
+            if (base == null || href.indexOf(":") > 1) {
+                // Null base - href must be an absolute URL
+                xslSource = m_resolver.resolveURI(href);
+            } else if (href.length() == 0) {
+                // Empty href resolves to base
+                xslSource = m_resolver.resolveURI(base);
+            } else {
+                // is the base a file or a real m_url
+                if (!base.startsWith("file:")) {
+                    int lastPathElementPos = base.lastIndexOf('/');
+                    if (lastPathElementPos == -1) {
+                        // this should never occur as the base should
+                        // always be protocol:/....
+                        return null; // we can't resolve this
+                    } else {
+                        xslSource = m_resolver.resolveURI(base.substring(0, lastPathElementPos) + "/" + href);
+                    }
+                } else {
+                    File parent = new File(base.substring(5));
+                    File parent2 = new File(parent.getParentFile(), href);
+                    xslSource = m_resolver.resolveURI(parent2.toURL().toExternalForm());
+                }
+            }
+
+            InputSource is = getInputSource(xslSource);
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("xslSource = " + xslSource + ", system id = " + xslSource.getURI());
+            }
+
+            if (m_checkIncludes) {
+                // Populate included validities
+                List includes = (List) m_includesMap.get(base);
+                if (includes != null) {
+                    SourceValidity included = xslSource.getValidity();
+                    if (included != null) {
+                        includes.add(new Object[] { xslSource.getURI(), xslSource.getValidity() });
+                    } else {
+                        // One of the included stylesheets is not cacheable
+                        m_includesMap.remove(base);
+                    }
+                }
+            }
+
+            return new StreamSource(is.getByteStream(), is.getSystemId());
+        } catch (SourceException e) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", e);
+            }
+
+            // CZ: To obtain the same behaviour as when the resource is
+            // transformed by the XSLT Transformer we should return null here.
+            return null;
+        } catch (java.net.MalformedURLException mue) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", mue);
+            }
+
+            return null;
+        } catch (IOException ioe) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Failed to resolve " + href + "(base = " + base + "), return null", ioe);
+            }
+
+            return null;
+        } finally {
+            m_resolver.release(xslSource);
+        }
+    }
+
+    /**
+     * Return a new <code>InputSource</code> object that uses the
+     * <code>InputStream</code> and the system ID of the <code>Source</code>
+     * object.
+     * 
+     * @throws IOException
+     *             if I/O error occured.
+     */
+    private static InputSource getInputSource(final Source source) throws IOException, SourceException {
+        final InputSource newObject = new InputSource(source.getInputStream());
+        newObject.setSystemId(source.getURI());
+        return newObject;
+    }
+
+    /**
+     * Recycle the component
+     */
+    public void recycle() {
+        m_includesMap.clear();
+        // restore default factory
+        if (m_factory != m_defaultFactory) {
+            m_factory = m_defaultFactory;
+        }
+    }
+
+    /**
+     * Subclass to allow for instanciation, as for some unknown reason the
+     * constructor is protected....
+     */
+    public static class MyTransformerHandlerAndValidity extends TransformerHandlerAndValidity {
+
+        protected MyTransformerHandlerAndValidity(TransformerHandler handler, SourceValidity validity) {
+            super(handler, validity);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/configuration/ConfigurationBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/configuration/ConfigurationBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/configuration/ConfigurationBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/configuration/ConfigurationBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,421 @@
+/*
+ * Copyright 2004-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.configuration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Iterator;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.core.container.util.PropertyHelper;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.NamespaceSupport;
+
+/**
+ * A ConfigurationBuilder builds {@link Configuration}s from XML,
+ * via a SAX2 compliant parser.
+ *
+ * <p>
+ * The mapping from XML namespaces to {@link Configuration} namespaces is pretty
+ * straightforward, with one caveat: attribute namespaces are (deliberately) not
+ * supported. Enabling namespace processing has the following effects:</p>
+ * <ul>
+ *  <li>Attributes starting with <code>xmlns:</code> are interpreted as
+ *  declaring a prefix:namespaceURI mapping, and won't result in the creation of
+ *  <code>xmlns</code>-prefixed attributes in the <code>Configuration</code>.
+ *  </li>
+ *  <li>
+ *  Prefixed XML elements, like <tt>&lt;doc:title xmlns:doc="http://foo.com"&gt;,</tt>
+ *  will result in a <code>Configuration</code> with <code>{@link
+ *  Configuration#getName getName()}.equals("title")</code> and <code>{@link
+ *  Configuration#getNamespace getNamespace()}.equals("http://foo.com")</code>.
+ *  </li>
+ * </ul>
+ * <p>
+ * Whitespace handling. Since mixed content is not allowed in the
+ * configurations, whitespace is completely discarded in non-leaf nodes.
+ * For the leaf nodes the default behavior is to trim the space
+ * surrounding the value. This can be changed by specifying
+ * <code>xml:space</code> attribute with value of <code>preserve</code>
+ * in that case the whitespace is left intact.
+ * </p>
+ *
+ * @version SVN $Id: ConfigurationBuilder.java 179045 2005-05-30 11:08:13Z cziegeler $
+ */
+public class ConfigurationBuilder
+    extends DefaultHandler
+    implements ErrorHandler {
+    
+    private XMLReader parser;
+    
+    /**
+     * Likely number of nested configuration items. If more is
+     * encountered the lists will grow automatically.
+     */
+    private static final int EXPECTED_DEPTH = 4;
+    private final ArrayList elements = new ArrayList( EXPECTED_DEPTH );
+    private final ArrayList prefixes = new ArrayList( EXPECTED_DEPTH );
+    private final ArrayList values = new ArrayList( EXPECTED_DEPTH );
+    
+    /**
+     * Contains true at index n if space in the configuration with
+     * depth n is to be preserved.
+     */
+    private final BitSet preserveSpace = new BitSet();
+    private Configuration configuration;
+    private Locator locator;
+    private final NamespaceSupport namespaceSupport = new NamespaceSupport();
+    private final Settings settings;
+    
+    /**
+     * Create a Configuration Builder
+     */
+    public ConfigurationBuilder(Settings s) {
+        this.settings = s;
+        try {
+            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+
+            saxParserFactory.setNamespaceAware( true );
+
+            final SAXParser saxParser = saxParserFactory.newSAXParser();
+
+            this.parser = saxParser.getXMLReader();
+
+            this.parser.setContentHandler( this );
+            this.parser.setErrorHandler( this );
+        } catch( final Exception se ) {
+            throw new Error( "Unable to setup SAX parser" + se );
+        }
+    }
+
+    /**
+     * Build a configuration object using an InputStream.
+     * @param inputStream an <code>InputStream</code> value
+     * @return a <code>Configuration</code> object
+     * @throws SAXException if a parsing error occurs
+     * @throws IOException if an I/O error occurs
+     */
+    public Configuration build( final InputStream inputStream )
+    throws SAXException, IOException {
+        return this.build( new InputSource( inputStream ) );
+    }
+
+    /**
+     * Build a configuration object using an InputStream;
+     * supplying a systemId to make messages about all
+     * kinds of errors more meaningfull.
+     * @param inputStream an <code>InputStream</code> value
+     * @param systemId the systemId to set on the intermediate sax
+     *         inputSource
+     * @return a <code>Configuration</code> object
+     * @throws SAXException if a parsing error occurs
+     * @throws IOException if an I/O error occurs
+     */
+    public Configuration build( final InputStream inputStream, 
+                                final String systemId )
+    throws SAXException, IOException {
+        final InputSource inputSource = new InputSource( inputStream );
+        inputSource.setSystemId( systemId );
+        return this.build( inputSource );
+    }
+
+    /**
+     * Build a configuration object using an URI
+     * @param uri a <code>String</code> value
+     * @return a <code>Configuration</code> object
+     * @throws SAXException if a parsing error occurs
+     * @throws IOException if an I/O error occurs
+     */
+    public Configuration build( final String uri )
+    throws SAXException, IOException {
+        return this.build( new InputSource( uri ) );
+    }
+
+    /**
+     * Build a configuration object using an XML InputSource object
+     * @param input an <code>InputSource</code> value
+     * @return a <code>Configuration</code> object
+     * @throws SAXException if a parsing error occurs
+     * @throws IOException if an I/O error occurs
+     */
+    public Configuration build( final InputSource input )
+    throws SAXException, IOException {
+        synchronized( this ) {
+            this.clear();
+            this.parser.parse( input );
+            return this.configuration;
+        }
+    }
+
+    /**
+     * Sets the <code>EntityResolver</code> to 
+     * be used by parser. Useful when dealing with xml
+     * files that reference external entities.
+     * 
+     * @param resolver implementation of <code>EntityResolver</code>
+     */
+    public void setEntityResolver( final EntityResolver resolver ) {
+        this.parser.setEntityResolver( resolver );
+    }
+
+    /**
+     * Clears all data from this configuration handler.
+     */
+    protected void clear() {
+        this.elements.clear();
+        Iterator i = this.prefixes.iterator();
+        while( i.hasNext() ) {
+            ( (ArrayList)i.next() ).clear();
+        }
+        this.prefixes.clear();
+        this.values.clear();
+        this.locator = null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
+     */
+    public void setDocumentLocator( final Locator locator ) {
+        this.locator = locator;
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#startDocument()
+     */
+    public void startDocument()
+    throws SAXException {
+        this.namespaceSupport.reset();
+        super.startDocument();
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#endDocument()
+     */
+    public void endDocument()
+    throws SAXException {
+        super.endDocument();
+        this.namespaceSupport.reset();
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+     */
+    public void characters( final char[] ch, int start, int end )
+    throws SAXException {
+        // it is possible to play micro-optimization here by doing
+        // manual trimming and thus preserve some precious bits
+        // of memory, but it's really not important enough to justify
+        // resulting code complexity
+        final int depth = this.values.size() - 1;
+        final StringBuffer valueBuffer = (StringBuffer)this.values.get( depth );
+        valueBuffer.append( ch, start, end );
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+     */
+    public void endElement( final String namespaceURI,
+                            final String localName,
+                            final String rawName )
+    throws SAXException {
+        final int depth = this.elements.size() - 1;
+        final DefaultConfiguration finishedConfiguration =
+        (DefaultConfiguration)this.elements.remove( depth );
+        final String accumulatedValue =
+        ( (StringBuffer)this.values.remove( depth ) ).toString();
+        final ArrayList prefixes = (ArrayList)this.prefixes.remove( depth );
+
+        final Iterator i = prefixes.iterator();
+        while( i.hasNext() ) {
+            endPrefixMapping( (String)i.next() );
+        }
+        prefixes.clear();
+
+        if( finishedConfiguration.getChildren().length == 0 ) {
+            // leaf node
+            String finishedValue;
+            if( this.preserveSpace.get( depth ) ) {
+                finishedValue = accumulatedValue;
+            } else if( accumulatedValue.length() == 0 ) {
+                finishedValue = null;
+            } else {
+                finishedValue = accumulatedValue.trim();
+            }
+            finishedConfiguration.setValue( PropertyHelper.replace(finishedValue, this.settings) );
+        } else {
+            final String trimmedValue = accumulatedValue.trim();
+            if( trimmedValue.length() > 0 ) {
+                throw new SAXException( "Not allowed to define mixed content in the " 
+                        + "element " + finishedConfiguration.getName() + " at "
+                        + finishedConfiguration.getLocation() );
+            }
+        }
+
+        if( depth == 0 ) {
+            this.configuration = finishedConfiguration;
+        }
+        this.namespaceSupport.popContext();
+    }
+
+    /**
+     * Create a new <code>DefaultConfiguration</code> with the specified
+     * local name, namespace, and location.
+     *
+     * @param localName a <code>String</code> value
+     * @param namespaceURI a <code>String</code> value
+     * @param location a <code>String</code> value
+     * @return a <code>DefaultConfiguration</code> value
+     */
+    protected DefaultConfiguration createConfiguration( final String localName,
+                                                        final String namespaceURI,
+                                                        final String location ) {
+        String prefix = this.namespaceSupport.getPrefix( namespaceURI );
+        if( prefix == null ) {
+            prefix = "";
+        }
+        return new DefaultConfiguration( localName, location, namespaceURI, prefix );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+     */
+    public void startElement( final String namespaceURI,
+                              final String localName,
+                              final String rawName,
+                              final Attributes attributes )
+    throws SAXException {
+        this.namespaceSupport.pushContext();
+        final DefaultConfiguration configuration =
+            createConfiguration( localName, namespaceURI, getLocationString() );
+        // depth of new configuration (not decrementing here, configuration
+        // is to be added)
+        final int depth = this.elements.size();
+        boolean preserveSpace = false; // top level element trims space by default
+
+        if( depth > 0 ) {
+            final DefaultConfiguration parent =
+                (DefaultConfiguration)this.elements.get( depth - 1 );
+            parent.addChild( configuration );
+            // inherits parent's space preservation policy
+            preserveSpace = this.preserveSpace.get( depth - 1 );
+        }
+
+        this.elements.add( configuration );
+        this.values.add( new StringBuffer() );
+
+        final ArrayList prefixes = new ArrayList();
+        AttributesImpl componentAttr = new AttributesImpl();
+
+        for( int i = 0; i < attributes.getLength(); i++ ) {
+            if( attributes.getQName( i ).startsWith( "xmlns" ) ) {
+                prefixes.add( attributes.getLocalName( i ) );
+                this.startPrefixMapping( attributes.getLocalName( i ),
+                                         attributes.getValue( i ) );
+            } else if( attributes.getQName( i ).equals( "xml:space" ) ) {
+                preserveSpace = attributes.getValue( i ).equals( "preserve" );
+            } else {
+                componentAttr.addAttribute( attributes.getURI( i ),
+                                            attributes.getLocalName( i ),
+                                            attributes.getQName( i ),
+                                            attributes.getType( i ),
+                                            attributes.getValue( i ) );
+            }
+        }
+
+        if( preserveSpace ) {
+            this.preserveSpace.set( depth );
+        } else {
+            this.preserveSpace.clear( depth );
+        }
+
+        this.prefixes.add( prefixes );
+
+        final int attributesSize = componentAttr.getLength();
+
+        for( int i = 0; i < attributesSize; i++ ) {
+            final String name = componentAttr.getQName( i );
+            final String value = componentAttr.getValue( i );
+            configuration.setAttribute( name, PropertyHelper.replace(value, this.settings) );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+     */
+    public void error( final SAXParseException exception )
+    throws SAXException {
+        throw exception;
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+     */
+    public void warning( final SAXParseException exception )
+    throws SAXException {
+        throw exception;
+    }
+
+    /* (non-Javadoc)
+     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+     */
+    public void fatalError( final SAXParseException exception )
+    throws SAXException {
+        throw exception;
+    }
+
+    /**
+     * Returns a string showing the current system ID, line number and column number.
+     *
+     * @return a <code>String</code> value
+     */
+    private String getLocationString() {
+        if( this.locator == null ) {
+            return "Unknown";
+        } 
+        final int columnNumber = this.locator.getColumnNumber();
+        return this.locator.getSystemId() + ":"
+            + this.locator.getLineNumber()
+            + ( columnNumber >= 0 ? ( ":" + columnNumber ) : "" );
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
+     */
+    public void startPrefixMapping( String prefix, String uri )
+    throws SAXException {
+        this.namespaceSupport.declarePrefix( prefix, uri );
+        super.startPrefixMapping( prefix, uri );
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/configuration/ConfigurationBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BaseSettings.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BaseSettings.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BaseSettings.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BaseSettings.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,271 @@
+/*
+ * Copyright 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;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The settings (configuration) for the Cocoon core are described through the {@link BaseSettings}
+ * interface and the {@link DynamicSettings} interface.
+ * Whereas the settings of the {@link BaseSettings} object can't be changed at runtime,
+ * the settings of the {@link DynamicSettings} object are mutable. Use the {@link Core} instance
+ * to update the settings.
+ *
+ * @version $Id: BaseSettings.java 312637 2005-10-10 13:00:42Z cziegeler $
+ * @since 2.2
+ */
+public interface BaseSettings {
+
+    /** Default value for {@link #isManageExceptions()}. */
+    boolean MANAGE_EXCEPTIONS = true;
+
+    /** Name of the property specifying a custom user properties file. */
+    String PROPERTY_USER_SETTINGS = "org.apache.cocoon.settings";
+
+    /** Name of the property specifying the running mode. */
+    String PROPERTY_RUNNING_MODE = "org.apache.cocoon.mode";
+
+    /** The default running mode. */
+    String DEFAULT_RUNNING_MODE = "dev";
+
+    /**
+     * This parameter allows to set system properties
+     */
+    String KEY_FORCE_PROPERTIES = "system.properties";
+
+    /**
+     * This parameter points to the main configuration file for Cocoon.
+     * Note that the path is specified in absolute notation but it will be
+     * resolved relative to the application context path.
+     */
+    String KEY_CONFIGURATION = "configuration";
+
+    /**
+     * This parameter indicates the configuration file of the LogKit management
+     */
+    String KEY_LOGGING_CONFIGURATION = "logging.configuration";
+
+    /**
+     * This parameter indicates the log level to use throughout startup of the
+     * system. As soon as the logkit.xconf the setting of the logkit.xconf
+     * configuration is used instead! Only for startup and if the logkit.xconf is
+     * not readable/available this log level is of importance.
+     */
+    String KEY_LOGGING_BOOTSTRAP_LOGLEVEL = "logging.bootstrap.loglevel";
+
+    /**
+     * This parameter switches the logging system from LogKit to Log4J for Cocoon.
+     * Log4J has to be configured already.
+     */
+    String KEY_LOGGING_MANAGER_CLASS = "logging.manager.class";
+
+    /**
+     * This parameter is used to list classes that should be loaded at
+     * initialization time of the servlet. For example, JDBC Drivers used need to
+     * be named here. Additional entries may be inserted here during build
+     * depending on your build properties.
+     */
+    String KEY_LOAD_CLASSES = "classloader.load.classes";
+
+    /**
+     * This parameter allows to specify additional directories or jars
+     * which Cocoon should put into it's own classpath.
+     * Note that absolute pathes are taken as such but relative pathes
+     * are rooted at the context root of the Cocoon servlet.
+     */
+    String KEY_EXTRA_CLASSPATHS = "extra.classpaths";
+
+    /**
+     * This parameter allows you to select the parent service manager.
+     * The class will be instantiated via the constructor that takes a single
+     * String as a parameter. That String will be equal to the text after the '/'.
+     *
+     * Cocoon honors the LogEnabled, Initializable and Disposable interfaces for
+     * this class, if it implements them.
+     */
+    String KEY_PARENT_SERVICE_MANAGER = "parentservicemanager";
+
+    /**
+     * This parameter indicates the category id of the logger from the LogKit
+     * configuration used by the environment.
+     */
+    String KEY_LOGGING_ENVIRONMENT_LOGGER = "logging.category.environment";
+
+    /**
+     * This parameter indicates the category id of the logger from the LogKit
+     * management configuration for the Cocoon engine.
+     * This logger is used for all components described in the cocoon.xconf
+     * and sitemap.xmap file not having specified a logger with the
+     * logger="..." attribute in the component configuration file.
+     */
+    String KEY_LOGGING_COCOON_LOGGER = "logging.category.cocoon";
+
+    /**
+     * This parameter allows to specify where Cocoon should put uploaded files.
+     * The path specified can be either absolute or relative to the context
+     * path of the servlet. On windows platform, absolute directory must start
+     * with volume: C:\Path\To\Upload\Directory.
+     */
+    String KEY_UPLOADS_DIRECTORY = "uploads.directory";
+
+    /**
+     * This parameter allows to specify where Cocoon should create its page
+     * and other objects cache. The path specified can be either absolute or
+     * relative to the context path of the servlet. On windows platform,
+     * absolute directory must start with volume: C:\Path\To\Cache\Directory.
+     */
+    String KEY_CACHE_DIRECTORY = "cache.directory";
+
+    /**
+     * This parameter allows to specify where Cocoon should put it's
+     * working files. The path specified is either absolute or relative
+     * to the context path of the Cocoon servlet. On windows platform,
+     * absolute directory must start with volume: C:\Path\To\Work\Directory.
+     */
+    String KEY_WORK_DIRECTORY = "work.directory";
+
+    /**
+     * If true or not set, this class will try to catch and handle all Cocoon exceptions.
+     * If false, it will rethrow them to the servlet container.
+     */
+    String KEY_MANAGE_EXCEPTIONS = "manageexceptions";
+
+    /**
+     * Set form encoding. This will be the character set used to decode request
+     * parameters. If not set the ISO-8859-1 encoding will be assumed.
+    */
+    String KEY_FORM_ENCODING = "formencoding";
+
+    /**
+     * If this value is specified, it will be interpreted as a log level and
+     * all logging categories will be set to this level regardless of their
+     * definition in the logging configuration.
+     */
+    String KEY_LOGGING_OVERRIDE_LOGLEVEL = "override.loglevel";
+
+    /**
+     * This key allows to add own {@link PropertyProvider}s.
+     */
+    String KEY_PROPERTY_PROVIDER = "property.provider";
+
+    /**
+     * @return Returns the configuration.
+     * @see #KEY_CONFIGURATION
+     */
+    String getConfiguration();
+
+    /**
+     * @return Returns the extraClasspaths.
+     * @see #KEY_EXTRA_CLASSPATHS
+     */
+    List getExtraClasspaths();
+
+    /**
+     * @return Returns the forceProperties.
+     * @see #KEY_FORCE_PROPERTIES
+     */
+    Map getForceProperties();
+
+    /**
+     * @return Returns the loadClasses.
+     * @see #KEY_LOAD_CLASSES
+     */
+    List getLoadClasses();
+
+    /**
+     * @return Returns the loggerManagerClassName.
+     * @see #KEY_LOGGING_MANAGER_CLASS
+     */
+    String getLoggerManagerClassName();
+
+    /**
+     * @return Returns the loggingConfiguration.
+     * @see #KEY_LOGGING_CONFIGURATION
+     */
+    String getLoggingConfiguration();
+
+    /**
+     * @return Returns the logLevel.
+     * @see #KEY_LOGGING_BOOTSTRAP_LOGLEVEL
+     */
+    String getBootstrapLogLevel();
+
+    /**
+     * @return Returns the parentServiceManagerClassName.
+     * @see #KEY_PARENT_SERVICE_MANAGER
+     */
+    String getParentServiceManagerClassName();
+
+    /**
+     * @return Returns the uploadDirectory.
+     * @see #KEY_UPLOADS_DIRECTORY
+     */
+    String getUploadDirectory();
+
+    /**
+     * @return Returns the workDirectory.
+     * @see #KEY_WORK_DIRECTORY
+     */
+    String getWorkDirectory();
+
+    /**
+     * @return Returns the logger for the environment.
+     * @see #KEY_LOGGING_ENVIRONMENT_LOGGER
+     */
+    String getEnvironmentLogger();
+
+    /**
+     * @return Returns the overrideLogLevel.
+     * @see #KEY_LOGGING_OVERRIDE_LOGLEVEL
+     */
+    String getOverrideLogLevel();
+
+    /**
+     * @return Returns the formEncoding.
+     * @see #KEY_FORM_ENCODING
+     */
+    String getFormEncoding();
+
+    /**
+     * @return Returns the manageExceptions.
+     * @see #KEY_MANAGE_EXCEPTIONS
+     */
+    boolean isManageExceptions();
+
+    /**
+     * @return Returns the cacheDirectory.
+     * @see #KEY_CACHE_DIRECTORY
+     */
+    String getCacheDirectory();
+
+    /**
+     * @return Returns the cocoonLogger.
+     * @see #KEY_LOGGING_COCOON_LOGGER
+     */
+    String getCocoonLogger();
+
+    /**
+     * The creation time of the current Cocoon instance.
+     */
+    long getCreationTime();
+
+    /**
+     * @return All property providers.
+     * @see #KEY_PROPERTY_PROVIDER
+     */
+    List getPropertyProviders();
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BaseSettings.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BootstrapEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BootstrapEnvironment.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BootstrapEnvironment.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BootstrapEnvironment.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 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;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.logger.Logger;
+
+/**
+ * The BootstrapEnvironment is the connection between the real environment
+ * (servlet, cli etc.) and the Cocoon core. The core uses this object to
+ * access information from the real environment and to pass several objects
+ * back.
+ * A BootstrapEnvironment can be used to create a new Cocoon system using
+ * the {@link CoreUtil}.
+ * 
+ * @version $Id: BootstrapEnvironment.java 312659 2005-10-10 14:11:48Z cziegeler $
+ * @since 2.2
+ */
+public interface BootstrapEnvironment {
+
+    /**
+     * Convenience class to define some constants for log levels.
+     * @see BootstrapEnvironment#getBootstrapLogger(LogLevel)
+     */
+    public static final class LogLevel {
+
+        public static final LogLevel DEBUG = new LogLevel( "DEBUG", 0 );
+        public static final LogLevel INFO = new LogLevel( "INFO", 1 );
+        public static final LogLevel WARN = new LogLevel( "WARN", 2 );
+        public static final LogLevel ERROR = new LogLevel( "ERROR", 3 );
+        public static final LogLevel FATAL_ERROR = new LogLevel( "FATAL_ERROR", 4 );
+        public static final LogLevel DISABLED = new LogLevel( "NONE", 5 );
+
+        public static LogLevel getLogLevelForName(final String name) {
+            if( DEBUG.getName().equals( name ) ) {
+                return DEBUG;
+            } else if( INFO.getName().equals( name ) ) {
+                return INFO;
+            } else if( WARN.getName().equals( name ) ) {
+                return WARN;
+            } else if( ERROR.getName().equals( name ) ) {
+                return ERROR;
+            } else if( FATAL_ERROR.getName().equals( name ) ) {
+                return FATAL_ERROR;
+            } else if( DISABLED.getName().equals( name ) ) {
+                return DISABLED;
+            } else {
+                return DEBUG;
+            }
+        }    
+
+        private final String name;
+        private final int level;
+
+        public LogLevel(String name, int level) {
+            this.name = name;
+            this.level = level;
+        }
+
+        public int getLevel() {
+            return this.level;
+        }
+
+        public String getName() {
+            return this.name;
+        }
+    }
+
+    /**
+     * Get the bootstrap logger.
+     * @param logLevel The log level to use according to the {@link Logger} interface.
+     */
+    Logger getBootstrapLogger(LogLevel logLevel);
+
+    /** Log a message during bootstrapping. This is used to log
+     * information before the logging system is setup.
+     * @param message A message.
+     */
+    void log(String 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.
+     */
+    void log(String message, Throwable 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.
+     */
+    void setLogger(Logger rootLogger);
+
+    /**
+     * This callback can be used by the environment to add environment specific
+     * settings. For example the servlet environment parsed the web.xml and adjusts
+     * the settings based on the parameters.
+     * @param settings The settings for Cocoon.
+     */
+    void configure(MutableSettings settings);
+
+    /**
+     * This callback can be used by the environment to add environment specific
+     * information for the logging system.
+     * @param context The context passed to the logging system.
+     */
+    void configureLoggingContext(DefaultContext context);
+
+    /**
+     * This callback can be used by the environment to add environment specific
+     * information.
+     * @param context The context passed to all Avalon based components that are context aware.
+     */
+    void configure(DefaultContext context);
+
+    /**
+     * Create the context object of the environment.
+     * @return The context object.
+     */
+    org.apache.cocoon.environment.Context getEnvironmentContext();
+
+    /**
+     * Returns the URL to the application context.
+     */
+    String getContextURL();
+
+    /**
+     * Returns a file to the application context.
+     * @return A file pointing to the context or null if the context is not
+     *         writeable.
+     */
+    File getContextForWriting();
+
+    /**
+     * Set the ConfigFile for the Cocoon object.
+     *
+     * @param configFileName The file location for the cocoon.xconf
+     *
+     * @throws Exception
+     */
+    URL getConfigFile(String configFileName)
+    throws Exception;
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/BootstrapEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/Core.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/Core.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/Core.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/Core.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,243 @@
+/*
+ * Copyright 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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.Processor;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.flow.Interpreter;
+import org.apache.cocoon.core.container.ComponentLocatorWrapper;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.sitemap.ComponentLocator;
+import org.apache.cocoon.sitemap.Sitemap;
+import org.apache.commons.lang.NotImplementedException;
+
+/**
+ * This is the core Cocoon component.
+ * It can be looked up to get access to various information about the
+ * current installation.
+ *
+ * The core of Cocoon is a singleton object that is created on startup.
+ *
+ * @version $Id: Core.java 312659 2005-10-10 14:11:48Z cziegeler $
+ * @since 2.2
+ */
+public class Core {
+
+    /** The key to lookup the component. */
+    public static String ROLE = Core.class.getName();
+
+    /**
+     * The cleanup threads that are invoked after the processing of a
+     * request is finished.
+     */
+    private static final ThreadLocal cleanup = new ThreadLocal();
+
+    /** The component context. */
+    private final Context context;
+
+    private final Settings settings;
+
+    /**
+     * Constructor
+     * The core object is created by the {@link CoreUtil} class. Never construct
+     * a core object yourself (apart from testing of course)!
+     * @param s The settings
+     * @param c The context
+     */
+    public Core(Settings s, Context c) {
+        this.settings = s;
+        this.context = c;
+    }
+
+    /**
+     * Add a cleanup task.
+     * A cleanup task is run after a request is processed.
+     * @param task The task to run.
+     */
+    public static void addCleanupTask(CleanupTask task) {
+        List l = (List)cleanup.get();
+        if ( l == null ) {
+            l = new ArrayList();
+            cleanup.set(l);
+        }
+        l.add(task);
+    }
+
+    /**
+     * Invoke all registered cleanup tasks for the current process.
+     * This method should not be called directly!
+     */
+    public static void cleanup() {
+        List l = (List)cleanup.get();
+        if ( l != null ) {
+            final Iterator i = l.iterator();
+            while ( i.hasNext() ) {
+                final CleanupTask t = (CleanupTask)i.next();
+                t.invoke();
+            }
+            l.clear();
+            cleanup.set(null);
+        }
+    }
+
+    /**
+     * The interface for the cleanup task.
+     * A cleanup task can be run after a request has been processed.
+     */
+    public static interface CleanupTask {
+
+        /**
+         * Start the cleanup.
+         * This method should never raise any exception!
+         */
+        void invoke();
+    }
+
+    /**
+     * Return the settings.
+     */
+    public Settings getSettings() {
+        return this.settings;
+    }
+
+    /**
+     * Update the dynamic settings at runtime.
+     * @param dynSettings
+     */
+    public void update(DynamicSettings dynSettings) {
+        throw new NotImplementedException("The update method is not implemented yet.");
+    }
+
+    /**
+     * Return the environment context object.
+     * @return The environment context.
+     */
+    public org.apache.cocoon.environment.Context getEnvironmentContext() {
+        try {
+            return (org.apache.cocoon.environment.Context)this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+        } catch (ContextException ce) {
+            throw new CoreResourceNotFoundException("Unable to get the environment object from the context.", ce);
+        }
+    }
+
+    /**
+     * Return the Avalon context.
+     * @return The Avalon context.
+     */
+    public Context getContext() {
+        return this.context;
+    }
+
+    /**
+     * Return the current object model
+     * @return The object model.
+     */
+    public Map getCurrentObjectModel() {
+        return ContextHelper.getObjectModel(this.context);
+    }
+
+    /**
+     * Return the work directory.
+     */
+    public File getWorkDirectory() {
+        try {
+            return (File)this.context.get(Constants.CONTEXT_WORK_DIR);
+        } catch (ContextException ce) {
+            throw new CoreResourceNotFoundException("Unable to get the working directory from the context.", ce);
+        }        
+    }
+
+    /**
+     * Return the upload directory.
+     */
+    public File getUploadDirectory() {
+        try {
+            return (File)this.context.get(Constants.CONTEXT_UPLOAD_DIR);
+        } catch (ContextException ce) {
+            throw new CoreResourceNotFoundException("Unable to get the upload directory from the context.", ce);
+        }        
+    }
+
+    /**
+     * Return the cache directory.
+     */
+    public File getCacheDirectory() {
+        try {
+            return (File)this.context.get(Constants.CONTEXT_CACHE_DIR);
+        } catch (ContextException ce) {
+            throw new CoreResourceNotFoundException("Unable to get the cache directory from the context.", ce);
+        }        
+    }
+
+    /**
+     * Return the current sitemap.
+     * @return The current sitemap or null if no request is currently processed
+     */
+    public Sitemap getCurrentSitemap() {
+        Processor p = EnvironmentHelper.getCurrentProcessor();
+        if ( p != null ) {
+            return SITEMAP;            
+        }
+        return null;
+    }
+
+    private final static Sitemap SITEMAP = new SitemapImpl();
+
+    public final static class SitemapImpl implements Sitemap {
+
+        /**
+         * @see org.apache.cocoon.sitemap.Sitemap#getComponentLocator()
+         */
+        public ComponentLocator getComponentLocator() {
+            final ServiceManager m = EnvironmentHelper.getSitemapServiceManager();
+            ComponentLocator l = null;
+            if ( m != null ) {
+                if ( !(m instanceof ComponentLocator) ) {
+                    l = new ComponentLocatorWrapper(m);
+                } else {
+                    l = (ComponentLocator)m;
+                }
+            }
+            return l;
+        }
+
+        /**
+         * @see org.apache.cocoon.sitemap.Sitemap#getProcessor()
+         */
+        public Processor getProcessor() {
+            return EnvironmentHelper.getCurrentProcessor();
+        }
+
+        /**
+         * @see org.apache.cocoon.sitemap.Sitemap#getInterpreter(java.lang.String)
+         */
+        public Interpreter getInterpreter(String language) {
+            // TODO We ignore the language for now
+            return (Interpreter)this.getProcessor().getAttribute(Interpreter.ROLE);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/Core.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class CoreException extends CascadingRuntimeException {
+
+    public CoreException(String message) {
+        super(message, null);
+    }
+
+    public CoreException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreFatalException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreFatalException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreFatalException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreFatalException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public final class CoreFatalException extends CoreException {
+
+    public CoreFatalException(String message) {
+        super(message, null);
+    }
+
+    public CoreFatalException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreFatalException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreInitializationException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreInitializationException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreInitializationException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreInitializationException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public final class CoreInitializationException extends CoreException {
+
+    public CoreInitializationException(String message) {
+        super(message, null);
+    }
+
+    public CoreInitializationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreInitializationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreResourceNotFoundException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreResourceNotFoundException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreResourceNotFoundException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreResourceNotFoundException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public final class CoreResourceNotFoundException extends CoreException {
+
+    public CoreResourceNotFoundException(String message) {
+        super(message, null);
+    }
+
+    public CoreResourceNotFoundException(String message, Throwable cause){
+        super(message, cause);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/core/CoreResourceNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message