You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/09/01 15:41:11 UTC
svn commit: r265724 -
/cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
Author: sylvain
Date: Thu Sep 1 06:41:08 2005
New Revision: 265724
URL: http://svn.apache.org/viewcvs?rev=265724&view=rev
Log:
Fix bug #35575, thanks to Jean-Baptiste Quenot <jb...@anyware-tech.com>
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java?rev=265724&r1=265723&r2=265724&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java Thu Sep 1 06:41:08 2005
@@ -15,17 +15,26 @@
*/
package org.apache.cocoon.components.source.impl;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+
import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.cocoon.CascadingIOException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.source.helpers.SourceCredential;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.xml.IncludeXMLConsumer;
@@ -34,7 +43,6 @@
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.xml.sax.XMLizable;
-
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@@ -48,13 +56,6 @@
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.modules.XPathQueryService;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-
/**
* This class implements the xmldb:// pseudo-protocol and allows to get XML
* content from an XML:DB enabled XML database.
@@ -433,31 +434,25 @@
}
/**
- * Get an InputSource for the given URL. Shamelessly stolen
- * from SitemapSource.
- *
+ * Get an InputSource for the given URL.
*/
public InputStream getInputStream()
throws IOException {
- ServiceManager manager = null;
ServiceSelector serializerSelector = null;
Serializer serializer = null;
// this.manager does not have Serializer
try {
- manager = (ServiceManager) this.context.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
- serializerSelector = (ServiceSelector) manager.lookup(Serializer.ROLE + "Selector");
- serializer = (Serializer)serializerSelector.select("xml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- serializer.setOutputStream(os);
-
- toSAX(serializer);
-
- return new ByteArrayInputStream(os.toByteArray());
- } catch (ServiceException e) {
- throw new CascadingIOException("Could not lookup pipeline components", e);
- } catch (ContextException ce) {
- throw new CascadingIOException("Could not get service manager.", ce);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ TransformerHandler th =
+ ((SAXTransformerFactory) tf).newTransformerHandler();
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(bOut);
+ th.setResult(result);
+
+ toSAX(th);
+
+ return new ByteArrayInputStream(bOut.toByteArray());
} catch (Exception e) {
throw new CascadingIOException("Exception during processing of " + getURI(), e);
} finally {