List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:com.mirth.connect.model.converters.DICOMSerializer.java
private void renameTagToAttr(Document document, Node node) throws DOMException { NamedNodeMap attr = node.getAttributes(); if (attr != null) { Node tagAttr = attr.getNamedItem("tag"); if (tagAttr != null) { String tag = "tag" + tagAttr.getNodeValue(); if (!tag.equals("?") && tag.equals(node.getNodeName())) { document.renameNode(node, null, "attr"); }/*www . ja va 2 s. c o m*/ } } }
From source file:com.microsoft.alm.plugin.external.commands.StatusCommand.java
/** * Parses the output of the status command when formatted as xml. * SAMPLE//from w w w .j ava 2s .c o m * <?xml version="1.0" encoding="utf-8"?> * <status> * <pending-changes/> * <candidate-pending-changes> * <pending-change server-item="$/tfsTest_01/test.txt" version="0" owner="jason" date="2016-07-13T12:36:51.060-0400" lock="none" change-type="add" workspace="MyNewWorkspace2" computer="JPRICKET-DEV2" local-item="D:\tmp\test\test.txt"/> * </candidate-pending-changes> * </status> */ @Override public List<PendingChange> parseOutput(final String stdout, final String stderr) { super.throwIfError(stderr); final List<PendingChange> changes = new ArrayList<PendingChange>(100); final NodeList nodes = super.evaluateXPath(stdout, "/status/*/pending-change"); // Convert all the xpath nodes to pending change models if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { final NamedNodeMap attributes = nodes.item(i).getAttributes(); final boolean isCandidate = StringUtils .equalsIgnoreCase(nodes.item(i).getParentNode().getNodeName(), CANDIDATE_TAG); final Node sourceItem = attributes.getNamedItem("source-item"); // not always present changes.add(new PendingChange(attributes.getNamedItem("server-item").getNodeValue(), attributes.getNamedItem("local-item").getNodeValue(), attributes.getNamedItem("version").getNodeValue(), attributes.getNamedItem("owner").getNodeValue(), attributes.getNamedItem("date").getNodeValue(), attributes.getNamedItem("lock").getNodeValue(), attributes.getNamedItem("change-type").getNodeValue(), attributes.getNamedItem("workspace").getNodeValue(), attributes.getNamedItem("computer").getNodeValue(), isCandidate, sourceItem != null ? sourceItem.getNodeValue() : StringUtils.EMPTY)); } } return changes; }
From source file:com.axelor.apps.base.test.PrepareCsv.java
@Test public void prepareCsv() { String xmlDir = System.getProperty("xmlDir"); String csvDir = System.getProperty("csvDir"); List<String> ignoreType = Arrays.asList("one-to-one", "many-to-many", "one-to-many"); try {// www . j ava2 s . c o m if (xmlDir != null && csvDir != null) { File xDir = new File(xmlDir); File cDir = new File(csvDir); List<String[]> blankData = new ArrayList<String[]>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); if (xDir.isDirectory() && cDir.isDirectory()) { for (File xf : xDir.listFiles()) { LOG.info("Processing XML: " + xf.getName()); List<String> fieldList = new ArrayList<String>(); Document doc = dBuilder.parse(xf); NodeList nList = doc.getElementsByTagName("module"); String module = nList.item(0).getAttributes().getNamedItem("name").getNodeValue(); nList = doc.getElementsByTagName("entity"); if (nList != null) { NodeList fields = nList.item(0).getChildNodes(); Integer count = 0; String csvFileName = module + "_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, xf.getName().replace(".xml", ".csv")); while (count < fields.getLength()) { Node field = fields.item(count); NamedNodeMap attrs = field.getAttributes(); String type = field.getNodeName(); if (attrs != null && attrs.getNamedItem("name") != null && !ignoreType.contains(type)) { String fieldName = attrs.getNamedItem("name").getNodeValue(); if (type.equals("many-to-one")) { String[] objName = attrs.getNamedItem("ref").getNodeValue().split("\\."); String refName = objName[objName.length - 1]; String nameColumn = getNameColumn(xmlDir + "/" + refName + ".xml"); if (nameColumn != null) fieldList.add(fieldName + "." + nameColumn); else { fieldList.add(fieldName); LOG.error("No name column found for " + refName + ", field '" + attrs.getNamedItem("name").getNodeValue() + "'"); } } else fieldList.add(fieldName); } count++; } cTool.csvWriter(csvDir, csvFileName, ';', StringUtils.join(fieldList, ",").split(","), blankData); LOG.info("CSV file prepared: " + csvFileName); } } } else LOG.error("XML and CSV paths must be directory"); } else LOG.error("Please input XML and CSV directory path"); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.planets_project.tb.impl.services.tags.DefaultServiceTagHandlerImpl.java
private void parseTags() { int defaultPriority = 2; NodeList tags = root.getElementsByTagName("tag"); for (int k = 0; k < tags.getLength(); k++) { ServiceTagImpl serTag = new ServiceTagImpl(); Node tag = tags.item(k);//from www . j av a 2 s . com NodeList tag_children = tag.getChildNodes(); NamedNodeMap tagattributes = tag.getAttributes(); try { //priority not mandatory - may have a default value int priority = Integer.parseInt(tagattributes.getNamedItem("priority").getNodeValue()); serTag.setPriority(priority); } catch (Exception e) { serTag.setPriority(defaultPriority); } for (int i = 0; i < tag_children.getLength(); i++) { Node child = tag_children.item(i); if (child.getNodeName().equals("name") && child.getNodeType() == Node.ELEMENT_NODE) { //set name serTag.setName(child.getTextContent()); } if (child.getNodeName().equals("description") && child.getNodeType() == Node.ELEMENT_NODE) { //set description serTag.setDescription(child.getTextContent()); } } //store tag, name is id this.hmDefaultTags.put(serTag.getName(), serTag); } }
From source file:com.axelor.csv.script.PrepareCsv.java
/** * Method to generate csv files/*w w w . j a v a2s. c o m*/ * @param xmlDir * @param csvDir */ public void prepareCsv(String xmlDir, String csvDir) { List<String> ignoreType = Arrays.asList("one-to-one", "many-to-many", "one-to-many"); try { if (xmlDir != null && csvDir != null) { File xDir = new File(xmlDir); File cDir = new File(csvDir); List<String[]> blankData = new ArrayList<String[]>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); if (xDir.isDirectory() && cDir.isDirectory()) { for (File xf : xDir.listFiles()) { LOG.info("Processing XML: " + xf.getName()); List<String> fieldList = new ArrayList<String>(); Document doc = dBuilder.parse(xf); NodeList nList = doc.getElementsByTagName("module"); String module = nList.item(0).getAttributes().getNamedItem("name").getNodeValue(); nList = doc.getElementsByTagName("entity"); if (nList != null) { NodeList fields = nList.item(0).getChildNodes(); Integer count = 0; String csvFileName = module + "_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, xf.getName().replace(".xml", ".csv")); while (count < fields.getLength()) { Node field = fields.item(count); NamedNodeMap attrs = field.getAttributes(); String type = field.getNodeName(); if (attrs != null && attrs.getNamedItem("name") != null && !ignoreType.contains(type)) { String fieldName = attrs.getNamedItem("name").getNodeValue(); if (type.equals("many-to-one")) { String[] objName = attrs.getNamedItem("ref").getNodeValue().split("\\."); String refName = objName[objName.length - 1]; String nameColumn = getNameColumn(xmlDir + "/" + refName + ".xml"); if (nameColumn != null) fieldList.add(fieldName + "." + nameColumn); else { fieldList.add(fieldName); LOG.error("No name column found for " + refName + ", field '" + attrs.getNamedItem("name").getNodeValue() + "'"); } } else fieldList.add(fieldName); } count++; } CsvTool.csvWriter(csvDir, csvFileName, ';', StringUtils.join(fieldList, ",").split(","), blankData); LOG.info("CSV file prepared: " + csvFileName); } } } else LOG.error("XML and CSV paths must be directory"); } else LOG.error("Please input XML and CSV directory path"); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.masconsult.bgbanking.banks.fibank.ebanking.EFIBankClient.java
private void obtainSession(DefaultHttpClient httpClient, AuthToken authToken) throws IOException, AuthenticationException { HttpEntity entity;/*from www. j a v a2 s . co m*/ try { entity = new StringEntity("<?xml version=\"1.0\"?><LOGIN><USER_NAME>" + authToken.username + "</USER_NAME><USER_PASS>" + authToken.password + "</USER_PASS><USER_LANG>BG</USER_LANG><PATH>Login</PATH></LOGIN>", "utf-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } HttpPost post = new HttpPost(LOGIN_URL); post.addHeader("Content-Type", "text/xml"); post.setHeader("Accept", "*/*"); post.setEntity(entity); HttpResponse resp = httpClient.execute(post); if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new AuthenticationException("Invalid credentials!"); } String response = EntityUtils.toString(resp.getEntity()); Log.v(TAG, "response = " + response); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage()); } InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc; try { doc = db.parse(is); } catch (SAXException e) { throw new ParseException(e.getMessage()); } NodeList session = doc.getElementsByTagName("SESSION"); if (session == null || session.getLength() != 1) { throw new ParseException("can't find SESSION "); } NamedNodeMap attributes = session.item(0).getAttributes(); authToken.sessionId = attributes.getNamedItem("id").getTextContent(); }
From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
private Element getRouterElement(Document document) { NodeList beanNodesList = document.getElementsByTagName("bean"); Node routerNode = null;/* w ww. j av a 2s . co m*/ for (int i = 0; i < beanNodesList.getLength(); i++) { Node node = beanNodesList.item(i); NamedNodeMap nodeMap = node.getAttributes(); Node idNode = nodeMap.getNamedItem("id"); String id = idNode.getNodeValue(); // FIXME What happens if the router is not called router? if (id.equals("Router")) { routerNode = node; } } return (Element) routerNode; }
From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
private void stripOffProcessors(Element routerElement) { NodeList propertyNodes = routerElement.getElementsByTagName("property"); for (int i = 0; i < propertyNodes.getLength(); i++) { Node node = propertyNodes.item(i); NamedNodeMap nodeMap = node.getAttributes(); Node nameNode = nodeMap.getNamedItem("name"); String value = nameNode.getNodeValue(); // FIXME What happens if no map is used within the router? if (value.equals("processMap")) { NodeList propertyChilds = ((Element) node).getElementsByTagName("map"); Node mapNode = propertyChilds.item(0); removeProcessors(mapNode);//from w w w .j a v a2 s. c o m } } }
From source file:com.mediaworx.intellij.opencmsplugin.opencms.OpenCmsConfiguration.java
/** * Reads the export points from the module configuration * @param moduleName the module whose export points should be returned * @return A List of export points for the given module */// w w w .j av a2 s . c om public List<OpenCmsModuleExportPoint> getExportPointsForModule(String moduleName) { List<OpenCmsModuleExportPoint> exportPoints = new ArrayList<OpenCmsModuleExportPoint>(); Document configDocument = getParsedModuleConfigurationFile(); if (configDocument != null) { try { NodeList nl = xmlHelper.getNodeListForXPath(configDocument, String.format(EXPORTPOINT_XPATH, moduleName)); int numExportPoints = nl.getLength(); for (int i = 0; i < numExportPoints; i++) { Node n = nl.item(i); NamedNodeMap attr = n.getAttributes(); String uri = attr.getNamedItem("uri").getNodeValue(); String destination = attr.getNamedItem("destination").getNodeValue(); LOG.info("Exportpoint " + (i + 1) + ": uri=" + uri + " - destination=" + destination); exportPoints.add(new OpenCmsModuleExportPoint(uri, destination)); } } catch (Exception e) { LOG.warn("There was an Exception initializing export points for module " + moduleName, e); } } return exportPoints; }
From source file:com.mediaworx.intellij.opencmsplugin.opencms.OpenCmsConfiguration.java
/** * Reads the module resource from the module configuration * @param moduleName the module whose resources should be returned * @return A List of module resources for the given module *//*ww w . jav a2s . c om*/ public List<String> getModuleResourcesForModule(String moduleName) { List<String> moduleResources = new ArrayList<String>(); Document configDocument = getParsedModuleConfigurationFile(); if (configDocument != null) { try { NodeList nl = xmlHelper.getNodeListForXPath(configDocument, String.format(MODULE_RESOURCE_XPATH, moduleName)); int numResources = nl.getLength(); for (int i = 0; i < numResources; i++) { Node n = nl.item(i); NamedNodeMap attr = n.getAttributes(); String uri = attr.getNamedItem("uri").getNodeValue(); LOG.info("Module Resource " + (i + 1) + ": uri=" + uri); moduleResources.add(uri); } } catch (Exception e) { LOG.warn("There was an Exception initializing export points for module " + moduleName, e); } } return moduleResources; }