cziegeler 2003/01/30 02:59:24
Modified: src/java/org/apache/cocoon/components/source SourceUtil.java
src/deprecated/java/org/apache/cocoon/environment
SourceResolver.java URLFactorySourceResolver.java
src/java/org/apache/cocoon/transformation
CIncludeTransformer.java
src/java/org/apache/cocoon cocoon.roles
src/java/org/apache/cocoon/environment
AbstractEnvironment.java
Log:
Adding mime-type to cinclude transformer
Revision Changes Path
1.17 +53 -44
xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java
Index: SourceUtil.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SourceUtil.java 30 Jan 2003 08:23:36 -0000 1.16
+++ SourceUtil.java 30 Jan 2003 10:59:23 -0000 1.17
@@ -96,36 +96,49 @@
* <b>NOTE</b> : if the implementation can produce lexical events, care should
be taken
* that <code>handler</code> can actually
* directly implement the LexicalHandler interface!
- * @param source The data
- * @param handler Content handler
- * @param manager Component manager
- *
- * @throws IOException If a io exception occurs.
+ * @param source the data
* @throws ProcessingException if no suitable converter is found
- * @throws SAXException If a SAX exception occurs.
*/
- static public void toSAX(Source source, ContentHandler handler,
- ComponentManager manager)
- throws SAXException, IOException,
- ProcessingException {
- if (source instanceof org.apache.excalibur.xml.sax.XMLizable) {
- ((org.apache.excalibur.xml.sax.XMLizable) source).toSAX(handler);
- } else if (source instanceof org.apache.cocoon.xml.XMLizable) {
- ((org.apache.cocoon.xml.XMLizable) source).toSAX(handler);
+ static public void toSAX( Source source,
+ ContentHandler handler,
+ ComponentManager manager )
+ throws SAXException, IOException, ProcessingException {
+ toSAX(source, null, handler, manager);
+ }
+
+ /**
+ * Generates SAX events from the given source
+ * <b>NOTE</b> : if the implementation can produce lexical events, care should
be taken
+ * that <code>handler</code> can actually
+ * directly implement the LexicalHandler interface!
+ * @param source the data
+ * @throws ProcessingException if no suitable converter is found
+ */
+ static public void toSAX( Source source,
+ String mimeTypeHint,
+ ContentHandler handler,
+ ComponentManager manager )
+ throws SAXException, IOException, ProcessingException {
+ if ( source instanceof org.apache.excalibur.xml.sax.XMLizable ) {
+ ((org.apache.excalibur.xml.sax.XMLizable)source).toSAX( handler );
+ } else if ( source instanceof org.apache.cocoon.xml.XMLizable ) {
+ ((org.apache.cocoon.xml.XMLizable)source).toSAX( handler );
} else {
+ String mimeType = source.getMimeType();
+ if ( null == mimeType) mimeType = mimeTypeHint;
XMLizer xmlizer = null;
-
try {
- xmlizer = (XMLizer) manager.lookup(XMLizer.ROLE);
- xmlizer.toSAX(source.getInputStream(), source.getMimeType(),
- source.getURI(), handler);
+ xmlizer = (XMLizer) manager.lookup( XMLizer.ROLE);
+ xmlizer.toSAX( source.getInputStream(),
+ mimeType,
+ source.getURI(),
+ handler );
} catch (SourceException se) {
throw SourceUtil.handle(se);
} catch (ComponentException ce) {
- throw new ProcessingException("Exception during streaming source.",
- ce);
+ throw new ProcessingException("Exception during streaming source.",
ce);
} finally {
- manager.release((Component) xmlizer);
+ manager.release( (Component)xmlizer );
}
}
}
@@ -135,36 +148,32 @@
* <b>NOTE</b> : if the implementation can produce lexical events, care should
be taken
* that <code>handler</code> can actually
* directly implement the LexicalHandler interface!
- *
- * @param source The data.
- * @param handler Content handler.
- * @param manager Component manager.
- * @param typeParameters
- * @param filterDocumentEvent
- *
- * @throws IOException If a io exception occurs.
+ *
+ * @param source the data
* @throws ProcessingException if no suitable converter is found
- * @throws SAXException If a SAX exception occurs.
*/
- static public void toSAX(Source source, ContentHandler handler,
- ComponentManager manager,
- Parameters typeParameters,
- boolean filterDocumentEvent)
- throws SAXException, IOException,
- ProcessingException {
-
+ static public void toSAX( Source source,
+ ContentHandler handler,
+ ComponentManager manager,
+ Parameters typeParameters,
+ boolean filterDocumentEvent)
+ throws SAXException, IOException, ProcessingException {
+
+
// Test for url rewriting
- if ((typeParameters!=null) &&
- (typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null)!=
- null)) {
+ if (typeParameters != null
+ && typeParameters.getParameter(URLRewriter.PARAMETER_MODE, null) !=
null) {
handler = new URLRewriter(typeParameters, handler);
}
+ String mimeTypeHint = null;
+ if (typeParameters != null) {
+ mimeTypeHint = typeParameters.getParameter("mime-type", mimeTypeHint);
+ }
if (filterDocumentEvent) {
IncludeXMLConsumer filter = new IncludeXMLConsumer(handler);
-
- toSAX(source, filter, manager);
+ toSAX(source, mimeTypeHint, filter, manager);
} else {
- toSAX(source, handler, manager);
+ toSAX(source, mimeTypeHint, handler, manager);
}
}
1.2 +17 -1
xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/SourceResolver.java
Index: SourceResolver.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/SourceResolver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SourceResolver.java 26 Dec 2002 18:38:57 -0000 1.1
+++ SourceResolver.java 30 Jan 2003 10:59:23 -0000 1.2
@@ -85,5 +85,21 @@
void toSAX( org.apache.excalibur.source.Source source,
ContentHandler handler )
throws SAXException, IOException, ProcessingException;
+
+
+ /**
+ * Generates SAX events from the given source
+ * <b>NOTE</b> : if the implementation can produce lexical events, care should
be taken
+ * that <code>handler</code> can actually
+ * directly implement the LexicalHandler interface!
+ * @param source the data
+ * @param mimeTypeHint A hint for the mime-type, if the source does not
+ * provide one
+ * @throws ProcessingException if no suitable converter is found
+ */
+ void toSAX( org.apache.excalibur.source.Source source,
+ String mimeTypeHint,
+ ContentHandler handler )
+ throws SAXException, IOException, ProcessingException;
}
1.2 +15 -1
xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/URLFactorySourceResolver.java
Index: URLFactorySourceResolver.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/deprecated/java/org/apache/cocoon/environment/URLFactorySourceResolver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- URLFactorySourceResolver.java 26 Dec 2002 18:38:57 -0000 1.1
+++ URLFactorySourceResolver.java 30 Jan 2003 10:59:23 -0000 1.2
@@ -152,4 +152,18 @@
throw new RuntimeException("ProcessingException.toSAX() is not implemented
yet.");
}
+ /**
+ * Generates SAX events from the given source
+ * <b>NOTE</b> : if the implementation can produce lexical events, care should
be taken
+ * that <code>handler</code> can actually
+ * directly implement the LexicalHandler interface!
+ * @param source the data
+ * @throws ProcessingException if no suitable converter is found
+ */
+ public void toSAX( org.apache.excalibur.source.Source source,
+ String mimeTypeHint,
+ ContentHandler handler )
+ throws SAXException, IOException, ProcessingException {
+ throw new RuntimeException("ProcessingException.toSAX() is not implemented
yet.");
+ }
}
1.21 +27 -8
xml-cocoon2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
Index: CIncludeTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- CIncludeTransformer.java 30 Jan 2003 08:23:37 -0000 1.20
+++ CIncludeTransformer.java 30 Jan 2003 10:59:23 -0000 1.21
@@ -286,10 +286,16 @@
this.resourceParameters = new SourceParameters();
// Now get the parameters off the stack
String label = (String)stack.pop();
- String value;
+ String key = null;
+ String value = null;
while (!label.equals("end")) {
- value = (String)stack.pop();
- this.resourceParameters.setParameter(label, value);
+ if (label.equals("name")) key = (String)stack.pop();
+ if (label.equals("value")) value = (String)stack.pop();
+ if (key != null && value != null) {
+ this.resourceParameters.setParameter(key, value);
+ key = null;
+ value = null;
+ }
label = (String)stack.pop();
}
@@ -298,10 +304,16 @@
this.configurationParameters = new Parameters();
// Now get the parameters off the stack
String label = (String)stack.pop();
- String value;
+ String key = null;
+ String value = null;
while (!label.equals("end")) {
- value = (String)stack.pop();
- this.configurationParameters.setParameter(label, value);
+ if (label.equals("name")) key = (String)stack.pop();
+ if (label.equals("value")) value = (String)stack.pop();
+ if (key != null && value != null) {
+ this.configurationParameters.setParameter(key, value);
+ key = null;
+ value = null;
+ }
label = (String)stack.pop();
}
@@ -311,11 +323,13 @@
} else if (name.equals(CINCLUDE_NAME_ELEMENT) == true
&& this.state == STATE_INCLUDE) {
stack.push(this.endTextRecording());
+ stack.push("name");
// parameter value
} else if (name.equals(CINCLUDE_VALUE_ELEMENT) == true
&& this.state == STATE_INCLUDE) {
stack.push(this.endSerializedXMLRecording());
+ stack.push("value");
} else {
super.endTransformingElement(uri, name, raw);
@@ -381,7 +395,12 @@
this.manager.release((Component)processor);
}
} else {
- this.resolver.toSAX(source, consumer);
+ String mimeType = null;
+ if ( null != this.configurationParameters ) {
+ mimeType =
this.configurationParameters.getParameter("mime-type", mimeType);
+ System.out.println("Using mime-type:" +mimeType);
+ }
+ this.resolver.toSAX(source, mimeType, consumer);
}
1.45 +2 -0 xml-cocoon2/src/java/org/apache/cocoon/cocoon.roles
Index: cocoon.roles
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/cocoon.roles,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- cocoon.roles 22 Jan 2003 05:19:17 -0000 1.44
+++ cocoon.roles 30 Jan 2003 10:59:23 -0000 1.45
@@ -44,6 +44,8 @@
shorthand="entity-resolver"
default-class="org.apache.cocoon.components.resolver.ResolverImpl"/>
+ <!-- A Dom Serializer -->
+ <role default-class="org.apache.excalibur.xml.dom.DefaultDOMSerializer"
name="org.apache.excalibur.xml.dom.DOMSerializer" shorthand="dom-serializer"/>
<!-- XSLT:
-->
1.36 +11 -2
xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
Index: AbstractEnvironment.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- AbstractEnvironment.java 30 Jan 2003 08:23:39 -0000 1.35
+++ AbstractEnvironment.java 30 Jan 2003 10:59:23 -0000 1.36
@@ -529,6 +529,15 @@
public void toSAX( org.apache.excalibur.source.Source source,
ContentHandler handler )
throws SAXException, IOException, ProcessingException {
+ this.toSAX( source, null, handler);
+ }
+
+ public void toSAX( org.apache.excalibur.source.Source source,
+ String mimeTypeHint,
+ ContentHandler handler )
+ throws SAXException, IOException, ProcessingException {
+ String mimeType = source.getMimeType();
+ if ( null == mimeType) mimeType = mimeTypeHint;
if ( source instanceof org.apache.excalibur.xml.sax.XMLizable ) {
((org.apache.excalibur.xml.sax.XMLizable)source).toSAX( handler );
} else if ( source instanceof org.apache.cocoon.xml.XMLizable ) {
@@ -536,7 +545,7 @@
} else {
try {
xmlizer.toSAX( source.getInputStream(),
- source.getMimeType(),
+ mimeType,
source.getURI(),
handler );
} catch (SourceException se) {
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]