You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2003/10/02 18:11:07 UTC

DO NOT REPLY [Bug 23575] New: - [PATCH] (XPath)TraversableGenerator improvements

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23575>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23575

[PATCH] (XPath)TraversableGenerator improvements

           Summary: [PATCH] (XPath)TraversableGenerator improvements
           Product: Cocoon 2
           Version: Current CVS 2.1
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: sitemap components
        AssignedTo: dev@cocoon.apache.org
        ReportedBy: unico@hippo.nl
                CC: arje@hippo.nl


The discussion about this patch took place on the cocoon dev list and can be
found here:

http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106510328905939&w=2

To summerize:
- allow non-collection resources to be input source
- check whether input source exists
- query Context object mime-type mapping when deciding whether to execute the
xpath in XPathTraversableGenerator.

--- unified diffs:

Index: TraversableGenerator.java
===================================================================
RCS file:
/home/cvspublic/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/TraversableGenerator.java,v
retrieving revision 1.2
diff -u -r1.2 TraversableGenerator.java
--- TraversableGenerator.java	25 Sep 2003 17:28:38 -0000	1.2
+++ TraversableGenerator.java	2 Oct 2003 15:48:13 -0000
@@ -308,8 +308,8 @@
         try {
             inputSource = (TraversableSource)
this.resolver.resolveURI(this.source);
 
-            if (!inputSource.isCollection()) {
-                throw new ResourceNotFoundException(this.source + " is not a
collection.");
+            if (!inputSource.exists()) {
+                throw new ResourceNotFoundException(this.source + " does not
exist.");
             }
 
             this.contentHandler.startDocument();
Index: XPathTraversableGenerator.java
===================================================================
RCS file:
/home/cvspublic/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/XPathTraversableGenerator.java,v
retrieving revision 1.1
diff -u -r1.1 XPathTraversableGenerator.java
--- XPathTraversableGenerator.java	4 Sep 2003 12:42:40 -0000	1.1
+++ XPathTraversableGenerator.java	2 Oct 2003 15:48:14 -0000
@@ -61,6 +61,8 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.xml.dom.DOMStreamer;
 import org.apache.excalibur.source.SourceException;
@@ -83,7 +85,10 @@
  * It can be used both as a plain TraversableGenerator or, if an XPath is
  * specified, it will perform an XPath query on every XML resource, where "xml
  * resource" is, by default, any resource ending with ".xml", which can be
- * overriden by setting the (regexp) pattern "xmlFiles as a sitemap parameter.
+ * overriden by setting the (regexp) pattern "xmlFiles as a sitemap parameter, 
+ * or where the name of the resource has a container-wide mime-type mapping to 
+ * 'text/xml' such as specified by mime-mapping elements in a web.xml 
+ * descriptor file.
  * 
  * The XPath can be specified in two ways:
  * <ol>
@@ -150,8 +155,10 @@
 	protected XPathProcessor processor = null;
 	/** The parser for the XML snippets to be included. */
 	protected DOMParser parser = null;
-   /** The prefix resolver for namespaced queries */
+    /** The prefix resolver for namespaced queries */
 	protected XPathPrefixResolver prefixResolver;
+    /** The cocoon context used for mime-type mappings */
+    protected Context context;
 	 	
     public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par)
         throws ProcessingException, SAXException, IOException {
@@ -206,8 +213,10 @@
             	this.prefixResolver.addPrefix(paramName, paramValue);
             }
         }
+        
+        this.context = ObjectModelHelper.getContext(objectModel);
     }
-
+    
     public void service(ServiceManager manager) throws ServiceException {
         super.service(manager);
         processor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
@@ -330,7 +339,8 @@
 	 * otherwise.
 	 */
 	protected boolean isXML(TraversableSource path) {
-		return this.xmlRE.match(path.getName());
+        String mimeType = this.context.getMimeType(path.getName());
+		return this.xmlRE.match(path.getName()) || "text/xml".equalsIgnoreCase(mimeType);
 	}
 	
 	/**
@@ -375,6 +385,9 @@
       this.xpath = null;
       this.attributes = null;
       this.doc = null;
+      this.xmlRE = null;
+      this.prefixResolver = null;
+      this.context = null;
     }
 
     /**