List of usage examples for org.w3c.dom NamedNodeMap getLength
public int getLength();
From source file:com.twinsoft.convertigo.beans.core.Sequence.java
private static Node cloneNodeWithUserData(Node node, boolean recurse) { if (node != null) { Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT); Node clonedNode = node.cloneNode(false); clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null); if (node.getNodeType() == Node.ELEMENT_NODE) { // attributes NamedNodeMap attributeMap = clonedNode.getAttributes(); for (int i = 0; i < attributeMap.getLength(); i++) { Node clonedAttribute = attributeMap.item(i); String attr_name = clonedAttribute.getNodeName(); Object attr_output = ((Element) node).getAttributeNode(attr_name) .getUserData(Step.NODE_USERDATA_OUTPUT); clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null); }/*w w w .j a v a 2 s .c o m*/ // recurse on element child nodes only if (recurse && node.hasChildNodes()) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node clonedChild = cloneNodeWithUserData(list.item(i), recurse); if (clonedChild != null) { clonedNode.appendChild(clonedChild); } } } } return clonedNode; } return null; }
From source file:org.mumod.android.provider.StatusNet.java
private String getTagValueWithMultiItem(Element eElement) { String returnVal = ""; Node eNode;//from ww w . j av a 2 s . c o m int NumOFItem = eElement.getElementsByTagName("link").getLength(); for (int y = 0; y < NumOFItem; y++) { eNode = eElement.getElementsByTagName("link").item(y); NamedNodeMap attributes = eNode.getAttributes(); for (int g = 0; g < attributes.getLength(); g++) { Attr attribute = (Attr) attributes.item(g); if (attribute.getNodeName().equals("rel") && attribute.getNodeValue().equals("alternate")) { try { if (eNode.getAttributes().getNamedItem("type").getNodeValue() .equals("application/atom+xml")) returnVal = eNode.getAttributes().getNamedItem("href").getNodeValue(); } catch (Exception e) { if (MustardApplication.DEBUG) e.printStackTrace(); } } } } return returnVal; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Canvas element/* www .j ava 2 s . co 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 * //from w w w . j a v a2 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/* ww w . j a v a2s.co 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 w w . j a v a 2 s. c o m * @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 .ja va 2s. co 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 Annotation element/*from w ww . j a v a2s . c o m*/ * * @param element the Annotation element * @return Annotation data object * @throws InkMLException */ protected Annotation getAnnotation(final Element element) throws InkMLException { final Annotation annotation = new Annotation(); final NamedNodeMap attributesMap = element.getAttributes(); final int length = attributesMap.getLength(); for (int index = 0; index < length; index++) { final Attr attribute = (Attr) attributesMap.item(index); final String attributeName = attribute.getName(); if ("type".equals(attributeName)) { annotation.setType(attribute.getValue()); } else if ("encoding".equals(attributeName)) { annotation.setEncoding(attribute.getValue()); } else { annotation.addToOtherAttributesMap(attributeName, attribute.getValue()); } } final Node valueNode = element.getFirstChild(); if (null != valueNode) { annotation.setAnnotationTextValue(valueNode.getNodeValue()); } return annotation; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the price of the License Model/*from w w w .j a v a 2 s. com*/ * * @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; }