Java 类org.w3c.dom.NamedNodeMap 实例源码

项目:ats-framework    文件:ElementsMap.java   
private UiElementProperties collectElementProperties( Element elementNode, String mapId ) {

        UiElementProperties elementProperties = new UiElementProperties();

        NamedNodeMap nodeAttributes = (elementNode).getAttributes();
        for (int i = 0; i < nodeAttributes.getLength(); i++) {
            Node node = nodeAttributes.item(i);
            if (StringUtils.isNullOrEmpty(node.getNodeValue())) {
                throw new ElementsMapException("Error loading '" + mapId + "' element from map. '"
                                               + node.getNodeName() + "' contains an empty value");
            }
            if (StringUtils.isNullOrEmpty(node.getNodeName())) {
                throw new ElementsMapException("Error loading '" + mapId + "' element from map. '"
                                               + node.getNodeValue() + "' contains an empty key");
            }
            elementProperties.addProperty(node.getNodeName(), node.getNodeValue());
        }

        return elementProperties;
    }
项目:bdf2    文件:ResourcesElementParser.java   
public Resource[] parse(Node rootNode, ParserContext parserContext) {
    NamedNodeMap nodeMap=rootNode.getAttributes();
    String locations=getAttributeValue("locations",nodeMap);
    if(StringUtils.isNotEmpty(locations)){
        String[] locationsArray=locations.split(LOCATION_SEPARATOR);
        List<Resource> resources=new ArrayList<Resource>();
        for(int i=0;i<locationsArray.length;i++){
            String location=locationsArray[i];
            if(StringUtils.isNotEmpty(location)){
                resources.add(resourcePatternResolver.getResource(location));                   
            }
        }
        return resources.toArray(new Resource[resources.size()]);
    }else{
        return null;            
    }
}
项目:bdf2    文件:JoinNode.java   
@Override
public void parseXml(Node node) {
    super.parseXml(node);
    NamedNodeMap map=node.getAttributes();
    Node lockmodeNode=map.getNamedItem("lockmode");
    if(lockmodeNode!=null){
        LockModeType type=null;
        for(LockModeType mode:LockModeType.values()){
            if(mode.toString().equals(lockmodeNode.getNodeValue())){
                type=mode;
            }
        }
        this.lockmode=type;
    }
    Node multiplicityNode=map.getNamedItem("multiplicity");
    if(multiplicityNode!=null){
        this.multiplicity=multiplicityNode.getNodeValue();
    }
}
项目:openjdk-jdk10    文件:MagentaEXIFTest.java   
static void displayMetadata(Node node, int level) {
    for (int i = 0; i < level; i++) System.out.print("  ");
    System.out.print("<" + node.getNodeName());
    NamedNodeMap map = node.getAttributes();
    if (map != null) { // print attribute values
        int length = map.getLength();
        for (int i = 0; i < length; i++) {
            Node attr = map.item(i);
            System.out.print(" " + attr.getNodeName() +
                             "=\"" + attr.getNodeValue() + "\"");
        }
    }

    Node child = node.getFirstChild();
    if (child != null) {
        System.out.println(">"); // close current tag
        while (child != null) { // emit child tags recursively
            displayMetadata(child, level + 1);
            child = child.getNextSibling();
        }
        for (int i = 0; i < level; i++) System.out.print("  ");
        System.out.println("</" + node.getNodeName() + ">");
    } else {
        System.out.println("/>");
    }
}
项目:mnp    文件:CustomMasksParser.java   
@Override
public void parse(Consumer<MnoInfo> consumer) throws Exception {
    File fXmlFile = config.toFile();

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();
    XPathExpression xpathMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mno']");
    XPathExpression xpathMasksMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mask']");
    NodeList mnoNodes = (NodeList) xpathMno.evaluate(doc, XPathConstants.NODESET);
    for (int i=0; i<mnoNodes.getLength(); i++) {
        Node node = mnoNodes.item(i);
        NamedNodeMap attributes = node.getAttributes();
        String country = getValue(attributes.getNamedItem("country"));
        String title = getValue(attributes.getNamedItem("title"));
        String area = getValue(attributes.getNamedItem("area"));
        Set<Mask> masks = new HashSet<>();
        NodeList maskNodes = (NodeList) xpathMasksMno.evaluate(doc, XPathConstants.NODESET);
        for (int j=0; j<maskNodes.getLength(); j++) {
            masks.add(Mask.parse(getValue(maskNodes.item(j))));
        }
        consumer.accept(new MnoInfo(title, area, country, masks));
    }
}
项目:wrdocletbase    文件:UniversalNamespaceCache.java   
/**
 * A single node is read, the namespace attributes are extracted and stored.
 * 
 * @param node
 *            to examine
 * @param attributesOnly,
 *            if true no recursion happens
 */
