Example usage for org.w3c.dom NamedNodeMap setNamedItem

List of usage examples for org.w3c.dom NamedNodeMap setNamedItem

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap setNamedItem.

Prototype

public Node setNamedItem(Node arg) throws DOMException;

Source Link

Document

Adds a node using its nodeName attribute.

Usage

From source file:com.ext.portlet.epsos.EpsosHelperService.java

/**
 * Add a tag of the form below under the given node:
 * /*from w  w w . j a v  a2 s.com*/
 * <product>
                <manufacturedProduct xmlns:epsos="urn:epsos-org:ep:medication" classCode="MANU">
                   <templateId root='1.3.6.1.4.1.19376.1.5.3.1.4.7.2'/>
                   <templateId root='2.16.840.1.113883.10.20.1.53'/>
                   <manufacturedMaterial classCode="MMAT" determinerCode="KIND">
                      <templateId root='1.3.6.1.4.1.12559.11.10.1.3.1.3.1'/>
                      <!-- Id  dispensed product--> 
                      <epsos:id root="222" extension="3213"/>
                      <code code="409120009" displayName="Metformin and rosiglitazone" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED CT">
                         <!-- Optional generic name -->
                         <originalText>
                            <reference value="reference"/>
                         </originalText>
                      </code>
                      <name>Metformina y rosiglitazona</name>
                      <!--Dose form  -->
                      <epsos:formCode code="10221000" displayName="Film-coated tablet" codeSystem="1.3.6.1.4.1.12559.11.10.1.3.1.42.2" codeSystemName="epSOS:DoseForm"/>
                              
                      <epsos:asContent classCode="CONT">
                         <!-- Package size-->
                         <epsos:quantity>
                            <epsos:numerator xsi:type="epsos:PQ" value="112" unit="1" />
                            <epsos:denominator xsi:type="epsos:PQ" value="1" unit="1"/>
                         </epsos:quantity>
                         <!-- Package -->
                         <epsos:containerPackagedMedicine classCode="CONT" determinerCode="INSTANCE">
                            <epsos:formCode code="30009000" displayName="Box" codeSystem="1.3.6.1.4.1.12559.11.10.1.3.1.42.3" codeSystemName="epSOS:Package"/>
                            <!-- A10BD03 Metformin and rosiglitazone -->
                            <epsos:name> Metformin and rosiglitazone</epsos:name>
                            <!-- random lot number has been assigned-->
                            <epsos:lotNumberText>1322231</epsos:lotNumberText>
                            <epsos:capacityQuantity value=' 112' unit='1'/>
                                    
                            <!-- child proof-->
                            <epsos:capTypeCode code="ChildProof"/>
                         </epsos:containerPackagedMedicine>
                      </epsos:asContent>
                      <epsos:ingredient classCode="ACTI">
                         <!--Strength, -->
                         <epsos:quantity>
                            <epsos:numerator xsi:type="epsos:PQ" value="500+2" unit="mg"/>
                            <epsos:denominator xsi:type="epsos:PQ" value="1" unit="1"/>
                         </epsos:quantity>
                         <epsos:ingredient classCode="MMAT" determinerCode="KIND">
                            <!-- ATC-code-->
                            <epsos:code code="A10BD03" codeSystem="2.16.840.1.113883.6.73" displayName="Metformin and rosiglitazone"/>
                            <epsos:name>Metformin and rosiglitazone</epsos:name>
                         </epsos:ingredient>
                      </epsos:ingredient>
                   </manufacturedMaterial>
                </manufacturedProduct>
             </product>
 * 
 * 
 * 
 * 
 * 
 * @param dom
 * @param node
 * @param doctor
 */
