Java Code Examples for org.w3c.dom.Node#getLocalName()
The following examples show how to use
org.w3c.dom.Node#getLocalName() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dss File: DSSXMLUtils.java License: GNU Lesser General Public License v2.1 | 6 votes |
private static Integer getPosition(Node parentNode, Node childToCheck) { if (parentNode != null && childToCheck != null) { String nodeName = childToCheck.getLocalName(); NodeList newNodeChildList = parentNode.getChildNodes(); for (int i = 0; i < newNodeChildList.getLength(); i++) { Node newChildNode = newNodeChildList.item(i); if (nodeName.equals(newChildNode.getLocalName())) { String idIdentifier = getIDIdentifier(childToCheck); if (idIdentifier == null || idIdentifier.equals(getIDIdentifier(newChildNode))) { return i + 1; } } } } return null; }
Example 2
Source Project: cougar File: ResponseToSimpleResponseMangler.java License: Apache License 2.0 | 6 votes |
private Node getNodeToBeReplaced(Node parametersNode) { Node toBeReplaced = null; int responseCount = 0; NodeList childNodes = parametersNode.getChildNodes(); if (childNodes != null) { for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); String name=childNode.getLocalName(); if ("simpleResponse".equals(name) || "response".equals(name)) { responseCount++; if("response".equals(name)){ //This is the node that will need to be replaced with a copy with a localName of "simpleResponse" toBeReplaced=childNode; } } //If responseCount>1 This implies that both a simpleResponse and response have //been defined - this is allowed by the xsd, but makes no sense if (responseCount > 1) { throw new IllegalArgumentException("Only one of either simpleResponse or response should define the response type"); } } } return toBeReplaced; }
Example 3
Source Project: kfs File: KualiBeanDefinitionParserBase.java License: GNU Affero General Public License v3.0 | 6 votes |
protected void parseEmbeddedPropertyElements(Element element, BeanDefinitionBuilder bean) { NodeList children = element.getChildNodes(); for ( int i = 0; i < children.getLength(); i++ ) { Node child = children.item(i); if ( child.getLocalName() != null && child.getLocalName().equals("property") ) { Element propertyElement = (Element)child; String propName = propertyElement.getAttribute("name"); String propValue = propertyElement.getAttribute("value"); if ( propValue != null ) { bean.addPropertyValue(propName, propValue); } else if ( propertyElement.getAttribute("ref") != null ) { bean.addPropertyReference(propName, propertyElement.getAttribute("ref") ); } } } }
Example 4
Source Project: openjdk-jdk9 File: DOMStreamReader.java License: GNU General Public License v2.0 | 6 votes |
/** * Return an attribute's qname. Handle the case of DOM level 1 nodes. */ public QName getAttributeName(int index) { if (_state == START_ELEMENT) { Node attr = _currentAttributes.get(index); String localName = attr.getLocalName(); if (localName != null) { String prefix = attr.getPrefix(); String uri = attr.getNamespaceURI(); return new QName(fixNull(uri), localName, fixNull(prefix)); } else { return QName.valueOf(attr.getNodeName()); } } throw new IllegalStateException("DOMStreamReader: getAttributeName() called in illegal state"); }
Example 5
Source Project: netbeans File: AbstractDocumentComponent.java License: Apache License 2.0 | 6 votes |
/** * @return mapping from prefix to namespace. */ public Map<String, String> getPrefixes() { Map<String,String> prefixes = new HashMap<String,String>(); NamedNodeMap nodes = getPeer().getAttributes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); String name = n.getLocalName(); String prefix = n.getPrefix(); final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N if (xmlns.equals(name) || // default namespace xmlns.equals(prefix)) { // namespace prefix String ns = n.getNodeValue(); prefixes.put(name, ns); } } String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE); if (defaultNamespace != null) { prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace); } return prefixes; }
Example 6
Source Project: powsybl-core File: XmlModuleConfigRepository.java License: Mozilla Public License 2.0 | 5 votes |
private static Map<Object, Object> readProperties(Node moduleNode) { Map<Object, Object> properties = new HashMap<>(); NodeList propertyNodes = moduleNode.getChildNodes(); for (int i = 0; i < propertyNodes.getLength(); i++) { Node propertyNode = propertyNodes.item(i); if (propertyNode.getNodeType() == Node.ELEMENT_NODE) { String propertyName = propertyNode.getLocalName(); Node child = propertyNode.getFirstChild(); String propertyValue = child != null ? child.getTextContent() : ""; properties.put(propertyName, propertyValue); } } return properties; }
Example 7
Source Project: openjdk-jdk8u-backup File: DOMNormalizer.java License: GNU General Public License v2.0 | 5 votes |
protected final void updateQName (Node node, QName qname){ String prefix = node.getPrefix(); String namespace = node.getNamespaceURI(); String localName = node.getLocalName(); // REVISIT: the symbols are added too often: start/endElement // and in the namespaceFixup. Should reduce number of calls to symbol table. qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null; qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null; qname.rawname = fSymbolTable.addSymbol(node.getNodeName()); qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null; }
Example 8
Source Project: openjdk-8 File: SOAPFaultBuilder.java License: GNU General Public License v2.0 | 5 votes |
public @XmlTransient @Nullable QName getFirstDetailEntryName() { DetailType dt = getDetail(); if (dt != null) { Node entry = dt.getDetail(0); if (entry != null) { return new QName(entry.getNamespaceURI(), entry.getLocalName()); } } return null; }
Example 9
Source Project: openjdk-jdk8u-backup File: SOAPFaultBuilder.java License: GNU General Public License v2.0 | 5 votes |
public @XmlTransient @Nullable QName getFirstDetailEntryName() { DetailType dt = getDetail(); if (dt != null) { Node entry = dt.getDetail(0); if (entry != null) { return new QName(entry.getNamespaceURI(), entry.getLocalName()); } } return null; }
Example 10
Source Project: openjdk-jdk8u File: DOM2SAX.java License: GNU General Public License v2.0 | 5 votes |
/** * If the DOM was created using a DOM 1.0 API, the local name may be * null. If so, get the local name from the qualified name before * generating the SAX event. */ private static String getLocalName(Node node) { final String localName = node.getLocalName(); if (localName == null) { final String qname = node.getNodeName(); final int col = qname.lastIndexOf(':'); return (col > 0) ? qname.substring(col + 1) : qname; } return localName; }
Example 11
Source Project: openjdk-jdk9 File: DOMSignatureProperties.java License: GNU General Public License v2.0 | 5 votes |
/** * Creates a <code>DOMSignatureProperties</code> from an element. * * @param propsElem a SignatureProperties element * @throws MarshalException if a marshalling error occurs */ public DOMSignatureProperties(Element propsElem, XMLCryptoContext context) throws MarshalException { // unmarshal attributes Attr attr = propsElem.getAttributeNodeNS(null, "Id"); if (attr != null) { id = attr.getValue(); propsElem.setIdAttributeNode(attr, true); } else { id = null; } NodeList nodes = propsElem.getChildNodes(); int length = nodes.getLength(); List<SignatureProperty> properties = new ArrayList<SignatureProperty>(length); for (int i = 0; i < length; i++) { Node child = nodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { String name = child.getLocalName(); if (!name.equals("SignatureProperty")) { throw new MarshalException("Invalid element name: " + name + ", expected SignatureProperty"); } properties.add(new DOMSignatureProperty((Element)child, context)); } } if (properties.isEmpty()) { throw new MarshalException("properties cannot be empty"); } else { this.properties = Collections.unmodifiableList(properties); } }
Example 12
Source Project: javaide File: ValueResourceParser2.java License: GNU General Public License v3.0 | 5 votes |
/** * Returns the type of the ResourceItem based on a node's attributes. * @param node the node * @return the ResourceType or null if it could not be inferred. */ static ResourceType getType(@NonNull Node node, @Nullable File from) throws MergingException { String nodeName = node.getLocalName(); String typeString = null; if (TAG_ITEM.equals(nodeName)) { Attr attribute = (Attr) node.getAttributes().getNamedItemNS(null, ATTR_TYPE); if (attribute != null) { typeString = attribute.getValue(); } } else if (TAG_EAT_COMMENT.equals(nodeName) || TAG_SKIP.equals(nodeName)) { return null; } else { // the type is the name of the node. typeString = nodeName; } if (typeString != null) { ResourceType type = ResourceType.getEnum(typeString); if (type != null) { return type; } throw MergingException.withMessage("Unsupported type '%s'", typeString).withFile(from) .build(); } throw MergingException.withMessage("Unsupported node '%s'", nodeName).withFile(from).build(); }
Example 13
Source Project: steady File: KerberosTokenBuilder.java License: Apache License 2.0 | 4 votes |
public Assertion build(Element element, AssertionBuilderFactory factory) { SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI()) ? SP11Constants.INSTANCE : SP12Constants.INSTANCE; KerberosToken kerberosToken = new KerberosToken(consts); kerberosToken.setOptional(PolicyConstants.isOptional(element)); kerberosToken.setIgnorable(PolicyConstants.isIgnorable(element)); String attribute = element.getAttributeNS(element.getNamespaceURI(), SPConstants.ATTR_INCLUDE_TOKEN); if (attribute != null) { kerberosToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim())); } Element child = DOMUtils.getFirstElement(element); boolean foundPolicy = false; while (child != null) { String ln = child.getLocalName(); if (org.apache.neethi.Constants.ELEM_POLICY.equals(ln)) { foundPolicy = true; NodeList policyChildren = child.getChildNodes(); if (policyChildren != null) { for (int i = 0; i < policyChildren.getLength(); i++) { Node policyChild = policyChildren.item(i); if (policyChild instanceof Element) { QName qname = new QName(policyChild.getNamespaceURI(), policyChild.getLocalName()); String localpart = qname.getLocalPart(); if (SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11.equals(localpart)) { kerberosToken.setV5ApReqToken11(true); } else if (SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11.equals(localpart)) { kerberosToken.setGssV5ApReqToken11(true); } else if (SPConstants.REQUIRE_DERIVED_KEYS.equals(localpart)) { kerberosToken.setDerivedKeys(true); } } } } } child = DOMUtils.getNextElement(child); } if (!foundPolicy && consts != SP11Constants.INSTANCE) { throw new IllegalArgumentException( "sp:KerberosToken/wsp:Policy must have a value" ); } return kerberosToken; }
Example 14
Source Project: openjdk-8 File: DOM2DTM.java License: GNU General Public License v2.0 | 4 votes |
/** * Retrieves an attribute node by by qualified name and namespace URI. * * @param nodeHandle int Handle of the node upon which to look up this attribute.. * @param namespaceURI The namespace URI of the attribute to * retrieve, or null. * @param name The local name of the attribute to * retrieve. * @return The attribute node handle with the specified name ( * <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such * attribute. */ public int getAttributeNode(int nodeHandle, String namespaceURI, String name) { // %OPT% This is probably slower than it needs to be. if (null == namespaceURI) namespaceURI = ""; int type = getNodeType(nodeHandle); if (DTM.ELEMENT_NODE == type) { // Assume that attributes immediately follow the element. int identity = makeNodeIdentity(nodeHandle); while (DTM.NULL != (identity = getNextNodeIdentity(identity))) { // Assume this can not be null. type = _type(identity); // %REVIEW% // Should namespace nodes be retrievable DOM-style as attrs? // If not we need a separate function... which may be desirable // architecturally, but which is ugly from a code point of view. // (If we REALLY insist on it, this code should become a subroutine // of both -- retrieve the node, then test if the type matches // what you're looking for.) if (type == DTM.ATTRIBUTE_NODE || type==DTM.NAMESPACE_NODE) { Node node = lookupNode(identity); String nodeuri = node.getNamespaceURI(); if (null == nodeuri) nodeuri = ""; String nodelocalname = node.getLocalName(); if (nodeuri.equals(namespaceURI) && name.equals(nodelocalname)) return makeNodeHandle(identity); } else // if (DTM.NAMESPACE_NODE != type) { break; } } } return DTM.NULL; }
Example 15
Source Project: openjdk-8 File: DOMUtil.java License: GNU General Public License v2.0 | 4 votes |
/** returns local name of this element if not null, otherwise returns the name of the node */ public static String getLocalName(Node node) { String name = node.getLocalName(); return (name!=null)? name:node.getNodeName(); }
Example 16
Source Project: j2objc File: DOM3TreeWalker.java License: Apache License 2.0 | 4 votes |
/** * Records local namespace declarations, to be used for normalization later * * @param Node, The element node, whose namespace declarations are to be recorded */ protected void recordLocalNSDecl(Node node) { NamedNodeMap atts = ((Element) node).getAttributes(); int length = atts.getLength(); for (int i = 0; i < length; i++) { Node attr = atts.item(i); String localName = attr.getLocalName(); String attrPrefix = attr.getPrefix(); String attrValue = attr.getNodeValue(); String attrNS = attr.getNamespaceURI(); localName = localName == null || XMLNS_PREFIX.equals(localName) ? "" : localName; attrPrefix = attrPrefix == null ? "" : attrPrefix; attrValue = attrValue == null ? "" : attrValue; attrNS = attrNS == null ? "" : attrNS; // check if attribute is a namespace decl if (XMLNS_URI.equals(attrNS)) { // No prefix may be bound to http://www.w3.org/2000/xmlns/. if (XMLNS_URI.equals(attrValue)) { String msg = Utils.messages.createMessage( MsgKey.ER_NS_PREFIX_CANNOT_BE_BOUND, new Object[] { attrPrefix, XMLNS_URI }); if (fErrorHandler != null) { fErrorHandler.handleError( new DOMErrorImpl( DOMError.SEVERITY_ERROR, msg, MsgKey.ER_NS_PREFIX_CANNOT_BE_BOUND, null, null, null)); } } else { // store the namespace-declaration if (XMLNS_PREFIX.equals(attrPrefix) ) { // record valid decl if (attrValue.length() != 0) { fNSBinder.declarePrefix(localName, attrValue); } else { // Error; xmlns:prefix="" } } else { // xmlns // empty prefix is always bound ("" or some string) fNSBinder.declarePrefix("", attrValue); } } } } }
Example 17
Source Project: openjdk-jdk9 File: NodeImpl.java License: GNU General Public License v2.0 | 4 votes |
/** * Tests whether two nodes are equal. * <br>This method tests for equality of nodes, not sameness (i.e., * whether the two nodes are references to the same object) which can be * tested with <code>Node.isSameNode</code>. All nodes that are the same * will also be equal, though the reverse may not be true. * <br>Two nodes are equal if and only if the following conditions are * satisfied: The two nodes are of the same type.The following string * attributes are equal: <code>nodeName</code>, <code>localName</code>, * <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code> * , <code>baseURI</code>. This is: they are both <code>null</code>, or * they have the same length and are character for character identical. * The <code>attributes</code> <code>NamedNodeMaps</code> are equal. * This is: they are both <code>null</code>, or they have the same * length and for each node that exists in one map there is a node that * exists in the other map and is equal, although not necessarily at the * same index.The <code>childNodes</code> <code>NodeLists</code> are * equal. This is: they are both <code>null</code>, or they have the * same length and contain equal nodes at the same index. This is true * for <code>Attr</code> nodes as for any other type of node. Note that * normalization can affect equality; to avoid this, nodes should be * normalized before being compared. * <br>For two <code>DocumentType</code> nodes to be equal, the following * conditions must also be satisfied: The following string attributes * are equal: <code>publicId</code>, <code>systemId</code>, * <code>internalSubset</code>.The <code>entities</code> * <code>NamedNodeMaps</code> are equal.The <code>notations</code> * <code>NamedNodeMaps</code> are equal. * <br>On the other hand, the following do not affect equality: the * <code>ownerDocument</code> attribute, the <code>specified</code> * attribute for <code>Attr</code> nodes, the * <code>isWhitespaceInElementContent</code> attribute for * <code>Text</code> nodes, as well as any user data or event listeners * registered on the nodes. * @param arg The node to compare equality with. * @param deep If <code>true</code>, recursively compare the subtrees; if * <code>false</code>, compare only the nodes themselves (and its * attributes, if it is an <code>Element</code>). * @return If the nodes, and possibly subtrees are equal, * <code>true</code> otherwise <code>false</code>. * @since DOM Level 3 */ public boolean isEqualNode(Node arg) { if (arg == this) { return true; } if (arg.getNodeType() != getNodeType()) { return false; } // in theory nodeName can't be null but better be careful // who knows what other implementations may be doing?... if (getNodeName() == null) { if (arg.getNodeName() != null) { return false; } } else if (!getNodeName().equals(arg.getNodeName())) { return false; } if (getLocalName() == null) { if (arg.getLocalName() != null) { return false; } } else if (!getLocalName().equals(arg.getLocalName())) { return false; } if (getNamespaceURI() == null) { if (arg.getNamespaceURI() != null) { return false; } } else if (!getNamespaceURI().equals(arg.getNamespaceURI())) { return false; } if (getPrefix() == null) { if (arg.getPrefix() != null) { return false; } } else if (!getPrefix().equals(arg.getPrefix())) { return false; } if (getNodeValue() == null) { if (arg.getNodeValue() != null) { return false; } } else if (!getNodeValue().equals(arg.getNodeValue())) { return false; } return true; }
Example 18
Source Project: xmlunit File: DifferenceEngine.java License: Apache License 2.0 | 4 votes |
private static String getQName(Node aNode, boolean isNamespacedNode) { if (isNamespacedNode) { return "{" + aNode.getNamespaceURI() + "}" + aNode.getLocalName(); } return aNode.getNodeName(); }
Example 19
Source Project: jdk8u60 File: DOM2Helper.java License: GNU General Public License v2.0 | 3 votes |
/** * Returns the local name of the given node, as defined by the * XML Namespaces specification. This is prepared to handle documents * built using DOM Level 1 methods by falling back upon explicitly * parsing the node name. * * @param n Node to be examined * * @return String containing the local name, or null if the node * was not assigned a Namespace. */ public String getLocalNameOfNode(Node n) { String name = n.getLocalName(); return (null == name) ? getLocalNameOfNodeFallback(n) : name; }
Example 20
Source Project: openjdk-jdk8u File: DOM2Helper.java License: GNU General Public License v2.0 | 2 votes |
/** * Returns the local name of the given node, as defined by the XML * Namespaces specification. This is prepared to handle documents built * using DOM Level 1 methods by falling back upon explicitly parsing the * node name. * * @param n Node to be examined * * @return String containing the local name, or null if the node was not * assigned a Namespace. */ public static String getLocalNameOfNode(Node n) { String name = n.getLocalName(); return (null == name) ? getLocalNameOfNodeFallback(n) : name; }