Example usage for org.w3c.dom NamedNodeMap getLength

List of usage examples for org.w3c.dom NamedNodeMap getLength

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap getLength.

Prototype

public int getLength();

Source Link

Document

The number of nodes in this map.

Usage

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parsePlayerCondition(Node n, Object template) {
    Condition cond = null;/*from w w w  .  j  ava  2  s .co  m*/

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parsePlayerCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <player> condition");

    return cond;
}

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parseTargetCondition(Node n, Object template) {
    Condition cond = null;/*from w ww. ja  v a2s.c  om*/

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parseTargetCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <target> condition");

    return cond;
}

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parseUsingCondition(Node n, Object template) {
    Condition cond = null;//  w  ww . jav a2 s.  c  o  m

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parseUsingCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <using> condition");

    return cond;
}

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parseGameCondition(Node n, Object template) {
    Condition cond = null;//www  .  j a  va2s  .com

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parseGameCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <game> condition");

    return cond;
}

From source file:DOMWriter.java

/** Returns a sorted list of attributes. */
private Attr[] sortAttributes(NamedNodeMap attrs) {

    int len = (attrs != null) ? attrs.getLength() : 0;
    Attr array[] = new Attr[len];
    for (int i = 0; i < len; i++) {
        array[i] = (Attr) attrs.item(i);
    }//  www .  j  a  v a  2 s .c  o  m
    for (int i = 0; i < len - 1; i++) {
        String name = array[i].getNodeName();
        int index = i;
        for (int j = i + 1; j < len; j++) {
            String curName = array[j].getNodeName();
            if (curName.compareTo(name) < 0) {
                name = curName;
                index = j;
            }
        }
        if (index != i) {
            Attr temp = array[i];
            array[i] = array[index];
            array[index] = temp;
        }
    }
    return (array);
}

From source file:edu.lternet.pasta.datapackagemanager.LevelOneEMLFactory.java

private void modifyAccessElementAttributes(Document emlDocument) throws TransformerException {
    CachedXPathAPI xpathapi = new CachedXPathAPI();

    // Parse the access elements
    NodeList accessNodeList = xpathapi.selectNodeList(emlDocument, ACCESS_PATH);
    if (accessNodeList != null) {
        for (int i = 0; i < accessNodeList.getLength(); i++) {
            boolean hasSystemAttribute = false;
            Element accessElement = (Element) accessNodeList.item(i);
            NamedNodeMap accessAttributesList = accessElement.getAttributes();

            for (int j = 0; j < accessAttributesList.getLength(); j++) {
                Node attributeNode = accessAttributesList.item(j);
                String nodeName = attributeNode.getNodeName();
                String nodeValue = attributeNode.getNodeValue();
                if (nodeName.equals("authSystem")) {
                    attributeNode.setNodeValue(LEVEL_ONE_AUTH_SYSTEM_ATTRIBUTE);
                } else if (nodeName.equals("system")) {
                    attributeNode.setNodeValue(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                    hasSystemAttribute = true;
                }//w w w  .  j  a  v  a 2s  . c  o m
            }

            /*
             * No @system attribute was found in the access element, so we
             * need to add one.
             */
            if (!hasSystemAttribute) {
                Attr systemAttribute = emlDocument.createAttribute("system");
                systemAttribute.setTextContent(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                accessElement.setAttributeNode(systemAttribute);
            }
        }
    }
}

From source file:com.nridge.ds.solr.SolrSchemaXML.java

private DataField loadField(Element anElement) {
    Attr nodeAttr;//from   w w  w . ja  va2 s. co m
    DataField dataField;
    Field.Type fieldType;
    String nodeName, nodeValue;
    Logger appLogger = mAppMgr.getLogger(this, "loadField");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    String attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue)) {
        String fieldName = attrValue;
        attrValue = anElement.getAttribute("type");
        if (StringUtils.isNotEmpty(attrValue))
            fieldType = mapSolrFieldType(attrValue);
        else
            fieldType = Field.Type.Text;
        dataField = new DataField(fieldType, fieldName);
        dataField.setTitle(Field.nameToTitle(fieldName));

        NamedNodeMap namedNodeMap = anElement.getAttributes();
        int attrCount = namedNodeMap.getLength();
        for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
            nodeAttr = (Attr) namedNodeMap.item(attrOffset);
            nodeName = nodeAttr.getNodeName();
            nodeValue = nodeAttr.getNodeValue();

            if (StringUtils.isNotEmpty(nodeValue)) {
                if ((!StringUtils.equalsIgnoreCase(nodeName, "name"))
                        && (!StringUtils.equalsIgnoreCase(nodeName, "type")))
                    assignSolrFieldFeature(dataField, nodeName, nodeValue);
            }
        }
    } else
        dataField = null;

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return dataField;
}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

