List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:org.wso2.carbon.humantask.core.engine.runtime.xpath.XPathExpressionRuntime.java
private Element replaceElement(Element lval, Element src) { Document doc = lval.getOwnerDocument(); NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) { lval.appendChild(doc.importNode(nl.item(i), true)); }/*from w w w . j a v a 2 s .com*/ NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { lval.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) { lval.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } } return lval; }
From source file:org.wso2.carbon.tomcat.internal.ServerManager.java
/** * initialization code goes here.i.e : configuring tomcat instance using catalina-server.xml *//*from w w w . ja v a2s .c o m*/ public void init() { bundleCtxtClassLoader = Thread.currentThread().getContextClassLoader(); String carbonHome = System.getProperty("carbon.home"); String catalinaHome = new File(carbonHome).getAbsolutePath() + File.separator + "lib" + File.separator + "tomcat"; String catalinaXML = new File(carbonHome).getAbsolutePath() + File.separator + "repository" + File.separator + "conf" + File.separator + "tomcat" + File.separator + "catalina-server.xml"; try { inputStream = new FileInputStream(new File(catalinaXML)); } catch (FileNotFoundException e) { log.error("could not locate the file catalina-server.xml", e); } //setting catalina.base system property. tomcat configurator refers this property while tomcat instance creation. //you can override the property in wso2server.sh if (System.getProperty("catalina.base") == null) { System.setProperty("catalina.base", System.getProperty("carbon.home") + File.separator + "lib" + File.separator + "tomcat"); } tomcat = new CarbonTomcat(); if (SecretManager.getInstance().isInitialized()) { //creates DOM from input stream Element config = inputStreamToDOM(inputStream); //creates Secret resolver resolver = SecretResolverFactory.create(config, true); //resolves protected passwords resolveSecuredConfig(config, null); config.getAttributes() .removeNamedItem(XMLConstants.XMLNS_ATTRIBUTE + SecurityConstants.NS_SEPARATOR + SVNS); // creates new input stream from processed DOM element InputStream newStream = domToInputStream(config); tomcat.configure(catalinaHome, newStream); } else { tomcat.configure(catalinaHome, inputStream); } }
From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java
/** * Extracts any namespace definitions ("xmlns:prefix=uri") declared on the * element./*from w ww . j a va 2s. c o m*/ * * @param element * {@link Element} to be examined. * @return mapping of namespace prefixes to URIs. */ protected Map<String, String> extractNamespaces(Element element) { Map<String, String> namespaces = new HashMap<String, String>(); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (attr.getName().startsWith("xmlns:")) { namespaces.put(attr.getName().substring("xmlns:".length()), attr.getValue()); } } return namespaces; }
From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java
protected void setNameSpace(Element elem) { NamedNodeMap atts = elem.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node currentAttribute = atts.item(i); String currentPrefix = currentAttribute.getPrefix(); if (currentPrefix != null && currentPrefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) { String prfx = currentAttribute.getLocalName(); String uri = currentAttribute.getNodeValue(); definitions.setNamespaceURI(prfx, uri); }/*from w w w . j a v a 2 s . c o m*/ } }
From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java
void parseAttributes(Object base, Element rootElement) { ConvertingWrapDynaBean wrap = new ConvertingWrapDynaBean(base); DynaClass danaClass = wrap.getDynaClass(); NamedNodeMap atts = rootElement.getAttributes(); String defNamespace = rootElement.getNamespaceURI(); for (int i = 0; i < atts.getLength(); i++) { Node currentAttribute = atts.item(i); String ns = currentAttribute.getNamespaceURI(); if (ns == null) { ns = defNamespace;//from ww w . j a v a2s . co m } String attrName = currentAttribute.getLocalName(); // getNodeName(); switch (ns) { case BPMN2_NS: { DynaProperty dynaProperty = danaClass.getDynaProperty(attrName); if (dynaProperty != null) { Class clazz = dynaProperty.getType(); if (clazz.isAssignableFrom(Reference.class)) { String value = currentAttribute.getNodeValue(); Reference ref = createReference(value); wrap.set(attrName, ref); } else if (clazz.isAssignableFrom(QName.class)) { String value = currentAttribute.getNodeValue(); QName ret = createQName(value); wrap.set(attrName, ret); } else if (clazz.isAssignableFrom(MultiInstanceBehavior.class)) { String value = currentAttribute.getNodeValue(); wrap.set(attrName, MultiInstanceBehavior.valueOf(value)); } else { String value = currentAttribute.getNodeValue(); wrap.set(attrName, value); } } break; } case BPMNDI_NS: case DC_NS: case DI_NS: { DynaProperty dynaProperty = danaClass.getDynaProperty(attrName); if (dynaProperty != null) { String value = currentAttribute.getNodeValue(); wrap.set(attrName, value); } break; } } } }
From source file:org.yawlfoundation.yawl.util.DOMUtil.java
public static void removeAllAttributes(Element element) { Vector<String> names = new Vector<String>(); int length = element.getAttributes().getLength(); NamedNodeMap atts = element.getAttributes(); for (int i = 0; i < length; names.add(atts.item(i).getLocalName()), i++) ;//w ww. j ava 2 s . co m for (String name : names) element.removeAttribute(name); }
From source file:oscar.oscarLab.ca.all.upload.handlers.IHAHandler.java
@Override public String parse(String serviceName, String fileName, int fileId) { Document xmlDoc = getXML(fileName); Node node;//from w w w . j a va2 s. c o m Element element; NamedNodeMap nnm = null; String msgId = null; String result = null; if (xmlDoc != null) { String hl7Body = null; String attrName = null; try { msgId = null; NodeList allNodes = xmlDoc.getElementsByTagNameNS("*", "*"); for (int i = 1; i < allNodes.getLength(); i++) { try { element = (Element) allNodes.item(i); nnm = element.getAttributes(); if (nnm != null) { for (int j = 0; j < nnm.getLength(); j++) { node = nnm.item(j); attrName = node.getNodeName(); if (attrName.equals("msgId")) { msgId = node.getNodeValue(); } } } hl7Body = allNodes.item(i).getFirstChild().getTextContent(); if (hl7Body != null && hl7Body.indexOf("\nPID|") > 0) { logger.info("using xml HL7 Type " + getHl7Type()); MessageUploader.routeReport(serviceName, "IHA", hl7Body, fileId); result += "success:" + msgId + ","; } } catch (Exception e) { result += "fail:" + msgId + ","; } } } catch (Exception e) { MessageUploader.clean(fileId); logger.error("ERROR:", e); return null; } } return (result); }
From source file:test.unit.be.fedict.eid.applet.service.signer.AbstractXmlSignatureServiceTest.java
private boolean isDigested(NodeList nodes, VerifyReference[] references) { for (int idx = 0; idx < nodes.getLength(); idx++) { Node node = nodes.item(idx); LOG.debug("node name: " + node.getLocalName()); boolean changed = false; if (node.getNodeType() == Node.TEXT_NODE) { String originalTextValue = node.getNodeValue(); String changedTextValue = originalTextValue + "foobar"; node.setNodeValue(changedTextValue); changed = false; // need to have impact anyway for (int referenceIdx = 0; referenceIdx < references.length; referenceIdx++) { VerifyReference reference = references[referenceIdx]; changed |= reference.hasChanged(); }// w ww .j a v a 2s .co m if (false == changed) { return false; } node.setNodeValue(originalTextValue); } else if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; NamedNodeMap attributes = element.getAttributes(); for (int attributeIdx = 0; attributeIdx < attributes.getLength(); attributeIdx++) { Node attributeNode = attributes.item(attributeIdx); String originalAttributeValue = attributeNode.getNodeValue(); String changedAttributeValue = originalAttributeValue + "foobar"; attributeNode.setNodeValue(changedAttributeValue); for (int referenceIdx = 0; referenceIdx < references.length; referenceIdx++) { VerifyReference reference = references[referenceIdx]; changed |= reference.hasChanged(); } attributeNode.setNodeValue(originalAttributeValue); } changed |= isDigested(element.getChildNodes(), references); } else if (node.getNodeType() == Node.COMMENT_NODE) { // not always digested } else { throw new RuntimeException("unsupported node type: " + node.getNodeType()); } if (false == changed) { return false; } } return true; }
From source file:tkwatch.Utilities.java
/** * Recursively travels through a DOM tree. Adapted from Vohra and Vohra, * <i>Pro XML Development with Java Technology</i>, p. 47. This was used * during development and is not called by <strong>TKWatch+</strong>. * Retained for completeness./*from w ww .j a va 2s . c om*/ * * @param previousNode * @param visitNode */ public static void visitNode(Element previousNode, Element visitNode) { if (previousNode != null) { System.out.println("Element " + previousNode.getTagName() + " has element:"); } System.out.println("Element Name: " + visitNode.getTagName()); if (visitNode.hasAttributes()) { System.out.println("Element " + visitNode.getTagName() + " has attributes: "); NamedNodeMap attributes = visitNode.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attribute = (Attr) (attributes.item(j)); System.out.println("Attribute:" + attribute.getName() + " with value " + attribute.getValue()); } } // Obtain a NodeList of nodes in an Element node. NodeList nodeList = visitNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; visitNode(visitNode, element); } else if (node.getNodeType() == Node.TEXT_NODE) { String str = node.getNodeValue().trim(); if (str.length() > 0) { System.out.println("Element Text: " + str); } } } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * process the given node//from ww w . j av a2 s . co m * * @param node Node to process * @param procNode The procedure node * * @return keep going * * @throws Throwable On badness */ protected boolean processTagCall(Element node, Element procNode) throws Throwable { if (procNode == null) { return error("Could not find procedure node for call:" + XmlUtil.toString(node)); } pushProperties(); String cdata = XmlUtil.getChildText(node); if ((cdata != null) && (cdata.trim().length() > 0)) { putProperty("paramtext", cdata); } else { putProperty("paramtext", ""); } NamedNodeMap procnnm = procNode.getAttributes(); if (procnnm != null) { for (int i = 0; i < procnnm.getLength(); i++) { Attr attr = (Attr) procnnm.item(i); if (!ATTR_NAME.equals(attr.getNodeName())) { putProperty(attr.getNodeName(), applyMacros(attr.getNodeValue())); } } } NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { for (int i = 0; i < nnm.getLength(); i++) { Attr attr = (Attr) nnm.item(i); if (!ATTR_NAME.equals(attr.getNodeName())) { putProperty(attr.getNodeName(), applyMacros(attr.getNodeValue())); } } } try { if (!processChildren(node)) { return false; } try { if (!processChildren(procNode)) { return false; } } catch (MyReturnException mre) { //noop } } catch (Throwable throwable) { popProperties(); throw throwable; } popProperties(); return true; }