List of usage examples for org.w3c.dom Node setNodeValue
public void setNodeValue(String nodeValue) throws DOMException;
From source file:com.ext.portlet.epsos.EpsosHelperService.java
/** * Add a tag of the form below under the given node: * /*w ww . jav a 2 s. c om*/ * <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:de.betterform.xml.xforms.model.submission.Submission.java
/** * Performs replace processing according to section 11.1, para 5. *///from www .j av a 2 s .c o m protected void submitReplaceText(Map response) throws XFormsException { if (getLogger().isDebugEnabled()) { getLogger().debug(this + " submit: replacing text"); } Node targetNode; if (this.targetExpr != null) { targetNode = XPathUtil .getAsNode( XPathCache.getInstance() .evaluate( this.instance == null ? evalInScopeContext() : this.model.getInstance(this.instance).getRootContext() .getNodeset(), 1, this.targetExpr, this.prefixMapping, this.xpathFunctionContext), 1); } else if (this.instance == null) { targetNode = this.model.getInstance(getInstanceId()).getInstanceDocument().getDocumentElement(); } else { targetNode = this.model.getInstance(this.instance).getInstanceDocument().getDocumentElement(); } final InputStream responseStream = (InputStream) response.get(XFormsProcessor.SUBMISSION_RESPONSE_STREAM); StringBuilder text = new StringBuilder(512); try { String contentType = (String) response.get("Content-Type"); String encoding = "UTF-8"; if (contentType != null) { final String[] contTypeEntries = contentType.split(", ?"); for (int i = 0; i < contTypeEntries.length; i++) { if (contTypeEntries[i].startsWith("charset=")) { encoding = contTypeEntries[i].substring(8); } } } byte[] buffer = new byte[512]; int bytesRead; while ((bytesRead = responseStream.read(buffer)) > 0) { text.append(new String(buffer, 0, bytesRead, encoding)); } responseStream.close(); } catch (Exception e) { // todo: check for response media type (needs submission response // refactoring) in order to dispatch xforms-link-exception throw new XFormsSubmitError("instance parsing failed", e, this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath, XFormsConstants.PARSE_ERROR, getResourceURI(), 200d, null, "", "")); } if (targetNode == null) { throw new XFormsSubmitError("Invalid target", this.getTarget(), XFormsSubmitError.constructInfoObject(this.element, this.container, locationPath, XFormsConstants.TARGET_ERROR, getResourceURI(), 200d, null, "", "")); } else if (targetNode.getNodeType() == Node.ELEMENT_NODE) { while (targetNode.getFirstChild() != null) { targetNode.removeChild(targetNode.getFirstChild()); } targetNode.appendChild(targetNode.getOwnerDocument().createTextNode(text.toString())); } else if (targetNode.getNodeType() == Node.ATTRIBUTE_NODE) { targetNode.setNodeValue(text.toString()); } else { LOGGER.warn("Don't know how to handle targetNode '" + targetNode.getLocalName() + "', node is neither an element nor an attribute Node"); } // perform rebuild, recalculate, revalidate, and refresh this.model.rebuild(); this.model.recalculate(); this.model.revalidate(); this.container.refresh(); // deferred update behaviour UpdateHandler updateHandler = this.model.getUpdateHandler(); if (updateHandler != null) { updateHandler.doRebuild(false); updateHandler.doRecalculate(false); updateHandler.doRevalidate(false); updateHandler.doRefresh(false); } // dispatch xforms-submit-done this.container.dispatch(this.target, XFormsEventNames.SUBMIT_DONE, constructEventInfo(response)); }
From source file:com.portfolio.data.provider.MysqlDataProvider.java
/*****************************/ @Override//from www .j a v a 2 s . c om public String postMacroOnNode(int userId, String nodeUuid, String macroName) { String val = "erreur"; String sql = ""; PreparedStatement st; /// SELECT grid, role, RD,WR,DL,AD,types_id,rules_id FROM rule_table rt LEFT JOIN group_right_info gri ON rt.role=gri.label LEFT JOIN node n ON n.portfolio_id=gri.portfolio_id WHERE rule_id=1 AND n.node_uuid=uuid2bin('d48cafa1-5180-4c83-9e22-5d4d45bbf6e2'); /// SELECT grid,bin2uuid(id),RD,WR,DL,SB,AD,types_id,rules_id FROM group_rights WHERE id=uuid2bin('d48cafa1-5180-4c83-9e22-5d4d45bbf6e2'); // If admin // and reset is called try { /// Pour retrouver les enfants du noeud et affecter les droits if (dbserveur.equals("mysql")) { sql = "CREATE TEMPORARY TABLE t_struc_nodeid(" + "uuid binary(16) UNIQUE NOT NULL, " + "t_level INT) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; st = connection.prepareStatement(sql); st.execute(); st.close(); } else if (dbserveur.equals("oracle")) { String v_sql = "CREATE GLOBAL TEMPORARY TABLE t_struc_nodeid(" + "uuid RAW(16) NOT NULL, " + "t_level NUMBER(10,0)" + ", CONSTRAINT t_struc_nodeid_UK_uuid UNIQUE (uuid)) ON COMMIT PRESERVE ROWS"; sql = "{call create_or_empty_table('t_struc_nodeid','" + v_sql + "')}"; CallableStatement ocs = connection.prepareCall(sql); ocs.execute(); ocs.close(); } // En double car on ne peut pas faire d'update/select d'une mme table temporaire if (dbserveur.equals("mysql")) { sql = "CREATE TEMPORARY TABLE t_struc_nodeid_2(" + "uuid binary(16) UNIQUE NOT NULL, " + "t_level INT) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; st = connection.prepareStatement(sql); st.execute(); st.close(); } else if (dbserveur.equals("oracle")) { String v_sql = "CREATE GLOBAL TEMPORARY TABLE t_struc_nodeid_2(" + "uuid RAW(16) NOT NULL, " + "t_level NUMBER(10,0)" + ", CONSTRAINT t_struc_nodeid_2_UK_uuid UNIQUE (uuid)) ON COMMIT PRESERVE ROWS"; sql = "{call create_or_empty_table('t_struc_nodeid_2','" + v_sql + "')}"; CallableStatement ocs = connection.prepareCall(sql); ocs.execute(); ocs.close(); } /// Dans la table temporaire on retrouve les noeuds concerns /// (assure une convergence de la rcursion et limite le nombre de lignes dans la recherche) /// Init table sql = "INSERT INTO t_struc_nodeid(uuid, t_level) " + "SELECT n.node_uuid, 0 " + "FROM node n " + "WHERE n.node_uuid=uuid2bin(?)"; st = connection.prepareStatement(sql); st.setString(1, nodeUuid); st.executeUpdate(); st.close(); // /* /// On boucle, rcursion par niveau int level = 0; int added = 1; if (dbserveur.equals("mysql")) { sql = "INSERT IGNORE INTO t_struc_nodeid_2(uuid, t_level) "; } else if (dbserveur.equals("oracle")) { sql = "INSERT /*+ ignore_row_on_dupkey_index(t_struc_nodeid_2,t_struc_nodeid_2_UK_uuid)*/ INTO t_struc_nodeid_2(uuid, t_level) "; } sql += "SELECT n.node_uuid, ? " + "FROM node n WHERE n.node_parent_uuid IN (SELECT uuid FROM t_struc_nodeid t " + "WHERE t.t_level=?)"; String sqlTemp = null; if (dbserveur.equals("mysql")) { sqlTemp = "INSERT IGNORE INTO t_struc_nodeid SELECT * FROM t_struc_nodeid_2;"; } else if (dbserveur.equals("oracle")) { sqlTemp = "INSERT INTO t_struc_nodeid SELECT * FROM t_struc_nodeid_2"; } PreparedStatement stTemp = connection.prepareStatement(sqlTemp); st = connection.prepareStatement(sql); while (added != 0) { st.setInt(1, level + 1); st.setInt(2, level); st.executeUpdate(); added = stTemp.executeUpdate(); // On s'arrte quand rien t ajout level = level + 1; // Prochaine tape } st.close(); stTemp.close(); //*/ /// Selection du grid de l'utilisateur sql = "SELECT gr.grid, gi.label " + "FROM group_rights gr, group_info gi, group_user gu " + "WHERE gr.grid=gi.grid AND gi.gid=gu.gid AND gu.userid=? AND gr.id=uuid2bin(?) AND NOT gi.label=\"all\""; st = connection.prepareStatement(sql); st.setInt(1, userId); st.setString(2, nodeUuid); ResultSet res = st.executeQuery(); /// res.getFetchSize() retourne 0, mme avec un bon rsultat int grid = 0; String grlabl = ""; if (res.next()) { grid = res.getInt("grid"); grlabl = res.getString("label"); } res.close(); st.close(); // Fetch metadata sql = "SELECT metadata_wad FROM node WHERE node_uuid=uuid2bin(?)"; st = connection.prepareStatement(sql); st.setString(1, nodeUuid); res = st.executeQuery(); String meta = ""; if (res.next()) meta = res.getString("metadata_wad"); res.close(); st.close(); // Parse it, for the amount of manipulation we do, it will be simpler than find/replace DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); meta = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><metadata-wad " + meta + "></metadata-wad>"; System.out.println("ACTION OUT: " + meta); InputSource is = new InputSource(new StringReader(meta)); Document doc = documentBuilder.parse(is); Element rootMeta = doc.getDocumentElement(); boolean doUpdate = true; NamedNodeMap metaAttr = rootMeta.getAttributes(); if ("reset".equals(macroName) && credential.isAdmin(userId)) { /// if reset and admin // Call specific function to process current temporary table resetRights(); } else if ("show".equals(macroName) || "hide".equals(macroName)) { /// FIXME: Could only change the needed rights // Check if current group can show stuff String roles = metaAttr.getNamedItem("showroles").getNodeValue(); if (roles.contains(grlabl)) // Can activate it { String showto = metaAttr.getNamedItem("showtoroles").getNodeValue(); showto = showto.replace(" ", "\",\""); showto = "(\"" + showto + "\")"; //// Il faut qu'il y a un showtorole if (!"(\"\")".equals(showto)) { // Update rights /// Ajoute/remplace les droits // FIXME: Je crois que quelque chose manque sql = "INSERT INTO group_rights(grid, id, RD, WR, DL, AD, types_id, rules_id) " + "SELECT gr.grid, gr.id, ?, 0, 0, 0, NULL, NULL " + "FROM group_right_info gri, group_rights gr " + "WHERE gri.label IN " + showto + " AND gri.grid=gr.grid AND gr.id IN (SELECT uuid FROM t_struc_nodeid) " + "ON DUPLICATE KEY UPDATE RD=?, WR=gr.WR, DL=gr.DL, AD=gr.AD, types_id=gr.types_id, rules_id=gr.rules_id"; if (dbserveur.equals("oracle")) { sql = "MERGE INTO group_rights d USING (SELECT gr.grid, gr.id, ? RD, 0 WR, 0 DL, 0 AD, NULL types_id, NULL rules_id FROM group_right_info gri, group_rights gr WHERE gri.label IN " + showto + " AND gri.grid=gr.grid AND gr.id IN (SELECT uuid FROM t_struc_nodeid)) s WHEN MATCHED THEN UPDATE SET d.RD=?, d.WR=gr.WR, d.DL=gr.DL, d.AD=gr.AD, d.types_id=gr.types_id, d.rules_id=gr.rules_id WHEN NOT MATCHED THEN INSERT (d.grid, d.id, d.RD, d.WR, d.DL, d.AD, d.types_id, d.rules_id) VALUES (s.grid, s.id, s.RD, s.WR, s.DL, s.AD, s.types_id, s.rules_id)"; } st = connection.prepareStatement(sql); if ("hide".equals(macroName)) { st.setInt(1, 0); st.setInt(2, 0); } else if ("show".equals(macroName)) { st.setInt(1, 1); st.setInt(2, 1); } // st.setString(2, showto); st.executeUpdate(); st.close(); Node isPriv = metaAttr.getNamedItem("private"); // Update local string if ("hide".equals(macroName)) isPriv.setNodeValue("Y"); else if ("show".equals(macroName)) isPriv.setNodeValue("N"); } } // Update DB if (doUpdate) { meta = DomUtils.getNodeAttributesString(rootMeta); System.out.println("META: " + meta); sql = "UPDATE node SET metadata_wad=? WHERE node_uuid=uuid2bin(?)"; st = connection.prepareStatement(sql); st.setString(1, meta); st.setString(2, nodeUuid); st.executeUpdate(); } } else if ("submit".equals(macroName)) { System.out.println("ACTION: " + macroName + " grid: " + grid + " -> uuid: " + nodeUuid); // Update rights /// Ajoute/remplace les droits // FIXME: Je crois que quelque chose manque sql = "INSERT INTO group_rights(grid, id, RD, WR, DL, AD, SB, types_id, rules_id) " + "SELECT gr.grid, gr.id, 1, 0, 0, 0, 0, NULL, NULL " + "FROM group_rights gr " + "WHERE gr.id IN (SELECT uuid FROM t_struc_nodeid) " + "ON DUPLICATE KEY UPDATE RD=1, WR=0, DL=0, AD=0, SB=0, types_id=null, rules_id=null"; if (dbserveur.equals("oracle")) { sql = "MERGE INTO group_rights d USING (SELECT gr.grid, gr.id, 1 RD, 0 WR, 0 DL, 0 AD, 0 SB, NULL types_id, NULL rules_id FROM group_rights gr WHERE gr.id IN (SELECT uuid FROM t_struc_nodeid)) s WHEN MATCHED THEN UPDATE SET d.RD=1, d.WR=0, d.DL=0, d.AD=0, d.SB=0, d.types_id=s.types_id, d.rules_id=s.rules_id WHEN NOT MATCHED THEN INSERT (d.grid, d.id, d.RD, d.WR, d.DL, d.AD, d.SB, d.types_id, d.rules_id) VALUES (s.grid, s.id, s.RD, s.WR, s.DL, s.AD, s.SB, s.types_id, s.rules_id)"; } st = connection.prepareStatement(sql); st.executeUpdate(); st.close(); /// Vrifie le showtoroles String showto = metaAttr.getNamedItem("showtoroles").getNodeValue(); showto = showto.replace(" ", "\",\""); showto = "(\"" + showto + "\")"; //// Il faut qu'il y a un showtorole System.out.println("SHOWTO: " + showto); if (!"(\"\")".equals(showto)) { System.out.println("SHOWING TO: " + showto); // Update rights /// Ajoute/remplace les droits // FIXME: Je crois que quelque chose manque sql = "INSERT INTO group_rights(grid, id, RD, WR, DL, AD, types_id, rules_id) " + "SELECT gri.grid, gr.id, 1, 0, 0, 0, NULL, NULL " + "FROM group_right_info gri, group_rights gr " + "WHERE gri.label IN " + showto + " " + "AND gri.portfolio_id=(" + "SELECT portfolio_id FROM node " + "WHERE node_uuid=uuid2bin(?)) " + "AND gr.id IN (SELECT uuid FROM t_struc_nodeid) " + "ON DUPLICATE KEY UPDATE RD=1, WR=gr.WR, DL=gr.DL, AD=gr.AD, types_id=gr.types_id, rules_id=gr.rules_id"; if (dbserveur.equals("oracle")) { sql = "MERGE INTO group_rights d USING (SELECT gri.grid, n.node_uuid, rt.RD, rt.WR, rt.DL, rt.AD, rt.types_id, rt.rules_id FROM rule_table rt LEFT JOIN group_right_info gri ON rt.role=gri.label LEFT JOIN node n ON n.portfolio_id=gri.portfolio_id WHERE rt.rule_id=? AND n.node_uuid IN (SELECT uuid FROM t_struc_nodeid)) s ON (d.grid = s.grid AND d.id = s.id) WHEN MATCHED THEN UPDATE SET d.RD=rt.RD, d.WR=rt.WR, d.DL=rt.DL, d.AD=rt.AD, d.types_id=rt.types_id, d.rules_id=rt.rules_id WHEN NOT MATCHED THEN INSERT (d.grid, d.id, d.RD, d.WR, d.DL, d.AD, d.types_id, d.rules_id) VALUES (s.grid, s.id, s.RD, s.WR, s.DL, s.AD, s.types_id, s.rules_id)"; } st = connection.prepareStatement(sql); st.setString(1, nodeUuid); st.executeUpdate(); st.close(); // Node isPriv = metaAttr.getNamedItem("private"); // isPriv.setNodeValue("Y"); } } val = "OK"; } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { // Les 'pooled connection' ne se ferment pas vraiment. On nettoie manuellement les tables temporaires... if (dbserveur.equals("mysql")) { sql = "DROP TEMPORARY TABLE IF EXISTS t_struc_nodeid, t_struc_nodeid_2"; st = connection.prepareStatement(sql); st.execute(); st.close(); } connection.close(); } catch (SQLException e) { e.printStackTrace(); } } return val; }
From source file:net.wastl.webmail.xml.XMLCommon.java
/** * Set the node value of the node selected by the given xpath expression. */// w w w.jav a 2 s. c o m public static void setValueXPath(Element root, String path, String value) { root.normalize(); try { Node n = XPathAPI.selectSingleNode(root, path); if (n != null) { n.setNodeValue(value); } else { addNodeXPath(root, getParentXPath(path), root.getOwnerDocument().createTextNode(value)); } } catch (TransformerException ex) { addNodeXPath(root, getParentXPath(path), root.getOwnerDocument().createTextNode(value)); } catch (Exception ex) { log.error("Failed to set value '" + value + "' for path '" + path + "'. Continuing, but should not.", ex); // TODO: Throw here. } }
From source file:net.wastl.webmail.xml.XMLData.java
/** * Set the node value of the node selected by the given xpath expression. *///from w ww.java 2 s . c o m public void setValueXPath(String path, String value) { data.normalize(); try { Node n = xpath_api.selectSingleNode(data, path); if (n != null) { if (!n.getNodeValue().equals(value)) { n.setNodeValue(value); invalidateCache(); } } else { addNodeXPath(getParentXPath(path), root.createTextNode(value)); } } catch (TransformerException ex) { addNodeXPath(getParentXPath(path), root.createTextNode(value)); } catch (Exception ex) { log.error("XML error when trying to set value '" + value + "' for path '" + path + "'"); // TODO: throw } }
From source file:nl.b3p.ogc.sld.SldNamedStyle.java
public void setName(String name) throws XPathExpressionException { Node n = (Node) xpath_name.evaluate(node, XPathConstants.NODE); n.setNodeValue(name); }
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 www. ja v a 2 s .c o m } 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);//w ww. ja v a 2 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.axis2.description.AxisService.java
private void processImport(Node importNode) throws AxisFault { NamedNodeMap nodeMap = importNode.getAttributes(); Node attribute; String attributeValue;//w ww. j ava2s .co m for (int i = 0; i < nodeMap.getLength(); i++) { attribute = nodeMap.item(i); if (attribute.getNodeName().equals(SCHEMA_LOCATION)) { attributeValue = attribute.getNodeValue(); if (getParameter(Constants.CUSTOM_SCHEMA_NAME_PREFIX) != null) { String customSchemaNamePrefix = getParameter(Constants.CUSTOM_SCHEMA_NAME_PREFIX).getValue() .toString(); URL customUrl = null; try { URL base = new URL(customSchemaNamePrefix); customUrl = new URL(base, attributeValue); } catch (MalformedURLException e) { log.error("Malformed schema URL: " + customUrl, e); throw AxisFault.makeFault(e); } attribute.setNodeValue(customUrl.toString()); } else if (attributeValue.indexOf("://") == -1 && attributeValue.indexOf("?xsd=") == -1) { attribute.setNodeValue(this.getServiceEPR() + "?xsd=" + attributeValue); } } } }
From source file:org.apache.cocoon.xml.dom.DOMUtil.java
/** * Set the value of the DOM node./*from ww w.j a v a2 s . c o m*/ * All current children of the node are removed and a new text node * with the value is appended. */ public static void setValueOfNode(Node node, String value) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { node.setNodeValue(value); } else { while (node.hasChildNodes() == true) { node.removeChild(node.getFirstChild()); } node.appendChild(node.getOwnerDocument().createTextNode(value)); } }