List of usage examples for javax.xml.xpath XPathExpressionException printStackTrace
public void printStackTrace()
From source file:org.iish.visualmets.services.TocDaoImp.java
private ArrayList<TocMetsItem> getFilesRecursive(Document doc, ArrayList<TocMetsItem> lijst, String group, int recursive) { XPathExpression expr = null;/* w w w. j a v a 2s . co m*/ try { // als geen group pak dan root mets:div directory if (group.equals("")) { // expr = getXPathExpression("/mets:mets/mets:structMap/mets:div"); expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap"); } else { expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap//" + namespaceName + "div[@ID='" + group + "']"); } } catch (XPathExpressionException e) { e.printStackTrace(); } Object result = null; try { result = expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } NodeList nodes = (NodeList) result; // System.out.println("++++ " + "/mets:mets/mets:structMap//mets:div[@ID='" + group +"']"); for (int j = 0; j < nodes.item(0).getChildNodes().getLength(); j++) { if (nodes.item(0).getChildNodes().item(j).getNodeName().equals(namespaceName + "div")) { int somethingFound = 0; String xlink_href = ""; String thumbnail_href = ""; String FILEID = ""; for (int k = 0; k < nodes.item(0).getChildNodes().item(j).getChildNodes().getLength(); k++) { if (nodes.item(0).getChildNodes().item(j).getChildNodes().item(k).getNodeName() .equals(namespaceName + "mptr")) { somethingFound = 1; xlink_href = nodes.item(0).getChildNodes().item(j).getChildNodes().item(k).getAttributes() .getNamedItem("xlink:href").getNodeValue(); } if (nodes.item(0).getChildNodes().item(j).getChildNodes().item(k).getNodeName() .equals(namespaceName + "fptr")) { somethingFound = 1; FILEID = nodes.item(0).getChildNodes().item(j).getChildNodes().item(k).getAttributes() .getNamedItem("FILEID").getNodeValue(); } } if (somethingFound == 1) { String title = null; try { title = nodes.item(0).getChildNodes().item(j).getAttributes().getNamedItem("LABEL") .getNodeValue(); } catch (NullPointerException e) { title = "BIJ FILE DIV MOET OOK EEN LABEL!"; } if (!FILEID.equals("")) { thumbnail_href = getThumbnailUrl(doc, FILEID); } // add doc to list TocMetsItem ttt = addItem(xlink_href, title, thumbnail_href); lijst.add(ttt); } } } if (recursive == 1) { // find if current directory has subdirectories ArrayList<String> listOfSubDirectories = getArrayOfSubDirectories(nodes.item(0)); if (listOfSubDirectories.size() > 0) { for (String s : listOfSubDirectories) { lijst = getFilesRecursive(doc, lijst, s, recursive); } } } return lijst; }
From source file:org.iish.visualmets.services.TocDaoImp.java
private String getThumbnailUrl(Document doc, String FILEID) { String url = ""; // XPathFactory factory = XPathFactory.newInstance(); XPathExpression expr = null;//from w w w. ja va2 s. com try { expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "fileSec/" + namespaceName + "fileGrp/" + namespaceName + "file[@ID='" + FILEID + "']/" + namespaceName + "FLocat"); } catch (XPathExpressionException e) { e.printStackTrace(); } Object result = null; try { result = expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } NodeList nodes = (NodeList) result; if (nodes.getLength() > 0) { url = nodes.item(0).getAttributes().getNamedItem("xlink:href").getNodeValue(); } return url; }
From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java
public void removePersonObjects(Document doc) { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression personProperties = null; try {/* www . j av a 2 s. c o m*/ personProperties = xpath.compile("//*[@class='org.kuali.rice.kim.impl.identity.PersonImpl']"); NodeList matchingNodes = (NodeList) personProperties.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < matchingNodes.getLength(); i++) { Node tempNode = matchingNodes.item(i); tempNode.getParentNode().removeChild(tempNode); } } catch (XPathExpressionException e) { e.printStackTrace(); } }
From source file:org.lobid.lodmill.XmlFilenameWriter.java
@Override public void literal(final String str, String xml) { String identifier = null;/* w ww . j a v a 2 s .c o m*/ try { identifier = xPath.evaluate(filenameUtil.property, new InputSource(new StringReader(xml))); } catch (XPathExpressionException e2) { e2.printStackTrace(); } if (identifier == null || identifier.length() < filenameUtil.endIndex) { LOG.info("No identifier found, skip writing"); LOG.debug("the xml:" + xml); return; } String directory = identifier; if (directory.length() >= filenameUtil.endIndex) { directory = directory.substring(filenameUtil.startIndex, filenameUtil.endIndex); } final String file = FilenameUtils.concat(filenameUtil.target, FilenameUtils.concat(directory + File.separator, identifier + "." + filenameUtil.fileSuffix)); LOG.info("Write to " + file); filenameUtil.ensurePathExists(file); try { final Writer writer = new OutputStreamWriter(new FileOutputStream(file), filenameUtil.encoding); IOUtils.write(xml, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); throw new MetafactureException(e); } }
From source file:org.onosproject.drivers.ciena.waveserverai.netconf.CienaWaveserverAiDeviceDescriptionTest.java
@Test public void testDiscoverDeviceDetails() { XPath xp = XPathFactory.newInstance().newXPath(); SparseAnnotations expectAnnotation = DefaultAnnotations.builder().set("hostname", "hostnameWaveServer") .build();//w ww . j av a2 s . co m DefaultDeviceDescription expectResult = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "waveserver-1.1.0.302", "M000", new ChassisId(0L), expectAnnotation); try { Node node = doRequest("/response/discoverDeviceDetails.xml", "/rpc-reply/data"); SparseAnnotations annotationDevice = DefaultAnnotations.builder() .set("hostname", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)) .build(); DefaultDeviceDescription result = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(0L), annotationDevice); assertEquals(expectResult, result); } catch (XPathExpressionException e) { e.printStackTrace(); } }
From source file:org.onosproject.drivers.ciena.waveserverai.netconf.CienaWaveserverAiDeviceDescriptionTest.java
@Test public void testDiscoverPortDetails() { List<PortDescription> result = new ArrayList<>(); List<PortDescription> expectResult = getExpectedPorts(); try {//from w ww .ja v a 2 s . co m XPath xp = XPathFactory.newInstance().newXPath(); Node nodeListItem; Node node = doRequest("/response/discoverPortDetails.xml", "/rpc-reply/data"); NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET); int count = nodeList.getLength(); for (int i = 0; i < count; ++i) { nodeListItem = nodeList.item(i); DefaultAnnotations annotationPort = DefaultAnnotations.builder() .set(AnnotationKeys.PORT_NAME, xp.evaluate("port-id/text()", nodeListItem)) .set(AnnotationKeys.PROTOCOL, xp.evaluate("id/type/text()", nodeListItem)).build(); String port = xp.evaluate("port-id/text()", nodeListItem); result.add(DefaultPortDescription.builder() .withPortNumber(PortNumber.portNumber(portIdConvert(port), port)) .isEnabled(portStateConvert(xp.evaluate("state/operational-state/text()", nodeListItem))) .portSpeed(portSpeedToLong(xp.evaluate("id/speed/text()", nodeListItem))) .type(Port.Type.PACKET).annotations(annotationPort).build()); } } catch (XPathExpressionException e) { e.printStackTrace(); } assertEquals(expectResult, result); }
From source file:org.onosproject.drivers.ciena.waveserverai.netconf.CienaWaveserverAiDeviceDescriptionTest.java
@Test public void testDiscoverPortStatistics() { Collection<PortStatistics> result = new ArrayList<>(); Collection<PortStatistics> expectResult = getExpectedPortsStatistics(); try {/*from ww w . ja v a2 s .co m*/ XPath xp = XPathFactory.newInstance().newXPath(); String tx = "current-bin/statistics/interface-counts/tx/"; String rx = "current-bin/statistics/interface-counts/rx/"; Node node = doRequest("/response/discoverPortStatistics.xml", "/rpc-reply/data"); NodeList nodeList = (NodeList) xp.evaluate("waveserver-pm/ethernet-performance-instances", node, XPathConstants.NODESET); Node nodeListItem; int count = nodeList.getLength(); for (int i = 0; i < count; ++i) { nodeListItem = nodeList.item(i); result.add(DefaultPortStatistics.builder().setDeviceId(mockDeviceId) .setPort(PortNumber .portNumber(portIdConvert(xp.evaluate("instance-name/text()", nodeListItem)))) .setBytesReceived(Long.parseLong(xp.evaluate(rx + "bytes/value/text()", nodeListItem))) .setPacketsReceived(Long.parseLong(xp.evaluate(rx + "packets/value/text()", nodeListItem))) .setBytesSent(Long.parseLong(xp.evaluate(tx + "bytes/value/text()", nodeListItem))) .setPacketsSent(Long.parseLong(xp.evaluate(tx + "packets/value/text()", nodeListItem))) .build()); } } catch (XPathExpressionException e) { e.printStackTrace(); } // TODO: the builder causes this test to fail // assertEquals(expectResult, result); }
From source file:org.openhab.binding.fritzboxtr064.internal.Tr064Comm.java
/** * Connects to fbox service xml to get a list of all services which are offered * by TR064. Saves it into local list.//from ww w . j a v a2s . c o m */ private void readAllServices() { Document xml = getFboxXmlResponse(_url + "/" + TR064DOWNLOADFILE); if (xml == null) { logger.error("Could not read xml response services"); return; } NodeList nlServices = xml.getElementsByTagName("service"); // get all service nodes Node currentNode = null; XPath xPath = XPathFactory.newInstance().newXPath(); for (int i = 0; i < nlServices.getLength(); i++) { // iterate over all services fbox offered us currentNode = nlServices.item(i); Tr064Service trS = new Tr064Service(); try { trS.setControlUrl((String) xPath.evaluate("controlURL", currentNode, XPathConstants.STRING)); trS.setEventSubUrl((String) xPath.evaluate("eventSubURL", currentNode, XPathConstants.STRING)); trS.setScpdurl((String) xPath.evaluate("SCPDURL", currentNode, XPathConstants.STRING)); trS.setServiceId((String) xPath.evaluate("serviceId", currentNode, XPathConstants.STRING)); trS.setServiceType((String) xPath.evaluate("serviceType", currentNode, XPathConstants.STRING)); } catch (XPathExpressionException e) { logger.debug("Could not parse service {}", currentNode.getTextContent()); e.printStackTrace(); } _allServices.put(trS.getServiceId(), trS); } }
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 {/*w w w . j a v a 2s . c om*/ // 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 a v a 2s. c om*/ 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; }