本文整理汇总了Java中javax.xml.xpath.XPathExpressionException类的典型用法代码示例。如果您正苦于以下问题:Java XPathExpressionException类的具体用法?Java XPathExpressionException怎么用?Java XPathExpressionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathExpressionException类属于javax.xml.xpath包,在下文中一共展示了XPathExpressionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVersion
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
/**
* Returns the version
*
* @return String
*/
public static String getVersion() {
String jarImplementation = VISNode.class.getPackage().getImplementationVersion();
if (jarImplementation != null) {
return jarImplementation;
}
String file = VISNode.class.getResource(".").getFile();
String pack = VISNode.class.getPackage().getName().replace(".", "/") + '/';
File pomXml = new File(file.replace("target/classes/" + pack, "pom.xml"));
if (pomXml.exists()) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new FileReader(pomXml)));
XPath xPath = XPathFactory.newInstance().newXPath();
return (String) xPath.evaluate("/project/version", document, XPathConstants.STRING);
} catch (IOException | ParserConfigurationException | XPathExpressionException | SAXException e) { }
}
return "Unknown version";
}
示例2: runPartnerReport
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
private RDOPartnerReport runPartnerReport(PlatformUser user,
OrganizationRoleType roleType, int month, int year)
throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException, ParseException {
if (!hasRole(roleType, user)) {
return new RDOPartnerReport();
}
Calendar c = initializeCalendar(month, year);
long periodStart = c.getTimeInMillis();
c.add(Calendar.MONTH, 1);
long periodEnd = c.getTimeInMillis();
PartnerRevenueDao sqlDao = new PartnerRevenueDao(ds);
sqlDao.executeSinglePartnerQuery(periodStart, periodEnd, user
.getOrganization().getKey(), roleType.name().toUpperCase());
PartnerRevenueBuilder builder;
builder = new PartnerRevenueBuilder(new Locale(user.getLocale()),
sqlDao.getReportData());
RDOPartnerReport result = builder.buildSingleReport();
return result;
}
示例3: unwrapSoapMessage
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
public Element unwrapSoapMessage(Element soapElement) {
XPath xpath = XPathFactory.newInstance().newXPath();
NamespaceContextImpl context = new NamespaceContextImpl();
context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
xpath.setNamespaceContext(context);
try {
final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);
if (element == null) {
String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE,
writeToString(soapElement), expression);
LOG.error(errorMessage);
throw new IllegalArgumentException(errorMessage);
}
return element;
} catch (XPathExpressionException e) {
throw propagate(e);
}
}
示例4: shouldNotModifyDocumentWhenAllXPathsTraversable
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
@Test
public void shouldNotModifyDocumentWhenAllXPathsTraversable()
throws XPathExpressionException, ParsingException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
String xml = fixtureAccessor.getPutValueXml();
Document oldDocument = stringToXml(xml);
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties)
.build(oldDocument);
assertThat(xmlToString(builtDocument)).isEqualTo(xml);
builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties.keySet())
.build(oldDocument);
assertThat(xmlToString(builtDocument)).isEqualTo(xml);
}
示例5: evaluateXPathMultiNode
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
private NodeList evaluateXPathMultiNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
NodeList nlst;
try {
xpath.setNamespaceContext(namespaceContext);
nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATION_ERROR(e.getMessage()), e);
return null; // abort processing this <jaxb:bindings>
}
if (nlst.getLength() == 0) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
return null; // abort
}
return nlst;
}
示例6: shouldBuildDocumentFromSetOfXPathsAndSetValues
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPathsAndSetValues() throws XPathExpressionException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document newDocument = new Document((Element) root.copy());
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties)
.build(newDocument);
for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
Nodes nodes = null == namespaceContext
? builtDocument.query(xpathToValuePair.getKey())
: builtDocument.query(xpathToValuePair.getKey(), toXpathContext(namespaceContext));
assertThat(nodes.get(0).getValue()).isEqualTo(xpathToValuePair.getValue());
}
assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutValueXml());
}
示例7: migrateBillingResultXml
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
protected String migrateBillingResultXml(String billingXml)
throws ParserConfigurationException, SAXException, IOException,
TransformerException, XPathExpressionException {
Document document = XMLConverter.convertToDocument(billingXml, false);
NodeList nodeList = XMLConverter.getNodeListByXPath(document,
XPATH_GATHEREDEVENTS);
for (int i = 0; i < nodeList.getLength(); i++) {
Node gatheredEvents = nodeList.item(i);
if (!istotalEventCostsAlreadyPresent(gatheredEvents)
&& gatheredEvents.getChildNodes().getLength() > 0) {
Element totalCosts = createNodeTotalEventCosts(gatheredEvents);
gatheredEvents.appendChild(totalCosts);
}
}
return XMLConverter.convertToString(document, false);
}
示例8: getDocument
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
/**
* Parse the input source and return a Document.
* @param source The {@code InputSource} of the document
* @return a DOM Document
* @throws XPathExpressionException if there is an error parsing the source.
*/
Document getDocument(InputSource source)
throws XPathExpressionException {
requireNonNull(source, "Source");
try {
// we'd really like to cache those DocumentBuilders, but we can't because:
// 1. thread safety. parsers are not thread-safe, so at least
// we need one instance per a thread.
// 2. parsers are non-reentrant, so now we are looking at having a
// pool of parsers.
// 3. then the class loading issue. The look-up procedure of
// DocumentBuilderFactory.newInstance() depends on context class loader
// and system properties, which may change during the execution of JVM.
//
// so we really have to create a fresh DocumentBuilder every time we need one
// - KK
DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(useServiceMechanism);
dbf.setNamespaceAware(true);
dbf.setValidating(false);
return dbf.newDocumentBuilder().parse(source);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new XPathExpressionException (e);
}
}
示例9: MultiplicativeExpr
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
private Expr MultiplicativeExpr(Context context) throws XPathExpressionException {
Expr left = UnaryExpr(context);
Type type = context.tokenAt(1).getType();
while (Type.STAR == type) {
Expr right;
switch (type) {
case STAR:
context.match(Type.STAR);
right = UnaryExpr(context);
left = new MultiplicationExpr(left, right);
break;
default:
throw new XPathParserException(context.tokenAt(1), Type.STAR);
}
type = context.tokenAt(1).getType();
}
return left;
}
示例10: verify_SupplierResult_Service
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
private void verify_SupplierResult_Service(Document xml,
Organization resaleOrg, OfferingType type, String roleString)
throws XPathExpressionException {
NodeList services = XMLConverter.getNodeListByXPath(xml, "/"
+ roleString
+ "RevenueShareResult/Currency/Marketplace/Service");
for (int i = 0; i < services.getLength(); i++) {
String model = XMLConverter.getStringAttValue(services.item(i),
"model");
if (type.name().equals(model)) {
verify_SupplierResult_RevenueShareDetails(services.item(i));
if (resaleOrg != null) {
verify_ResaleOrganization(services.item(i), resaleOrg);
}
}
}
}
示例11: buildReports
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
public RDOPartnerReports buildReports()
throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException, ParseException {
if (sqlData == null || sqlData.isEmpty()) {
return new RDOPartnerReports();
}
RDOPartnerReports result = new RDOPartnerReports();
result.setEntryNr(idGen.nextValue());
result.setServerTimeZone(DateConverter.getCurrentTimeZoneAsUTCString());
for (ReportData data : sqlData) {
xmlDocument = XMLConverter.convertToDocument(data.getResultXml(),
false);
partnerType = Strings.firstCharToUppercase(data.getResulttype());
result.getReports().add(build(data, result.getEntryNr()));
}
return result;
}
示例12: evaluate
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
public Object evaluate(String expression, InputSource source,
QName returnType) throws XPathExpressionException {
isSupported(returnType);
try {
Document document = getDocument(source);
XObject resultObject = eval(expression, document);
return getResultAsType(resultObject, returnType);
} catch (TransformerException te) {
Throwable nestedException = te.getException();
if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
throw (javax.xml.xpath.XPathFunctionException)nestedException;
} else {
throw new XPathExpressionException (te);
}
}
}
示例13: shouldBuildDocumentFromSetOfXPathsAndSetValues
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPathsAndSetValues() throws XPathExpressionException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties)
.build(DocumentHelper.createDocument());
for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
XPath xpath = builtDocument.createXPath(xpathToValuePair.getKey());
if (null != namespaceContext) {
xpath.setNamespaceContext(new SimpleNamespaceContextWrapper(namespaceContext));
}
assertThat(xpath.selectSingleNode(builtDocument).getText()).isEqualTo(xpathToValuePair.getValue());
}
assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutValueXml());
}
示例14: buildReports
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
public RDOSupplierRevenueShareReports buildReports()
throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException, ParseException {
if (sqlData == null || sqlData.isEmpty()) {
return new RDOSupplierRevenueShareReports();
}
RDOSupplierRevenueShareReports result = new RDOSupplierRevenueShareReports();
result.setEntryNr(idGen.nextValue());
result.setServerTimeZone(DateConverter.getCurrentTimeZoneAsUTCString());
for (ReportData data : sqlData) {
xmlDocument = XMLConverter.convertToDocument(data.getResultXml(),
false);
result.getReports().add(build(data, result.getEntryNr()));
}
return result;
}
示例15: evaluateExpression
import javax.xml.xpath.XPathExpressionException; //导入依赖的package包/类
@Override
public <T>T evaluateExpression(Object item, Class<T> type)
throws XPathExpressionException {
isSupportedClassType(type);
try {
XObject resultObject = eval(item, xpath);
if (type.isAssignableFrom(XPathEvaluationResult.class)) {
return getXPathResult(resultObject, type);
} else {
return XPathResultImpl.getValue(resultObject, type);
}
} catch (javax.xml.transform.TransformerException te) {
throw new XPathExpressionException(te);
}
}