private void addProductTag(Document dom, Node node, ViewResult dispensedLine, Node prescriptionNode) {
    Node productNode = dom.createElement("product");
    Node product = dom.createElement("manufacturedProduct");
    addAttribute(dom, product, "xmlns:epsos", XML_DISPENSATION_PRODUCT_EPSOSNS);
    addAttribute(dom, product, "classCode", XML_DISPENSATION_PRODUCT_CLASSCODE);
    addTemplateId(dom, product, XML_DISPENSATION_PRODUCT_TEMPLATE1);
    addTemplateId(dom, product, XML_DISPENSATION_PRODUCT_TEMPLATE2);

    // change after September 29/30-2010 workshop: product tag must be the same as the one in prescription.
    // only changes allowed (if substituting) are the brand name and the package quantity tags
    Node materialNode = null;
    // use identical material info from prescription
    try {
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression materialExpr = xpath
                .compile("substanceAdministration/consumable/manufacturedProduct/manufacturedMaterial");
        Node oldMaterialNode = (Node) materialExpr.evaluate(prescriptionNode, XPathConstants.NODE);

        // fix to add epsos:id node

        XPathExpression code = xpath
                .compile("substanceAdministration/consumable/manufacturedProduct/manufacturedMaterial/code");
        Node codeNode = (Node) code.evaluate(prescriptionNode, XPathConstants.NODE);

        if (codeNode == null) {
            code = xpath.compile(
                    "substanceAdministration/consumable/manufacturedProduct/manufacturedMaterial/name");
            codeNode = (Node) code.evaluate(prescriptionNode, XPathConstants.NODE);
        }

        Node epsosID = dom.createElement("epsos:id");
        addAttribute(dom, epsosID, "root", XML_DISPENSATION_ENTRY_SUPPLY_TEMPLATE3);
        addAttribute(dom, epsosID, "extension", (String) dispensedLine.getField1());
        oldMaterialNode.insertBefore(epsosID, codeNode);

        materialNode = oldMaterialNode.cloneNode(true);

        if (dispensedLine.getField3() != null && ((Boolean) dispensedLine.getField3()).booleanValue()) {
            // substitute case, change brand name and quantity tags
            XPathExpression brandNameExpr = xpath.compile("name");
            Node nameNode = (Node) brandNameExpr.evaluate(materialNode, XPathConstants.NODE);
            nameNode.setTextContent((String) dispensedLine.getField2());

            XPathExpression packContentExpr = xpath.compile("asContent");
            Node contentNode = (Node) packContentExpr.evaluate(materialNode, XPathConstants.NODE);
            XPathExpression packQuantityExpr = xpath.compile("containerPackagedMedicine/capacityQuantity");
            Node oldQuant = (Node) packQuantityExpr.evaluate(contentNode, XPathConstants.NODE);
            NamedNodeMap attributes = oldQuant.getAttributes();
            Node unitNode = node.getOwnerDocument().createAttribute("unit");
            unitNode.setNodeValue((String) dispensedLine.getField12());
            attributes.setNamedItem(unitNode);
            Node attNode = node.getOwnerDocument().createAttribute("value");
            attNode.setNodeValue((String) dispensedLine.getField7());
            attributes.setNamedItem(attNode);

            //            Node quant = createEpsosCapacityQuantityNode(dom, (String)dispensedLine.getField7(),(String)dispensedLine.getField12());
            //            if (contentNode != null && oldQuant != null)
            //               contentNode.replaceChild(quant, oldQuant);
        }
    } catch (Exception e) {
        _log.error("error using identical material info from prescription");

    }
    product.appendChild(materialNode);
    productNode.appendChild(product);
    node.appendChild(productNode);
}

From source file:org.alternativevision.gpx.GPXParser.java

