Java Code Examples for org.w3c.dom.Node.getLocalName()

The following are Jave code examples for showing how to use getLocalName() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: M2AuxilaryConfigImpl.java   Source Code and License Vote up 6 votes
static void findDuplicateElements(@NonNull Element parent, @NonNull ProblemProvider pp, FileObject config) {
    NodeList l = parent.getChildNodes();
    int nodeCount = l.getLength();
    Set<String> known = new HashSet<String>();
    for (int i = 0; i < nodeCount; i++) {
        if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
            Node node = l.item(i);
            String localName = node.getLocalName();
            localName = localName == null ? node.getNodeName() : localName;
            String id = localName + "|" + node.getNamespaceURI();
            if (!known.add(id)) {
                //we have a duplicate;
                pp.setProblem(ProjectProblem.createWarning(
                                TXT_Problem_Broken_Config2(), 
                                DESC_Problem_Broken_Config2(), 
                                new ProblemReporterImpl.MavenProblemResolver(ProblemReporterImpl.createOpenFileAction(config), BROKEN_NBCONFIG)));
            }
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: AbstractDocumentComponent.java   Source Code and License Vote up 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 3
Project: OpenJSharp   File: DOMValidatorHelper.java   Source Code and License Vote up 6 votes
private void fillQName(QName toFill, Node node) {
    final String prefix = node.getPrefix();
    final String localName = node.getLocalName();
    final String rawName = node.getNodeName();
    final String namespace = node.getNamespaceURI();

    toFill.uri = (namespace != null && namespace.length() > 0) ? fSymbolTable.addSymbol(namespace) : null;
    toFill.rawname = (rawName != null) ? fSymbolTable.addSymbol(rawName) : XMLSymbols.EMPTY_STRING;

    // Is this a DOM level1 document?
    if (localName == null) {
        int k = rawName.indexOf(':');
        if (k > 0) {
            toFill.prefix = fSymbolTable.addSymbol(rawName.substring(0, k));
            toFill.localpart = fSymbolTable.addSymbol(rawName.substring(k + 1));
        }
        else {
            toFill.prefix = XMLSymbols.EMPTY_STRING;
            toFill.localpart = toFill.rawname;
        }
    }
    else {
        toFill.prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;
        toFill.localpart = (localName != null) ? fSymbolTable.addSymbol(localName) : XMLSymbols.EMPTY_STRING;
    }
}
 
Example 4
Project: incubator-netbeans   File: AbstractDocumentModel.java   Source Code and License Vote up 5 votes
protected boolean isDomainElement(Node e) {
    if (! (e instanceof Element)) {
        return false;
    }
    
    QName q = new QName(e.getNamespaceURI(), e.getLocalName());
    return getQNames().contains(q) || getElementNames().contains(q.getLocalPart());
}
 
Example 5
Project: incubator-netbeans   File: AbstractDocumentComponent.java   Source Code and License Vote up 5 votes
public static QName getQName(Node n) {
    String namespace = n.getNamespaceURI();
    String localName = n.getLocalName();
    String prefix = n.getPrefix();
    assert(localName != null);
    if (namespace == null && prefix == null) {
        return new QName(localName);
    } else if (namespace != null && prefix == null) {
        return new QName(namespace, localName);
    } else {
        return new QName(namespace, localName, prefix);
    }
}
 
Example 6
Project: powsybl-core   File: XmlPlatformConfig.java   Source Code and License Vote up 5 votes
public XmlPlatformConfig(FileSystem fileSystem, Path configDir, Path cacheDir, String configName)
        throws IOException, SAXException, ParserConfigurationException {
    super(fileSystem, configDir, cacheDir);

    Path file = configDir.resolve(configName + ".xml");
    if (Files.exists(file)) {
        LOGGER.info("Platform configuration defined by XML file {}", file);
        try (InputStream is = Files.newInputStream(file)) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(is);
            Element root = doc.getDocumentElement();
            root.normalize();
            NodeList moduleNodes = root.getChildNodes();
            for (int i = 0; i < moduleNodes.getLength(); i++) {
                Node moduleNode = moduleNodes.item(i);
                if (moduleNode.getNodeType() == Node.ELEMENT_NODE) {
                    String moduleName = moduleNode.getLocalName();
                    Map<Object, Object> properties = new HashMap<>();
                    NodeList propertyNodes = moduleNode.getChildNodes();
                    for (int j = 0; j < propertyNodes.getLength(); j++) {
                        Node propertyNode = propertyNodes.item(j);
                        if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
                            String propertyName = propertyNode.getLocalName();
                            Node child = propertyNode.getFirstChild();
                            String propertyValue = child != null ? child.getTextContent() : "";
                            properties.put(propertyName, propertyValue);
                        }
                    }
                    ((InMemoryModuleConfigContainer) container).getConfigs().put(moduleName, new MapModuleConfig(properties, fileSystem));
                }
            }
        }
    } else {
        LOGGER.info("Platform configuration XML file {} not found", file);
    }
}
 
