cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r225582 - in /cocoon/trunk: ./ src/java/org/apache/cocoon/components/source/impl/ src/java/org/apache/cocoon/generation/ src/webapp/WEB-INF/xconf/
Date Wed, 27 Jul 2005 19:26:13 GMT
Author: cziegeler
Date: Wed Jul 27 12:26:02 2005
New Revision: 225582

URL: http://svn.apache.org/viewcvs?rev=225582&view=rev
Log:
    <action dev="CZ" type="add" fixes-bug="35521" due-to="Mark Lundquist" due-to-email="mlundquist2@comcast.net">
      Added the create-document source than either generates empty documents or documents
containing
      just a root node.
    </action>
    <action dev="CZ" type="fix" fixes-bug="35457" due-to="Doug Bennett" due-to-email="dbennett1556@netscape.net">
      Fix NPE in RequestGenerator when request.getHeaderNames() returns null.
    </action>

Added:
    cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
  (with props)
    cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
  (with props)
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/generation/RequestGenerator.java
    cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf
    cocoon/trunk/status.xml

Added: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java?rev=225582&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
(added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
Wed Jul 27 12:26:02 2005
@@ -0,0 +1,136 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * A <code>Source</code> that generates an empty XML document or an
+ * XML document just containing a root node.
+ * The URI syntax is "create-document:" or "create-document:ROOT_ELEMENT_NAME".
+ *
+ * @version $Id:$
+ * @since 2.1.8
+ */
+public class CreateDocumentSource
+    implements XMLizable, Source {
+
+    protected String rootElementName;
+    protected String scheme;
+    protected String uri;
+    protected String xmlDocument;
+
+    public CreateDocumentSource(String location) {
+        this.uri = location;
+        final int pos = location.indexOf(':');
+        this.scheme = location.substring(0, pos);
+        final String rootName = location.substring(pos+1);
+        if (rootName != null && rootName.trim().length() > 0 ) {
+            this.rootElementName = rootName.trim();
+            this.xmlDocument = '<' + this.rootElementName + "/>";
+        } else {
+            this.xmlDocument = "";
+        }
+    }
+
+    /**
+     * @see org.apache.excalibur.xml.sax.XMLizable#toSAX(org.xml.sax.ContentHandler)
+     */
+    public void toSAX(ContentHandler handler) throws SAXException {
+        handler.startDocument();
+        if ( rootElementName != null ) {
+            XMLUtils.createElement(handler, this.rootElementName);
+        }
+        handler.endDocument();
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#exists()
+     */
+    public boolean exists() {
+        return true;
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getContentLength()
+     */
+    public long getContentLength() {
+        return this.xmlDocument.length();
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getInputStream()
+     */
+    public InputStream getInputStream() throws IOException, SourceNotFoundException {
+        return new ByteArrayInputStream(this.xmlDocument.getBytes("utf-8"));
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getLastModified()
+     */
+    public long getLastModified() {
+        // this document *never* changes
+        return 1;
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getMimeType()
+     */
+    public String getMimeType() {
+        return "text/xml";
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getScheme()
+     */
+    public String getScheme() {
+        return this.scheme;
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getURI()
+     */
+    public String getURI() {
+        return this.uri;
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#getValidity()
+     */
+    public SourceValidity getValidity() {
+        return NOPValidity.SHARED_INSTANCE;
+    }
+
+    /**
+     * @see org.apache.excalibur.source.Source#refresh()
+     */
+    public void refresh() {
+        // nothing to do here
+    }
+
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSource.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java?rev=225582&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
(added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
Wed Jul 27 12:26:02 2005
@@ -0,0 +1,57 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+
+/**
+ * A factory for 'create-document:' sources (see {@link CreateDocumentSource}).
+ * 
+ * @version $Id:$
+ * @since 2.1.8
+ */
+public class CreateDocumentSourceFactory 
+    extends AbstractLogEnabled
+    implements SourceFactory, ThreadSafe {
+    
+    /**
+     * Get a {@link CreateDocumentSource} object.
+     * 
+     * @param location   The URI to resolve - this URI includes the scheme.
+     * @param parameters this is optional and not used here
+     *
+     * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+     */
+    public Source getSource( String location, Map parameters )
+    throws IOException, MalformedURLException {
+        return new CreateDocumentSource(location);
+    }
+    
+    /**
+     * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+     */
+    public void release( Source source ) {
+        // Do nothing here
+    }
+
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/CreateDocumentSourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/RequestGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/RequestGenerator.java?rev=225582&r1=225581&r2=225582&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/RequestGenerator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/RequestGenerator.java Wed Jul 27 12:26:02
2005
@@ -120,12 +120,14 @@
 
         start("requestHeaders", attr);
         Enumeration headers = request.getHeaderNames();
-        while (headers.hasMoreElements()) {
-            String header = (String)headers.nextElement();
-            attribute(attr, "name", header);
-            start("header", attr);
-            data(request.getHeader(header));
-            end("header");
+        if ( headers != null ) {
+            while (headers.hasMoreElements()) {
+                String header = (String)headers.nextElement();
+                attribute(attr, "name", header);
+                start("header", attr);
+                data(request.getHeader(header));
+                end("header");
+            }
         }
         end("requestHeaders");
 

Modified: cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf?rev=225582&r1=225581&r2=225582&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf (original)
+++ cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf Wed Jul 27 12:26:02 2005
@@ -540,6 +540,8 @@
     <component-instance name="module" class="org.apache.cocoon.components.source.impl.ModuleSourceFactory"/>
     <component-instance name="xmodule" class="org.apache.cocoon.components.source.impl.XModuleSourceFactory"/>
 
+    <component-instance name="create-document" class="org.apache.cocoon.components.source.impl.CreateDocumentSourceFactory"/>
+
     <!--+
         | The "*" protocol handles all uri schemes that are not explicitely
         | specified. This includes all JDK standard protocols.

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=225582&r1=225581&r2=225582&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Wed Jul 27 12:26:02 2005
@@ -509,6 +509,13 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
+    <action dev="CZ" type="add" fixes-bug="35521" due-to="Mark Lundquist" due-to-email="mlundquist2@comcast.net">
+      Added the create-document source than either generates empty documents or documents
containing
+      just a root node.
+    </action>
+    <action dev="CZ" type="fix" fixes-bug="35457" due-to="Doug Bennett" due-to-email="dbennett1556@netscape.net">
+      Fix NPE in RequestGenerator when request.getHeaderNames() returns null.
+    </action>
     <action dev="CZ" type="fix" fixes-bug="29506" due-to-email="tobias@lentus.se">
       Fix wrong caching behaviour in DirectoryGenerator.
     </action>



Mime
View raw message