XPathXmlXPathExpression.java :  » Search-Engine » compass-2.0 » org » compass » core » xml » javax » Java Open Source

Java Open Source » Search Engine » compass 2.0 
compass 2.0 » org » compass » core » xml » javax » XPathXmlXPathExpression.java
package org.compass.core.xml.javax;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;

import org.compass.core.xml.XmlObject;
import org.compass.core.xml.XmlXPathExpression;
import org.w3c.dom.NodeList;

/**
 * A java 5 implementation of {@link XmlXPathExpression} wrapping a {@link XPathExpression}.
 *
 * @author kimchy
 */
public class XPathXmlXPathExpression implements XmlXPathExpression {

    private XPathExpression xPathExpression;

    public XPathXmlXPathExpression(XPathExpression xPathExpression) {
        this.xPathExpression = xPathExpression;
    }

    public XmlObject[] select(XmlObject xmlObject) throws Exception {
        NodeList nodeList = (NodeList) xPathExpression.evaluate(((NodeXmlObject) xmlObject).getNode(), XPathConstants.NODESET);
        if (nodeList == null) {
            return null;
        }
        XmlObject[] xmlObjects = new XmlObject[nodeList.getLength()];
        for (int i = 0; i < xmlObjects.length; i++) {
            xmlObjects[i] = new NodeXmlObject(nodeList.item(i));
        }
        return xmlObjects;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.