use of org.loboevolution.html.xpath.XPathException in project LoboEvolution by LoboEvolution.
the class XPathExpressionImpl method evaluate.
/**
* {@inheritDoc}
*/
@Override
public Object evaluate(Node contextNode, short type, Object result) throws XPathException, DOMException {
// If the XPathEvaluator was determined by "casting" the document
if (m_doc != null) {
// Check that the context node is owned by the same document
if (!Objects.equals(contextNode, m_doc) && !contextNode.getOwnerDocument().equals(m_doc)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, fmsg);
}
// Check that the context node is an acceptable node type
NodeType nodeType = contextNode.getNodeType();
switch(nodeType) {
case DOCUMENT_NODE:
case ELEMENT_NODE:
case ATTRIBUTE_NODE:
case TEXT_NODE:
case CDATA_SECTION_NODE:
case COMMENT_NODE:
case PROCESSING_INSTRUCTION_NODE:
break;
default:
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);
throw new UnsupportedOperationException(fmsg);
}
}
if (!XPathResultImpl.isValidType(type)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] { (int) type });
throw new XPathException(XPathException.TYPE_ERR, fmsg);
}
XPathContext xpathSupport = new XPathContext(false);
XObject xobj = null;
return new XPathResultImpl(type, xobj, contextNode, m_xpath);
}
use of org.loboevolution.html.xpath.XPathException in project LoboEvolution by LoboEvolution.
the class XPathResultImpl method getSingleNodeValue.
/**
* {@inheritDoc}
*/
@Override
public Node getSingleNodeValue() throws XPathException {
if (m_resultType != ANY_UNORDERED_NODE_TYPE && m_resultType != FIRST_ORDERED_NODE_TYPE) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] { m_xpath.getPatternString(), getTypeString(m_resultType) });
throw new XPathException(XPathException.TYPE_ERR, fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType
// of {1} which cannot be converted to a single node.
// This method applies only to types ANY_UNORDERED_NODE_TYPE and
// FIRST_ORDERED_NODE_TYPE."
}
NodeIterator result = null;
if (null == result) {
return null;
}
Node node = result.nextNode();
if (isNamespaceNode(node)) {
return new XPathNamespaceImpl(node);
} else {
return node;
}
}
Aggregations