List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:Main.java
/** * Checks if Element Node is same as a Element name String *///w w w .j av a2s . co m public static boolean isStrElementNode(String elementName, Node elementNode, boolean ignoreCase) { if ((elementNode == null) || (elementName == null) || (elementName.trim().equals("")) || (elementNode.getNodeType() != Node.ELEMENT_NODE)) return false; StringTokenizer tokenizer = new StringTokenizer(":"); int numTokens = tokenizer.countTokens(); if (numTokens == 1) { String name = (String) tokenizer.nextElement(); Element element = (Element) elementNode; if (element.getNamespaceURI() != null) return false; if (ignoreCase) return element.getNodeName().trim().equalsIgnoreCase(elementName); return element.getNodeName().trim().equals(elementName); } else if (numTokens == 2) { String namespace = (String) tokenizer.nextElement(); String localName = (String) tokenizer.nextElement(); Element element = (Element) elementNode; if (element.getNamespaceURI() == null) return false; if (ignoreCase) return ((element.getLocalName().trim().equalsIgnoreCase(localName)) && (element.getNamespaceURI().equalsIgnoreCase(namespace.trim()))); return ((element.getLocalName().trim().equals(localName)) && (element.getNamespaceURI().equals(namespace.trim()))); } else return false; }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * @param element DOM element/* w ww .j a v a 2 s. c om*/ * @param writer XML stream writer * @throws XMLStreamException the XML stream exception */ public static void addElement(Element element, XMLStreamWriter writer) throws XMLStreamException { String nameSpace = element.getNamespaceURI(); String prefix = element.getPrefix(); String localName = element.getLocalName(); if (prefix == null) { prefix = ""; } if (localName == null) { localName = element.getNodeName(); if (localName == null) { throw new IllegalStateException("Element's local name cannot be null!"); } } String decUri = writer.getNamespaceContext().getNamespaceURI(prefix); boolean declareNamespace = decUri == null || !decUri.equals(nameSpace); if (nameSpace == null || nameSpace.length() == 0) { writer.writeStartElement(localName); } else { writer.writeStartElement(prefix, localName, nameSpace); } NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); String name = attr.getNodeName(); String attrPrefix = ""; int prefixIndex = name.indexOf(':'); if (prefixIndex != -1) { attrPrefix = name.substring(0, prefixIndex); name = name.substring(prefixIndex + 1); } if ("xmlns".equals(attrPrefix)) { writer.writeNamespace(name, attr.getNodeValue()); if (name.equals(prefix) && attr.getNodeValue().equals(nameSpace)) { declareNamespace = false; } } else { if ("xmlns".equals(name) && "".equals(attrPrefix)) { writer.writeNamespace("", attr.getNodeValue()); if (attr.getNodeValue().equals(nameSpace)) { declareNamespace = false; } } else { writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue()); } } } if (declareNamespace) { if (nameSpace == null) { writer.writeNamespace(prefix, ""); } else { writer.writeNamespace(prefix, nameSpace); } } NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); writeNode(n, writer); } writer.writeEndElement(); }
From source file:org.escidoc.browser.elabsmodul.service.ELabsService.java
private static InvestigationBean resolveInvestigation(final ContainerProxy containerProxy) { final String URI_DC = "http://purl.org/dc/elements/1.1/"; final String URI_EL = "http://escidoc.org/ontologies/bw-elabs/re#"; final String URI_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; if (containerProxy == null) { throw new NullPointerException("Container Proxy is null."); }/*from w w w . j a va 2 s. com*/ final InvestigationBean investigationBean = new InvestigationBean(); final Element e = containerProxy.getMetadataRecords().get("escidoc").getContent(); investigationBean.setObjid(containerProxy.getId()); if (!(("Investigation".equals(e.getLocalName()) && URI_EL.equals(e.getNamespaceURI())) || "el:Investigation".equals(e.getTagName()))) { LOG.error("Container is not an eLabs Investigation"); return investigationBean; } final NodeList nodeList = e.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); final String nodeName = node.getLocalName(); final String nsUri = node.getNamespaceURI(); if (nodeName == null || nsUri == null) { continue; } if ("title".equals(nodeName) && URI_DC.equals(nsUri)) { investigationBean.setName(node.getTextContent()); } else if ("description".equals(nodeName) && URI_DC.equals(nsUri)) { investigationBean.setDescription(node.getTextContent()); } else if ("max-runtime".equals(nodeName) && URI_EL.equals(nsUri)) { investigationBean.setMaxRuntime("<<not used>>"); try { investigationBean.setMaxRuntimeInMin(Integer.valueOf(node.getTextContent())); } catch (final NumberFormatException nfe) { LOG.error(nfe.getMessage()); investigationBean.setMaxRuntimeInMin(0); } } else if ("deposit-endpoint".equals(nodeName) && URI_EL.equals(nsUri)) { investigationBean.setDepositEndpoint(node.getTextContent()); } else if ("investigator".equals(nodeName) && URI_EL.equals(nsUri)) { final String investigatorId = node.getAttributes().getNamedItemNS(URI_RDF, "resource") .getTextContent(); investigationBean.setInvestigator(investigatorId); } else if ("rig".equals(nodeName) && URI_EL.equals(nsUri)) { final String rigId = node.getAttributes().getNamedItemNS(URI_RDF, "resource").getTextContent(); if (StringUtils.notEmpty(rigId)) { final RigBean rigBean = new RigBean(); rigBean.setObjectId(rigId); investigationBean.setRigBean(rigBean); } } else if ("instrument".equals(nodeName) && URI_EL.equals(nsUri)) { final String instrument = node.getAttributes().getNamedItemNS(URI_RDF, "resource").getTextContent(); final String folder = node.getTextContent().trim(); investigationBean.getInstrumentFolder().put(instrument, folder); } } return investigationBean; }
From source file:eu.esdihumboldt.hale.common.core.io.HaleIO.java
/** * Get the value of a complex property represented as a DOM element. * /*from ww w . jav a 2 s .c o m*/ * @param element the DOM element * @param expectedType the expected parameter type, this must be either * {@link String}, DOM {@link Element} or a complex value type * defined in the {@link ComplexValueExtension} * @param context the context object, may be <code>null</code> * @return the complex value or <code>null</code> if it could not be created * from the element */ @SuppressWarnings("unchecked") public static <T> T getComplexValue(Element element, Class<T> expectedType, Object context) { if (element == null) { return null; } QName name; if (element.getNamespaceURI() != null && !element.getNamespaceURI().isEmpty()) { name = new QName(element.getNamespaceURI(), element.getLocalName()); } else { String ln = element.getTagName(); // .getLocalName(); name = new QName(ln); } ComplexValueDefinition cvt = ComplexValueExtension.getInstance().getDefinition(name); Object value = null; if (cvt != null) { try { value = cvt.fromDOM(element, context); } catch (Exception e) { throw new IllegalStateException("Failed to load complex value from DOM", e); } } if (value != null && expectedType.isAssignableFrom(value.getClass())) { return (T) value; } // maybe the element itself is OK if (expectedType.isAssignableFrom(element.getClass())) { return (T) element; } if (expectedType.isAssignableFrom(String.class)) { // FIXME use legacy complex value if possible } return null; }
From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java
/** * Find the next sibling at DOM level of the given XAdES DOM element. * //from w w w.ja v a 2s . c o m * @param xadesElement * @param namespace * @param localName * @param jaxbType * @return * @throws XAdESValidationException */ public static <T> T findNextSibling(Element xadesElement, String namespace, String localName, Class<T> jaxbType) throws XAdESValidationException { Node siblingNode = xadesElement.getNextSibling(); while (siblingNode != null && siblingNode.getNodeType() != Node.ELEMENT_NODE) { /* * Can happen as shown during latest ETSI XAdES plugtests. */ LOG.debug("skipping a non-Element sibling: " + siblingNode.getNodeType()); if (Node.TEXT_NODE == siblingNode.getNodeType()) { LOG.debug("TEXT node sibling: \"" + siblingNode.getNodeValue() + "\""); } siblingNode = siblingNode.getNextSibling(); } if (null == siblingNode) { return null; } Element element = (Element) siblingNode; if (false == namespace.equals(element.getNamespaceURI())) { return null; } if (false == localName.equals(element.getLocalName())) { return null; } return unmarshall(element, jaxbType); }
From source file:XMLUtils.java
/** * Get the first child element to match a given name. * Look for a child element in the same namespace as the parent. * //w ww. ja va2s .c o m * @param parent * @param name * @return */ public static Element getChild(Element parent, String name) { Element child = getFirstChild(parent); while (child != null) { String tagName = child.getTagName(); if (tagName != null && tagName.equals(name)) { return child; } if (child.getPrefix() != null && child.getPrefix().equals(parent.getPrefix()) && child.getLocalName() != null && child.getLocalName().equals(name)) { return child; } child = getNext(child); } return child; }
From source file:DomUtils.java
/** * Get the name from the supplied element. * <p/>// w w w . j a v a 2 s . c o m * Returns the {@link Node#getLocalName() localName} of the element * if set (namespaced element), otherwise the * element's {@link Element#getTagName() tagName} is returned. * @param element The element. * @return The element name. */ public static String getName(Element element) { String name = element.getLocalName(); if (name != null) { return name; } else { return element.getTagName(); } }
From source file:org.urbantower.j4s.spring.HandlerCollectionParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(HandlerCollection.class); List<Element> handlerElms = DomUtils.getChildElements(element); List<Object> handlerDefs = new ManagedList<>(); for (Element elm : handlerElms) { if ("handler".equals(elm.getLocalName())) { RuntimeBeanReference reference = new RuntimeBeanReference(elm.getAttribute("ref")); handlerDefs.add(reference);/*from w ww . j a v a 2s . c om*/ } else { BeanDefinition handlerDef = parserContext.getDelegate().parseCustomElement(elm, builder.getBeanDefinition()); handlerDefs.add(handlerDef); } } builder.addPropertyValue("handlers", handlerDefs); return builder.getBeanDefinition(); }
From source file:uk.co.bssd.monitoring.spring.MonitorBeanDefinitionParser.java
private Element getChildElement(NodeList childNodes, String elementName) { for (int i = 0, max = childNodes.getLength(); i < max; i++) { Node childNode = childNodes.item(i); if (childNode instanceof Element) { Element childElement = (Element) childNode; if (childElement.getLocalName().equals(elementName)) { return childElement; }// w ww. ja v a 2 s . c o m } } return null; }
From source file:org.drools.container.spring.namespace.GridNodeDefinitionParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(GridNodeBeanFactory.class); String id = element.getAttribute("id"); factory.addPropertyValue("id", id); String connectionRef = element.getAttribute(GRID_ATTRIBUTE); if (StringUtils.hasText(connectionRef)) { factory.addPropertyReference(GRID_ATTRIBUTE, connectionRef); }//from w w w . j a v a 2 s.co m for (int i = 0, length = element.getChildNodes().getLength(); i < length; i++) { Node n = element.getChildNodes().item(i); if (n instanceof Element) { Element e = (Element) n; if ("socket-service".equals(e.getLocalName())) { String port = e.getAttribute(PORT_ATTRIBUTE); if (StringUtils.hasText(port)) { factory.addPropertyValue("port", port); } } } } return factory.getBeanDefinition(); }