private void examineNode(Node node, boolean attributesOnly) {
    while(node != null && node.getNodeType() == Node.COMMENT_NODE) {
        node = node.getNextSibling();
    }
    if(node != null) {
        NamedNodeMap attributes = node.getAttributes();
        if(attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                Node attribute = attributes.item(i);
                storeAttribute((Attr) attribute);
            }
        }

        if (!attributesOnly) {
            NodeList chields = node.getChildNodes();
            for (int i = 0; i < chields.getLength(); i++) {
                Node chield = chields.item(i);
                if (chield.getNodeType() == Node.ELEMENT_NODE)
                    examineNode(chield, false);
            }
        }
    }
}
项目:L2J-Global    文件:NpcData.java   
private void parseDropListItem(Node drop_list_item, DropListScope dropListScope, List<IDropItem> drops)
{
    final NamedNodeMap attrs = drop_list_item.getAttributes();
    switch (drop_list_item.getNodeName().toLowerCase())
    {
        case "item":
        {
            final IDropItem dropItem = dropListScope.newDropItem(parseInteger(attrs, "id"), parseLong(attrs, "min"), parseLong(attrs, "max"), parseDouble(attrs, "chance"));
            if (dropItem != null)
            {
                drops.add(dropItem);
            }
            break;
        }
    }
}
项目:incubator-netbeans    文件:DOMCompare.java   
private static boolean compareElementAttrs(Element e1, Element e2) {
    NamedNodeMap at1 = e1.getAttributes();
    NamedNodeMap at2 = e2.getAttributes();
    if (at1.getLength() != at2.getLength()) {
        System.out.println("Different number of attributes");
    }
    for (int i = 0; i < at1.getLength(); i++) {
        Attr attr1 = (Attr)at1.item(i);
        Attr attr2 = (Attr)at2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName());
        if (attr2 == null) {
            System.out.println("Attribute " + attr1.getNodeName() + " not found");
            return false;
        }
        if (!compareStrings(attr1.getNodeValue(), attr2.getNodeValue())) {
            System.out.println("Different attributes " + attr1.getNodeName() + " and " + attr2.getNodeName());
            return false;
        }
    }
    return true;
}
项目:bdf2    文件:DecisionNode.java   
@Override
public void parseXml(Node node) {
    super.parseXml(node);
    NamedNodeMap nodeMap=node.getAttributes();
    Node expr=nodeMap.getNamedItem("expr");
    if(expr!=null){
        this.type=DecisionType.expression;
        this.expression=expr.getNodeValue();
    }else{
        NodeList list=node.getChildNodes();
        for(int i=0;i<list.getLength();i++){
            Node cnode=list.item(i);
            if(cnode.getNodeName().equals("handler")){
                this.type=DecisionType.handlerClass;
                NamedNodeMap map=cnode.getAttributes();
                this.handlerClass=map.getNamedItem("class").getNodeValue();
                break;
            }
        }           
    }
}
项目:L2J-Global    文件:ClanRewardData.java   
private void parseHuntingBonus(Node node)
{
    forEach(node, IXmlReader::isNode, memberNode ->
    {
        if ("hunting".equalsIgnoreCase(memberNode.getNodeName()))
        {
            final NamedNodeMap attrs = memberNode.getAttributes();
            final int requiredAmount = parseInteger(attrs, "points");
            final int level = parseInteger(attrs, "level");
            final ClanRewardBonus bonus = new ClanRewardBonus(ClanRewardType.HUNTING_MONSTERS, level, requiredAmount);
            forEach(memberNode, IXmlReader::isNode, itemsNode ->
            {
                if ("item".equalsIgnoreCase(itemsNode.getNodeName()))
                {
                    final NamedNodeMap itemsAttr = itemsNode.getAttributes();
                    final int id = parseInteger(itemsAttr, "id");
                    final int count = parseInteger(itemsAttr, "count");
                    bonus.setItemReward(new ItemHolder(id, count));
                }
            });
            _clanRewards.computeIfAbsent(bonus.getType(), key -> new ArrayList<>()).add(bonus);
        }
    });
}
项目:incubator-netbeans    文件:DiffFinder.java   
protected boolean checkAttributesEqual(final Element p1, final Element p2) {
    if (p1 == null || p2 == null) return false;
    NamedNodeMap nm1 = p1.getAttributes();
    NamedNodeMap nm2 = p2.getAttributes();
    if( nm1.getLength() != nm2.getLength() ) return false;

    for ( int i = 0; i < nm1.getLength(); i++ ) {
        Node attr2 = (Node) nm2.getNamedItem(nm1.item(i).getNodeName());
        if ( attr2 == null ) return false;
        if(nm2.item(i) != attr2) return false;
        List<Token> t1List = ((NodeImpl)nm1.item(i)).getTokens();            
        List<Token> t2List = ( (NodeImpl) attr2 ).getTokens();
        boolean status = compareTokenEquals( t1List, t2List );
        if ( !status ) return false;
    }
    return true;
}
项目:incubator-netbeans    文件:XDMModel.java   
private void consolidateAttributePrefix(List<Node> parentAndAncestors, Element newNode) {
    NamedNodeMap nnm = newNode.getAttributes();
    for (int i=0; i<nnm.getLength(); i++) {
        if (! (nnm.item(i) instanceof Attribute))  continue;
        Attribute attr = (Attribute) nnm.item(i);
        String prefix = attr.getPrefix();
        if (prefix != null && ! attr.isXmlnsAttribute()) {
            String namespace = newNode.lookupNamespaceURI(prefix);
            if (namespace == null) continue;
            prefix = NodeImpl.lookupPrefix(namespace, parentAndAncestors);
              if (prefix != null) {
                attr.setPrefix(prefix);
            }
        }
    }
}
项目:openjdk-jdk10    文件:JPEGMetadata.java   
private void mergeStandardTextNode(Node node)
    throws IIOInvalidTreeException {
    // Convert to comments.  For the moment ignore the encoding issue.
    // Ignore keywords, language, and encoding (for the moment).
    // If compression tag is present, use only entries with "none".
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        NamedNodeMap attrs = child.getAttributes();
        Node comp = attrs.getNamedItem("compression");
        boolean copyIt = true;
        if (comp != null) {
            String compString = comp.getNodeValue();
            if (!compString.equals("none")) {
                copyIt = false;
            }
        }
        if (copyIt) {
            String value = attrs.getNamedItem("value").getNodeValue();
            COMMarkerSegment com = new COMMarkerSegment(value);
            insertCOMMarkerSegment(com);
        }
    }
}
项目:jdk8u-jdk    文件:Utils.java   
/**
 * Converts an Iterator to a Set of Nodes, according to the XPath
 * Data Model.
 *
 * @param i the Iterator
 * @return the Set of Nodes
 */
