List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:de.dplatz.padersprinter.control.TripService.java
static String parseStringNode(Node node, String expr, XPath xpath) throws XPathExpressionException { String val = (String) xpath.evaluate(expr, node, XPathConstants.STRING); val = StringEscapeUtils.unescapeHtml4(val); return val; }
From source file:com.espertech.esper.event.xml.SimpleXMLEventType.java
protected EventPropertyGetter doResolvePropertyGetter(String propertyExpression) { EventPropertyGetter getter = propertyGetterCache.get(propertyExpression); if (getter != null) { return getter; }/*from w ww . j a v a 2 s . co m*/ if (!this.getConfigurationEventTypeXMLDOM().isXPathPropertyExpr()) { Property prop = PropertyParser.parse(propertyExpression, false); getter = prop.getGetterDOM(); if (!prop.isDynamic()) { getter = new DOMConvertingGetter(propertyExpression, (DOMPropertyGetter) getter, String.class); } } else { XPathExpression xPathExpression; String xPathExpr; boolean isDynamic; try { Tree ast = PropertyParser.parse(propertyExpression); isDynamic = PropertyParser.isPropertyDynamic(ast); xPathExpr = SimpleXMLPropertyParser.parse(ast, propertyExpression, getRootElementName(), defaultNamespacePrefix, isResolvePropertiesAbsolute); XPath xpath = getXPathFactory().newXPath(); xpath.setNamespaceContext(namespaceContext); if (log.isInfoEnabled()) { log.info("Compiling XPath expression for property '" + propertyExpression + "' as '" + xPathExpr + "'"); } xPathExpression = xpath.compile(xPathExpr); } catch (XPathExpressionException e) { throw new EPException( "Error constructing XPath expression from property name '" + propertyExpression + '\'', e); } QName xPathReturnType; if (isDynamic) { xPathReturnType = XPathConstants.NODE; } else { xPathReturnType = XPathConstants.STRING; } getter = new XPathPropertyGetter(propertyExpression, xPathExpr, xPathExpression, xPathReturnType, null, null); } // no fragment factory, fragments not allowed propertyGetterCache.put(propertyExpression, getter); return getter; }
From source file:cz.cas.lib.proarc.common.export.cejsh.CejshBuilderTest.java
@Test public void testCreateCejshXml_TitleVolumeIssue() throws Exception { CejshConfig conf = new CejshConfig(); CejshBuilder cb = new CejshBuilder(conf); Document articleDoc = cb.getDocumentBuilder() .parse(CejshBuilderTest.class.getResource("article_mods.xml").toExternalForm()); // issn must match some cejsh_journals.xml/cejsh/journal[@issn=$issn] final String pkgIssn = "0231-5955"; Issue issue = new Issue(); issue.setIssn(pkgIssn);//from w w w . j a v a 2s .c o m issue.setIssueId("uuid-issue"); issue.setIssueNumber("issue1"); Volume volume = new Volume(); volume.setVolumeId("uuid-volume"); volume.setVolumeNumber("volume1"); volume.setYear("1985"); Article article = new Article(null, articleDoc.getDocumentElement(), null); cb.setIssue(issue); cb.setVolume(volume); Document articleCollectionDoc = cb.mergeElements(Collections.singletonList(article)); DOMSource cejshSource = new DOMSource(articleCollectionDoc); DOMResult cejshResult = new DOMResult(); // dump(cejshSource); TransformErrorListener xslError = cb.createCejshXml(cejshSource, cejshResult); assertEquals(Collections.emptyList(), xslError.getErrors()); final Node cejshRootNode = cejshResult.getNode(); // dump(new DOMSource(cejshRootNode)); List<String> errors = cb.validateCejshXml(new DOMSource(cejshRootNode)); assertEquals(Collections.emptyList(), errors); XPath xpath = ProarcXmlUtils.defaultXPathFactory().newXPath(); xpath.setNamespaceContext(new SimpleNamespaceContext().add("b", CejshBuilder.NS_BWMETA105)); assertNotNull( xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.ebfd7bf2-169d-476e-a230-0cc39f01764c']", cejshRootNode, XPathConstants.NODE)); assertEquals("volume1", xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.uuid-volume']/b:name", cejshRootNode, XPathConstants.STRING)); assertEquals("issue1", xpath.evaluate("/b:bwmeta/b:element[@id='bwmeta1.element.uuid-issue']/b:name", cejshRootNode, XPathConstants.STRING)); assertEquals("1985", xpath.evaluate( "/b:bwmeta/b:element[@id='bwmeta1.element.9358223b-b135-388f-a71e-24ac2c8422c7-1985']/b:name", cejshRootNode, XPathConstants.STRING)); }
From source file:org.opencastproject.remotetest.server.FailingPreProcessingWorkflowTest.java
/** * Adds a new recording event to the scheduling service and returns the event id. * // ww w . j av a 2 s .c om * @param start * start date * @param end * end date * @return the event identifier */ private String scheduleEvent(Date start, Date end) throws Exception { HttpPut request = new HttpPut(BASE_URL + "/scheduler"); // Create the request body Calendar c = Calendar.getInstance(); c.roll(Calendar.MINUTE, 1); long startTime = c.getTimeInMillis(); c.roll(Calendar.MINUTE, 1); long endTime = c.getTimeInMillis(); String eventXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><event>" + "<contributor>demo contributor</contributor><creator>demo creator</creator>" + "<startDate>{start}</startDate><endDate>{stop}</endDate><device>{device}</device>" + "<language>en</language><license>creative commons</license><resources>vga, audio</resources>" + "<title>demo title</title><additionalMetadata><metadata id=\"0\"><key>location</key>" + "<value>demo location</value></metadata><metadata id=\"0\"><key>org.opencastproject.workflow.definition</key>" + "<value>" + WORKFLOW_DEFINITION_ID + "</value></metadata></additionalMetadata></event>"; eventXml = eventXml.replace("{device}", CAPTURE_AGENT_ID).replace("{start}", Long.toString(startTime)) .replace("{stop}", Long.toString(endTime)); // Prepare the request List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("event", eventXml)); request.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Submit and check the response HttpResponse response = client.execute(request); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); String responseBody = StringUtils.trimToNull(EntityUtils.toString(response.getEntity())); assertNotNull(responseBody); String eventId = StringUtils.trimToNull( (String) Utils.xpath(responseBody, "/*[local-name() = 'event']/@id", XPathConstants.STRING)); assertNotNull("No event id found", eventId); return eventId; }
From source file:de.bayern.gdi.processor.AtomDownloadJob.java
private String figureoutDatasource() throws JobExecutionException { HashMap<String, String> vars = new HashMap<>(); vars.put("CODE", this.dataset); String ds = (String) XML.xpath(getDocument(this.url), DATASOURCE_XPATH, XPathConstants.STRING, NAMESPACE_CONTEXT, vars);/*from w ww .j av a 2s . co m*/ if (ds == null || ds.isEmpty()) { throw new JobExecutionException(I18n.format("atom.dataset.not.found", this.dataset)); } return ds; }
From source file:de.dplatz.padersprinter.control.TripService.java
static int parseIntegerNode(Node node, String expr, XPath xpath) throws XPathExpressionException { return Integer.parseInt((String) xpath.evaluate(expr, node, XPathConstants.STRING)); }
From source file:eu.planets_project.tb.impl.services.EvaluationTestbedServiceTemplateImpl.java
/** * @param node a Node obtained by getAllEvalResultsRootNodes() * @return/* w ww . j a v a 2 s . c o m*/ * @throws XPathExpressionException */ public String getEvalResultSrcValue(Node node) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); String result = (String) xpath.evaluate(sSrcXpath, node, XPathConstants.STRING); return result; }
From source file:com.cordys.coe.ac.httpconnector.samples.JIRAResponseHandler.java
/** * This method checks the HTML for errors during processing. * /* w w w .j a v a 2 s .c o m*/ * @param document * The HTML document. * @param httpMethod * The actual HTTP method that was executed. * * @throws HandlerException * In case the response contains any functional errors. * @throws XPathExpressionException * In case one of the XPaths fail. */ protected void checkErrors(org.w3c.dom.Document document, HttpMethod httpMethod) throws HandlerException, XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nodeList = (NodeList) xpath.evaluate("//span[@class='errMsg']/text()", document, XPathConstants.NODESET); int length = nodeList.getLength(); if (length != 0) { // The first error message found will be used. HandlerException he = new HandlerException( HandlerExceptionMessages.ERROR_CONVERTING_THE_RESPONSE_TO_PROPER_XML, nodeList.item(0).getNodeValue()); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); he.addAdditionalErrorMessage(node.getNodeValue()); } throw he; } // There is another possibility of which errors might be returned. There // is a td with // class formErrors. And it that holds the errors as list items. nodeList = (NodeList) xpath.evaluate("//td[@class='formErrors']/div[@class='errorArea']/ul/li/text()", document, XPathConstants.NODESET); length = nodeList.getLength(); if (length != 0) { // The first error message found will be used. HandlerException he = new HandlerException( HandlerExceptionMessages.ERROR_CONVERTING_THE_RESPONSE_TO_PROPER_XML, nodeList.item(0).getNodeValue()); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); he.addAdditionalErrorMessage(node.getNodeValue()); } throw he; } if (httpMethod.getStatusCode() == 500) { // Find the short description Node n = (Node) xpath.evaluate("//b[.='Cause: ']", document, XPathConstants.NODE); String shortError = n.getNextSibling().getNextSibling().getNodeValue().trim(); // The first error message found will be used. HandlerException he = new HandlerException( HandlerExceptionMessages.ERROR_CONVERTING_THE_RESPONSE_TO_PROPER_XML, "System Error: " + shortError); // Find the stacktrace if available. he.addAdditionalErrorMessage( (String) xpath.evaluate("//pre[@id='stacktrace']/text()", document, XPathConstants.STRING)); throw he; } }
From source file:org.opencastproject.remotetest.server.YoutubeDistributionRestEndpointTest.java
private String getPayloadFromJob(String jobXML) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from w w w . j a v a2 s . co m*/ DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(IOUtils.toInputStream(jobXML, "UTF-8")); XPath xPath = XPathFactory.newInstance().newXPath(); return (String) xPath.evaluate("/*[local-name() = 'job']/*[local-name() = 'payload']", doc, XPathConstants.STRING); }