List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:com.wavemaker.tools.ws.WebServiceToolsManager.java
private void modifyServiceName(java.io.File wsdlf) throws IOException, ParserConfigurationException, SAXException, TransformerException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);//from ww w . j a v a 2 s. c o m DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document doc = docBuilder.parse(wsdlf); NodeList nlistOp = doc.getElementsByTagNameNS("*", "operation"); NodeList nlistSvc = doc.getElementsByTagNameNS("*", "service"); if (nlistOp == null || nlistOp.getLength() == 0 || nlistSvc == null || nlistSvc.getLength() == 0) { return; } String[] opList = new String[nlistOp.getLength()]; for (int i = 0; i < nlistOp.getLength(); i++) { Node nodeOp = nlistOp.item(i); NamedNodeMap nMap = nodeOp.getAttributes(); for (int j = 0; j < nMap.getLength(); j++) { Node attr = nMap.item(j); if (attr.getNodeName().equals("name")) { opList[i] = attr.getNodeValue(); break; } } } String svcName = null; Node nodeSvc = nlistSvc.item(0); // assumes there is only once service // name defined in a WSDL Node svcNameAttr = null; NamedNodeMap nMap = nodeSvc.getAttributes(); nMap.getLength(); for (int j = 0; j < nMap.getLength(); j++) { svcNameAttr = nMap.item(j); if (svcNameAttr.getNodeName().equals("name")) { svcName = svcNameAttr.getNodeValue(); break; } } if (opList.length == 0 || svcName == null) { return; } boolean sameName = false; for (String opName : opList) { if (opName != null && opName.equals(svcName)) { sameName = true; break; } } if (!sameName) { return; } svcNameAttr.setNodeValue(svcName + "Svc"); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer tFormer = tFactory.newTransformer(); Source source = new DOMSource(doc); Result dest = new StreamResult(wsdlf); tFormer.transform(source, dest); }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Canvas element// w w w . j a v a2 s . c o m * * @param element the Canvas element * @param definitions the definitions data object to resolve the reference attributes * @return Canvas data object * @throws InkMLException */ protected Canvas getCanvas(final Element element, final Definitions definitions) throws InkMLException { final Canvas canvas = new Canvas(); // Extract and set Attribute values final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); canvas.setAttribute(attr.getLocalName(), attr.getNodeValue()); } final NodeList list = element.getElementsByTagName("traceFormat"); if (list.getLength() != 0) { canvas.setTraceFormat(this.getTraceFormat((Element) list.item(0), definitions)); } return canvas; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind CanvasTransform element * /* w w w . j ava2 s . c o m*/ * @param element the CanvasTransform element * @return CanvasTransform data object * @throws InkMLException */ protected CanvasTransform getCanvasTransform(final Element element) throws InkMLException { final CanvasTransform canvasTransform = new CanvasTransform(); // Extract and set Attribute values final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); canvasTransform.setAttribute(attr.getLocalName(), attr.getNodeValue()); } final NodeList list = element.getElementsByTagName("mapping"); final int nMappingChildren = list.getLength(); if (nMappingChildren == 2) { canvasTransform.setForwardMapping(this.getMapping((Element) list.item(0))); canvasTransform.setReverseMapping(this.getMapping((Element) list.item(1))); } else if (nMappingChildren == 1) { canvasTransform.setForwardMapping(this.getMapping((Element) list.item(0))); } return canvasTransform; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Context element/*w w w. j a va2 s . c o m*/ * * @param element the Context element * @param definitions the definitions data object to resolve the reference attributes * @return Context data object * @throws InkMLException */ protected Context getContext(final Element element, final Definitions definitions) throws InkMLException { final Context context = new Context(); // set value of the object from the value of the DOM element // Extract and set Attribute values final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); context.setAttribute(attr.getLocalName(), attr.getNodeValue()); } final NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { final Node node = list.item(i); if (!(node instanceof Element)) { continue; } final Element child = (Element) node; this.addToContextChildrenList(child, context, definitions); } return context; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind InkSource.ActiveArea element * // w ww . j av a 2s .com * @param element the InkSource.ActiveArea element * @param inkSrc the enclosing InkSource data object * @return InkSource.ActiveArea data object * @throws InkMLException */ protected InkSource.ActiveArea getActiveArea(final Element element, final InkSource inkSrc) throws InkMLException { final InkSource.ActiveArea activeArea = inkSrc.new ActiveArea(); final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); final String attrName = attr.getLocalName(); if ("size".equals(attrName)) { activeArea.setSize(attr.getNodeValue()); } if ("height".equals(attrName)) { activeArea.setHegiht(Double.valueOf(attr.getNodeValue()).doubleValue()); } if ("width".equals(attrName)) { activeArea.setWidth(Double.valueOf(attr.getNodeValue()).doubleValue()); } if ("units".equals(attrName)) { activeArea.setUnits(attr.getNodeValue()); } } return activeArea; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Trace element/*from w w w . j a v a 2 s . c o m*/ * * @param element the Trace element * @return Trace data object * @throws InkMLException */ protected Trace getTrace(final Element element) throws InkMLException { final Trace trace = new Trace(); // set value of the object from the value of the DOM element // Extract and set Attribute values final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); trace.setAttribute(attr.getLocalName(), attr.getNodeValue()); } // get trace data String traceText = ""; final NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.TEXT_NODE) { traceText += nl.item(i).getNodeValue(); } } final Ink ink = this.inkMLProcessor.getInk(); final Context currCtx = ink.getCurrentContext(); final Definitions defs = ink.getDefinitions(); trace.resolveAssociatedContext(currCtx, defs); trace.processTraceElement(traceText, currCtx, defs); return trace; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Channel element/*from w ww . j av a 2 s .c om*/ * * @param channelElement Channel element * @return Channel data object * @throws InkMLException */ protected Channel getChannel(final Element channelElement) throws InkMLException { Channel channel = null; final String chnName = channelElement.getAttribute("name"); if ("".equals(chnName)) { throw new InkMLException("Channel element must have value for 'name' attribute"); } else { channel = new Channel(chnName); } // checking for intermittend channel if ("intermittentChannels".equalsIgnoreCase(channelElement.getParentNode().getLocalName())) { channel.setIntermittent(true); } // Extract and set Attribute values final NamedNodeMap attrMap = channelElement.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); channel.setAttribute(attr.getLocalName(), attr.getNodeValue()); } return channel; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind InkSource element/*w ww. jav a 2s .c o m*/ * * @param element the InkSource element * @param definitions the definitions data object to resolve the reference attributes * @return InkSource data object * @throws InkMLException */ protected InkSource getInkSource(final Element element, final Definitions definitions) throws InkMLException { final InkSource inkSrc = new InkSource(); // Extract and set Attribute values final NamedNodeMap attrMap = element.getAttributes(); final int length = attrMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attrMap.item(i); inkSrc.setAttribute(attr.getLocalName(), attr.getNodeValue()); } NodeList list = element.getElementsByTagName("traceFormat"); if (list.getLength() != 0) { inkSrc.setTraceFormat(this.getTraceFormat((Element) list.item(0), definitions)); } list = element.getElementsByTagName("sampleRate"); if (list.getLength() != 0) { inkSrc.setSampleRate(this.getSampleRate((Element) list.item(0), inkSrc)); } list = element.getElementsByTagName("latency"); if (list.getLength() != 0) { inkSrc.setLatency(this.getLatency((Element) list.item(0), inkSrc)); } list = element.getElementsByTagName("activeArea"); if (list.getLength() != 0) { inkSrc.setActiveArea(this.getActiveArea((Element) list.item(0), inkSrc)); } list = element.getElementsByTagName("srcProperty"); for (int i = 0; i < list.getLength(); i++) { inkSrc.addSourceProperty(this.getSourceProperty((Element) list.item(i), inkSrc)); } list = element.getElementsByTagName("channelProperties"); if (list.getLength() != 0) { inkSrc.setChannelProperties(this.getChannelProperties((Element) list.item(0), inkSrc)); } return inkSrc; }
From source file:com.netspective.sparx.util.xml.XmlSource.java
public void inheritElement(Element srcElement, Element destElem, Set excludeElems, String inheritedFromNode) { NamedNodeMap inhAttrs = srcElement.getAttributes(); for (int i = 0; i < inhAttrs.getLength(); i++) { Node attrNode = inhAttrs.item(i); final String nodeName = attrNode.getNodeName(); if (!excludeElems.contains(nodeName) && destElem.getAttribute(nodeName).equals("")) destElem.setAttribute(nodeName, attrNode.getNodeValue()); }/*from w w w .j a va 2 s . c o m*/ DocumentFragment inheritFragment = xmlDoc.createDocumentFragment(); NodeList inhChildren = srcElement.getChildNodes(); for (int i = inhChildren.getLength() - 1; i >= 0; i--) { Node childNode = inhChildren.item(i); // only add if there isn't an attribute overriding this element final String nodeName = childNode.getNodeName(); if (destElem.getAttribute(nodeName).length() == 0 && (!excludeElems.contains(nodeName))) { Node cloned = childNode.cloneNode(true); if (inheritedFromNode != null && cloned.getNodeType() == Node.ELEMENT_NODE) ((Element) cloned).setAttribute("_inherited-from", inheritedFromNode); inheritFragment.insertBefore(cloned, inheritFragment.getFirstChild()); } } destElem.insertBefore(inheritFragment, destElem.getFirstChild()); }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the price of the License Model//from ww w.j av a 2 s.c o m * * @param lm - LicenseModel object * @param userId - UserId * @throws Exception * @return - ProductPriceSum as String */ public String getLicenseModelPrice(LicenseModel lm, String userId) throws Exception { StringBuffer buf = null; String productPriceSum = ""; List<LicenseParam> lpList = lm.getParams(); String productPriceQuery = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wpos:WPOSRequest xmlns:wpos=\"http://www.conterra.de/wpos/1.1\" version=\"1.1.0\">" + "<wpos:GetPrice collapse=\"true\">" + "<wpos:Product id=\"" + StringEscapeUtils.escapeXml10(lm.getId()) + "\">" + "<wpos:ConfigParams>"; for (int i = 0; i < lpList.size(); i++) { if (lpList.get(i).getParameterClass().equals("configurationParameter")) { LicenseParam lp = (LicenseParam) lpList.get(i); String priceQuery = "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lp.getName()) + "\">"; if (lp instanceof LicenseParamInt) { LicenseParamInt lpi = (LicenseParamInt) lp; priceQuery += "<wpos:Value selected=\"true\">" + lpi.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } else if (lp instanceof LicenseParamBln) { LicenseParamBln lpBln = (LicenseParamBln) lp; priceQuery += "<wpos:Value selected=\"true\">" + lpBln.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } else if (lp instanceof LicenseParamDisplay) { LicenseParamDisplay lpd = (LicenseParamDisplay) lp; List<String> values = lpd.getValues(); if (lp.getName().equals("LICENSE_USER_GROUP")) { priceQuery += "<wpos:Value>Users</wpos:Value>"; } else if (lp.getName().equals("LICENSE_USER_ID")) { priceQuery += "<wpos:Value>" + userId + "</wpos:Value>"; } else { for (int l = 0; l < values.size(); l++) { priceQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(values.get(l)) + "</wpos:Value>"; } } priceQuery += "</wpos:Parameter>"; } else if (lp instanceof LicenseParamEnum) { LicenseParamEnum lpEnum = (LicenseParamEnum) lp; List<String> tempOptions = lpEnum.getOptions(); List<String> tempSelections = lpEnum.getSelections(); if (tempSelections.size() == 0) { priceQuery = ""; } else { String selectionsString = ""; for (int j = 0; j < tempSelections.size(); j++) { if (j == 0) { selectionsString = tempSelections.get(j); } else { selectionsString += ", " + tempSelections.get(j); } } priceQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(selectionsString) + "</wpos:Value>" + "</wpos:Parameter>"; } } else if (lp instanceof LicenseParamText) { LicenseParamText lpText = (LicenseParamText) lp; List<String> values = lpText.getValues(); for (int k = 0; k < values.size(); k++) { priceQuery += "<wpos:Value selected=\"true\">" + lpText.getValues() + "</wpos:Value>"; } priceQuery += "</wpos:Parameter>"; } productPriceQuery += priceQuery; } } productPriceQuery += "</wpos:ConfigParams>" + "</wpos:Product>" + "</wpos:GetPrice>" + "</wpos:WPOSRequest>"; //System.out.println("query: "+productPriceQuery.toString()); try { buf = doHTTPQuery(this.wposURL, "post", productPriceQuery, false); //System.out.println("response: "+buf.toString()); // Get productPriceInfo from the response Document xmlDoc = LicenseParser.createXMLDocumentFromString(buf.toString()); Element catalogElement = (Element) xmlDoc .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "catalog").item(0); NodeList productGroupElementList = catalogElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productGroup"); for (int m = 0; m < productGroupElementList.getLength(); m++) { Element productGroupElement = (Element) productGroupElementList.item(m); Element calculationElement = (Element) productGroupElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "calculation").item(0); Element declarationListElement = (Element) calculationElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "declarationList").item(0); Element referencedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "referencedParameters").item(0); NodeList referencedParametersParameterList = referencedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < referencedParametersParameterList.getLength(); n++) { Element referencedParametersParameterElement = (Element) referencedParametersParameterList .item(n); NamedNodeMap referencedParametersParameterAttributeMap = referencedParametersParameterElement .getAttributes(); for (int o = 0; o < referencedParametersParameterAttributeMap.getLength(); o++) { Attr attrs = (Attr) referencedParametersParameterAttributeMap.item(o); if (attrs.getNodeName().equals("name")) { if (attrs.getNodeValue().equals("productPriceSum")) { Element valueElement = (Element) referencedParametersParameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); productPriceSum = valueElement.getTextContent(); } } } } } } catch (Exception e) { throw e; } return productPriceSum; }