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:43 UTC
svn commit: r265726 -
/cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
Author: sylvain
Date: Thu Sep 1 06:41:41 2005
New Revision: 265726
URL: http://svn.apache.org/viewcvs?rev=265726&view=rev
Log:
Fix bug #35575, thanks to Jean-Baptiste Quenot <jb...@anyware-tech.com>
Modified:
cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
Modified: cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java?rev=265726&r1=265725&r2=265726&view=diff
==============================================================================
--- cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java (original)
+++ cocoon/blocks/xmldb/trunk/java/org/apache/cocoon/components/source/impl/XMLDBSource.java Thu Sep 1 06:41:41 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,20 +56,13 @@
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.
*
* @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
- * @version CVS $Id: XMLDBSource.java,v 1.18 2004/06/11 14:27:32 upayavira Exp $
+ * @version CVS $Id$
*/
public class XMLDBSource extends AbstractLogEnabled
implements Source, ModifiableSource, XMLizable {
@@ -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 {