Example 7
Project: OpenJSharp   File: DOM2SAX.java   Source Code and License Vote up 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 8
Project: OpenJSharp   File: DOMNormalizer.java   Source Code and License Vote up 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 9
Project: dpdirect   File: SchemaLoader.java   Source Code and License Vote up 5 votes
public String getNodeName(Node node){
 String nodeName = node.getLocalName();
    if (nodeName == null) {
 	   nodeName = node.getNodeName();
    }
    return nodeName;
}
 
Example 10
Project: javaide   File: ValueResourceParser2.java   Source Code and License Vote up 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) {
    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;
        }

        if (from != null) {
            throw new RuntimeException(String.format("Unsupported type '%s' in file %s", typeString, from));
        }
        throw new RuntimeException(String.format("Unsupported type '%s'", typeString));
    }

    if (from != null) {
        throw new RuntimeException(String.format("Unsupported node '%s' in file %s", nodeName, from));
    }
    throw new RuntimeException(String.format("Unsupported node '%s'", nodeName));
}
 
Example 11
Project: Svg2AndroidXml   File: Svg2Vector.java   Source Code and License Vote up 5 votes
private static void printlnCommon(Node n) {
    logger.log(Level.FINE, " nodeName=\"" + n.getNodeName() + "\"");

    String val = n.getNamespaceURI();
    if (val != null) {
        logger.log(Level.FINE, " uri=\"" + val + "\"");
    }

    val = n.getPrefix();

    if (val != null) {
        logger.log(Level.FINE, " pre=\"" + val + "\"");
    }

    val = n.getLocalName();
    if (val != null) {
        logger.log(Level.FINE, " local=\"" + val + "\"");
    }

    val = n.getNodeValue();
    if (val != null) {
        logger.log(Level.FINE, " nodeValue=");
        if (val.trim().equals("")) {
            // Whitespace
            logger.log(Level.FINE, "[WS]");
        } else {
            logger.log(Level.FINE, "\"" + n.getNodeValue() + "\"");
        }
    }
}
 
Example 12
Project: OpenJSharp   File: SOAPFaultBuilder.java   Source Code and License Vote up 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 13
Project: OpenJSharp   File: DOMStreamReader.java   Source Code and License Vote up 5 votes
private static void verifyDOMIntegrity(Node node) {
    switch (node.getNodeType()) {
        case ELEMENT_NODE:
        case ATTRIBUTE_NODE:

            // DOM level 1?
            if (node.getLocalName() == null) {
                System.out.println("WARNING: DOM level 1 node found");
                System.out.println(" -> node.getNodeName() = " + node.getNodeName());
                System.out.println(" -> node.getNamespaceURI() = " + node.getNamespaceURI());
                System.out.println(" -> node.getLocalName() = " + node.getLocalName());
                System.out.println(" -> node.getPrefix() = " + node.getPrefix());
            }

            if (node.getNodeType() == ATTRIBUTE_NODE) return;

            NamedNodeMap attrs = node.getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                verifyDOMIntegrity(attrs.item(i));
            }
        case DOCUMENT_NODE:
            NodeList children = node.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                verifyDOMIntegrity(children.item(i));
            }
    }
}
 
Example 14
Project: openjdk-jdk10   File: LSParserTCKTest.java   Source Code and License Vote up 4 votes
public boolean checkXMLs(Node template, Node source) {
    if (source == null || template == null) {
        return template == source;
    }
    String tname = template.getLocalName();
    String tvalue = template.getNodeValue();
    NamedNodeMap tattr = template.getAttributes();
    NodeList tchildren = template.getChildNodes();

    String sname = source.getLocalName();
    String svalue = source.getNodeValue();
    NamedNodeMap sattr = source.getAttributes();
    NodeList schildren = source.getChildNodes();
    if (tname != null && !tname.equals(sname)) {
        return false;
    }
    if (tvalue != null && !tvalue.equals(svalue)) {
        return false;
    }
    if (tattr != null && sattr != null) {
        if (sattr.getLength() != tattr.getLength()) {
            return false;
        }
        for (int i = 0; i < tattr.getLength(); i++) {
            Attr t = (Attr) tattr.item(i);
            Attr s = (Attr) sattr.getNamedItem(t.getName());
            if (!checkXMLAttrs(t, s)) {
                // ref.println(sname+": [expected attr: " + t +
                // "; actual attr: " +s+"]");
                return false;
            }
        }
    } else if (tattr != null || sattr != null) {
        return false;
    }

    for (int i = 0; i < tchildren.getLength(); i++) {
        if (!checkXMLs(tchildren.item(i), schildren.item(i))) {
            // ref.println(sname+": [expected node: "+tchildren.item(i)
            // +"; actual node: "+schildren.item(i)+"]");
            return false;
        }
    }
    return true;
}
 