static Set<Node> toNodeSet(Iterator<Node> i) {
    Set<Node> nodeSet = new HashSet<Node>();
    while (i.hasNext()) {
        Node n = i.next();
        nodeSet.add(n);
        // insert attributes nodes to comply with XPath
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            NamedNodeMap nnm = n.getAttributes();
            for (int j = 0, length = nnm.getLength(); j < length; j++) {
                nodeSet.add(nnm.item(j));
            }
        }
    }
    return nodeSet;
}
项目:homebank_android    文件:AccountFactory.java   
@Override
public Account fromNode(Node node) {
    NamedNodeMap attributes = node.getAttributes();
    float initialAmount = 0;
    if (attributes.getNamedItem("initial") != null) {
        initialAmount = Float.parseFloat(attributes.getNamedItem("initial").getNodeValue());
    }
    Account account = new Account(
            Integer.parseInt(attributes.getNamedItem("key").getNodeValue()),
            attributes.getNamedItem("name").getNodeValue(),
            Integer.parseInt(attributes.getNamedItem("curr").getNodeValue()),
            initialAmount
    );

    Node flags = attributes.getNamedItem("flags");
    if (flags != null) {
        account.setFlags(Integer.parseInt(flags.getNodeValue()));
    }
    return account;
}
项目:DAFramework    文件:XmlUtil.java   
public static StrMap getAttributes(Node node) {
    StrMap attrs = new StrMap();
    ArgCheck.checkNotNull(node);
    NamedNodeMap attrNodeMap = node.getAttributes();
    if (attrNodeMap != null) {
        for (int i = 0; i < attrNodeMap.getLength(); i++) {
            Node attNode = attrNodeMap.item(i);
            if (attNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                attrs.put(attNode.getNodeName(), attNode.getNodeValue());
            } else {
                LOG.warn("error node type:" + attNode.getNodeType());
            }
        }
    }
    return attrs;
}
项目:myfaces-trinidad    文件:AttributeDocumentChange.java   
/**
 * {@inheritDoc}
 */
