List of usage examples for javax.xml.xpath XPathFactory newXPath
public abstract XPath newXPath();
Return a new XPath
using the underlying object model determined when the XPathFactory was instantiated.
From source file:org.jembi.rhea.orchestration.SaveEncounterORU_R01ValidatorAndEnricher.java
/** * Fetch patient demographic data from the Client Registry and enrich the ORU_R01 with any details that may be missing. * @throws ClientValidationException // w ww . java 2 s . co m */ protected void enrichClientDemographics(MuleClient client, ORU_R01 oru_r01, String ecid) throws MuleException, EncounterEnrichmentException, ClientValidationException { PID pid = oru_r01.getPATIENT_RESULT().getPATIENT().getPID(); String givenName = pid.getPatientName(0).getGivenName().getValue(); String familyName = pid.getPatientName(0).getFamilyName().getFn1_Surname().getValue(); String gender = pid.getAdministrativeSex().getValue(); String dob = pid.getDateTimeOfBirth().getTime().getValue(); try { if ((givenName == null || givenName.isEmpty()) || (familyName == null || familyName.isEmpty()) || (gender == null || gender.isEmpty()) || (dob == null || dob.isEmpty())) { // fetch client record from CR to enrich message as it is missing key values String clientRecord = fetchClientRecord_OpenEMPI(ecid, client); if (clientRecord == null) throw new ClientValidationException(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document document = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(clientRecord))); XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); String givenNameFromCR = getNodeContent(xpath, document, "/ADT_A05/PID/PID.5/XPN.2"); String familyNameFromCR = getNodeContent(xpath, document, "/ADT_A05/PID/PID.5/XPN.1/FN.1"); String genderFromCR = getNodeContent(xpath, document, "/ADT_A05/PID/PID.8"); String dobStrFromCR = getNodeContent(xpath, document, "/ADT_A05/PID/PID.7/TS.1"); // replace the missing fields with the CR content if (givenName == null || givenName.isEmpty()) { pid.getPatientName(0).getGivenName().setValue(givenNameFromCR); } if (familyName == null || familyName.isEmpty()) { pid.getPatientName(0).getFamilyName().getFn1_Surname().setValue(familyNameFromCR); } if (gender == null || gender.isEmpty()) { pid.getAdministrativeSex().setValue(genderFromCR); } if (dob == null || dob.isEmpty()) { pid.getDateTimeOfBirth().getTime().setValue(dobStrFromCR); } } } catch (XPathException ex) { throw new EncounterEnrichmentException(ex); } catch (SAXException ex) { throw new EncounterEnrichmentException(ex); } catch (IOException ex) { throw new EncounterEnrichmentException(ex); } catch (ParserConfigurationException ex) { throw new EncounterEnrichmentException(ex); } catch (DataTypeException ex) { throw new EncounterEnrichmentException(ex); } }
From source file:org.jenkinsci.plugins.tibco.installation.TibcoInstallation.java
/** * find Tibco executable fo exec name. actually it finds only ant wrapper * TODO add a registry wher lookup for exec name and version * @param home/* ww w . jav a2 s . co m*/ * @param execName * @return File executable */ private File findTibcoExecutable(String home, String execName) { String installPath = ""; File installInfo = new File(home, "_installInfo"); if (execName.startsWith("amx_eclipse_ant")) { WildcardFileFilter filter = new WildcardFileFilter("amx-design_*_prodInfo.xml"); String[] list = installInfo.list(filter); javax.xml.xpath.XPathFactory xpathFactory = javax.xml.xpath.XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { //for(int i = 0; i<list.length;i++){ InputSource source = new InputSource(new FileInputStream(new File(installInfo, list[0])));//TODO add combo with more exec version for installation installPath = (String) xpath.evaluate( "/TIBCOInstallerFeatures/installerFeature[@name=\"sds-core\"]/assemblyList/assembly[@uid=\"product_tibco_com_tibco_amx_eclipse_ant\"]/@installLocation", source, XPathConstants.STRING); //String execVersion= (String)xpath.evaluate("/TIBCOInstallerFeatures/installerFeature[@name=\"sds-core\"]/assemblyList/assembly[@uid=\"product_tibco_com_tibco_amx_eclipse_ant\"]/@version", source,XPathConstants.STRING); //TibcoExecVersion version = new TibcoExecVersion(i, installPath, execName, execVersion); //this.addTibcoExecVersion(version); //} } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else {//TODO fixme it doesn't really good. i need to find a way to lookup a studio tools installation WildcardFileFilter filter = new WildcardFileFilter("businessevents-standard_*_prodInfo.xml"); String[] list = installInfo.list(filter); javax.xml.xpath.XPathFactory xpathFactory = javax.xml.xpath.XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { //for(int i = 0; i<list.length;i++){ installPath += getHome(); installPath += "/"; InputSource source = new InputSource(new FileInputStream(new File(installInfo, list[0]))); installPath += (String) xpath.evaluate( "/TIBCOInstallerFeatures/productDef[@compatDisplayName=\"TIBCO BusinessEvents\"]/@installDir", source, XPathConstants.STRING); installPath += "/studio/bin"; //String execVersion ="5.1";//(String)xpath.evaluate("/TIBCOInstallerFeatures/productDef/featureConfigInclude/include[@id=\"be-studio\"]/@version", source,XPathConstants.STRING); //TibcoExecVersion version = new TibcoExecVersion(i, installPath, execName, execVersion); //this.addTibcoExecVersion(version); //} } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return new File(installPath, execName); }
From source file:org.kepler.kar.karxml.KarXml.java
private static void setupXPathExpressions() { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); try {/*from w ww .j av a 2 s . c om*/ GET_KAR_VERSION_EXPRESSION = xpath .compile("/*[local-name() = 'kar']/mainAttributes/KAR-Version/text()"); GET_NAME_EXPRESSION = xpath.compile("/*[local-name() = 'kar']/karFileName/text()"); GET_SIZE_EXPRESSION = xpath.compile("/*[local-name() = 'kar']/karFileSize/text()"); GET_MANIFEST_VERSION_EXPRESSION = xpath .compile("/*[local-name() = 'kar']/mainAttributes/Manifest-Version/text()"); GET_MODULE_DEPENDENCIES_EXPRESSION = xpath .compile("/*[local-name() = 'kar']/mainAttributes/module-dependencies/text()"); GET_LSID_EXPRESSION = xpath.compile("/*[local-name() = 'kar']/mainAttributes/lsid/text()"); GET_KAR_ENTRIES = xpath.compile("/*[local-name() = 'kar']/karEntry"); GKE_NAME_EXPRESSION = xpath.compile("karEntryAttributes/Name/text()"); GKE_DEPENDS_ON_EXPRESSION = xpath.compile("karEntryAttributes/dependsOn/text()"); GKE_TYPE_EXPRESSION = xpath.compile("karEntryAttributes/type/text()"); GKE_LSID_EXPRESSION = xpath.compile("karEntryAttributes/lsid/text()"); GKE_HANDLER_EXPRESSION = xpath.compile("karEntryAttributes/handler/text()"); //only used by 2.0.0: GKE_DEPENDS_ON_MODULE_EXPRESSION = xpath.compile("karEntryAttributes/dependsOnModule/text()"); GKE_XML_EXPRESSION = xpath.compile("karEntryXML"); GKE_GET_SEMANTIC_TYPES = xpath .compile("karEntryXML/entity/property[@class=\"org.kepler.sms.SemanticType\"]/@value"); GKE_GET_WORKFLOW_NAME = xpath.compile("karEntryXML/entity/@name"); GKE_GET_DIRECTOR = xpath.compile("karEntryXML/entity/property/property[@name=\"entityId\"]/@value"); GKE_GET_DERIVEDFROM = xpath .compile("karEntryXML/entity/property/property[@name=\"derivedFrom\"]/@value"); } catch (XPathExpressionException ex) { log.error("Exception", ex); // Make sure all expression are in a mutually consistent state GET_KAR_VERSION_EXPRESSION = null; GET_NAME_EXPRESSION = null; GET_SIZE_EXPRESSION = null; GET_MANIFEST_VERSION_EXPRESSION = null; GET_MODULE_DEPENDENCIES_EXPRESSION = null; GET_LSID_EXPRESSION = null; GET_KAR_ENTRIES = null; GKE_DEPENDS_ON_EXPRESSION = null; GKE_TYPE_EXPRESSION = null; GKE_LSID_EXPRESSION = null; GKE_HANDLER_EXPRESSION = null; //only used by 2.0.0: GKE_DEPENDS_ON_MODULE_EXPRESSION = null; GKE_XML_EXPRESSION = null; GKE_GET_SEMANTIC_TYPES = null; GKE_GET_WORKFLOW_NAME = null; GKE_GET_DIRECTOR = null; GKE_GET_DERIVEDFROM = null; } }
From source file:org.kramerius.replications.SecondPhase.java
private void replicateImg(String pid, String url, File foxml) throws PhaseException { try {//from ww w . j a v a2 s. c o m String handlePid = K4ReplicationProcess.pidFrom(url); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(foxml); String relsExt = RelsExtHelper.getRelsExtTilesUrl(document); // url of tiles if (relsExt != null) { InputStream stream = orignalImgData(pid, url); String imageserverDir = KConfiguration.getInstance().getConfiguration() .getString("convert.imageServerDirectory"); String path = imageserverDir + File.separator + handlePid.substring(5) + File.separator; FileUtils.forceMkdir(new File(path)); File replicatedImage = new File(path + pid.substring(5) + ".jp2"); FileUtils.copyInputStreamToFile(stream, replicatedImage); XPathFactory xpfactory = XPathFactory.newInstance(); XPath xpath = xpfactory.newXPath(); xpath.setNamespaceContext(new FedoraNamespaceContext()); Node nodeTilesUrl = (Node) xpath.evaluate("//kramerius:tiles-url", document, XPathConstants.NODE); String imageServerTilesUrl = KConfiguration.getInstance().getConfiguration() .getString("convert.imageServerTilesURLPrefix"); String suffixTiles = KConfiguration.getInstance().getConfiguration() .getString("convert.imageServerSuffix.tiles"); String imageTilesUrl; if (KConfiguration.getInstance().getConfiguration() .getBoolean("convert.imageServerSuffix.removeFilenameExtensions", false)) { imageTilesUrl = imageServerTilesUrl + "/" + handlePid.substring(5) + pid.substring(5) + suffixTiles; } else { imageTilesUrl = imageServerTilesUrl + "/" + handlePid.substring(5) + pid.substring(5) + ".jp2" + suffixTiles; } nodeTilesUrl.setTextContent(imageTilesUrl); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new StreamResult(foxml)); } } catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException | TransformerException e) { throw new PhaseException(this, e); } }
From source file:org.kuali.ole.select.service.impl.BibInfoServiceImpl.java
public BibInfoBean retrieve(String titleId) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("inside BibInfoService retrieve-- titleid----------->" + titleId); }//w w w . j a va 2 s . c om XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); XPathExpression expr = xpath.compile("//bibData[titleId='" + titleId + "']"); Object result = expr.evaluate(parseDocStoreContent(), XPathConstants.NODESET); NodeList nodes = (NodeList) result; BibInfoBean bibInfoBean = new BibInfoBean(); if (nodes.getLength() > 0) { Node node = nodes.item(0); NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node tempNode = list.item(i); convertToBean(bibInfoBean, tempNode.getNodeName(), tempNode.getTextContent()); if (LOG.isDebugEnabled()) { LOG.debug("node name--------->" + tempNode.getNodeName()); LOG.debug("node text--------->" + tempNode.getTextContent()); } } } return bibInfoBean; }
From source file:org.kuali.ole.select.service.impl.BibInfoServiceImpl.java
@Override public boolean isExists(HashMap map) throws Exception { String externalDirectory = configurationService .getPropertyValueAsString(OLEConstants.STAGING_DIRECTORY_KEY); String fileName = configurationService.getPropertyValueAsString(OLEConstants.DOCSTORE_FILE_KEY); if (LOG.isInfoEnabled()) { LOG.info("Doc Store file Path :" + externalDirectory + fileName); }//from www . j a v a2s . c o m File file = new File(externalDirectory + fileName); if (!file.exists()) { return false; } if (map.size() == 0) { return false; } XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); StringBuilder sBuff = new StringBuilder("//bibData"); Set set = map.keySet(); Iterator<String> setIt = set.iterator(); String value = null; while (setIt.hasNext()) { String key = setIt.next(); //sBuff.append("[" + key + "='" + map.get(key) + "']"); value = (String) map.get(key); if (value.indexOf("\"") != -1) { sBuff.append("[translate(" + key + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate('" + map.get(key) + "','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]"); } else { sBuff.append("[translate(" + key + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate(\"" + map.get(key) + "\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]"); } } if (LOG.isDebugEnabled()) { LOG.debug("XPath expr :" + sBuff.toString()); } XPathExpression expr = xpath.compile(sBuff.toString()); Object result = expr.evaluate(parseDocStoreContent(), XPathConstants.NODESET); NodeList nodeList = (NodeList) result; if (LOG.isDebugEnabled()) { LOG.debug("NodeList length :" + nodeList.getLength()); } if (nodeList.getLength() > 0) { return true; } else { return false; } }
From source file:org.kuali.ole.select.service.impl.BibInfoServiceImpl.java
@Override public List search(HashMap map, int noOfRecords) throws Exception { List<BibInfoBean> bibInfoBeanList = new ArrayList<BibInfoBean>(); XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); StringBuilder stringExpression = new StringBuilder("//bibData"); Set set = map.keySet();/*from w w w . ja v a2 s .c om*/ Iterator<String> setIt = set.iterator(); String value = null; while (setIt.hasNext()) { String key = setIt.next(); //sBuff.append("[" + key + "='" + map.get(key) + "']"); value = (String) map.get(key); if (value.indexOf("\"") != -1) { stringExpression.append("[translate(" + key + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate('" + map.get(key) + "','ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]"); } else { stringExpression.append("[translate(" + key + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate(\"" + map.get(key) + "\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')]"); } } if (LOG.isDebugEnabled()) { LOG.debug("XPath expr :" + stringExpression.toString()); } XPathExpression expr = xpath.compile(stringExpression.toString()); Object result = expr.evaluate(parseDocStoreContent(), XPathConstants.NODESET); NodeList nodeList = (NodeList) result; BibInfoBean bibInfoBean; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); NodeList list = node.getChildNodes(); bibInfoBean = new BibInfoBean(); for (int j = 0; j < list.getLength(); j++) { Node tempNode = list.item(j); convertToBean(bibInfoBean, tempNode.getNodeName(), tempNode.getTextContent()); } bibInfoBeanList.add(bibInfoBean); if (i == (noOfRecords - 1)) { break; } } return bibInfoBeanList; }
From source file:org.metaeffekt.dcc.commons.ant.MergeXmlTaskTest.java
private NodeList getNodes(Document document, String xpathString) throws XPathExpressionException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath nodesToFindXPath = xPathfactory.newXPath(); XPathExpression nodesToFindExpression = nodesToFindXPath.compile(xpathString); return (NodeList) nodesToFindExpression.evaluate(document, XPathConstants.NODESET); }
From source file:org.mule.GoogleMapsModule.java
private String getXPath(InputStream inputStream, String xpath) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);//from ww w . j a va 2 s .com Document doc = dbf.newDocumentBuilder().parse(inputStream); XPathFactory factory = XPathFactory.newInstance(); XPathExpression expr = factory.newXPath().compile(xpath); return (String) expr.evaluate(doc, XPathConstants.STRING); }
From source file:org.mycontroller.standalone.api.XmlApi.java
private XPathExpression getXPathExpression(String xpath) throws XPathExpressionException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpathObj = xPathfactory.newXPath(); return xpathObj.compile(xpath); }