You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ne...@apache.org on 2001/10/29 19:26:30 UTC
cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/xml/xpath XPathProcessorImpl.java XPathProcessor.java JaxenProcessorImpl.java
neeme 01/10/29 10:26:30
Added: src/java/org/apache/avalon/excalibur/xml/xpath
XPathProcessorImpl.java XPathProcessor.java
JaxenProcessorImpl.java
Log:
moved these abstractions from Cocoon to Avalon Excalibur
Revision Changes Path
1.1 jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/xml/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.avalon.excalibur.xml.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:dims@yahoo.com">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/10/29 18:26:30 $ $Author: neeme $
*/
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.1 jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/xml/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.avalon.excalibur.xml.xpath;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This is the interface of the XPath processor.
*
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/10/29 18:26:30 $ $Author: neeme $
*/
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 jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/xml/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.avalon.excalibur.xml.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 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:dims@yahoo.com">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/10/29 18:26:30 $ $Author: neeme $
*/
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){
// ignore it
}
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){
// ignore it
}
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();
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>