public void changeDocument(Node componentNode)
{
  NamedNodeMap attributes = componentNode.getAttributes();

  if (attributes != null)
  {
    // remove the attribute
    if (_attributeValueString == null)
      attributes.removeNamedItem(_attributeName);
    else
    {
      ((Element)componentNode).setAttribute(_attributeName,
                                            _attributeValueString);
    }
  }
}
项目:uavstack    文件:ComponentProfileHandler.java   
@Override
public DescriptorCollector selectDescriptorCollector(String xpath) {

    final DescriptorProcessor dp = this;

    DescriptorCollector ic = null;

    if ("/endpoints/endpoint/@implementation".equals(xpath)) {

        // get servlets
        ic = new DescriptorCollector() {

            @Override
            public void loadInfo(String sKey, String sKeyRawValue, Map<String, Object> sInfo) {

                Node endpoint = dp.selectXMLNode("/endpoints/endpoint[@implementation='" + sKeyRawValue + "']");
                // service-name

                NamedNodeMap map = endpoint.getAttributes();

                if (endpoint != null) {
                    for (int i = 0; i < map.getLength(); i++) {
                        Node attr = map.item(i);
                        sInfo.put(attr.getNodeName(), attr.getNodeValue());
                    }
                }
            }
        };
    }

    return ic;
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:XmlConverter.java   
private static void handleAttributes(String nodeName, NamedNodeMap attributes, StringBuilder layoutXml) {
    if (attributes == null)
        return;
    int len = attributes.getLength();
    for (int i = 0; i < len; i++) {
        Node attr = attributes.item(i);
        handleAttribute(nodeName, attr, layoutXml);
    }
}
项目:openjdk-jdk10    文件:DocumentTypeTest.java   
@Test
public void testGetEntities() throws Exception {
    DocumentType documentType = createDOM("DocumentType01.xml").getDoctype();
    NamedNodeMap namedNodeMap = documentType.getEntities();
    // should return both external and internal. Parameter entities are not
    // contained. Duplicates are discarded.
    assertEquals(namedNodeMap.getLength(), 3);
    assertEquals(namedNodeMap.item(0).getNodeName(), "author");
    assertEquals(namedNodeMap.item(1).getNodeName(), "test");
    assertEquals(namedNodeMap.item(2).getNodeName(), "writer");
}
项目:Hydrograph    文件:ComponentValidationEventHandler.java   
private boolean isIdAttributePresent(NamedNodeMap attributes) {
    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.item(i).getLocalName().equals("id")) {
            if (!attributes.item(i).getNodeValue().equals("")) {
                return true;

            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    return false;
}
项目:OpenJSharp    文件:DOMValidatorHelper.java   
private void processAttributes(NamedNodeMap attrMap) {
    final int attrCount = attrMap.getLength();
    fAttributes.removeAllAttributes();
    for (int i = 0; i < attrCount; ++i) {
        Attr attr = (Attr) attrMap.item(i);
        String value = attr.getValue();
        if (value == null) {
            value = XMLSymbols.EMPTY_STRING;
        }
        fillQName(fAttributeQName, attr);
        // REVISIT: Assuming all attributes are of type CDATA. The actual type may not matter. -- mrglavas
        fAttributes.addAttributeNS(fAttributeQName, XMLSymbols.fCDATASymbol, value);
        fAttributes.setSpecified(i, attr.getSpecified());
        // REVISIT: Should we be looking at non-namespace attributes
        // for additional mappings? Should we detect illegal namespace
        // declarations and exclude them from the context? -- mrglavas
        if (fAttributeQName.uri == NamespaceContext.XMLNS_URI) {
            // process namespace attribute
            if (fAttributeQName.prefix == XMLSymbols.PREFIX_XMLNS) {
                fNamespaceContext.declarePrefix(fAttributeQName.localpart, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
            }
            else {
                fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
            }
        }
    }
}
项目:Java-APIs    文件:CSProcess.java   
public CSProcess(Element element) {

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        for (int a = 0; a < namedNodeMap.getLength(); a++) {
            Attr attributeNode = (Attr) namedNodeMap.item(a);
            if ("id".equals(attributeNode.getName())) {
                setId(Long.parseLong(attributeNode.getValue()));
            } else if ("pid".equals(attributeNode.getName())) {
                setProcessId(Long.parseLong(attributeNode.getValue()));
            } else if ("generation".equals(attributeNode.getName())) {
                setGeneration(Integer.parseInt(attributeNode.getValue()));
            } else if ("status".equals(attributeNode.getName())) {
                setStatus(attributeNode.getValue());
            } else if ("access_count".equals(attributeNode.getName())) {
                setAccessCount(Integer.parseInt(attributeNode.getValue()));
            } else if ("exception_count".equals(attributeNode.getName())) {
                setExceptionCount(Integer.parseInt(attributeNode.getValue()));
            } else if ("bytes".equals(attributeNode.getName())) {
                setBytes(Long.parseLong(attributeNode.getValue()));
            } else if ("start_time".equals(attributeNode.getName())) {
                setStartTime(new Date((long) Double.parseDouble(attributeNode.getValue())));
            } else if ("stop_time".equals(attributeNode.getName())) {
                double dTime = Double.parseDouble(attributeNode.getValue());
                setStopTime(new Date((long)dTime));
            } else if ("last_used".equals(attributeNode.getName())) {
                setLastUsed(new Date(1000 * Long.parseLong(attributeNode.getValue())));
            } else {
                logger.warn("Unrecognized attribute: '" + attributeNode.getName() + "' (" + this.getClass().getName() + ")");
            }
        }
    }
}
项目:monarch    文件:XmlUtils.java   
public static String getAttribute(Node node, String name) {
  NamedNodeMap attributes = node.getAttributes();
  if (attributes == null) {
    return null;
  }

  Node attributeNode = node.getAttributes().getNamedItem(name);
  if (attributeNode == null) {
    return null;
  }
  return attributeNode.getTextContent();
}
项目:OpenJSharp    文件:DocumentTypeImpl.java   
/**
 * Access the collection of Notations defined in the DTD.  A
 * notation declares, by name, the format of an XML unparsed entity
 * or is used to formally declare a Processing Instruction target.
 */
public NamedNodeMap getNotations() {
    if (needsSyncChildren()) {
        synchronizeChildren();
        }
    return notations;
}
项目:ats-framework    文件:ConfigurationResource.java   
/**
 * This method will read a tree of elements and their attributes
 * 
 * @param element the root element of the tree
 */
private void readXmlElement(
                             LinkedList<String> currentElementPath,
                             Element element ) {

    //append this node element to the current path
    currentElementPath.add(element.getNodeName());

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
            readXmlElement(currentElementPath, (Element) childNode);
        }
    }

    //read all attributes
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);

        String propertyName = getCurrentXmlElementPath(currentElementPath) + attribute.getName();
        String propertyValue = attribute.getValue();

        //put in the properties table
        properties.put(propertyName, propertyValue);

        log.debug("Added property with name '" + propertyName + "' and value '" + propertyValue + "'");
    }

    //after we are done with the node, remove it from the path
    currentElementPath.removeLast();
}
项目:javaide    文件:ResourceItem.java   
@Nullable
private ResourceType getType(String qName, NamedNodeMap attributes) {
    String typeValue;

    // if the node is <item>, we get the type from the attribute "type"
    if (SdkConstants.TAG_ITEM.equals(qName)) {
        typeValue = getAttributeValue(attributes, ATTR_TYPE);
    } else {
        // the type is the name of the node.
        typeValue = qName;
    }

    return ResourceType.getEnum(typeValue);
}
项目:incubator-netbeans    文件:HyperlinkEnv.java   
private Map<String, String> collectAttributes(Node currentTag) {
   Map<String, String> attribsMap = new HashMap<String, String>();
   NamedNodeMap attribsNodeMap = currentTag.getAttributes();
   for(int i = 0; i < attribsNodeMap.getLength(); i++) {
       Node n = attribsNodeMap.item(i);
       attribsMap.put(n.getNodeName(), n.getNodeValue());
   }

   return Collections.unmodifiableMap(attribsMap);
}
项目:incubator-netbeans    文件:DocumentContext.java   
private void populateNamespaces() {
    // Find the a start or empty tag just before the current syntax element.
    SyntaxElement element = this.element;
    while (element != null && !(syntaxSupport.isStartTag(element)) && !(syntaxSupport.isEmptyTag(element))) {
        element = element.getPrevious();
    }
    if (element == null) {
        return;
    }

    // To find all namespace declarations active at the caret offset, we
    // need to look at xmlns attributes of the current element and its ancestors.
    while (element != null) {
        Node node = element.getNode();
        if (syntaxSupport.isStartTag(element) || syntaxSupport.isEmptyTag(element)) {
            NamedNodeMap attributes = node.getAttributes();
            for (int index = 0; index < attributes.getLength(); index++) {
                Attr attr = (Attr) attributes.item(index);
                String attrName = attr.getName();
                String attrValue = attr.getValue();
                if (attrName == null || attrValue == null) {
                    continue;
                }
                String prefix = ContextUtilities.getPrefixFromNamespaceDeclaration(attrName);
                if (prefix == null) {
                    continue;
                }
                // Avoid overwriting a namespace declaration "closer" to the caret offset.
                if (!declaredNamespaces.containsKey(prefix)) {
                    declaredNamespaces.put(prefix, attrValue);
                }
            }
        }
        element = element.getParentElement();
    }
}
项目:javaide    文件:NodeUtils.java   
/**
 * Updates the namespace of a given node (and its children) to work in a given document
 * @param node the node to update
 * @param document the new document
 */
