use of javax.xml.xpath.XPathExpressionException in project honeycomb by altamiracorp.
the class ConfigurationParser method parseOptions.
private static Map<String, String> parseOptions(String adapterName, Document doc) {
String optionsQuery = String.format(QUERY_ADAPTER_CONFIG_NODES, adapterName);
NodeList optionNodes;
try {
optionNodes = (NodeList) xPath.evaluate(optionsQuery, doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
logger.error("Unable to parse options for " + adapterName + " adapter.", e);
throw new RuntimeException("Exception while parsing options for " + adapterName + " adapter.", e);
}
ImmutableMap.Builder<String, String> options = ImmutableMap.builder();
for (int i = 0; i < optionNodes.getLength(); i++) {
Node optionNode = optionNodes.item(i);
if (optionNode.getNodeType() == Node.ELEMENT_NODE) {
String optionName = optionNode.getNodeName();
String namespacedOptionName = isNamespaced(optionName) ? optionName : prependNamespace(adapterName, optionName);
options.put(namespacedOptionName, optionNode.getTextContent());
}
}
return options.build();
}
use of javax.xml.xpath.XPathExpressionException in project camel by apache.
the class XmlSignerProcessor method getContentReferenceUrisForDetachedCase.
private List<String> getContentReferenceUrisForDetachedCase(Message message, Node messageBodyNode) throws XmlSignatureException, XPathExpressionException {
List<XPathFilterParameterSpec> xpathsToIdAttributes = getXpathToIdAttributes(message);
if (xpathsToIdAttributes.isEmpty()) {
// should not happen, has already been checked earlier
throw new IllegalStateException("List of XPATHs to ID attributes is empty in detached signature case");
}
List<ComparableNode> result = new ArrayList<ComparableNode>(xpathsToIdAttributes.size());
for (XPathFilterParameterSpec xp : xpathsToIdAttributes) {
XPathExpression exp;
try {
exp = XmlSignatureHelper.getXPathExpression(xp);
} catch (XPathExpressionException e) {
throw new XmlSignatureException("The configured xpath expression " + xp.getXPath() + " is invalid.", e);
}
NodeList list = (NodeList) exp.evaluate(messageBodyNode, XPathConstants.NODESET);
if (list == null) {
//assume optional element, XSD validation has been done before
LOG.warn("No ID attribute found for xpath expression {}. Therfore this xpath expression will be ignored.", xp.getXPath());
continue;
}
int length = list.getLength();
for (int i = 0; i < length; i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
Attr attr = (Attr) node;
String value = attr.getValue();
// check that attribute is ID attribute
Element element = messageBodyNode.getOwnerDocument().getElementById(value);
if (element == null) {
throw new XmlSignatureException("Wrong configured xpath expression for ID attributes: The evaluation of the xpath expression " + xp.getXPath() + " resulted in an attribute which is not of type ID. The attribute value is " + value + ".");
}
result.add(new ComparableNode(element, "#" + value));
LOG.debug("ID attribute with value {} found for xpath {}", value, xp.getXPath());
} else {
throw new XmlSignatureException("Wrong configured xpath expression for ID attributes: The evaluation of the xpath expression " + xp.getXPath() + " returned a node which was not of type Attribute.");
}
}
}
if (result.size() == 0) {
throw new XmlSignatureException("No element to sign found in the detached case. No node found for the configured xpath expressions " + toString(xpathsToIdAttributes) + ". Either the configuration of the XML signature component is wrong or the incoming message has not the correct structure.");
}
// sort so that elements with deeper hierarchy level are treated first
Collections.sort(result);
return ComparableNode.getReferenceUris(result);
}
use of javax.xml.xpath.XPathExpressionException in project bazel by bazelbuild.
the class AndroidResourceProcessor method processDataBindings.
/**
* If resources exist and a data binding layout info file is requested: processes data binding
* declarations over those resources, populates the output file, and creates a new resources
* directory with data binding expressions stripped out (so aapt, which doesn't understand
* data binding, can properly read them).
*
* <p>Returns the resources directory that aapt should read.
*/
static Path processDataBindings(Path resourceDir, Path dataBindingInfoOut, VariantType variantType, String packagePath, Path androidManifest) throws IOException {
if (dataBindingInfoOut == null) {
return resourceDir;
} else if (!Files.isDirectory(resourceDir)) {
// No resources: no data binding needed. Create a dummy file to satisfy declared outputs.
Files.createFile(dataBindingInfoOut);
return resourceDir;
}
// Strip the file name (the data binding library automatically adds it back in).
// ** The data binding library assumes this file is called "layout-info.zip". **
dataBindingInfoOut = dataBindingInfoOut.getParent();
if (Files.notExists(dataBindingInfoOut)) {
Files.createDirectory(dataBindingInfoOut);
}
Path processedResourceDir = resourceDir.resolveSibling("res_without_databindings");
if (Files.notExists(processedResourceDir)) {
Files.createDirectory(processedResourceDir);
}
ProcessXmlOptions options = new ProcessXmlOptions();
options.setAppId(packagePath);
options.setLibrary(variantType == VariantType.LIBRARY);
options.setResInput(resourceDir.toFile());
options.setResOutput(processedResourceDir.toFile());
options.setLayoutInfoOutput(dataBindingInfoOut.toFile());
// Aggregate data-bound .xml files into a single .zip.
options.setZipLayoutInfo(true);
try {
Object minSdk = AndroidManifest.getMinSdkVersion(new FileWrapper(androidManifest.toFile()));
if (minSdk instanceof Integer) {
options.setMinSdk(((Integer) minSdk).intValue());
} else {
// TODO(bazel-team): Enforce the minimum SDK check.
options.setMinSdk(15);
}
} catch (XPathExpressionException | StreamException e) {
// TODO(bazel-team): Enforce the minimum SDK check.
options.setMinSdk(15);
}
try {
AndroidDataBinding.doRun(options);
} catch (Throwable t) {
throw new RuntimeException(t);
}
return processedResourceDir;
}
use of javax.xml.xpath.XPathExpressionException in project j2objc by google.
the class XPathImpl method evaluate.
/**
* <p>Evaluate an XPath expression in the context of the specified <code>InputSource</code>
* and return the result as the specified type.</p>
*
* <p>This method builds a data model for the {@link InputSource} and calls
* {@link #evaluate(String expression, Object item, QName returnType)} on the resulting document object.</p>
*
* <p>See "Evaluation of XPath Expressions" section of JAXP 1.3 spec
* for context item evaluation,
* variable, function and QName resolution and return type conversion.</p>
*
* <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
* then an <code>IllegalArgumentException</code> is thrown.</p>
*
* <p>If <code>expression</code>, <code>source</code> or <code>returnType</code> is <code>null</code>,
* then a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
* @param source The input source of the document to evaluate over.
* @param returnType The desired return type.
*
* @return The <code>Object</code> that encapsulates the result of evaluating the expression.
*
* @throws XPathExpressionException If expression cannot be evaluated.
* @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
* @throws NullPointerException If <code>expression</code>, <code>source</code> or <code>returnType</code>
* is <code>null</code>.
*/
public Object evaluate(String expression, InputSource source, QName returnType) throws XPathExpressionException {
// Checking validity of different parameters
if (source == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "source" });
throw new NullPointerException(fmsg);
}
if (expression == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "XPath expression" });
throw new NullPointerException(fmsg);
}
if (returnType == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "returnType" });
throw new NullPointerException(fmsg);
}
//returnType need to be defined in XPathConstants
if (!isSupported(returnType)) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, new Object[] { returnType.toString() });
throw new IllegalArgumentException(fmsg);
}
try {
Document document = getParser().parse(source);
XObject resultObject = eval(expression, document);
return getResultAsType(resultObject, returnType);
} catch (SAXException e) {
throw new XPathExpressionException(e);
} catch (IOException e) {
throw new XPathExpressionException(e);
} catch (javax.xml.transform.TransformerException te) {
Throwable nestedException = te.getException();
if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
throw (javax.xml.xpath.XPathFunctionException) nestedException;
} else {
throw new XPathExpressionException(te);
}
}
}
use of javax.xml.xpath.XPathExpressionException in project j2objc by google.
the class XPathImpl method compile.
/**
* <p>Compile an XPath expression for later evaluation.</p>
*
* <p>If <code>expression</code> contains any {@link XPathFunction}s,
* they must be available via the {@link XPathFunctionResolver}.
* An {@link XPathExpressionException} will be thrown if the <code>XPathFunction</code>
* cannot be resovled with the <code>XPathFunctionResolver</code>.</p>
*
* <p>If <code>expression</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
*
* @return Compiled XPath expression.
* @throws XPathExpressionException If <code>expression</code> cannot be compiled.
* @throws NullPointerException If <code>expression</code> is <code>null</code>.
*/
public XPathExpression compile(String expression) throws XPathExpressionException {
if (expression == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "XPath expression" });
throw new NullPointerException(fmsg);
}
try {
org.apache.xpath.XPath xpath = new XPath(expression, null, prefixResolver, org.apache.xpath.XPath.SELECT);
// Can have errorListener
XPathExpressionImpl ximpl = new XPathExpressionImpl(xpath, prefixResolver, functionResolver, variableResolver, featureSecureProcessing);
return ximpl;
} catch (javax.xml.transform.TransformerException te) {
throw new XPathExpressionException(te);
}
}
Aggregations