cziegeler 02/05/02 03:41:20 Modified: lib/core avalon-excalibur-20020501.jar src/java/org/apache/cocoon/webapps/session/connector ResourceConnector.java ResourceConnectorImpl.java Log: Fixed POST of resource connector Revision Changes Path 1.2 +383 -327 xml-cocoon2/lib/core/avalon-excalibur-20020501.jar <<Binary file>> 1.3 +1 -3 xml-cocoon2/src/java/org/apache/cocoon/webapps/session/connector/ResourceConnector.java Index: ResourceConnector.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/webapps/session/connector/ResourceConnector.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ResourceConnector.java 19 Apr 2002 11:02:58 -0000 1.2 +++ ResourceConnector.java 2 May 2002 10:41:20 -0000 1.3 @@ -70,7 +70,7 @@ * identifies the resource itself (filename, http-address etc). * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: ResourceConnector.java,v 1.2 2002/04/19 11:02:58 cziegeler Exp $ + * @version CVS $Id: ResourceConnector.java,v 1.3 2002/05/02 10:41:20 cziegeler Exp $ */ public interface ResourceConnector extends Component { @@ -89,8 +89,6 @@ * The <code>typeParameter</code> "method" specifies the http method (POST, * GET etc) - standard is POST if parameters are used, without parameters * it is GET. - * The <code>typeParameter</code> "followRedirects" specifies if the - * connection should follow redirects. * URLRewriting can be turned on by specifying the parameters defined * for the <code>URLRewriter</code>. * If an URI is saved (e.g. saveXML) this is the same as loading from 1.3 +54 -49 xml-cocoon2/src/java/org/apache/cocoon/webapps/session/connector/ResourceConnectorImpl.java Index: ResourceConnectorImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/webapps/session/connector/ResourceConnectorImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ResourceConnectorImpl.java 19 Apr 2002 11:02:58 -0000 1.2 +++ ResourceConnectorImpl.java 2 May 2002 10:41:20 -0000 1.3 @@ -55,8 +55,12 @@ import java.util.*; import org.apache.avalon.excalibur.pool.Recyclable; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceParameters; import org.apache.excalibur.source.SourceUtil; +import org.apache.excalibur.source.impl.URLSource; +import org.apache.avalon.excalibur.xml.Parser; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; @@ -72,14 +76,11 @@ import org.apache.cocoon.Processor; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.components.RequestLifecycleComponent; -import org.apache.cocoon.components.parser.Parser; -import org.apache.cocoon.components.source.URLSource; import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Response; -import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.webapps.session.xml.XMLUtil; import org.apache.cocoon.xml.XMLConsumer; @@ -97,7 +98,7 @@ * The Component for loading and saving xml to external resource connectors. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: ResourceConnectorImpl.java,v 1.2 2002/04/19 11:02:58 cziegeler Exp $ + * @version CVS $Id: ResourceConnectorImpl.java,v 1.3 2002/05/02 10:41:20 cziegeler Exp $ */ public final class ResourceConnectorImpl extends AbstractLoggable @@ -174,8 +175,7 @@ private Source getSource(String uri, Parameters typeParameters, SourceParameters resourceParameters) - throws IOException, SAXException, ProcessingException { - Source input; + throws IOException, SAXException, SourceException { // Test: local uri (= same servlet/cocoon) ? if (uri.startsWith("/") == true) { @@ -244,16 +244,10 @@ if (this.getLogger().isInfoEnabled() == true) { this.getLogger().info("Getting content of '"+uri+"' using method " + method); } - input = this.resolver.resolve(uri); - if (method.equalsIgnoreCase("POST") == true - && input instanceof URLSource) { - ((URLSource)input).setPostParameters(resourceParameters); - } - if (followRedirects == false && input instanceof URLSource) { - ((URLSource)input).setFollowRedirects(false); - } - - return input; + Map resolverParameters = new java.util.HashMap(); + resolverParameters.put(URLSource.HTTP_METHOD, method); + resolverParameters.put(URLSource.REQUEST_PARAMETERS, resourceParameters); + return this.resolver.resolveURI(uri, null, resolverParameters); } /** @@ -262,7 +256,7 @@ private DocumentFragment loadXMLFromURI(Parameters typeParameters, String uri, SourceParameters resourceParameters) - throws IOException, SAXException, ProcessingException { + throws IOException, SAXException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN loadXMLFromURI uri=" + uri + ", typeParams="+typeParameters+ @@ -297,10 +291,10 @@ input = this.getSource(uri, typeParameters, resourceParameters); if (input != null) { - input.toSAX(filter); + this.resolver.toSAX(input, filter); } } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -333,7 +327,7 @@ String uri, SourceParameters resourceParameters, DocumentFragment fragment) - throws IOException, SAXException, ProcessingException { + throws IOException, SAXException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN saveXMLToURI fragment="+(fragment == null ? "null" : XMLUtils.serializeNodeToXML(fragment))+ ", typeParams="+typeParameters+ @@ -370,7 +364,7 @@ String uri, SourceParameters resourceParameters, String content) - throws IOException, SAXException, ProcessingException { + throws IOException, SAXException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN saveContentToURI content="+content+ ", typeParams="+typeParameters+ @@ -467,7 +461,7 @@ private DocumentFragment loadXMLFromFile(Parameters typeParameters, String fileName, SourceParameters resourceParameters) - throws ProcessingException, IOException, SAXException { + throws ProcessingException, IOException, SourceException, SAXException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN loadXMLFromFile fileName=" + fileName+ ", typeParams="+typeParameters+ @@ -479,14 +473,14 @@ Source input = null; try { - input = this.resolver.resolve(fileName); + input = this.resolver.resolveURI(fileName); DOMBuilder builder = new DOMBuilder(); builder.startDocument(); builder.startElement("", "cocoon", "cocoon", this.emptyAttributes); IncludeXMLConsumer filter = new IncludeXMLConsumer(builder, builder); - input.toSAX(filter); + this.resolver.toSAX( input, filter ); builder.endElement("", "cocoon", "cocoon"); builder.endDocument(); @@ -503,7 +497,7 @@ frag.appendChild(child); } } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -521,7 +515,7 @@ String fileName, SourceParameters resourceParameters, DocumentFragment fragment) - throws SAXException, IOException, ProcessingException { + throws SAXException, IOException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN saveXMLToFile fragment="+(fragment == null ? "null" : XMLUtils.serializeNodeToXML(fragment))+ ", typeParams="+typeParameters+ @@ -553,7 +547,7 @@ try { Properties format = XMLUtils.defaultSerializeToXMLFormat(false); this.setOutputKeys(format, typeParameters); - input = this.resolver.resolve(fileName); + input = this.resolver.resolveURI(fileName); String absolutePath = input.getSystemId(); if (absolutePath.startsWith("file:") == false) { throw new ProcessingException("Saving to " + fileName + " is not possible."); @@ -573,7 +567,7 @@ writer.close(); writer = null; } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -593,7 +587,7 @@ String fileName, SourceParameters resourceParameters, String content) - throws SAXException, IOException, ProcessingException { + throws SAXException, IOException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN saveContentToFile content="+content+ ", typeParams="+typeParameters+ @@ -603,7 +597,7 @@ try { Source input = null; try { - input = this.resolver.resolve(fileName); + input = this.resolver.resolveURI(fileName); String absolutePath = input.getSystemId(); if (absolutePath.startsWith("file:") == false) { throw new ProcessingException("Saving to " + fileName + " is not possible."); @@ -622,7 +616,7 @@ writer.close(); writer = null; } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -661,6 +655,8 @@ default: throw new ProcessingException("ResourceConnector: type " + resourceType + " not supported."); } + } catch (SourceException se) { + throw new ProcessingException("SourceException: " + se, se); } catch (SAXException ioe) { throw new ProcessingException("SAXException: " + ioe, ioe); } catch (IOException ioe) { @@ -698,6 +694,8 @@ default: throw new ProcessingException("ResourceConnector: type " + resourceType + " not supported."); } + } catch (SourceException se) { + throw new ProcessingException("SourceException: " + se, se); } catch (SAXException ioe) { throw new ProcessingException("SAXException: " + ioe, ioe); } catch (IOException ioe) { @@ -725,17 +723,19 @@ long startTime = System.currentTimeMillis(); Source input = null; try { - input = this.resolver.resolve(fileName); + input = this.resolver.resolveURI(fileName); IncludeXMLConsumer filter = new IncludeXMLConsumer(contentHandler, lexicalHandler); - input.toSAX(filter); + this.resolver.toSAX( input, filter ); + } catch (SourceException se) { + throw new ProcessingException("SourceException: " + se, se); } catch (SAXException sax) { throw new ProcessingException("SAXException: " + sax, sax); } catch (IOException ioe) { throw new ProcessingException("IOException: " + ioe, ioe); } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -752,7 +752,7 @@ SourceParameters resourceParameters, org.xml.sax.ContentHandler contentHandler, LexicalHandler lexicalHandler) - throws IOException, SAXException, ProcessingException { + throws IOException, SAXException, SourceException, ProcessingException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN streamXMLFromURI uri=" + uri + ", typeParams="+typeParameters+ @@ -780,9 +780,9 @@ Source input = null; try { input = this.getSource(uri, typeParameters, resourceParameters); - input.toSAX(filter); + this.resolver.toSAX( input, filter ); } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -821,6 +821,8 @@ default: throw new ProcessingException("ResourceConnector: type " + resourceType + " not supported."); } + } catch (SourceException ioe) { + throw new ProcessingException("SourceException: " + ioe, ioe); } catch (SAXException ioe) { throw new ProcessingException("SAXException: " + ioe, ioe); } catch (IOException ioe) { @@ -838,7 +840,7 @@ private String getContentFromURI(Parameters typeParameters, String uri, SourceParameters resourceParameters) - throws SAXException, ProcessingException, IOException { + throws SAXException, ProcessingException, SourceException, IOException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN getContentFromURI uri=" + uri + ", typeParams="+typeParameters+ @@ -854,10 +856,9 @@ Source input = null; try { input = this.getSource(uri, typeParameters, resourceParameters); - InputSource source = input.getInputSource(); - InputStream stream = source.getByteStream(); + InputStream stream = input.getInputStream(); StringBuffer buffer = new StringBuffer(); - String encoding = source.getEncoding(); + //String encoding = source.getEncoding(); int available; byte[] data; do { @@ -865,16 +866,16 @@ data = new byte[available]; available = stream.read(data, 0, available); if (available > 0) { - if (encoding == null) { + //if (encoding == null) { buffer.append(new String(data, 0, available)); - } else { - buffer.append(new String(data, 0, available, encoding)); - } + //} else { + // buffer.append(new String(data, 0, available, encoding)); + //} } } while (available > 0); content = buffer.toString(); } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } @@ -890,7 +891,7 @@ private String getContentFromFile(Parameters typeParameters, String filename, SourceParameters resourceParameters) - throws SAXException, ProcessingException, IOException { + throws SAXException, ProcessingException, SourceException, IOException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN getContentFromFile filename=" + filename + ", typeParams="+typeParameters+ @@ -899,7 +900,7 @@ String content; Source input = null; try { - input = this.resolver.resolve(filename); + input = this.resolver.resolveURI(filename); String absolutePath = input.getSystemId(); if (absolutePath.startsWith("file:") == false) { throw new ProcessingException("Saving to " + filename + " is not possible."); @@ -928,7 +929,7 @@ } catch (FileNotFoundException local) { throw new ResourceNotFoundException("File not found '" + filename + "'", local); } finally { - if (input != null) input.recycle(); + this.resolver.release(input); input = null; } if (this.getLogger().isDebugEnabled() == true) { @@ -960,6 +961,8 @@ default: throw new ProcessingException("ResourceConnector: type " + resourceType + " not supported."); } + } catch (SourceException local) { + throw new ProcessingException("SourceException: " + local, local); } catch (SAXException local) { throw new ProcessingException("SAXException: " + local, local); } catch (IOException local) { @@ -1002,6 +1005,8 @@ default: throw new ProcessingException("ResourceConnector: type " + resourceType + " not supported."); } + } catch (SourceException local) { + throw new ProcessingException("SourceException: " + local, local); } catch (SAXException local) { throw new ProcessingException("SAXException: " + local, local); } catch (IOException local) {
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]