private void addGenericWaypointToGPXNode(String tagName, Waypoint wpt, Node gpxNode, Document doc) {
    Node wptNode = doc.createElement(tagName);
    NamedNodeMap attrs = wptNode.getAttributes();
    if (wpt.getLatitude() != null) {
        Node latNode = doc.createAttribute(GPXConstants.LAT_ATTR);
        latNode.setNodeValue(wpt.getLatitude().toString());
        attrs.setNamedItem(latNode);
    }//from   w w w .  j  a  v a 2  s . c om
    if (wpt.getLongitude() != null) {
        Node longNode = doc.createAttribute(GPXConstants.LON_ATTR);
        longNode.setNodeValue(wpt.getLongitude().toString());
        attrs.setNamedItem(longNode);
    }
    if (wpt.getElevation() != null) {
        Node node = doc.createElement(GPXConstants.ELE_NODE);
        node.appendChild(doc.createTextNode(wpt.getElevation().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getTime() != null) {
        Node node = doc.createElement(GPXConstants.TIME_NODE);
        node.appendChild(doc.createTextNode(sdfZ.format(wpt.getTime())));
        wptNode.appendChild(node);
    }
    if (wpt.getMagneticDeclination() != null) {
        Node node = doc.createElement(GPXConstants.MAGVAR_NODE);
        node.appendChild(doc.createTextNode(wpt.getMagneticDeclination().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getGeoidHeight() != null) {
        Node node = doc.createElement(GPXConstants.GEOIDHEIGHT_NODE);
        node.appendChild(doc.createTextNode(wpt.getGeoidHeight().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getName() != null) {
        Node node = doc.createElement(GPXConstants.NAME_NODE);
        node.appendChild(doc.createTextNode(wpt.getName()));
        wptNode.appendChild(node);
    }
    if (wpt.getComment() != null) {
        Node node = doc.createElement(GPXConstants.CMT_NODE);
        node.appendChild(doc.createTextNode(wpt.getComment()));
        wptNode.appendChild(node);
    }
    if (wpt.getDescription() != null) {
        Node node = doc.createElement(GPXConstants.DESC_NODE);
        node.appendChild(doc.createTextNode(wpt.getDescription()));
        wptNode.appendChild(node);
    }
    if (wpt.getSrc() != null) {
        Node node = doc.createElement(GPXConstants.SRC_NODE);
        node.appendChild(doc.createTextNode(wpt.getSrc()));
        wptNode.appendChild(node);
    }
    //TODO: write link node
    if (wpt.getSym() != null) {
        Node node = doc.createElement(GPXConstants.SYM_NODE);
        node.appendChild(doc.createTextNode(wpt.getSym()));
        wptNode.appendChild(node);
    }
    if (wpt.getType() != null) {
        Node node = doc.createElement(GPXConstants.TYPE_NODE);
        node.appendChild(doc.createTextNode(wpt.getType()));
        wptNode.appendChild(node);
    }
    if (wpt.getFix() != null) {
        Node node = doc.createElement(GPXConstants.FIX_NODE);
        node.appendChild(doc.createTextNode(wpt.getFix().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getSat() != null) {
        Node node = doc.createElement(GPXConstants.SAT_NODE);
        node.appendChild(doc.createTextNode(wpt.getSat().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getHdop() != null) {
        Node node = doc.createElement(GPXConstants.HDOP_NODE);
        node.appendChild(doc.createTextNode(wpt.getHdop().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getVdop() != null) {
        Node node = doc.createElement(GPXConstants.VDOP_NODE);
        node.appendChild(doc.createTextNode(wpt.getVdop().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getPdop() != null) {
        Node node = doc.createElement(GPXConstants.PDOP_NODE);
        node.appendChild(doc.createTextNode(wpt.getPdop().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getAgeOfGPSData() != null) {
        Node node = doc.createElement(GPXConstants.AGEOFGPSDATA_NODE);
        node.appendChild(doc.createTextNode(wpt.getAgeOfGPSData().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getDgpsid() != null) {
        Node node = doc.createElement(GPXConstants.DGPSID_NODE);
        node.appendChild(doc.createTextNode(wpt.getDgpsid().toString()));
        wptNode.appendChild(node);
    }
    if (wpt.getExtensionsParsed() > 0) {
        Node node = doc.createElement(GPXConstants.EXTENSIONS_NODE);
        Iterator<IExtensionParser> it = extensionParsers.iterator();
        while (it.hasNext()) {
            it.next().writeWaypointExtensionData(node, wpt, doc);
        }
        wptNode.appendChild(node);
    }
    gpxNode.appendChild(wptNode);
}

From source file:org.alternativevision.gpx.GPXParser.java

private void addBasicGPXInfoToNode(GPX gpx, Node gpxNode, Document doc) {
    NamedNodeMap attrs = gpxNode.getAttributes();
    if (gpx.getVersion() != null) {
        Node verNode = doc.createAttribute(GPXConstants.VERSION_ATTR);
        verNode.setNodeValue(gpx.getVersion());
        attrs.setNamedItem(verNode);
    }//from  www  .  ja  v a2 s .c om
    if (gpx.getCreator() != null) {
        Node creatorNode = doc.createAttribute(GPXConstants.CREATOR_ATTR);
        creatorNode.setNodeValue(gpx.getCreator());
        attrs.setNamedItem(creatorNode);
    }

    if (gpx.getExtensionsParsed() > 0) {
        Node node = doc.createElement(GPXConstants.EXTENSIONS_NODE);
        Iterator<IExtensionParser> it = extensionParsers.iterator();
        while (it.hasNext()) {
            it.next().writeGPXExtensionData(node, gpx, doc);
        }
        gpxNode.appendChild(node);
    }
}

From source file:org.apache.axis.message.NodeImpl.java

/**
 * The internal representation of Attributes cannot help being changed
 * It is because Attribute is not immutible Type, so if we keep out value and
 * just return it in another form, the application may chnae it, which we cannot
 * detect without some kind back track method (call back notifying the chnage.)
 * I am not sure which approach is better.
 *//*  ww w .j ava  2 s . c om*/
protected NamedNodeMap convertAttrSAXtoDOM(Attributes saxAttr) {
    try {
        org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument();
        AttributesImpl saxAttrs = (AttributesImpl) saxAttr;
        NamedNodeMap domAttributes = new NamedNodeMapImpl();
        for (int i = 0; i < saxAttrs.getLength(); i++) {
            String uri = saxAttrs.getURI(i);
            String qname = saxAttrs.getQName(i);
            String value = saxAttrs.getValue(i);
            if (uri != null && uri.trim().length() > 0) {
                // filterring out the tricky method to differentiate the null namespace
                // -ware case
                if (NULL_URI_NAME.equals(uri)) {
                    uri = null;
                }
                Attr attr = doc.createAttributeNS(uri, qname);
                attr.setValue(value);
                domAttributes.setNamedItemNS(attr);
            } else {
                Attr attr = doc.createAttribute(qname);
                attr.setValue(value);
                domAttributes.setNamedItem(attr);
            }
        }
        return domAttributes;
    } catch (Exception ex) {
        log.error(Messages.getMessage("saxToDomFailed00"), ex);

        return null;
    }
}

From source file:org.openbravo.erpCommon.modules.ImportModule.java

/**
 * Adds a single classpath entry to the xml file
 *///from w ww  . j a  va2s. c o  m
private void addClassPathEntry(Document doc, String dir) throws Exception {
    log4j.info("adding entry for directory" + dir);
    final Node root = doc.getFirstChild();
    final Node classpath = doc.createElement("classpathentry");
    final NamedNodeMap cpAttributes = classpath.getAttributes();

    Attr attr = doc.createAttribute("kind");
    attr.setValue("src");
    cpAttributes.setNamedItem(attr);

    attr = doc.createAttribute("path");
    attr.setValue(dir);
    cpAttributes.setNamedItem(attr);

    root.appendChild(classpath);

}