gianugo 2003/10/03 04:45:33
Modified: src/blocks/scratchpad/java/org/apache/cocoon/generation
TraversableGenerator.java
XPathTraversableGenerator.java
Log:
Additions and fixes to the *TraversableGenerator.
- They both can be used with plain resources now
- XML recognition takes into account mime types
- Non exixtent sources now throw Exception
PR: 23575
Submitted by: Unico Hommes ([EMAIL PROTECTED])
Revision Changes Path
1.3 +3 -3
cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/TraversableGenerator.java
Index: TraversableGenerator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/TraversableGenerator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TraversableGenerator.java 25 Sep 2003 17:28:38 -0000 1.2
+++ TraversableGenerator.java 3 Oct 2003 11:45:33 -0000 1.3
@@ -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();
1.2 +18 -5
cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/XPathTraversableGenerator.java
Index: XPathTraversableGenerator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/generation/XPathTraversableGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XPathTraversableGenerator.java 4 Sep 2003 12:42:40 -0000 1.1
+++ XPathTraversableGenerator.java 3 Oct 2003 11:45:33 -0000 1.2
@@ -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;
}
/**