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.rhq.modules.plugins.jbossas7.AbstractBaseDiscovery.java
/** * Run the passed xpathExpression on the prepopulated hostXml document and * return the target element or attribute as a String. * @param xpathExpression XPath Expression to evaluate * @return String value of the Element or Attribute the XPath was pointing to. * Null in case the xpathExpression could not be evaluated. * @throws IllegalArgumentException if hostXml is null * *///from ww w .j a v a2 s . c om protected String obtainXmlPropertyViaXPath(String xpathExpression) { if (hostXml == null) throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST); XPath xpath = factory.newXPath(); try { XPathExpression expr = xpath.compile(xpathExpression); Object result = expr.evaluate(hostXml, XPathConstants.STRING); return result.toString(); } catch (XPathExpressionException e) { log.error("Evaluation XPath expression failed: " + e.getMessage()); return null; } }
From source file:org.rhq.modules.plugins.jbossas7.helper.HostConfiguration.java
/** * Run the passed xpathExpression on the prepopulated hostXml document and * return the target element or attribute as a String. * @param xpathExpression XPath Expression to evaluate * @return String value of the Element or Attribute the XPath was pointing to. * Null in case the xpathExpression could not be evaluated. * @throws IllegalArgumentException if hostXml is null *//*from w w w .j a va 2 s. c o m*/ public String obtainXmlPropertyViaXPath(String xpathExpression) { XPath xpath = this.xpathFactory.newXPath(); try { XPathExpression expr = xpath.compile(xpathExpression); Object result = expr.evaluate(this.document, XPathConstants.STRING); return result.toString(); } catch (XPathExpressionException e) { log.error("Evaluation of XPath expression failed: " + e.getMessage()); return null; } }
From source file:org.rhq.modules.plugins.jbossas7.helper.JBossCliConfiguration.java
public String obtainXmlPropertyViaXPath(String xpathExpression) { return (String) xpathExpression(xpathExpression, XPathConstants.STRING); }
From source file:org.rhq.modules.plugins.wildfly10.helper.HostConfiguration.java
/** * Run the passed xpathExpression on the prepopulated hostXml document and * return the target element or attribute as a String. * @param xpathExpression XPath Expression to evaluate * @return String value of the Element or Attribute the XPath was pointing to. * Null in case the xpathExpression could not be evaluated. * @throws IllegalArgumentException if hostXml is null *///from www . j a v a 2 s.c o m public String obtainXmlPropertyViaXPath(String xpathExpression) { return (String) xpathExpression(xpathExpression, XPathConstants.STRING); }
From source file:org.rill.bpm.api.support.XpathVarConvertTaskLifecycleInterceptor.java
protected static void generateByXpath(Map<String, Object> workflowParams, String engineRelateDataname, Map<String, Object> convertAndFilter) { String expressionText = engineRelateDataname.substring(ENGINE_VARIABLE_DEFINITION_PREFIX.length()); String[] split = StringUtils.delimitedListToStringArray(expressionText, ENGINE_VARIABLE_DEFINITION_SPLIT); if (split.length > 1 && workflowParams.containsKey(split[0]) && workflowParams.get(split[0]) != null && ClassUtils.isPrimitiveOrWrapper(workflowParams.get(split[0]).getClass())) { throw new ProcessException("Can not generate engine variable " + engineRelateDataname + " from workflow param" + workflowParams.get(split[0])); }//from ww w .j av a2 s. c o m try { if (split.length > 1 && workflowParams.containsKey(split[0]) && workflowParams.get(split[0]) != null) { String workflowParamValue = (workflowParams.get(split[0]) instanceof String) ? workflowParams.get(split[0]).toString() : XStreamSerializeHelper.serializeXml(split[0], workflowParams.get(split[0])); log.debug("After XStream serialize :" + workflowParamValue); // Check it is XML or not DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(workflowParamValue.getBytes("UTF-8"))); XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); StringBuilder sb = new StringBuilder(); sb.append("//"); for (int i = 1; i < split.length; i++) { sb.append(split[i]); sb.append("/"); } sb.append("text()"); log.debug("Build xPath:" + sb.toString()); XPathExpression expr = xpath.compile(sb.toString()); String value = (String) expr.evaluate(doc, XPathConstants.STRING); if (StringUtils.hasText(value.toString())) { log.debug("Parse xPath:" + sb.toString() + " and save value:" + value); convertAndFilter.put(engineRelateDataname, value); } else { log.warn("Can not get value using XPath because invalid engine data name: " + engineRelateDataname); } } else { log.warn("Can not get value using XPath because invalid engine data name:" + engineRelateDataname); } } catch (Exception e) { log.warn("Exception occurred when parse expression using Xpath. Do next one.", e); } }
From source file:org.rippleosi.patient.contacts.search.SCCISContactDetailsTransformer.java
@Override public ContactDetails transform(Node xml) { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); ContactDetails contact = new ContactDetails(); boolean foundContact = false; try {//from ww w .j a v a2s . co m // Search contacts from Carers section of XML NodeList nodeSet = (NodeList) xpath.evaluate("/LCR/Carers/List/RelatedPerson", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); if (sourceId.equalsIgnoreCase(contactId)) { contact.setSource("SC-CIS"); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); String relationshipTeam = (String) xpath.evaluate("relationship/coding/display/@value", node, XPathConstants.STRING); String address = (String) xpath.evaluate("address/text/@value", node, XPathConstants.STRING); String phone = (String) xpath.evaluate("telecom[1]/value/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contact.setRelationship(relationshipTeam); contact.setAddress(address); contact.setPhone(phone); contact.setAuthor("Adult Social Care System"); foundContact = true; break; } } if (!foundContact) { // Search contacts from Allocations section of XML nodeSet = (NodeList) xpath.evaluate("/LCR/Allocations/List/Practitioner", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); if (sourceId.equalsIgnoreCase(contactId)) { contact.setSource("SC-CIS"); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); String relationshipTeam = (String) xpath.evaluate( "practitionerRole/role/coding/display/@value", node, XPathConstants.STRING); String phone = (String) xpath.evaluate("telecom[1]/value/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contact.setRelationship(relationshipTeam); contact.setPhone(phone); contact.setAuthor("Adult Social Care System"); break; } } } } catch (XPathExpressionException e) { e.printStackTrace(); } return contact; }
From source file:org.rippleosi.patient.contacts.search.SCCISContactHeadlineTransformer.java
@Override public List<ContactHeadline> transform(Node xml) { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); List<ContactHeadline> contactList = new ArrayList<ContactHeadline>(); try {/*from w w w . j ava 2 s . c o m*/ xml.normalize(); // Retrieve contacts from Carers section of XML NodeList nodeSet = (NodeList) xpath.evaluate("/LCR/Carers/List/RelatedPerson", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { ContactHeadline contact = new ContactHeadline(); contact.setSource("SC-CIS"); Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contactList.add(contact); } // Retrieve contacts from Allocations section of the XML nodeSet = (NodeList) xpath.evaluate("/LCR/Allocations/List/Practitioner", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { ContactHeadline contact = new ContactHeadline(); contact.setSource("SC-CIS"); Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contactList.add(contact); } } catch (XPathExpressionException e) { e.printStackTrace(); } return contactList; }
From source file:org.rippleosi.patient.contacts.search.SCCISContactSummaryTransformer.java
@Override public List<ContactSummary> transform(Node xml) { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); List<ContactSummary> contactList = new ArrayList<ContactSummary>(); try {/*from w ww . ja va 2 s. co m*/ xml.normalize(); // Retrieve contacts from Carers section of XML NodeList nodeSet = (NodeList) xpath.evaluate("/LCR/Carers/List/RelatedPerson", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { ContactSummary contact = new ContactSummary(); contact.setSource("SC-CIS"); Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); String relationshipTeam = (String) xpath.evaluate("relationship/coding/display/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contact.setRelationship(relationshipTeam); contactList.add(contact); } // Retrieve contacts from Allocations section of the XML nodeSet = (NodeList) xpath.evaluate("/LCR/Allocations/List/Practitioner", xml, XPathConstants.NODESET); for (int i = 0; i < nodeSet.getLength(); i++) { ContactSummary contact = new ContactSummary(); contact.setSource("SC-CIS"); Node node = nodeSet.item(i); String sourceId = (String) xpath.evaluate("identifier/value/@value", node, XPathConstants.STRING); String name = (String) xpath.evaluate("name/text/@value", node, XPathConstants.STRING); String relationshipTeam = (String) xpath.evaluate("practitionerRole/role/coding/display/@value", node, XPathConstants.STRING); contact.setSourceId(sourceId); contact.setName(name); contact.setRelationship(relationshipTeam); contactList.add(contact); } } catch (XPathExpressionException e) { e.printStackTrace(); } return contactList; }
From source file:org.roda.core.common.XMLUtility.java
/** * 20160518 hsilva: the inputStream gets closed in the end *///from w ww . ja v a 2 s . c o m public static String getString(InputStream inputStream, String xpath) { String ret = ""; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(new RodaEntityResolver()); Document doc; doc = builder.parse(inputStream); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xPath = xPathfactory.newXPath(); XPathExpression expr = xPath.compile(xpath); ret = (String) expr.evaluate(doc, XPathConstants.STRING); } catch (SAXException | ParserConfigurationException | XPathExpressionException | IOException e) { // do nothing and return already defined OTHER } finally { IOUtils.closeQuietly(inputStream); } return ret; }
From source file:org.roda_project.commons_ip.model.impl.hungarian.HungarianMETSUtils.java
public static void addAggregationDescriptiveMetadataToMETS(MetsWrapper metsWrapper, IPDescriptiveMetadata metadata) throws IPException, InterruptedException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); MdSecType dmdSec = metsWrapper.getMainDmdSec(); MdWrap mdWrap = dmdSec.getMdWrap();/*w ww . j ava2 s. com*/ mdWrap.setID(metadata.getId()); mdWrap.setMDTYPE(metadata.getMetadataType().getType().getType()); mdWrap.setMDTYPEVERSION(metadata.getMetadataVersion()); String mdOtherType = metadata.getMetadataType().getOtherType(); if (StringUtils.isNotBlank(mdOtherType)) { mdWrap.setOTHERMDTYPE(mdOtherType); } try (InputStream inputStream = Files.newInputStream(metadata.getMetadata().getPath())) { Document xmlDataContent = factory.newDocumentBuilder().parse(inputStream); try { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression levelExpression = xpath.compile("//archdesc/@level"); String level = (String) levelExpression.evaluate(xmlDataContent, XPathConstants.STRING); if (IPConstants.METS_LEVEL_OTHER.equalsIgnoreCase(level)) { XPathExpression otherExpression = xpath.compile("//archdesc/@otherlevel"); level = (String) otherExpression.evaluate(xmlDataContent, XPathConstants.STRING); } metsWrapper.getMainDiv().setTYPE(level); } catch (XPathExpressionException e) { LOGGER.error("Error getting archdesc level or otherlevel", e); } XmlData metadataContent = new XmlData(); metadataContent.getAny().add(xmlDataContent.getDocumentElement()); mdWrap.setXmlData(metadataContent); } catch (SAXException | ParserConfigurationException | IOException e) { LOGGER.error("Error adding EAD xml to xmlData", e); } }