private static void updateNamespace(Node node, Document document) {

    // first process this node
    processSingleNodeNamespace(node, document);

    // then its attributes
    NamedNodeMap attributes = node.getAttributes();
    if (attributes != null) {
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Node attribute = attributes.item(i);
            if (!processSingleNodeNamespace(attribute, document)) {
                String nsUri = attribute.getNamespaceURI();
                if (nsUri != null) {
                    attributes.removeNamedItemNS(nsUri, attribute.getLocalName());
                } else {
                    attributes.removeNamedItem(attribute.getLocalName());
                }
            }
        }
    }

    // then do it for the children nodes.
    NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0, n = children.getLength(); i < n; i++) {
            Node child = children.item(i);
            if (child != null) {
                updateNamespace(child, document);
            }
        }
    }
}
项目:OpenJSharp    文件:XSDocumentInfo.java   
/**
 * Initialize namespace support by collecting all of the namespace
 * declarations in the root's ancestors. This is necessary to
 * support schemas fragments, i.e. schemas embedded in other
 * documents. See,
 *
 * https://jaxp.dev.java.net/issues/show_bug.cgi?id=43
 *
 * Requires the DOM to be created with namespace support enabled.
 */
private void initNamespaceSupport(Element schemaRoot) {
    fNamespaceSupport = new SchemaNamespaceSupport();
    fNamespaceSupport.reset();

    Node parent = schemaRoot.getParentNode();
    while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE
            && !parent.getNodeName().equals("DOCUMENT_NODE"))
    {
        Element eparent = (Element) parent;
        NamedNodeMap map = eparent.getAttributes();
        int length = (map != null) ? map.getLength() : 0;
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr) map.item(i);
            String uri = attr.getNamespaceURI();

            // Check if attribute is an ns decl -- requires ns support
            if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) {
                String prefix = attr.getLocalName().intern();
                if (prefix == "xmlns") prefix = "";
                // Declare prefix if not set -- moving upwards
                if (fNamespaceSupport.getURI(prefix) == null) {
                    fNamespaceSupport.declarePrefix(prefix,
                            attr.getValue().intern());
                }
            }
        }
        parent = parent.getParentNode();
    }
}
项目:s-store    文件:ParsedUpdateStmt.java   
void parseColumns(Node columnsNode, Database db) {
    for (Node child = columnsNode.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE)
            continue;
        assert(child.getNodeName().equals("column"));

        Column col = null;
        NamedNodeMap attrs = child.getAttributes();
        Node node = attrs.getNamedItem("table");
        assert(node != null);
        assert(node.getNodeValue().equalsIgnoreCase(table.getTypeName()));
        node = attrs.getNamedItem("name");
        assert(node != null);
        col = table.getColumns().getIgnoreCase(node.getNodeValue().trim());

        AbstractExpression expr = null;
        for (Node subChild = child.getFirstChild(); subChild != null; subChild = subChild.getNextSibling()) {
            if (subChild.getNodeType() != Node.ELEMENT_NODE)
                continue;
            expr = parseExpressionTree(subChild, db);
            ExpressionUtil.assignLiteralConstantTypesRecursively(expr, VoltType.get((byte)col.getType()));
            ExpressionUtil.assignOutputValueTypesRecursively(expr);
        }
        assert(expr != null);
        columns.put(col, expr);
    }
}
项目:jaffa-framework    文件:AbstractLoader.java   
/** Reads the attributes within the input element and adds them to the input Map.
 * @param element An Element.
 * @param map A Map.
 */
