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.qualipso.interop.semantics.securecomm.asm.inout.MyInOutRouteBuilder.java
public void configure() { try {//from w ww .jav a 2 s. c om File file = new File(propertyFileName); FileInputStream fis = new FileInputStream(file); availableServicesAsProperties = new Properties(); availableServicesAsProperties.load(fis); fis.close(); from("jbi:service:urn:qualipso:wp32:secCommNode2:camelinout") .to("jbi:service:urn:qualipso:wp32:secCommNode2:secCommNode2beanwssecService?mep=in-out") .setHeader("endpointName", constant("jbi:service:urn:qualipso:wp32:secCommNode2:") .append(new Expression<Exchange>() { public Object evaluate(Exchange exchange) { Exchange copyEx = exchange.copy(); Message msg = copyEx.getIn(); org.w3c.dom.Document doc = (org.w3c.dom.Document) msg .getBody(org.w3c.dom.Document.class); Element root = doc.getDocumentElement(); System.out .println("MyInOutRouteBuilder elemNAME=[" + root.getLocalName() + "]"); NamedNodeMap attrs = root.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node temp = attrs.item(i); if (temp.getNodeName().equalsIgnoreCase(WS_NAME_ATTRIBUTE) || temp.getNodeName().equalsIgnoreCase(WS_NAME_ATTRIBUTE2)) { System.out.println( "MyInOutRouteBuilder ROUTING =>[" + temp.getNodeValue() + "]"); return availableServicesAsProperties.get(temp.getNodeValue().trim()); } } // assuming we'll have an error page, redirect there return "errata"; } })) .recipientList(header("endpointName")); //.to("jbi:service:urn:qualipso:wp32:secCommNode2:secCommNode2ServerServiceProvInOut?mep=in-out"); } catch (Exception ex) { //assuming we shall have an error page, redirect to that one. System.out.println("CAMEL_EXCEPTION"); ex.printStackTrace(System.out); } }
From source file:org.regenstrief.util.XMLUtil.java
/** * Strips namespaces and prefixes from a Node tree * // w w w . j a v a2 s.c om * @param n the root Node * @return the stripped Node **/ public final static Node stripNamespaces(final Node n) { if (n == null) { return null; } final Document doc = n.getOwnerDocument(); if (n instanceof Element) { final Element eOld = (Element) n; final Element eNew = doc.createElement(getLocalName(eOld)); final NamedNodeMap map = eOld.getAttributes(); for (int i = 0, size = size(map); i < size; i++) { final Attr attr = (Attr) map.item(i); String name = attr.getName(); if (name == null) { name = attr.getLocalName(); } if (!("xmlns".equals(name) || ((name != null) && name.startsWith("xmlns:")) || "xmlns".equals(attr.getPrefix()))) { final int j = name.indexOf(':'); eNew.setAttribute(j < 0 ? name : name.substring(j + 1), attr.getValue()); } } final NodeList list = n.getChildNodes(); for (int i = 0, size = size(list); i < size; i++) { appendChild(eNew, stripNamespaces(list.item(i))); } return eNew; } else if (n instanceof Attr) { return null; } return n.cloneNode(false); }
From source file:org.rhq.core.clientapi.agent.metadata.i18n.PropertiesGenerator.java
private void generateAtributes(Element element, String partialKey) { if (element.getNodeName().equals("server") || element.getNodeName().equals("service")) { this.contentWriter.println(); }//from w w w. j a va 2s .c o m NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node n = attrs.item(i); Set<String> localizedProperties = TAG_LOCALIZED_ATTRIBUTES.get(element.getTagName()); if ((localizedProperties != null) && localizedProperties.contains(n.getNodeName())) { String key = partialKey + n.getNodeName(); String value = " # " + n.getNodeValue(); if (!this.previousProperties.containsKey(key)) { this.contentWriter.println(key + "=" + value); properties.put(key, value); } } } }
From source file:org.safehaus.penrose.log.log4j.Log4jConfigReader.java
public void print(int level, Element node) { for (int i = 0; i < level; i++) { System.out.print(" "); }/*from w w w . j a v a 2 s . c o m*/ if (node instanceof Text) { System.out.println("Text: " + node.getNodeValue()); } else { System.out.println(node.getNodeName() + ": " + node.getNodeValue()); } NamedNodeMap map = node.getAttributes(); for (int i = 0; map != null && i < map.getLength(); i++) { Node n = map.item(i); System.out.println(" - " + n.getNodeName() + ": " + n.getNodeValue()); } NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { print(level + 1, (Element) list.item(i)); } }
From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java
public BeanDefinitionHolder decorateBeanDefinitionIfRequired(Element ele, BeanDefinitionHolder definitionHolder, @Nullable BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; // Decorate based on custom attributes first. NamedNodeMap attributes = ele.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); finalDefinition = decorateIfRequired(node, finalDefinition, containingBd); }//from www. j av a 2 s . c om // Decorate based on custom nested elements. NodeList children = ele.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { finalDefinition = decorateIfRequired(node, finalDefinition, containingBd); } } return finalDefinition; }
From source file:org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.java
private static boolean isDefaultHttpConfig(Element httpElt) { return httpElt.getChildNodes().getLength() == 0 && httpElt.getAttributes().getLength() == 0; }
From source file:org.talend.designer.maven.utils.PomUtil.java
/** * //from w w w .ja va 2s . com * Create pom without refresh eclipse resources * * @param artifact * @return */ public static String generatePom2(MavenArtifact artifact) { try { Project project = ProjectManager.getInstance().getCurrentProject(); IProject fsProject = ResourceUtils.getProject(project); SecureRandom random = new SecureRandom(); IPath tempPath = fsProject.getLocation().append("temp").append("pom" + Math.abs(random.nextLong())); File tmpFolder = new File(tempPath.toPortableString()); tmpFolder.mkdirs(); String pomFile = tempPath.append(TalendMavenConstants.POM_FILE_NAME).toPortableString(); Model pomModel = new Model(); pomModel.setModelVersion(TalendMavenConstants.POM_VERSION); pomModel.setModelEncoding(TalendMavenConstants.DEFAULT_ENCODING); pomModel.setGroupId(artifact.getGroupId()); pomModel.setArtifactId(artifact.getArtifactId()); pomModel.setVersion(artifact.getVersion()); String artifactType = artifact.getType(); if (artifactType == null || "".equals(artifactType)) { artifactType = TalendMavenConstants.PACKAGING_JAR; } pomModel.setPackaging(artifactType); ByteArrayOutputStream buf = new ByteArrayOutputStream(); MavenPlugin.getMaven().writeModel(pomModel, buf); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(false); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); TransformerFactory tfactory = TransformerFactory.newInstance(); Document document = documentBuilder.parse(new ByteArrayInputStream(buf.toByteArray())); Element documentElement = document.getDocumentElement(); NamedNodeMap attributes = documentElement.getAttributes(); if (attributes == null || attributes.getNamedItem("xmlns") == null) { //$NON-NLS-1$ Attr attr = document.createAttribute("xmlns"); //$NON-NLS-1$ attr.setTextContent("http://maven.apache.org/POM/4.0.0"); //$NON-NLS-1$ documentElement.setAttributeNode(attr); } if (attributes == null || attributes.getNamedItem("xmlns:xsi") == null) { //$NON-NLS-1$ Attr attr = document.createAttribute("xmlns:xsi"); //$NON-NLS-1$ attr.setTextContent("http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$ documentElement.setAttributeNode(attr); } if (attributes == null || attributes.getNamedItem("xsi:schemaLocation") == null) { //$NON-NLS-1$ Attr attr = document.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", //$NON-NLS-1$ "xsi:schemaLocation"); //$NON-NLS-1$ attr.setTextContent( "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"); //$NON-NLS-1$ documentElement.setAttributeNode(attr); } Transformer transformer = tfactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(new File(pomFile)); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(source, result); return pomFile; } catch (PersistenceException e) { ExceptionHandler.process(e); } catch (CoreException e) { ExceptionHandler.process(e); } catch (ParserConfigurationException e) { ExceptionHandler.process(e); } catch (SAXException e) { ExceptionHandler.process(e); } catch (IOException e) { ExceptionHandler.process(e); } catch (TransformerConfigurationException e) { ExceptionHandler.process(e); } catch (TransformerException e) { ExceptionHandler.process(e); } return null; }
From source file:org.tinygroup.jspengine.xmlparser.ParserUtils.java
private static Schema getSchema(Document document) throws SAXException, JasperException { Schema schema = null;//from w w w . j a v a 2 s . co m Element root = document.getDocumentElement(); NamedNodeMap map = root.getAttributes(); for (int i = 0; map != null && i < map.getLength(); i++) { if (SCHEMA_LOCATION_ATTR.equals(map.item(i).getLocalName())) { String schemaLocation = map.item(i).getNodeValue(); if (Constants.SCHEMA_LOCATION_JSP_20.equals(schemaLocation)) { schema = getSchema(Constants.TAGLIB_SCHEMA_PUBLIC_ID_20); break; } else if (Constants.SCHEMA_LOCATION_JSP_21.equals(schemaLocation)) { schema = getSchema(Constants.TAGLIB_SCHEMA_PUBLIC_ID_21); break; } else if (Constants.SCHEMA_LOCATION_WEBAPP_24.equals(schemaLocation)) { schema = getSchema(Constants.WEBAPP_SCHEMA_PUBLIC_ID_24); break; } else if (Constants.SCHEMA_LOCATION_WEBAPP_25.equals(schemaLocation)) { schema = getSchema(Constants.WEBAPP_SCHEMA_PUBLIC_ID_25); break; } else { throw new JasperException(Localizer.getMessage("jsp.error.parse.unknownTldSchemaLocation", document.getDocumentURI(), map.item(i).getNodeValue())); } } } return schema; }
From source file:org.unitedinternet.cosmo.util.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) { local = e.getNodeName();/* ww w .jav a2 s . co m*/ } String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { writeAttribute((Attr) attributes.item(i), writer); } NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { writeNode(children.item(i), writer); } writer.writeEndElement(); }
From source file:org.webtestingexplorer.state.CustomizedPropertiesElementsState.java
private Map<WebElementIdentifier, Map<String, String>> parseXML(String xmlString) { Map<WebElementIdentifier, Map<String, String>> elementProperties = new HashMap<WebElementIdentifier, Map<String, String>>(); XpathWebElementIdentifier identifier; Map<String, String> attributeMap; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document doc = null;/* w w w. j a v a2 s . co m*/ try { DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlString)); doc = db.parse(is); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } if (doc == null) { return elementProperties; } NodeList nl = doc.getElementsByTagName("element"); if (nl != null && nl.getLength() > 0) { // Loop through all elements for (int i = 0; i < nl.getLength(); ++i) { identifier = null; attributeMap = null; Element el = (Element) nl.item(i); // Get xpath NodeList xpaths = el.getElementsByTagName("xpath"); Element xpathElement = (Element) xpaths.item(0); String xpath = getCharacterDataFromElement(xpathElement); identifier = new XpathWebElementIdentifier(xpath); NodeList attributes = el.getElementsByTagName("attribute"); if (attributes != null && attributes.getLength() > 0) { // Loop through all attributes attributeMap = new HashMap<String, String>(); for (int j = 0; j < attributes.getLength(); ++j) { Element attributeElement = (Element) attributes.item(j); NamedNodeMap attributeNodeMap = attributeElement.getAttributes(); for (int m = 0; m < attributeNodeMap.getLength(); ++m) { Node attributeNode = attributeNodeMap.item(m); attributeMap.put(attributeNode.getNodeName(), attributeNode.getNodeValue()); } } // for } if (identifier != null && attributeMap != null) { elementProperties.put(identifier, attributeMap); } } // for } return elementProperties; }