Example 15
Project: OpenJSharp   File: AttributeMap.java   Source Code and License Vote up 4 votes
private final Node remove(AttrImpl attr, int index,
                          boolean addDefault) {

    CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
    String name = attr.getNodeName();
    if (attr.isIdAttribute()) {
        ownerDocument.removeIdentifier(attr.getValue());
    }

    if (hasDefaults() && addDefault) {
        // If there's a default, add it instead
        NamedNodeMapImpl defaults =
            ((ElementImpl) ownerNode).getDefaultAttributes();

        Node d;
        if (defaults != null &&
            (d = defaults.getNamedItem(name)) != null &&
            findNamePoint(name, index+1) < 0) {
                NodeImpl clone = (NodeImpl)d.cloneNode(true);
                if (d.getLocalName() !=null){
                        // we must rely on the name to find a default attribute
                        // ("test:attr"), but while copying it from the DOCTYPE
                        // we should not loose namespace URI that was assigned
                        // to the attribute in the instance document.
                        ((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
                }
                clone.ownerNode = ownerNode;
                clone.isOwned(true);
                clone.isSpecified(false);

                nodes.set(index, clone);
                if (attr.isIdAttribute()) {
                    ownerDocument.putIdentifier(clone.getNodeValue(),
                                            (ElementImpl)ownerNode);
                }
        } else {
            nodes.remove(index);
        }
    } else {
        nodes.remove(index);
    }

    //        changed(true);

    // remove reference to owner
    attr.ownerNode = ownerDocument;
    attr.isOwned(false);

    // make sure it won't be mistaken with defaults in case it's
    // reused
    attr.isSpecified(true);
    attr.isIdAttribute(false);

    // notify document
    ownerDocument.removedAttrNode(attr, ownerNode, name);

    return attr;
}
 
Example 16
Project: openjdk-jdk10   File: ElementImpl.java   Source Code and License Vote up 4 votes
private Iterator<javax.xml.soap.Node> getChildElements(final String nameUri, final String nameLocal) {
    return new Iterator<javax.xml.soap.Node>() {
        Iterator<Node> eachElement = getChildElementNodes();
        Node next = null;
        Node last = null;

        @Override
        public boolean hasNext() {
            if (next == null) {
                while (eachElement.hasNext()) {
                    Node element = eachElement.next();
                    String elementUri = element.getNamespaceURI();
                    elementUri = elementUri == null ? "" : elementUri;
                    String elementName = element.getLocalName();
                    if (elementUri.equals(nameUri)
                        && elementName.equals(nameLocal)) {
                        next = element;
                        break;
                    }
                }
            }
            return next != null;
        }

        @Override
        public javax.xml.soap.Node next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            last = next;
            next = null;
            return (javax.xml.soap.Node) last;
        }

        @Override
        public void remove() {
            if (last == null) {
                throw new IllegalStateException();
            }
            Node target = last;
            last = null;
            removeChild(target);
        }
    };
}
 
Example 17
Project: openjdk-jdk10   File: DOM2DTM.java   Source Code and License Vote up 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 18
Project: OpenJSharp   File: DOMUtil.java   Source Code and License Vote up 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 19
Project: openjdk-jdk10   File: AttributeMap.java   Source Code and License Vote up 4 votes
private final Node remove(AttrImpl attr, int index,
                          boolean addDefault) {

    CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
    String name = attr.getNodeName();
    if (attr.isIdAttribute()) {
        ownerDocument.removeIdentifier(attr.getValue());
    }

    if (hasDefaults() && addDefault) {
        // If there's a default, add it instead
        NamedNodeMapImpl defaults =
            ((ElementImpl) ownerNode).getDefaultAttributes();

        Node d;
        if (defaults != null &&
            (d = defaults.getNamedItem(name)) != null &&
            findNamePoint(name, index+1) < 0) {
                NodeImpl clone = (NodeImpl)d.cloneNode(true);
                if (d.getLocalName() !=null){
                        // we must rely on the name to find a default attribute
                        // ("test:attr"), but while copying it from the DOCTYPE
                        // we should not loose namespace URI that was assigned
                        // to the attribute in the instance document.
                        ((AttrNSImpl)clone).namespaceURI = attr.getNamespaceURI();
                }
                clone.ownerNode = ownerNode;
                clone.isOwned(true);
                clone.isSpecified(false);

                nodes.set(index, clone);
                if (attr.isIdAttribute()) {
                    ownerDocument.putIdentifier(clone.getNodeValue(),
                                            (ElementImpl)ownerNode);
                }
        } else {
            nodes.remove(index);
        }
    } else {
        nodes.remove(index);
    }

    //        changed(true);

    // remove reference to owner
    attr.ownerNode = ownerDocument;
    attr.isOwned(false);

    // make sure it won't be mistaken with defaults in case it's
    // reused
    attr.isSpecified(true);
    attr.isIdAttribute(false);

    // notify document
    ownerDocument.removedAttrNode(attr, ownerNode, name);

    return attr;
}
 
Example 20
Project: openjdk-jdk10   File: DOM2Helper.java   Source Code and License Vote up 1 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;
}