List of usage examples for org.w3c.dom Attr getNodeValue
public String getNodeValue() throws DOMException;
From source file:com.marklogic.dom.ElementImpl.java
/** {@inheritDoc} */ @Override/* w w w .j a v a 2 s . c o m*/ public boolean isDefaultNamespace(String namespaceURI) { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (prefix == null || prefix.length() == 0) { if (namespaceURI == null) { return (namespace == namespaceURI); } return namespaceURI.equals(namespace); } if (this.hasAttributes()) { Attr attr = this.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns"); if (attr != null) { String value = attr.getNodeValue(); if (namespaceURI == null) { return (namespace == value); } return namespaceURI.equals(value); } } Node ancestor = getParentNode(); if (ancestor != null) { short type = ancestor.getNodeType(); if (type == NodeKind.ELEM) { return ancestor.isDefaultNamespace(namespaceURI); } // otherwise, current node is root already } return false; }
From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java
@SuppressWarnings("restriction") public final IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { if (region == null || textViewer == null) { return null; }//from w ww. j av a2 s . c om IDocument document = textViewer.getDocument(); Node currentNode = BeansEditorUtils.getNodeByOffset(document, region.getOffset()); if (currentNode != null) { switch (currentNode.getNodeType()) { case Node.ELEMENT_NODE: // at first try to handle selected attribute value Attr currentAttr = BeansEditorUtils.getAttrByOffset(currentNode, region.getOffset()); IDOMAttr attr = (IDOMAttr) currentAttr; if (currentAttr != null && region.getOffset() >= attr.getValueRegionStartOffset()) { if (isLinkableAttr(currentAttr)) { IRegion hyperlinkRegion = getHyperlinkRegion(currentAttr); IHyperlink hyperLink = createHyperlink(currentAttr.getName(), currentAttr.getNodeValue(), currentNode, currentNode.getParentNode(), document, textViewer, hyperlinkRegion, region); if (hyperLink != null) { return new IHyperlink[] { hyperLink }; } } } break; case Node.TEXT_NODE: IRegion hyperlinkRegion = getHyperlinkRegion(currentNode); Node parentNode = currentNode.getParentNode(); if (parentNode != null) { IHyperlink hyperLink = createHyperlink(parentNode.getNodeName(), currentNode.getNodeValue(), currentNode, parentNode, document, textViewer, hyperlinkRegion, region); if (hyperLink != null) { return new IHyperlink[] { hyperLink }; } } break; } } return null; }
From source file:DOMWriter.java
/** Writes the specified node, recursively. */ public void write(Node node) { // is there anything to do? if (node == null) { return;/*from ww w .j av a 2s . co m*/ } short type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: { Document document = (Document) node; fXML11 = "1.1".equals(getVersion(document)); if (!fCanonical) { if (fXML11) { fOut.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); } else { fOut.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); } fOut.flush(); write(document.getDoctype()); } write(document.getDocumentElement()); break; } case Node.DOCUMENT_TYPE_NODE: { DocumentType doctype = (DocumentType) node; fOut.print("<!DOCTYPE "); fOut.print(doctype.getName()); String publicId = doctype.getPublicId(); String systemId = doctype.getSystemId(); if (publicId != null) { fOut.print(" PUBLIC '"); fOut.print(publicId); fOut.print("' '"); fOut.print(systemId); fOut.print('\''); } else if (systemId != null) { fOut.print(" SYSTEM '"); fOut.print(systemId); fOut.print('\''); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { fOut.println(" ["); fOut.print(internalSubset); fOut.print(']'); } fOut.println('>'); break; } case Node.ELEMENT_NODE: { fOut.print('<'); fOut.print(node.getNodeName()); Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; fOut.print(' '); fOut.print(attr.getNodeName()); fOut.print("=\""); normalizeAndPrint(attr.getNodeValue(), true); fOut.print('"'); } fOut.print('>'); fOut.flush(); Node child = node.getFirstChild(); while (child != null) { write(child); child = child.getNextSibling(); } break; } case Node.ENTITY_REFERENCE_NODE: { if (fCanonical) { Node child = node.getFirstChild(); while (child != null) { write(child); child = child.getNextSibling(); } } else { fOut.print('&'); fOut.print(node.getNodeName()); fOut.print(';'); fOut.flush(); } break; } case Node.CDATA_SECTION_NODE: { if (fCanonical) { normalizeAndPrint(node.getNodeValue(), false); } else { fOut.print("<![CDATA["); fOut.print(node.getNodeValue()); fOut.print("]]>"); } fOut.flush(); break; } case Node.TEXT_NODE: { normalizeAndPrint(node.getNodeValue(), false); fOut.flush(); break; } case Node.PROCESSING_INSTRUCTION_NODE: { fOut.print("<?"); fOut.print(node.getNodeName()); String data = node.getNodeValue(); if (data != null && data.length() > 0) { fOut.print(' '); fOut.print(data); } fOut.print("?>"); fOut.flush(); break; } case Node.COMMENT_NODE: { if (!fCanonical) { fOut.print("<!--"); String comment = node.getNodeValue(); if (comment != null && comment.length() > 0) { fOut.print(comment); } fOut.print("-->"); fOut.flush(); } } } if (type == Node.ELEMENT_NODE) { fOut.print("</"); fOut.print(node.getNodeName()); fOut.print('>'); fOut.flush(); } }
From source file:DOMWriter.java
private void printInternal(Node node, boolean indentEndMarker) { // is there anything to do? if (node == null) { return;/*from ww w .j a va 2 s.c o m*/ } // JBAS-2117 - Don't skip the DOCUMENT_NODE // if (node instanceof Document) node = ((Document)node).getDocumentElement(); if (wroteXMLDeclaration == false && writeXMLDeclaration == true && canonical == false) { out.print("<?xml version='1.0'"); if (charsetName != null) out.print(" encoding='" + charsetName + "'"); out.print("?>"); if (prettyprint) out.println(); wroteXMLDeclaration = true; } int type = node.getNodeType(); boolean hasChildNodes = node.getChildNodes().getLength() > 0; String nodeName = node.getNodeName(); switch (type) { // print document case Node.DOCUMENT_NODE: { NodeList children = node.getChildNodes(); for (int iChild = 0; iChild < children.getLength(); iChild++) { printInternal(children.item(iChild), false); } out.flush(); break; } // print element with attributes case Node.ELEMENT_NODE: { Element element = (Element) node; if (prettyprint) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } prettyIndent++; } out.print('<'); out.print(nodeName); Map nsMap = new HashMap(); String elPrefix = node.getPrefix(); String elNamespaceURI = node.getNamespaceURI(); if (elPrefix != null) { String nsURI = getNamespaceURI(elPrefix, element, rootNode); nsMap.put(elPrefix, nsURI); } Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; String atPrefix = attr.getPrefix(); String atName = attr.getNodeName(); String atValue = normalize(attr.getNodeValue(), canonical); if (atName.equals("xmlns")) currentDefaultNamespace = atValue; if (atPrefix != null && !atPrefix.equals("xmlns") && !atPrefix.equals("xml")) { String nsURI = getNamespaceURI(atPrefix, element, rootNode); nsMap.put(atPrefix, nsURI); // xsi:type='ns1:SubType', xsi:type='xsd:string' if (atName.equals(atPrefix + ":type") && atValue.indexOf(":") > 0) { // xsi defined on the envelope if (nsURI == null) nsURI = getNamespaceURI(atPrefix, element, null); if ("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI)) { String typePrefix = atValue.substring(0, atValue.indexOf(":")); String typeURI = getNamespaceURI(typePrefix, element, rootNode); nsMap.put(typePrefix, typeURI); } } } out.print(" " + atName + "='" + atValue + "'"); } // Add namespace declaration for prefixes // that are defined further up the tree if (completeNamespaces) { Iterator itPrefix = nsMap.keySet().iterator(); while (itPrefix.hasNext()) { String prefix = (String) itPrefix.next(); String nsURI = (String) nsMap.get(prefix); if (nsURI == null) { nsURI = getNamespaceURI(prefix, element, null); out.print(" xmlns:" + prefix + "='" + nsURI + "'"); } } } // The SAX ContentHandler will by default not add the namespace declaration // <Hello xmlns='http://somens'>World</Hello> if (elPrefix == null && elNamespaceURI != null) { String defaultNamespace = element.getAttribute("xmlns"); if (defaultNamespace.length() == 0 && !elNamespaceURI.equals(currentDefaultNamespace)) { out.print(" xmlns='" + elNamespaceURI + "'"); currentDefaultNamespace = elNamespaceURI; } } if (hasChildNodes) { out.print('>'); } // Find out if the end marker is indented indentEndMarker = isEndMarkerIndented(node); if (indentEndMarker) { out.print('\n'); } NodeList childNodes = node.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node childNode = childNodes.item(i); printInternal(childNode, false); } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { if (canonical) { NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { printInternal(children.item(i), false); } } } else { out.print('&'); out.print(nodeName); out.print(';'); } break; } // print cdata sections case Node.CDATA_SECTION_NODE: { if (canonical) { out.print(normalize(node.getNodeValue(), canonical)); } else { out.print("<![CDATA["); out.print(node.getNodeValue()); out.print("]]>"); } break; } // print text case Node.TEXT_NODE: { String text = normalize(node.getNodeValue(), canonical); if (text.trim().length() > 0) { out.print(text); } else if (prettyprint == false && ignoreWhitespace == false) { out.print(text); } break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { out.print("<?"); out.print(nodeName); String data = node.getNodeValue(); if (data != null && data.length() > 0) { out.print(' '); out.print(data); } out.print("?>"); break; } // print comment case Node.COMMENT_NODE: { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } out.print("<!--"); String data = node.getNodeValue(); if (data != null) { out.print(data); } out.print("-->"); if (prettyprint) { out.print('\n'); } break; } } if (type == Node.ELEMENT_NODE) { if (prettyprint) prettyIndent--; if (hasChildNodes == false) { out.print("/>"); } else { if (indentEndMarker) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } } out.print("</"); out.print(nodeName); out.print('>'); } if (prettyIndent > 0) { out.print('\n'); } } out.flush(); }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
public static final List<Element> createEntityFromBusinessObject(final BusinessEntity businessEntity) throws Exception { /* Create list of elements */ final List<Element> elementList = new ArrayList<Element>(); if (businessEntity != null) { final Node node = businessEntity.getDomNode(); if (node.hasChildNodes()) { final NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { /* To avoid : 'DOM Level 3 Not implemented' error */ final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document document = builder.newDocument(); final Element element = (Element) document.importNode(nodeList.item(i), true); if (element.getNodeName() != null && element.getNodeName().contains(":")) { final String nodeName = element.getNodeName().split(":")[1]; /* Check for attributes */ final NamedNodeMap attributes = element.getAttributes(); if (attributes != null && attributes.getLength() != 0) { /* Create new map for attributes */ final Map<String, String> attributeMap = new HashMap<String, String>(); for (int j = 0; j < attributes.getLength(); j++) { final Attr attr = (Attr) attributes.item(j); /* Set node name and value in map */ attributeMap.put(attr.getNodeName(), attr.getNodeValue()); }/*from w ww. j a va 2s. c om*/ /* Create node with attributes */ elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName, element.getTextContent(), attributeMap)); } else { /* Create node without attributes */ elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName, element.getTextContent())); } } } } return elementList; } else { return null; } }
From source file:DOMWriter.java
private void printInternal(Node node, boolean indentEndMarker) { // is there anything to do? if (node == null) { return;//ww w . j a v a 2 s. c o m } // JBAS-2117 - Don't skip the DOCUMENT_NODE // if (node instanceof Document) node = // ((Document)node).getDocumentElement(); if (wroteXMLDeclaration == false && writeXMLDeclaration == true && canonical == false) { out.print("<?xml version='1.0'"); if (charsetName != null) out.print(" encoding='" + charsetName + "'"); out.print("?>"); if (prettyprint) out.println(); wroteXMLDeclaration = true; } int type = node.getNodeType(); boolean hasChildNodes = node.getChildNodes().getLength() > 0; String nodeName = node.getNodeName(); switch (type) { // print document case Node.DOCUMENT_NODE: { NodeList children = node.getChildNodes(); for (int iChild = 0; iChild < children.getLength(); iChild++) { printInternal(children.item(iChild), false); } out.flush(); break; } // print element with attributes case Node.ELEMENT_NODE: { Element element = (Element) node; if (prettyprint) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } prettyIndent++; } out.print('<'); out.print(nodeName); Map nsMap = new HashMap(); String elPrefix = node.getPrefix(); String elNamespaceURI = node.getNamespaceURI(); if (elPrefix != null) { String nsURI = getNamespaceURI(elPrefix, element, rootNode); nsMap.put(elPrefix, nsURI); } Attr attrs[] = sortAttributes(node.getAttributes()); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; String atPrefix = attr.getPrefix(); String atName = attr.getNodeName(); String atValue = normalize(attr.getNodeValue(), canonical); if (atName.equals("xmlns")) currentDefaultNamespace = atValue; if (atPrefix != null && !atPrefix.equals("xmlns") && !atPrefix.equals("xml")) { String nsURI = getNamespaceURI(atPrefix, element, rootNode); nsMap.put(atPrefix, nsURI); // xsi:type='ns1:SubType', xsi:type='xsd:string' if (atName.equals(atPrefix + ":type") && atValue.indexOf(":") > 0) { // xsi defined on the envelope if (nsURI == null) nsURI = getNamespaceURI(atPrefix, element, null); if ("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI)) { String typePrefix = atValue.substring(0, atValue.indexOf(":")); String typeURI = getNamespaceURI(typePrefix, element, rootNode); nsMap.put(typePrefix, typeURI); } } } out.print(" " + atName + "='" + atValue + "'"); } // Add namespace declaration for prefixes // that are defined further up the tree if (completeNamespaces) { Iterator itPrefix = nsMap.keySet().iterator(); while (itPrefix.hasNext()) { String prefix = (String) itPrefix.next(); String nsURI = (String) nsMap.get(prefix); if (nsURI == null) { nsURI = getNamespaceURI(prefix, element, null); out.print(" xmlns:" + prefix + "='" + nsURI + "'"); } } } // The SAX ContentHandler will by default not add the namespace // declaration // <Hello xmlns='http://somens'>World</Hello> if (elPrefix == null && elNamespaceURI != null) { String defaultNamespace = element.getAttribute("xmlns"); if (defaultNamespace.length() == 0 && !elNamespaceURI.equals(currentDefaultNamespace)) { out.print(" xmlns='" + elNamespaceURI + "'"); currentDefaultNamespace = elNamespaceURI; } } if (hasChildNodes) { out.print('>'); } // Find out if the end marker is indented indentEndMarker = isEndMarkerIndented(node); if (indentEndMarker) { out.print('\n'); } NodeList childNodes = node.getChildNodes(); int len = childNodes.getLength(); for (int i = 0; i < len; i++) { Node childNode = childNodes.item(i); printInternal(childNode, false); } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { if (canonical) { NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { printInternal(children.item(i), false); } } } else { out.print('&'); out.print(nodeName); out.print(';'); } break; } // print cdata sections case Node.CDATA_SECTION_NODE: { if (canonical) { out.print(normalize(node.getNodeValue(), canonical)); } else { out.print("<![CDATA["); out.print(node.getNodeValue()); out.print("]]>"); } break; } // print text case Node.TEXT_NODE: { String text = normalize(node.getNodeValue(), canonical); if (text.trim().length() > 0) { out.print(text); } else if (prettyprint == false && ignoreWhitespace == false) { out.print(text); } break; } // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { out.print("<?"); out.print(nodeName); String data = node.getNodeValue(); if (data != null && data.length() > 0) { out.print(' '); out.print(data); } out.print("?>"); break; } // print comment case Node.COMMENT_NODE: { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } out.print("<!--"); String data = node.getNodeValue(); if (data != null) { out.print(data); } out.print("-->"); if (prettyprint) { out.print('\n'); } break; } } if (type == Node.ELEMENT_NODE) { if (prettyprint) prettyIndent--; if (hasChildNodes == false) { out.print("/>"); } else { if (indentEndMarker) { for (int i = 0; i < prettyIndent; i++) { out.print(' '); } } out.print("</"); out.print(nodeName); out.print('>'); } if (prettyIndent > 0) { out.print('\n'); } } out.flush(); }
From source file:com.nridge.core.base.io.xml.DataTableXML.java
/** * Parses an XML DOM element and loads it into a bag/table. * * @param anElement DOM element./*from ww w . ja v a 2 s. co m*/ * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; Attr nodeAttr; Element nodeElement; String nodeName, nodeValue, attrValue; attrValue = anElement.getAttribute("name"); if (StringUtils.isNotEmpty(attrValue)) mDataTable.setName(attrValue); NamedNodeMap namedNodeMap = anElement.getAttributes(); int attrCount = namedNodeMap.getLength(); for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) { nodeAttr = (Attr) namedNodeMap.item(attrOffset); nodeName = nodeAttr.getNodeName(); nodeValue = nodeAttr.getNodeValue(); if (StringUtils.isNotEmpty(nodeValue)) { if (!StringUtils.equalsIgnoreCase(nodeName, "name")) mDataTable.addFeature(nodeName, nodeValue); } } NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (nodeName.equalsIgnoreCase("Context")) { nodeElement = (Element) nodeItem; attrValue = nodeElement.getAttribute("start"); if (StringUtils.isNumeric(attrValue)) mContextStart = Integer.parseInt(attrValue); attrValue = nodeElement.getAttribute("limit"); if (StringUtils.isNumeric(attrValue)) mContextLimit = Integer.parseInt(attrValue); attrValue = nodeElement.getAttribute("total"); if (StringUtils.isNumeric(attrValue)) mContextTotal = Integer.parseInt(attrValue); } else if (nodeName.equalsIgnoreCase("Columns")) { nodeElement = (Element) nodeItem; DataBagXML dataBagXML = new DataBagXML(); dataBagXML.load(nodeElement); DataBag dataBag = dataBagXML.getBag(); dataBag.setName(mDataTable.getName()); mDataTable = new DataTable(dataBag); } else if (nodeName.equalsIgnoreCase("Rows")) { nodeElement = (Element) nodeItem; loadRows(nodeElement); } } }
From source file:com.nridge.core.base.io.xml.RelationshipXML.java
/** * Parses an XML DOM element and loads it into a relationship. * * @param anElement DOM element.//from w w w.java2 s . co m * * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; Attr nodeAttr; Element nodeElement; DataBagXML dataBagXML; DocumentXML documentXML; String nodeName, nodeValue; mRelationship.reset(); String attrValue = anElement.getAttribute("type"); if (StringUtils.isEmpty(attrValue)) throw new IOException("Relationship is missing type attribute."); mRelationship.setType(attrValue); NamedNodeMap namedNodeMap = anElement.getAttributes(); int attrCount = namedNodeMap.getLength(); for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) { nodeAttr = (Attr) namedNodeMap.item(attrOffset); nodeName = nodeAttr.getNodeName(); nodeValue = nodeAttr.getNodeValue(); if (StringUtils.isNotEmpty(nodeValue)) { if ((!StringUtils.equalsIgnoreCase(nodeName, "type"))) mRelationship.addFeature(nodeName, nodeValue); } } NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (nodeName.equalsIgnoreCase(IO.XML_PROPERTIES_NODE_NAME)) { nodeElement = (Element) nodeItem; dataBagXML = new DataBagXML(); dataBagXML.load(nodeElement); mRelationship.setBag(dataBagXML.getBag()); } else { nodeElement = (Element) nodeItem; documentXML = new DocumentXML(); documentXML.load(nodeElement); mRelationship.add(documentXML.getDocument()); } } }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addAttributes(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, NamedNodeMap attributes, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); int len = attributes.getLength(); Attr attribute; for (int i = 0; i < len; i++) { attribute = (Attr) attributes.item(i); String attributeName = attribute.getName(); String attributeValue = attribute.getNodeValue(); String attributeNsUri = attribute.getNamespaceURI(); String attributePrefix = getPrefix(context.projectName, attributeNsUri); XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttributeByName(context.projectName, attributeName); boolean isGlobal = xmlSchemaAttribute != null; if (isGlobal) { attributeNsUri = xmlSchemaAttribute.getQName().getNamespaceURI(); attributePrefix = getPrefix(context.projectName, attributeNsUri); }//from w ww.ja v a 2s .c om if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (attributePrefix == null) { soapElement.addAttribute(soapEnvelope.createName(attributeName, prefix, targetNamespace), attributeValue); } else { soapElement.addAttribute( soapEnvelope.createName(attributeName, attributePrefix, attributeNsUri), attributeValue); } } else { soapElement.addAttribute(soapEnvelope.createName(attributeName), attributeValue); } } }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the price of the License Model/* w w w .j av a 2 s.co 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; }