public static String removeUnneccessaryNamespaces(String xml) {
    if (StringUtils.isBlank(xml))
        return xml;

    XmlObject xmlObject = null;/*w  w  w . j  a va2 s .c om*/
    XmlCursor cursor = null;
    try {
        xmlObject = XmlObject.Factory.parse(xml);

        cursor = xmlObject.newCursor();
        while (cursor.currentTokenType() != TokenType.START && cursor.currentTokenType() != TokenType.ENDDOC) {
            cursor.toNextToken();
        }

        if (cursor.currentTokenType() == TokenType.START) {
            Map<?, ?> nsMap = new HashMap<Object, Object>();

            cursor.getAllNamespaces(nsMap);
            nsMap.remove(cursor.getDomNode().getPrefix());

            NamedNodeMap attributes = cursor.getDomNode().getAttributes();
            for (int c = 0; attributes != null && c < attributes.getLength(); c++) {
                nsMap.remove(attributes.item(c).getPrefix());
            }

            if (cursor.toFirstChild()) {
                while (cursor.getDomNode() != xmlObject.getDomNode()) {
                    attributes = cursor.getDomNode().getAttributes();
                    for (int c = 0; attributes != null && c < attributes.getLength(); c++) {
                        nsMap.remove(attributes.item(c).getPrefix());
                    }

                    nsMap.remove(cursor.getDomNode().getPrefix());
                    cursor.toNextToken();
                }
            }

            xml = xmlObject.xmlText(
                    new XmlOptions().setSaveOuter().setSavePrettyPrint().setSaveImplicitNamespaces(nsMap));
        }
    } catch (XmlException e) {

    } finally {
        if (cursor != null)
            cursor.dispose();
    }

    return xml;
}

From source file:de.betterform.xml.xforms.XFormsElement.java

/**
 * returns the list of all attributes that are not in 'known' namespaces and do not have the null (default?) namespace
 *
 * /*from ww  w . jav a2  s .co m*/
 * @return the key-value-pair of the attributes
 */
public Map<String, String> getCustomMIPAttributes() {

    HashMap<String, String> customMIPAttributes = new HashMap<String, String>();
    NamedNodeMap nnm = element.getAttributes();
    for (int i = 0; i < nnm.getLength(); i++) {
        Node attribute = nnm.item(i);
        if (attribute.getNamespaceURI() != null
                && !NamespaceConstants.BETTERFORM_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XFORMS_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XHTML_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLNS_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLSCHEMA_INSTANCE_NS.equals(attribute.getNamespaceURI())
                && !NamespaceConstants.XMLEVENTS_NS.equals(attribute.getNamespaceURI())) {
            customMIPAttributes.put(attribute.getPrefix() + WordUtils.capitalize(attribute.getLocalName()),
                    attribute.getTextContent());
        }
    }
    return customMIPAttributes;

}

From source file:com.marklogic.dom.NodeImpl.java

/** {@inheritDoc} */
public boolean isEqualNode(Node other) {

    // Note that normalization can affect equality; to avoid this,
    // nodes should be normalized before being compared.
    // For the moment, normalization cannot be done.
    if (other == null)
        return false;
    if (getNodeType() != other.getNodeType())
        return false;
    if (!getLocalName().equals(other.getLocalName()))
        return false;
    if (notequals(getNamespaceURI(), other.getNamespaceURI()))
        return false;
    if (notequals(getPrefix(), other.getPrefix()))
        return false;
    if (notequals(getNodeValue(), other.getNodeValue()))
        return false;
    if (hasChildNodes() != other.hasChildNodes())
        return false;
    if (hasAttributes() != other.hasAttributes())
        return false;
    if (hasChildNodes()) {
        NamedNodeMap thisAttr = getAttributes();
        NamedNodeMap otherAttr = other.getAttributes();
        if (thisAttr.getLength() != otherAttr.getLength())
            return false;
        for (int i = 0; i < thisAttr.getLength(); i++)
            if (thisAttr.item(i).isEqualNode(otherAttr.item(i)))
                return false;
    }/*from   www.  j  a  va2  s. com*/
    if (hasAttributes()) {
        NodeList thisChild = getChildNodes();
        NodeList otherChild = other.getChildNodes();
        if (thisChild.getLength() != otherChild.getLength())
            return false;
        for (int i = 0; i < thisChild.getLength(); i++)
            if (thisChild.item(i).isEqualNode(otherChild.item(i)))
                return false;
    }
    return true;
}