dims 01/09/19 12:37:56
Modified: . build.xml
src/org/apache/cocoon cocoon.roles
src/org/apache/cocoon/generation HTMLGenerator.java
src/org/apache/cocoon/i18n XMLResourceBundle.java
src/org/apache/cocoon/transformation I18nTransformer.java
XIncludeTransformer.java
webapp cocoon.xconf
Added: src/org/apache/cocoon/components/xpath
JaxenProcessorImpl.java XPathProcessor.java
XPathProcessorImpl.java
Log:
- Componentized XPath Processor
- Added Jaxen support for xpath expressions.
Revision Changes Path
1.64 +5 -4 xml-cocoon2/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/build.xml,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- build.xml 2001/09/19 16:47:26 1.63
+++ build.xml 2001/09/19 19:37:55 1.64
@@ -279,6 +279,9 @@
<available property="xpath.present" classname="org.apache.xpath.XPathAPI">
<classpath refid="classpath"/>
</available>
+ <available property="jaxen.present" classname="org.jaxen.dom.XPath">
+ <classpath refid="classpath"/>
+ </available>
<available property="ora.driver.present"
classname="oracle.jdbc.OracleResultSet">
<classpath refid="classpath"/>
</available>
@@ -421,11 +424,9 @@
<exclude name="**/renderer/*" unless="fop.present"/>
<exclude name="**/Php*" unless="php.present"/>
<exclude name="**/HTMLGenerator.java" unless="tidy.present"/>
- <exclude name="**/HTMLGenerator.java" unless="xpath.present"/>
<exclude name="**/J2eeDataSource.java" unless="j2ee.present"/>
- <exclude name="**/XIncludeTransformer.java" unless="xpath.present"/>
- <exclude name="**/I18n*" unless="xpath.present"/>
- <exclude name="**/i18n/*" unless="xpath.present"/>
+ <exclude name="**/xpath/XPathProcessorImpl*" unless="xpath.present"/>
+ <exclude name="**/Jaxen*" unless="jaxen.present"/>
<exclude name="**/Ora*" unless="ora.driver.present"/>
</javac>
</target>
1.22 +4 -0 xml-cocoon2/src/org/apache/cocoon/cocoon.roles
Index: cocoon.roles
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- cocoon.roles 2001/09/07 14:30:10 1.21
+++ cocoon.roles 2001/09/19 19:37:55 1.22
@@ -9,6 +9,10 @@
shorthand="xslt-processor"
default-class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"/>
+ <role name="org.apache.cocoon.components.xpath.XPathProcessor"
+ shorthand="xpath-processor"
+ default-class="org.apache.cocoon.components.xpath.XPathProcessorImpl"/>
+
<role name="org.apache.cocoon.components.browser.Browser"
shorthand="browser"
default-class="org.apache.cocoon.components.browser.BrowserImpl"/>
1.1
xml-cocoon2/src/org/apache/cocoon/components/xpath/JaxenProcessorImpl.java
Index: JaxenProcessorImpl.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.xpath;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.jaxen.dom.XPath;
import org.jaxen.JaxenException;
import java.util.List;
/**
* This class defines the implementation of the {@link XPathProcessor}
* component.
*
* To configure it, add the following lines in the
* <file>cocoon.xconf</file> file:
*
* <pre>
* <xslt-processor
class="org.apache.cocoon.components.xpath.JaxenProcessorImpl">
* </xslt-processor>
* </pre>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/09/19 19:37:55 $ $Author: dims $
*/
public class JaxenProcessorImpl
extends AbstractLoggable
implements XPathProcessor, Component
{
/**
* Use an XPath string to select a single node. XPath namespace
* prefixes are resolved from the context node, which may not
* be what you want (see the next method).
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return The first node found that matches the XPath, or null.
*/
public Node selectSingleNode(Node contextNode, String str)
{
try {
XPath path = new XPath(str);
return (Node)path.selectSingleNode((Object)contextNode);
} catch (Exception e){
return null;
}
}
/**
* Use an XPath string to select a nodelist.
* XPath namespace prefixes are resolved from the contextNode.
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return A NodeList, should never be null.
*/
public NodeList selectNodeList(Node contextNode, String str)
{
try {
XPath path = new XPath(str);
List list = path.selectNodes((Object)contextNode);
return new NodeListEx(list);
} catch (Exception e){
return new NodeListEx();
}
}
class NodeListEx implements NodeList{
List list = null;
NodeListEx(){
}
NodeListEx(List l){
list = l;
}
public Node item(int index) {
if(list==null)
return null;
return (Node)list.get(index);
}
public int getLength(){
if(list==null)
return 0;
return list.size();
}
}
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/xpath/XPathProcessor.java
Index: XPathProcessor.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.xpath;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This is the interface of the XPath processor in Cocoon.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/09/19 19:37:55 $ $Author: dims $
*/
public interface XPathProcessor
{
/**
* The role implemented by an <code>XSLTProcessor</code>.
*/
String ROLE = "org.apache.cocoon.components.xpath.XPathProcessor";
/**
* Use an XPath string to select a single node. XPath namespace
* prefixes are resolved from the context node, which may not
* be what you want (see the next method).
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return The first node found that matches the XPath, or null.
*/
public Node selectSingleNode(Node contextNode, String str);
/**
* Use an XPath string to select a nodelist.
* XPath namespace prefixes are resolved from the contextNode.
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return A List, should never be null.
*/
public NodeList selectNodeList(Node contextNode, String str);
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/xpath/XPathProcessorImpl.java
Index: XPathProcessorImpl.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.xpath;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xpath.XPathAPI;
/**
* This class defines the implementation of the {@link XPathProcessor}
* component.
*
* To configure it, add the following lines in the
* <file>cocoon.xconf</file> file:
*
* <pre>
* <xslt-processor
class="org.apache.cocoon.components.xpath.XPathProcessorImpl">
* </xslt-processor>
* </pre>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/09/19 19:37:55 $ $Author: dims $
*/
public class XPathProcessorImpl
extends AbstractLoggable
implements XPathProcessor, Component
{
/**
* Use an XPath string to select a single node. XPath namespace
* prefixes are resolved from the context node, which may not
* be what you want (see the next method).
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return The first node found that matches the XPath, or null.
*/
public Node selectSingleNode(Node contextNode, String str)
{
try {
return XPathAPI.selectSingleNode(contextNode, str);
} catch (javax.xml.transform.TransformerException e){
return null;
}
}
/**
* Use an XPath string to select a nodelist.
* XPath namespace prefixes are resolved from the contextNode.
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @return A NodeList, should never be null.
*/
public NodeList selectNodeList(Node contextNode, String str)
{
try {
return XPathAPI.selectNodeList(contextNode, str);
} catch (javax.xml.transform.TransformerException e){
return new NodeList(){
public Node item(int index) { return null;}
public int getLength(){return 0;}
};
}
}
}
1.13 +31 -8 xml-cocoon2/src/org/apache/cocoon/generation/HTMLGenerator.java
Index: HTMLGenerator.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/HTMLGenerator.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HTMLGenerator.java 2001/08/22 03:51:05 1.12
+++ HTMLGenerator.java 2001/09/19 19:37:55 1.13
@@ -8,10 +8,16 @@
package org.apache.cocoon.generation;
import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.activity.Disposable;
+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;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.components.xpath.XPathProcessor;
import org.apache.cocoon.caching.CacheValidity;
import org.apache.cocoon.caching.Cacheable;
import org.apache.cocoon.caching.TimeStampCacheValidity;
@@ -20,8 +26,8 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.util.HashUtil;
import org.apache.cocoon.xml.dom.DOMStreamer;
-import org.apache.xpath.XPathAPI;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.w3c.dom.traversal.NodeIterator;
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;
@@ -39,9 +45,9 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.12 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.13 $ $Date: 2001/09/19 19:37:55 $
*/
-public class HTMLGenerator extends ComposerGenerator implements Cacheable,
Recyclable {
+public class HTMLGenerator extends ComposerGenerator implements Cacheable,
Recyclable, Composable, Disposable {
/** The source */
private Source inputSource;
@@ -49,6 +55,18 @@
/** XPATH expression */
private String xpath = null;
+ /** XPath Processor */
+ private XPathProcessor processor = null;
+
+ public void compose(ComponentManager manager) {
+ this.manager = manager;
+ try {
+ this.processor =
(XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
+ } catch (Exception e) {
+ getLogger().error("cannot obtain XPathProcessor", e);
+ }
+ }
+
/**
* Recycle this component.
* All instance variables are set to <code>null</code>.
@@ -144,13 +162,13 @@
Transformer serializer =
TransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
- Node n;
- while ((n = nl.nextNode())!= null)
- {
+ NodeList nl = processor.selectNodeList(doc, xpath);
+ int length = nl.getLength();
+ for(int i=0;i<length;i++)
+ {
SAXResult result = new SAXResult(this.contentHandler);
result.setLexicalHandler(this.lexicalHandler);
- serializer.transform(new DOMSource(n), result);
+ serializer.transform(new DOMSource(nl.item(i)), result);
}
} else {
DOMStreamer streamer = new
DOMStreamer(this.contentHandler,this.lexicalHandler);
@@ -169,5 +187,10 @@
getLogger().error("Could not setup jtidy", e);
throw new ProcessingException("Exception in
HTMLGenerator.generate()",e);
}
+ }
+
+ public void dispose()
+ {
+ this.manager.release((Component)this.processor);
}
}
1.3 +30 -4 xml-cocoon2/src/org/apache/cocoon/i18n/XMLResourceBundle.java
Index: XMLResourceBundle.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/i18n/XMLResourceBundle.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLResourceBundle.java 2001/08/20 13:55:16 1.2
+++ XMLResourceBundle.java 2001/09/19 19:37:56 1.3
@@ -9,10 +9,16 @@
package org.apache.cocoon.i18n;
/** JDK classes **/
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.activity.Disposable;
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;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.logger.Loggable;
+import org.apache.cocoon.components.xpath.XPathProcessor;
import org.apache.log.Logger;
-import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -35,11 +41,11 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Engelhart</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Neeme Praks</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Oleg Podolsky</a>
- * @version $Id: XMLResourceBundle.java,v 1.2 2001/08/20 13:55:16 dims Exp $
+ * @version $Id: XMLResourceBundle.java,v 1.3 2001/09/19 19:37:56 dims Exp $
*/
public class XMLResourceBundle
extends ResourceBundle
- implements Loggable, Component
+ implements Loggable, Component, Composable, Disposable
{
/** DOM factory */
protected static DocumentBuilderFactory docfactory =
@@ -66,6 +72,21 @@
/** Logger */
protected Logger logger;
+ /** Component Manager */
+ protected ComponentManager manager = null;
+
+ /** XPath Processor */
+ private XPathProcessor processor = null;
+
+ public void compose(ComponentManager manager) {
+ this.manager = manager;
+ try {
+ this.processor =
(XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
+ } catch (Exception e) {
+ logger.error("cannot obtain XPathProcessor", e);
+ }
+ }
+
/**
* Initalize the bundle
*
@@ -369,7 +390,7 @@
Node node = null;
try
{
- node = XPathAPI.selectSingleNode(rootNode, key);
+ node = this.processor.selectSingleNode(rootNode, key);
}
catch (Exception e)
{
@@ -464,5 +485,10 @@
public Enumeration getKeys()
{
return cache.keys();
+ }
+
+ public void dispose()
+ {
+ this.manager.release((Component)this.processor);
}
}
1.20 +3 -0
xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java
Index: I18nTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- I18nTransformer.java 2001/09/08 11:45:49 1.19
+++ I18nTransformer.java 2001/09/19 19:37:56 1.20
@@ -426,6 +426,9 @@
dictionary =
(XMLResourceBundle) factory.select(catalogueName, locale);
+ //FIXME(DIMS): Why should i do this explicitly? Is there an alternative?
+ dictionary.compose(this.manager);
+
debug("selected dictionary " + dictionary);
setLocale(locale);
1.15 +17 -14
xml-cocoon2/src/org/apache/cocoon/transformation/XIncludeTransformer.java
Index: XIncludeTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/XIncludeTransformer.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XIncludeTransformer.java 2001/09/17 16:08:01 1.14
+++ XIncludeTransformer.java 2001/09/19 19:37:56 1.15
@@ -18,10 +18,10 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.parser.Parser;
import org.apache.cocoon.components.url.URLFactory;
+import org.apache.cocoon.components.xpath.XPathProcessor;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.cocoon.xml.dom.DOMStreamer;
-import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
@@ -49,12 +49,15 @@
* by the SAX event FSM yet.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
- * @version CVS $Revision: 1.14 $ $Date: 2001/09/17 16:08:01 $ $Author: dims $
+ * @version CVS $Revision: 1.15 $ $Date: 2001/09/19 19:37:56 $ $Author: dims $
*/
public class XIncludeTransformer extends AbstractTransformer implements Composable,
Recyclable, Disposable {
protected URLFactory urlFactory;
+ /** XPath Processor */
+ private XPathProcessor processor = null;
+
protected ComponentManager manager = null;
public static final String XMLBASE_NAMESPACE_URI =
"http://www.w3.org/XML/1998/namespace";
@@ -94,6 +97,11 @@
} catch (Exception e) {
getLogger().error("cannot obtain URLFactory", e);
}
+ try {
+ this.processor =
(XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
+ } catch (Exception e) {
+ getLogger().error("cannot obtain XPathProcessor", e);
+ }
}
public void startElement(String uri, String name, String raw, Attributes attr)
throws SAXException {
@@ -267,16 +275,11 @@
String xpath = suffix.substring(9,suffix.length()-1);
getLogger().debug("XPath is "+xpath);
Document document = parser.parseDocument(input);
- try {
- NodeList list = XPathAPI.selectNodeList(document,xpath);
- DOMStreamer streamer = new
DOMStreamer(super.contentHandler,super.lexicalHandler);
- int length = list.getLength();
- for (int i=0; i<length; i++) {
- streamer.stream(list.item(i));
- }
- } catch (TransformerException e){
- getLogger().error("TransformerException", e);
- return;
+ NodeList list = processor.selectNodeList(document,xpath);
+ DOMStreamer streamer = new
DOMStreamer(super.contentHandler,super.lexicalHandler);
+ int length = list.getLength();
+ for (int i=0; i<length; i++) {
+ streamer.stream(list.item(i));
}
} else {
IncludeXMLConsumer xinclude_handler = new
IncludeXMLConsumer(super.contentHandler,super.lexicalHandler);
@@ -317,7 +320,7 @@
public void dispose()
{
- if(this.urlFactory != null)
- this.manager.release((Component)this.urlFactory);
+ this.manager.release((Component)this.urlFactory);
+ this.manager.release((Component)this.processor);
}
}
1.34 +2 -0 xml-cocoon2/webapp/cocoon.xconf
Index: cocoon.xconf
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- cocoon.xconf 2001/09/10 18:28:03 1.33
+++ cocoon.xconf 2001/09/19 19:37:56 1.34
@@ -73,6 +73,8 @@
<parameter name="use-store" value="true"/>
</xslt-processor>
+ <xpath-processor class="org.apache.cocoon.components.xpath.XPathProcessorImpl"
logger="root.xslt"/>
+
<!-- The url factory adds special url protocols to the system, they
are then available inside Cocoon, e.g. as a source argument
for one of the sitemap components -->
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]