List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private OperationResult readOperationResult(Node operationResultNode) { OperationResult or = new OperationResult(); NamedNodeMap nodeAttributes = operationResultNode.getAttributes(); if (nodeAttributes.getNamedItem("version") != null) or.setVersion(nodeAttributes.getNamedItem("version").getNodeValue()); NodeList childsOfChild = operationResultNode.getChildNodes(); for (int c_count = 0; c_count < childsOfChild.getLength(); c_count++) { Node child_child = (Node) childsOfChild.item(c_count); if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("returnCode")) { or.setReturnCode(Integer.parseInt(readPCDATA(child_child))); } else if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("returnMessage")) { or.setMessage(readPCDATA(child_child)); } else if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("resourceDescriptor")) { or.getResourceDescriptors().add(readResourceDescriptor((Element) child_child)); }/*from w ww. j a v a2 s .com*/ } return or; }
From source file:com.avlesh.web.filter.responseheaderfilter.ConfigProcessor.java
/** * Parser for a <code><conditional></code> node; converts the node into a * {@link Mapping.Condition}/*from w w w. j a v a 2s .c o m*/ * <br/> * Nodes with empty or undeclared <code>queryParamName</code> and/or <code>queryParamValue</code> are not parsed * and return a null. * <br/> * <code>queryParamValue</code> is parsed as a {@link Pattern} * * @param node (<conditional> {@link Node} in the <code>configFile</code>) * @return {@link Mapping.Condition} (parsed <conditional> tag) */ private Mapping.Condition getCondition(Node node) { Mapping.Condition condition = null; NamedNodeMap attributeMap = node.getAttributes(); Node queryParamNameNode = attributeMap.getNamedItem("queryParamName"); Node queryParamValueNode = attributeMap.getNamedItem("queryParamValue"); //both attributes are mandatory if (queryParamNameNode != null && queryParamValueNode != null) { String queryParamName = queryParamNameNode.getNodeValue(); String queryParamValue = queryParamValueNode.getNodeValue(); //empty values for either of the attributes is not acceptable if (StringUtils.isNotEmpty(queryParamName) && StringUtils.isNotEmpty(queryParamValue)) { condition = new Mapping.Condition(); condition.setQueryParamName(queryParamName); condition.setQueryParamValue(Pattern.compile(queryParamValue)); } } return condition; }
From source file:com.blackbear.flatworm.ConfigurationReader.java
private Node getAttributeNamed(Node node, String name) { NamedNodeMap map = node.getAttributes(); return map.getNamedItem(name); }
From source file:fi.csc.kapaVirtaAS.WSDLManipulator.java
public void generateVirtaKapaWSDL() throws Exception { // Fetch current WSDL-file File inputFile = new File("opiskelijatiedot.wsdl"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.setXmlVersion("1.0"); doc.getDocumentElement().normalize(); // Manipulate WSDL to meet the requirements of xroad // Root element <wsdl:definitions> attribute manipulations Element root = doc.getDocumentElement(); root.setAttribute("xmlns:" + conf.getXroadSchemaPrefixForWSDL(), conf.getXroadSchema()); root.setAttribute("xmlns:" + conf.getXroadIdSchemaPrefixForWSDL(), conf.getXroadIdSchema()); root = replaceAttribute(root, "xmlns:tns", conf.getAdapterServiceSchema()); root = replaceAttribute(root, "targetNamespace", conf.getAdapterServiceSchema()); // Schema elements <xs:schema> attribute manipulations NodeList schemas = root.getElementsByTagName("xs:schema"); for (int i = 0; i < schemas.getLength(); ++i) { Node schema = schemas.item(i); if (schema != null) { NamedNodeMap schemaAttributes = schema.getAttributes(); if (schemaAttributes != null && schemaAttributes.getNamedItem("xmlns:virtaluku") != null) { schemaAttributes.getNamedItem("xmlns:virtaluku").setTextContent(conf.getAdapterServiceSchema()); if (schemaAttributes != null && schemaAttributes.getNamedItem("targetNamespace") != null) { schemaAttributes.getNamedItem("targetNamespace") .setTextContent(conf.getAdapterServiceSchema()); }// ww w. j a va 2 s .co m Element el = (Element) schema.appendChild(doc.createElement("xs:import")); el.setAttribute("id", conf.getXroadSchemaPrefixForWSDL()); el.setAttribute("namespace", conf.getXroadSchema()); el.setAttribute("schemaLocation", conf.getXroadSchema()); // Remove Request part from xs:element -elements NodeList elementsInSchema = schema.getChildNodes(); for (int j = 0; j < elementsInSchema.getLength(); ++j) { Element el1 = (Element) elementsInSchema.item(j); if (el1.getNodeName() == "xs:element") { replaceAttribute(el1, "name", StringUtils.substringBefore(el1.getAttribute("name"), "Request")); } } } } } // Append xroad request headers Element xroadReqHeadersElement = doc.createElement("wsdl:message"); xroadReqHeadersElement.setAttribute("name", "requestheader"); for (String xroadHeader : conf.getXroadHeaders()) { Element reqHeader = doc.createElement("wsdl:part"); reqHeader.setAttribute("name", xroadHeader); reqHeader.setAttribute("element", conf.getXroadSchemaPrefixForWSDL() + ":" + xroadHeader); xroadReqHeadersElement.appendChild(reqHeader); } root.appendChild(xroadReqHeadersElement); NodeList childrenList = root.getChildNodes(); for (int i = 0; i < childrenList.getLength(); ++i) { if (childrenList.item(i).getNodeName().contains(":binding")) { NodeList binding = childrenList.item(i).getChildNodes(); for (int j = 0; j < binding.getLength(); ++j) { if (binding.item(j).getNodeName().contains(":operation")) { Element el1 = (Element) binding.item(j) .appendChild(doc.createElement(conf.getXroadIdSchemaPrefixForWSDL() + ":version")); el1.setTextContent(conf.getVirtaVersionForXRoad()); for (Node child = binding.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { // Append xroad wsdl:binding operation headers if (child.getNodeName().contains(":input") || child.getNodeName().contains(":output")) { Element el = (Element) child; for (String xroadHeader : conf.getXroadHeaders()) { el.appendChild(soapHeader(doc.createElement("soap:header"), "tns:requestheader", xroadHeader, "literal")); } } if (child.getNodeName().contains(":input")) { Element el = (Element) child; replaceAttribute(el, "name", StringUtils.substringBefore(el.getAttribute("name"), "Request")); } } } } // Remove Request from wsdl:message > wsdl:part element so that can see element } else if (childrenList.item(i).getNodeName().contains(":message") && childrenList.item(i) .getAttributes().getNamedItem("name").getNodeValue().contains("Request")) { Element part = (Element) childrenList.item(i).getFirstChild().getNextSibling(); replaceAttribute(part, "element", StringUtils.substringBefore(part.getAttribute("element"), "Request")); } // Change wsdl input names to meet XRoad standard if (childrenList.item(i).getNodeName().contains(":portType")) { NodeList binding = childrenList.item(i).getChildNodes(); for (int j = 0; j < binding.getLength(); ++j) { if (binding.item(j).getNodeName().contains(":operation")) { for (Node child = binding.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeName().contains(":input")) { Element el = (Element) child; replaceAttribute(el, "name", StringUtils.substringBefore(el.getAttribute("name"), "Request")); } } } } } // Append kapaVirtaAS service address if (childrenList.item(i).getNodeName().contains(":service")) { NodeList service = childrenList.item(i).getChildNodes(); for (int j = 0; j < service.getLength(); ++j) { if (service.item(j).getNodeName().contains(":port")) { for (Node child = service.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeName().contains(":address")) { Element el = (Element) child; replaceAttribute(el, "location", conf.getAdapterServiceSOAPURL()); } } } } } } // Write manipulated WSDL to file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(conf.getAdapterServiceWSDLPath() + "/kapavirta_as.wsdl")); transformer.transform(source, result); }
From source file:hudson.plugins.plot.XMLSeries.java
private void addNodeToList(List<PlotPoint> ret, Node n, int buildNumber) { NamedNodeMap nodeMap = n.getAttributes(); if ((null != nodeMap) && (null != nodeMap.getNamedItem("name"))) { addValueToList(ret, nodeMap.getNamedItem("name").getTextContent().trim(), n, buildNumber); } else {/*w w w .j av a 2s .c om*/ addValueToList(ret, n.getLocalName().trim(), n, buildNumber); } }
From source file:edu.toronto.cs.cidb.ncbieutils.NCBIEUtilsAccessService.java
private Map<String, String> getNameForId(Node source) { Map<String, String> result = new HashMap<String, String>(); String id = null, name = null; NodeList data = source.getChildNodes(); for (int i = 0; i < data.getLength(); ++i) { Node n = data.item(i);/*from w w w . j av a2 s .c om*/ if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } if ("Id".equals(n.getNodeName())) { id = n.getTextContent(); } else if ("Item".equals(n.getNodeName())) { NamedNodeMap attrs = n.getAttributes(); if (attrs.getNamedItem("Name") != null && "Title".equals(attrs.getNamedItem("Name").getNodeValue())) { name = n.getTextContent(); } } } if (id != null) { if (name != null) { result.put(id, fixCase(name)); } else { result.put(id, id); } } return result; }
From source file:de.elbe5.base.data.XmlData.java
public String getStringAttribute(Node node, String key) { if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { return attr.getNodeValue(); }//from w ww . j av a2 s . com } return ""; }
From source file:de.elbe5.base.data.XmlData.java
public int getIntAttribute(Node node, String key) { int result = -1; if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = Integer.parseInt(attr.getNodeValue()); } catch (Exception ignored) { }//from w w w .j a v a 2 s . c om } } return result; }
From source file:de.elbe5.base.data.XmlData.java
public long getLongAttribute(Node node, String key) { long result = -1; if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = Long.parseLong(attr.getNodeValue()); } catch (Exception ignored) { }/* w w w . j a v a2 s. c o m*/ } } return result; }
From source file:de.elbe5.base.data.XmlData.java
public boolean getBooleanAttribute(Node node, String key) { boolean result = false; if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = Boolean.parseBoolean(attr.getNodeValue()); } catch (Exception ignored) { }//from w w w . java2 s. co m } } return result; }