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:org.nuxeo.apidoc.introspection.ServerInfo.java
protected static BundleInfoImpl computeBundleInfo(Bundle bundle) { RuntimeService runtime = Framework.getRuntime(); BundleInfoImpl binfo = new BundleInfoImpl(bundle.getSymbolicName()); binfo.setFileName(runtime.getBundleFile(bundle).getName()); binfo.setLocation(bundle.getLocation()); if (!(bundle instanceof BundleImpl)) { return binfo; }/* w w w .j a va 2s . c o m*/ BundleImpl nxBundle = (BundleImpl) bundle; File jarFile = nxBundle.getBundleFile().getFile(); if (jarFile == null) { return binfo; } try { if (jarFile.isDirectory()) { // directory: run from Eclipse in unit tests // .../nuxeo-runtime/nuxeo-runtime/bin // or sometimes // .../nuxeo-runtime/nuxeo-runtime/bin/main File manifest = new File(jarFile, META_INF_MANIFEST_MF); if (manifest.exists()) { InputStream is = new FileInputStream(manifest); String mf = IOUtils.toString(is, Charsets.UTF_8); binfo.setManifest(mf); } // find and parse pom.xml File up = new File(jarFile, ".."); File pom = new File(up, POM_XML); if (!pom.exists()) { pom = new File(new File(up, ".."), POM_XML); if (!pom.exists()) { pom = null; } } if (pom != null) { DocumentBuilder b = documentBuilderFactory.newDocumentBuilder(); Document doc = b.parse(new FileInputStream(pom)); XPath xpath = xpathFactory.newXPath(); String groupId = (String) xpath.evaluate("//project/groupId", doc, XPathConstants.STRING); if ("".equals(groupId)) { groupId = (String) xpath.evaluate("//project/parent/groupId", doc, XPathConstants.STRING); } String artifactId = (String) xpath.evaluate("//project/artifactId", doc, XPathConstants.STRING); if ("".equals(artifactId)) { artifactId = (String) xpath.evaluate("//project/parent/artifactId", doc, XPathConstants.STRING); } String version = (String) xpath.evaluate("//project/version", doc, XPathConstants.STRING); if ("".equals(version)) { version = (String) xpath.evaluate("//project/parent/version", doc, XPathConstants.STRING); } binfo.setArtifactId(artifactId); binfo.setGroupId(groupId); binfo.setArtifactVersion(version); } } else { try (ZipFile zFile = new ZipFile(jarFile)) { ZipEntry mfEntry = zFile.getEntry(META_INF_MANIFEST_MF); if (mfEntry != null) { try (InputStream mfStream = zFile.getInputStream(mfEntry)) { String mf = IOUtils.toString(mfStream, Charsets.UTF_8); binfo.setManifest(mf); } } Enumeration<? extends ZipEntry> entries = zFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith(POM_PROPERTIES)) { try (InputStream is = zFile.getInputStream(entry)) { PropertyResourceBundle prb = new PropertyResourceBundle(is); String groupId = prb.getString("groupId"); String artifactId = prb.getString("artifactId"); String version = prb.getString("version"); binfo.setArtifactId(artifactId); binfo.setGroupId(groupId); binfo.setArtifactVersion(version); } break; } } } try (ZipFile zFile = new ZipFile(jarFile)) { EmbeddedDocExtractor.extractEmbeddedDoc(zFile, binfo); } } } catch (IOException | ParserConfigurationException | SAXException | XPathException | NuxeoException e) { log.error(e, e); } return binfo; }
From source file:de.codesourcery.eve.apiclient.utils.XMLParseHelper.java
public static String selectAttributeValue(Document doc, XPathExpression expr, boolean isRequired) { final String result; try {// www . j av a2s. c o m result = (String) expr.evaluate(doc, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new RuntimeException("Internal error while evaluating XPath expression " + expr, e); } if (StringUtils.isBlank(result)) { if (isRequired) { throw new UnparseableResponseException( "Unexpected response XML," + " XPath expression returned nothing: " + expr); } return null; } return result; }
From source file:org.ala.harvester.MorphbankHarvester.java
private int getResultNumber(Document currentResDom) throws Exception { int resultNum = 0; XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); String xPathToResultNum = "/response/numMatches/text()"; resultNum = Integer//from w ww.j a va2s .co m .valueOf((String) xpath.evaluate(xPathToResultNum, currentResDom, XPathConstants.STRING)); return resultNum; }
From source file:org.opencastproject.remotetest.server.YouTubePublicationRestEndpointTest.java
private String getYoutubeURL(String mediaPackageElementXML) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from w w w . j a va 2 s. co m*/ DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(IOUtils.toInputStream(mediaPackageElementXML, "UTF-8")); XPath xPath = XPathFactory.newInstance().newXPath(); return (String) xPath.evaluate("/*[local-name() = 'publication']/*[local-name() = 'url']", doc, XPathConstants.STRING); }
From source file:org.ala.harvester.PpmlHarvester.java
/** * Process a single image, do the document mapping etc * /*w w w.j a v a 2 s. c o m*/ * @param infosourceId * @param imageIndex * @param currentResDom * @throws Exception */ private void processSingleImage(int infosourceId, int imageIndex, Document currentResDom) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); ParsedDocument pd = new ParsedDocument(); String subject = MappingUtils.getSubject(); String xPathToIdentifier = "//root/item[" + imageIndex + "]/url/text()"; String xPathToScientificName = "//root/item[" + imageIndex + "]/scientificName/text()"; String xPathToCommonName = "//root/item[" + imageIndex + "]/commonName/text()"; String xPathToPhylum = "//root/item[" + imageIndex + "]/phylum/text()"; String xPathToOrder = "//root/item[" + imageIndex + "]/order/text()"; String xPathToGenus = "//root/item[" + imageIndex + "]/genus/text()"; String xPathToSpecies = "//root/item[" + imageIndex + "]/species/text()"; // String xPathToImageUrl = "/response/object[" + imageIndex + "]/thumbUrl/text()"; // String xPathToLicense = "/response/object[" + imageIndex + "]/copyrightText/text()"; // String xPathToSpecificEpithet = "/response/object[" + imageIndex + "]/SpecificEpithet/text()"; // String xPathToCountry = "/response/object[" + imageIndex + "]/Country/text()"; // String xPathToLocality = "/response/object[" + imageIndex + "]/Locality/text()"; String identifier = null; String scientificName = null; String phylum = null; String order = null; String genus = null; String commonName = null; String species = null; try { identifier = (String) xpath.evaluate(xPathToIdentifier, currentResDom, XPathConstants.STRING); scientificName = (String) xpath.evaluate(xPathToScientificName, currentResDom, XPathConstants.STRING); phylum = (String) xpath.evaluate(xPathToPhylum, currentResDom, XPathConstants.STRING); order = (String) xpath.evaluate(xPathToOrder, currentResDom, XPathConstants.STRING); genus = (String) xpath.evaluate(xPathToGenus, currentResDom, XPathConstants.STRING); commonName = (String) xpath.evaluate(xPathToCommonName, currentResDom, XPathConstants.STRING); species = (String) xpath.evaluate(xPathToSpecies, currentResDom, XPathConstants.STRING); } catch (XPathExpressionException getPageFragmentationError) { String errMsg = "Failed to obtain Detail Page Url"; logger.error(errMsg); throw new Exception(errMsg, getPageFragmentationError); } // System.out.println("Index: " + imageIndex); System.out.println(imageIndex + ", PHOTO URL:" + identifier); List<Triple<String, String, String>> triples = pd.getTriples(); Map<String, String> dcs = pd.getDublinCore(); pd.setGuid(identifier); pd.setContent(getContent(identifier)); pd.setContentType(contentType); dcs.put(Predicates.DC_TITLE.toString(), scientificName); dcs.put(Predicates.DC_IDENTIFIER.toString(), identifier); // dcs.put(Predicates.DC_LICENSE.toString(), "Creative Commons Attribution-Non Commercial 3.0 Australia License, http://creativecommons.org/licenses/by-nc/3.0/au/deed.en"); // dcs.put(Predicates.DC_CREATOR.toString(), license); dcs.put(Predicates.COUNTRY.toString(), "Australia"); triples.add(new Triple(subject, Predicates.SCIENTIFIC_NAME.toString(), scientificName)); triples.add(new Triple(subject, Predicates.PHYLUM.toString(), phylum)); triples.add(new Triple(subject, Predicates.ORDER.toString(), order)); triples.add(new Triple(subject, Predicates.GENUS.toString(), genus)); triples.add(new Triple(subject, Predicates.SPECIES.toString(), species)); triples.add(new Triple(subject, Predicates.COMMON_NAME.toString(), commonName)); if (pd != null) { this.repository.storeDocument(infosourceId, pd); debugParsedDoc(pd); } String xpathToImageCount = "count(//root/item[" + imageIndex + "]/medium/media)"; int imageCount = getCount(currentResDom, xpathToImageCount); System.out.println("item: " + imageIndex + ", counts: " + imageCount); for (int imgCounter = 1; imgCounter <= imageCount; imgCounter++) { String xPathToImageUrl = "//root/item[" + imageIndex + "]/medium/media[" + imgCounter + "]/filename/text()"; String xPathToImageLicense = "//root/item[" + imageIndex + "]/medium/media[" + imgCounter + "]/rights/text()"; String xPathToImageCreator = "//root/item[" + imageIndex + "]/medium/media[" + imgCounter + "]/acknowledgement/text()"; String xPathToImageType = "//root/item[" + imageIndex + "]/medium/media[" + imgCounter + "]/type/text()"; String imageUrl = null; String license = null; String creator = null; String type = null; try { imageUrl = (String) xpath.evaluate(xPathToImageUrl, currentResDom, XPathConstants.STRING); license = (String) xpath.evaluate(xPathToImageLicense, currentResDom, XPathConstants.STRING); creator = (String) xpath.evaluate(xPathToImageCreator, currentResDom, XPathConstants.STRING); type = (String) xpath.evaluate(xPathToImageType, currentResDom, XPathConstants.STRING); } catch (XPathExpressionException getPageFragmentationError) { String errMsg = "Failed to obtain Image details"; logger.error(errMsg); throw new Exception(errMsg, getPageFragmentationError); } if (license != null && license.contains("CC BY") && imageUrl != null && !"".equals(imageUrl) && (type != null && (!type.contains("Thumb") && !type.contains("List")))) { ParsedDocument imageDoc = new ParsedDocument(); System.out.println(type); imageDoc = MappingUtils.retrieveImageDocument(pd, imageUrl); if (imageDoc != null) { imageDoc.getDublinCore().put(Predicates.DC_LICENSE.toString(), license); if (creator != null && !"".equals(creator)) { imageDoc.getDublinCore().put(Predicates.DC_CREATOR.toString(), creator); imageDoc.getDublinCore().put(Predicates.DC_RIGHTS.toString(), creator); debugParsedDoc(imageDoc); this.repository.storeDocument(infosourceId, imageDoc); } } } } }
From source file:de.slub.fedora.oai.OaiHarvester.java
private void handleXmlResult(InputStream content) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); Document document = documentBuilderFactory.newDocumentBuilder().parse(content); XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression xSelectIdentifier = xPath.compile("//header/identifier"); NodeList nodes = (NodeList) xSelectIdentifier.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i);/*from w w w . j av a 2 s. co m*/ jobQueue.add(new ObjectIndexJob(IndexJob.Type.CREATE, getLocalIdentifier(n.getTextContent()))); } XPathExpression xSelectResumptionToken = xPath.compile("//resumptionToken"); resumptionToken = (String) xSelectResumptionToken.evaluate(document, XPathConstants.STRING); XPathExpression xSelectExpirationDate = xPath.compile("//resumptionToken/@expirationDate"); String s = (String) xSelectExpirationDate.evaluate(document, XPathConstants.STRING); if (s == null || s.isEmpty()) { expirationDate = null; } else { expirationDate = DatatypeConverter.parseDateTime(s).getTime(); } }
From source file:com.eviware.soapui.testondemand.TestOnDemandCaller.java
@NonNull public String sendTestCase(@NonNull WsdlTestCase testCase, @NonNull Location location) throws Exception { final ExtendedPostMethod post = new ExtendedPostMethod(); post.setURI(new URI(UPLOAD_URI)); String locationCode = location.getCode(); String encodedTestSuiteName = getBase64EncodedString(testCase.getTestSuite().getName().getBytes()); String encodedTestCaseName = getBase64EncodedString(testCase.getName().getBytes()); File tempProjectFile = saveTemporaryProject(testCase.getTestSuite().getProject()); byte[] projectFileData = getBytes(tempProjectFile.getAbsolutePath()); byte[] zipedProjectFileData = zipBytes(testCase.getTestSuite().getProject().getName(), projectFileData); String encodedZipedProjectFile = getBase64EncodedString(zipedProjectFileData); String projectPassword = testCase.getTestSuite().getProject().getShadowPassword(); String encodedProjectPassword = getBase64EncodedString(Strings.nullToEmpty(projectPassword).getBytes()); String keystoreFilePath = SoapUI.getSettings().getString(SSLSettings.KEYSTORE, ""); byte[] keystoreFileData = getBytes(keystoreFilePath); String encodedKeystoreFile = getBase64EncodedString(keystoreFileData); String encodedKeystorePassword = getBase64EncodedString( SoapUI.getSettings().getString(SSLSettings.KEYSTORE_PASSWORD, "").getBytes()); String requestContent = generateUploadRequestXML(locationCode, encodedTestSuiteName, encodedTestCaseName, encodedZipedProjectFile, encodedProjectPassword, encodedKeystoreFile, encodedKeystorePassword); byte[] compressedRequestContent = CompressionSupport.compress(CompressionSupport.ALG_GZIP, requestContent.getBytes());//from ww w. ja va2s .co m post.setEntity(new ByteArrayEntity(compressedRequestContent)); Document responseDocument = makeCall(UPLOAD_URI, requestContent); String redirectURL = (String) xpath.evaluate(REDIRECT_URL_XPATH_EXPRESSION, responseDocument, XPathConstants.STRING); if (Strings.isNullOrEmpty(redirectURL)) { throw new RuntimeException("The RedirectURL element is missing in the response message"); } return redirectURL; }
From source file:com.codspire.mojo.artifactlookup.ProcessResponse.java
/** * /*from ww w . j av a2 s . c o m*/ * @param document * @param xPathfactory * @param targetXpath * @return */ private String getXpathValue(Document document, XPathFactory xPathfactory, String targetXpath) { XPath xpath = xPathfactory.newXPath(); String xpathValue = null; try { xpathValue = xpath.compile(targetXpath).evaluate(document, XPathConstants.STRING).toString(); } catch (XPathExpressionException e) { log.error(e); } return xpathValue; }
From source file:eu.planets_project.tb.impl.services.EvaluationTestbedServiceTemplateImpl.java
/** * @param node a Node obtained by getAllEvalResultsRootNodes() * @return/*from ww w .j a v a2 s . co m*/ * @throws XPathExpressionException */ public String getEvalResultCompStatus(Node node) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); String result = (String) xpath.evaluate(sCompStatusXpath, node, XPathConstants.STRING); return result; }
From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser.java
/** * Returns a single string matching the xpath expression * @param root//from w ww. j a v a2 s . c o m * @param xpathExpr * @return */ private String text(Node root, String xpathExpr) { try { return (String) xpath().evaluate(xpathExpr, root, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new RuntimeException(e); } }