本文整理汇总了Java中org.dom4j.InvalidXPathException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidXPathException类的具体用法?Java InvalidXPathException怎么用?Java InvalidXPathException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidXPathException类属于org.dom4j包,在下文中一共展示了InvalidXPathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findWithXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Searches XML element with XPath and returns list of nodes found
*
* @param xml input stream with the XML in which the element is being searched
* @param expression XPath expression used in search
* @return {@link NodeList} of elements matching the XPath in the XML
* @throws XPathExpressionException if there is an error in the XPath expression
* @throws IOException if the XML at the specified path is missing
* @throws SAXException if the XML cannot be parsed
* @throws ParserConfigurationException
*/
public static NodeList findWithXPath(InputStream xml, String expression)
throws IOException, SAXException, ParserConfigurationException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xml);
doc.getDocumentElement().normalize();
XPath xPath = XPathFactory.newInstance().newXPath();
try {
return (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
throw new InvalidXPathException(expression, e);
}
}
示例2: getAttribute
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public IAttributeValue getAttribute(IInstance row) {
if (row instanceof XMLRow) {
Node node = ((XMLRow)row).getNode();
Node selectedNode = null;
try {
selectedNode = node.selectSingleNode(getXpath());
} catch (InvalidXPathException e) {
throw new IllegalArgumentException("Invalid XPath '" + getXpath() + "' in attribute '" + getName() + "'", e);
}
if (selectedNode == null) {
return(new EmptyAttributeValue(this));
//throw new IllegalArgumentException("Column '" + getXPath() + "' not found in row '" + node.getPath() +"'");
}
TextAttributeValue col = new TextAttributeValue(this, selectedNode.getText());
return(col);
}
return(null);
}
示例3: validateXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Validates an XPath expression.
*
* @return {@link XPathActivityConfigurationBean#XPATH_VALID XPATH_VALID} -
* if the expression is valid;<br/>
* {@link XPathActivityConfigurationBean#XPATH_EMPTY XPATH_EMPTY} -
* if expression is empty;<br/>
* {@link XPathActivityConfigurationBean#XPATH_INVALID
* XPATH_INVALID} - if the expression is invalid / ill-formed.<br/>
*/
public static int validateXPath(String xpathExpressionToValidate) {
// no XPath expression
if (xpathExpressionToValidate == null
|| xpathExpressionToValidate.trim().isEmpty()) {
return XPATH_EMPTY;
}
try {
// try to parse the XPath expression...
createXPath(xpathExpressionToValidate.trim());
// ...success
return XPATH_VALID;
} catch (InvalidXPathException e) {
// ...failed to parse the XPath expression: notify of the error
return XPATH_INVALID;
}
}
开发者ID:apache,项目名称:incubator-taverna-common-activities,代码行数:28,代码来源:XPathActivityConfigurationBean.java
示例4: validateXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Validates an XPath expression.
*
* @return {@link XPathActivityConfigurationBean#XPATH_VALID XPATH_VALID} -
* if the expression is valid;<br/>
* {@link XPathActivityConfigurationBean#XPATH_EMPTY XPATH_EMPTY} -
* if expression is empty;<br/>
* {@link XPathActivityConfigurationBean#XPATH_INVALID
* XPATH_INVALID} - if the expression is invalid / ill-formed.<br/>
*/
public static int validateXPath(String xpathExpressionToValidate) {
// no XPath expression
if (xpathExpressionToValidate == null
|| xpathExpressionToValidate.trim().isEmpty()) {
return XPATH_EMPTY;
}
try {
// try to parse the XPath expression...
createXPath(xpathExpressionToValidate.trim());
// ...success
return XPATH_VALID;
} catch (InvalidXPathException e) {
// ...failed to parse the XPath expression: notify of the error
return XPATH_INVALID;
}
}
示例5: generateArclibInvalidXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Tests that the {@link InvalidXPathException} exception is thrown when the SIP profile contains an invalid xpath
*/
@Test
public void generateArclibInvalidXPath() throws IOException {
SipProfile profile = new SipProfile();
String sipProfileXml = Resources.toString(this.getClass().getResource(
"/arclibxmlgeneration/sipProfiles/sipProfileInvalidXPath.xml"), StandardCharsets.UTF_8);
profile.setXml(sipProfileXml);
store.save(profile);
assertThrown(() -> generator.generateArclibXml(SIP_PATH, profile.getId())).isInstanceOf(InvalidXPathException.class);
}
示例6: getXPathValidationErrorMessage
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
private String getXPathValidationErrorMessage() {
try {
// try to parse the XPath expression...
DocumentHelper.createXPath(tfXPathExpression.getText().trim());
// ...success
return ("");
} catch (InvalidXPathException e) {
// ...failed to parse the XPath expression: notify of the error
return (e.getMessage());
}
}
开发者ID:apache,项目名称:incubator-taverna-workbench-common-activities,代码行数:12,代码来源:XPathActivityConfigurationPanel.java
示例7: selectIterator
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Apply the given XPath expression to the given node.
*
* @param prefixes mapping of prefixes to namespace URIs for prefixes used in expr
* @return Iterator over org.w3c.dom.Node objects, never null
*/
public static Iterator selectIterator(org.dom4j.Node node, String expr, Map prefixes) {
try {
org.dom4j.XPath path = node.createXPath(expr);
path.setNamespaceContext(new SimpleNamespaceContext(prefixes));
return new IteratorFilter(path.selectNodes(node).iterator(), org.dom4j.Namespace.class);
} catch (InvalidXPathException e) {
throw new OXFException(e);
}
}
示例8: selectSingleNode
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
/**
* Apply the given XPath expression to the given node.
*
* @param prefixes mapping of prefixes to namespace URIs for prefixes used in expr
*/
public static org.dom4j.Node selectSingleNode(org.dom4j.Node node, String expr, Map prefixes) {
try {
org.dom4j.XPath path = node.createXPath(expr);
path.setNamespaceContext(new SimpleNamespaceContext(prefixes));
return path.selectSingleNode(node);
} catch (InvalidXPathException e) {
throw new OXFException(e);
}
}
示例9: selectObjectValue
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public static Object selectObjectValue(org.dom4j.Node node, String expr, Map prefixes, VariableContext variableContext, FunctionContext functionContext) {
try {
org.dom4j.XPath path = node.createXPath(expr);
hookupPath(path, prefixes, variableContext, functionContext);
return path.evaluate(node);
} catch (InvalidXPathException e) {
throw new OXFException(e);
}
}
示例10: selectStringValue
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public static String selectStringValue(org.dom4j.Node node, String expr, Map prefixes, VariableContext variableContext, FunctionContext functionContext) {
try {
org.dom4j.XPath path = node.createXPath(expr);
hookupPath(path, prefixes, variableContext, functionContext);
Object result = path.evaluate(node);
// Test for empty node-set
if (result == null || (result instanceof List && ((List) result).size() == 0))
return null;
// Otherwise return a String
return (result instanceof String) ? (String) result : node.createXPath(".").valueOf(result);
} catch (InvalidXPathException e) {
throw new OXFException(e);
}
}
示例11: selectBooleanValue
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public static Boolean selectBooleanValue(org.dom4j.Node node, String expr, Map prefixes, VariableContext variableContext, FunctionContext functionContext, boolean allowNull) {
try {
org.dom4j.XPath path = node.createXPath(expr);
hookupPath(path, prefixes, variableContext, functionContext);
Object result = path.evaluate(node);
if (allowNull && (result == null || (result instanceof List && ((List) result).size() == 0)))
return null;
else
return new Boolean(node.createXPath("boolean(.)").valueOf(result));
} catch (InvalidXPathException e) {
throw new OXFException(e);
}
}
示例12: findWithXPathInvalidXPathTest
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
@Test
public void findWithXPathInvalidXPathTest() throws SAXException, ParserConfigurationException, XPathExpressionException, IOException {
assertThrown(() -> XPathUtils.findWithXPath(new FileInputStream(SIP_PATH + "/info.xml"),
"///")).isInstanceOf(InvalidXPathException.class);
}
示例13: createXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public XPath createXPath(String xpath) throws InvalidXPathException {
return element.createXPath( xpath );
}
示例14: createXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public XPath createXPath(String xpathExpression)
throws InvalidXPathException {
return getWrapped().createXPath(xpathExpression);
}
示例15: createXPath
import org.dom4j.InvalidXPathException; //导入依赖的package包/类
public XPath createXPath(String xpath) throws InvalidXPathException {
return target().createXPath( xpath );
}