protected void attributesToMap(Element element, Map<String, String> map) {
    NamedNodeMap attributes = element.getAttributes();
    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            if (attribute.getNodeType() == Node.ATTRIBUTE_NODE)
                map.put(attribute.getNodeName(), attribute.getNodeValue());
        }
    }
}
项目:OpenJSharp    文件:EntityReferenceImpl.java   
/**
 * EntityReference's children are a reflection of those defined in the
 * named Entity. This method creates them if they haven't been created yet.
 * This doesn't support editing the Entity though, since this only called
 * once for all.
 */
protected void synchronizeChildren() {
    // no need to synchronize again
    needsSyncChildren(false);

    DocumentType doctype;
    NamedNodeMap entities;
    EntityImpl entDef;
    if (null != (doctype = getOwnerDocument().getDoctype()) &&
        null != (entities = doctype.getEntities())) {

        entDef = (EntityImpl)entities.getNamedItem(getNodeName());

        // No Entity by this name, stop here.
        if (entDef == null)
            return;

        // If entity's definition exists, clone its kids
        isReadOnly(false);
        for (Node defkid = entDef.getFirstChild();
            defkid != null;
            defkid = defkid.getNextSibling()) {
            Node newkid = defkid.cloneNode(true);
            insertBefore(newkid, null);
        }
        setReadOnly(true, true);
    }
}
项目:openjdk-jdk10    文件:SAXImpl.java   
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
项目:hashsdn-controller    文件:XmlElement.java   
private Map<String, String> extractNamespaces() throws DocumentedException {
    Map<String, String> namespaces = new HashMap<>();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        String attribKey = attribute.getNodeName();
        if (attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY)) {
            String prefix;
            if (attribKey.equals(XmlUtil.XMLNS_ATTRIBUTE_KEY)) {
                prefix = DEFAULT_NAMESPACE_PREFIX;
            } else {
                if (!attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY + ":")){
                    throw new DocumentedException("Attribute doesn't start with :",
                            DocumentedException.ErrorType.APPLICATION,
                            DocumentedException.ErrorTag.INVALID_VALUE,
                            DocumentedException.ErrorSeverity.ERROR);
                }
                prefix = attribKey.substring(XmlUtil.XMLNS_ATTRIBUTE_KEY.length() + 1);
            }
            namespaces.put(prefix, attribute.getNodeValue());
        }
    }

    // namespace does not have to be defined on this element but inherited
    if(!namespaces.containsKey(DEFAULT_NAMESPACE_PREFIX)) {
        Optional<String> namespaceOptionally = getNamespaceOptionally();
        if(namespaceOptionally.isPresent()) {
            namespaces.put(DEFAULT_NAMESPACE_PREFIX, namespaceOptionally.get());
        }
    }

    return namespaces;
}
项目:L2J-Global    文件:FourSepulchers.java   
@Override
public void parseDocument(Document doc, File f)
{
    for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
    {
        if ("list".equalsIgnoreCase(n.getNodeName()))
        {
            for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
            {
                if ("spawn".equalsIgnoreCase(b.getNodeName()))
                {
                    final NamedNodeMap attrs = b.getAttributes();
                    final int[] info =
                    {
                        parseInteger(attrs, "sepulcherId"),
                        parseInteger(attrs, "wave"),
                        parseInteger(attrs, "npcId"),
                        parseInteger(attrs, "x"),
                        parseInteger(attrs, "y"),
                        parseInteger(attrs, "z"),
                        parseInteger(attrs, "heading")
                    };
                    ROOM_SPAWN_DATA.add(info);
                }
            }
        }
    }
}
项目:VASSAL-src    文件:Widget.java   
/**
 * For memory efficiency reasons, a Widget is initialized lazily.
 * This method only stores the element from which the build the Widget.
 * The Widget is built from the stored element by invoking {@link #rebuild}.
 * Subclasses should invoke {@link #rebuild} before invoking {@link #getComponent}
 */
