cziegeler 2002/09/25 03:40:25 Modified: src/java/org/apache/cocoon/transformation CIncludeTransformer.java Log: Fixing xpath handling of cinclude transformer Revision Changes Path 1.10 +18 -22 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CIncludeTransformer.java 10 Sep 2002 12:15:49 -0000 1.9 +++ CIncludeTransformer.java 25 Sep 2002 10:40:25 -0000 1.10 @@ -50,6 +50,7 @@ */ package org.apache.cocoon.transformation; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; @@ -105,7 +106,6 @@ /** The current <code>ComponentManager</code>. */ protected ComponentManager manager = null; - private XPathProcessor processor = null; /** * Setup the component. @@ -121,11 +121,6 @@ */ public final void compose(final ComponentManager manager) { this.manager = manager; - try { - this.processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE); - } catch (Exception e) { - getLogger().error("cannot obtain XPathProcessor", e); - } } /** @@ -162,7 +157,8 @@ super.endElement(uri, name, raw); } - protected void processCIncludeElement(String src, String element, String select, String ns, String prefix) + protected void processCIncludeElement(String src, String element, + String select, String ns, String prefix) throws SAXException { if (element == null) element=""; @@ -192,36 +188,37 @@ } Source source = null; - Parser parser = null; try { source = this.sourceResolver.resolveURI(src); if (!"".equals(select)) { - - parser = (Parser)manager.lookup(Parser.ROLE); + + Parser parser = null; + XPathProcessor processor = null; + + try { + parser = (Parser)this.manager.lookup(Parser.ROLE); + processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE); InputSource input = SourceUtil.getInputSource(source); - String xpath = select; - if (this.getLogger().isDebugEnabled()) { - getLogger().debug("XPath is "+xpath); - } Document document = parser.parseDocument(input); - NodeList list = processor.selectNodeList(document,xpath); + NodeList list = processor.selectNodeList(document, select); int length = list.getLength(); for (int i=0; i<length; i++) { consumer.includeNode((Node)list.item(i), (ContentHandler)this, (LexicalHandler)this); } + } finally { + this.manager.release(parser); + this.manager.release((Component)processor); + } } else { - // do nothing, will result in the inclusion of the whole - // document + this.sourceResolver.toSAX(source, consumer); } - this.sourceResolver.toSAX(source, consumer); - } catch (IOException e) { throw new SAXException("CIncludeTransformer could not read resource", e); @@ -232,8 +229,7 @@ } catch(ComponentException e) { throw new SAXException(e); } finally { - this.manager.release(parser); - this.sourceResolver.release(source); + this.sourceResolver.release(source); } if (!"".equals(element)) {
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]