public void build(Element el) {
  buildElement = el;
  if (el != null) {
    NamedNodeMap n = el.getAttributes();
    for (int i = 0; i < n.getLength(); ++i) {
      Attr att = (Attr) n.item(i);
      setAttribute(att.getName(), att.getValue());
      Localization.getInstance().saveTranslatableAttribute(this, att.getName(), att.getValue());
    }
  }
}
项目:Java-APIs    文件:VersionInfo.java   
public VersionInfo(Element element) {
    logger.debug("Constructor - entry");

    NodeList nodeList = element.getChildNodes();
    for (int n = 0; n < nodeList.getLength(); n++) {
        Node node = nodeList.item(n);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) node;

            if ("VERSION".equals(childElement.getNodeName())) {
                String name = childElement.getAttribute("NAME");
                String revision = childElement.getAttribute("REVISION");
                if ("Compatible index structure version".equals(name)) {
                    setIndexStructure(revision);
                } else if ("SES API version".equals(name)) {
                    setApi(revision);
                } else if ("SES build".equals(name)) {
                    setBuild(revision);
                } else {
                    logger.trace("Unexpected version information: " + name + " (" + revision + ")");
                }
            } else {
                logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "'");
            }
        } else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue() != null) && (node.getNodeValue().trim().length() > 0)) {
            logger.trace("Unexpected text node (" + this.getClass().getName() + "): '" + node.getNodeValue() + "'");
        }
    }
    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        for (int a = 0; a < namedNodeMap.getLength(); a++) {
            Attr attributeNode = (Attr) namedNodeMap.item(a);
            logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");
        }
    }

    logger.debug("Constructor - exit");
}
项目:openjdk-jdk10    文件:DOMResultBuilder.java   
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}