Example usage for org.w3c.dom Attr getNodeValue

List of usage examples for org.w3c.dom Attr getNodeValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getNodeValue.

Prototype

public String getNodeValue() throws DOMException;

Source Link

Document

The value of this node, depending on its type; see the table above.

Usage

From source file:org.mumod.android.provider.StatusNet.java

private String getTagValueWithMultiItem(Element eElement) {
    String returnVal = "";
    Node eNode;//  ww w  .  j a  va 2 s.  c  o m
    int NumOFItem = eElement.getElementsByTagName("link").getLength();
    for (int y = 0; y < NumOFItem; y++) {
        eNode = eElement.getElementsByTagName("link").item(y);
        NamedNodeMap attributes = eNode.getAttributes();
        for (int g = 0; g < attributes.getLength(); g++) {
            Attr attribute = (Attr) attributes.item(g);
            if (attribute.getNodeName().equals("rel") && attribute.getNodeValue().equals("alternate")) {
                try {
                    if (eNode.getAttributes().getNamedItem("type").getNodeValue()
                            .equals("application/atom+xml"))
                        returnVal = eNode.getAttributes().getNamedItem("href").getNodeValue();
                } catch (Exception e) {
                    if (MustardApplication.DEBUG)
                        e.printStackTrace();
                }
            }
        }
    }
    return returnVal;
}

From source file:com.nridge.core.base.io.xml.DSCriteriaXML.java

/**
 * Parses an XML DOM element and loads it into a criteria.
 *
 * @param anElement DOM element./*from   w  w  w. java 2s  .co m*/
 *
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void load(Element anElement) throws IOException {
    Node nodeItem;
    Attr nodeAttr;
    Element nodeElement;
    DataField dataField;
    String nodeName, nodeValue, logicalOperator;

    String className = mDSCriteria.getClass().getName();
    String attrValue = anElement.getAttribute("type");
    if ((StringUtils.isNotEmpty(attrValue)) && (!IO.isTypesEqual(attrValue, className)))
        throw new IOException("Unsupported type: " + attrValue);

    attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue))
        mDSCriteria.setName(attrValue);

    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")))
                continue;
            else
                mDSCriteria.addFeature(nodeName, nodeValue);
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (nodeName.equalsIgnoreCase(IO.XML_FIELD_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            dataField = mDataFieldXML.load(nodeElement);
            if (dataField != null) {
                logicalOperator = dataField.getFeature("operator");
                if (StringUtils.isEmpty(logicalOperator))
                    logicalOperator = Field.operatorToString(Field.Operator.EQUAL);
                mDSCriteria.add(dataField, Field.stringToOperator(logicalOperator));
            }
        }
    }
}

From source file:com.nridge.core.base.io.xml.DataFieldXML.java

public DataField load(Element anElement) throws IOException {
    Attr nodeAttr;
    Node nodeItem;//from  w  w w. j  av a 2  s  .  c o  m
    DataField dataField;
    Element nodeElement;
    Field.Type fieldType;
    String nodeName, nodeValue;

    String attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue)) {
        String fieldName = attrValue;
        attrValue = anElement.getAttribute("type");
        if (StringUtils.isNotEmpty(attrValue))
            fieldType = Field.stringToType(attrValue);
        else
            fieldType = Field.Type.Text;
        dataField = new DataField(fieldType, 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"))
                        || (StringUtils.equalsIgnoreCase(nodeName, "rangeType")))
                    continue;
                else if (StringUtils.equalsIgnoreCase(nodeName, "title"))
                    dataField.setTitle(nodeValue);
                else if (StringUtils.equalsIgnoreCase(nodeName, "isMultiValue"))
                    dataField.setMultiValueFlag(StrUtl.stringToBoolean(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "displaySize"))
                    dataField.setDisplaySize(Field.createInt(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "sortOrder"))
                    dataField.setSortOrder(Field.Order.valueOf(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "defaultValue"))
                    dataField.setDefaultValue(nodeValue);
                else
                    dataField.addFeature(nodeName, nodeValue);
            }
        }
        String rangeType = anElement.getAttribute("rangeType");
        if (StringUtils.isNotEmpty(rangeType)) {
            NodeList nodeList = anElement.getChildNodes();
            for (int i = 0; i < nodeList.getLength(); i++) {
                nodeItem = nodeList.item(i);

                if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
                    continue;

                nodeName = nodeItem.getNodeName();
                if (StringUtils.equalsIgnoreCase(nodeName, "Range")) {
                    nodeElement = (Element) nodeItem;
                    dataField.setRange(mRangeXML.load(nodeElement));
                } else if (StringUtils.equalsIgnoreCase(nodeName, "Value")) {
                    nodeValue = XMLUtl.getNodeStrValue(nodeItem);
                    String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER);
                    if (StringUtils.isNotEmpty(mvDelimiter))
                        dataField.expand(nodeValue, mvDelimiter.charAt(0));
                    else
                        dataField.expand(nodeValue);
                }
            }
        } else {
            nodeItem = (Node) anElement;
            if (dataField.isFeatureTrue(Field.FEATURE_IS_CONTENT))
                nodeValue = XMLUtl.getNodeCDATAValue(nodeItem);
            else
                nodeValue = XMLUtl.getNodeStrValue(nodeItem);
            if (dataField.isMultiValue()) {
                String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER);
                if (StringUtils.isNotEmpty(mvDelimiter))
                    dataField.expand(nodeValue, mvDelimiter.charAt(0));
                else
                    dataField.expand(nodeValue);
            } else
                dataField.setValue(nodeValue);
        }
    } else
        dataField = null;

    return dataField;
}

From source file:com.nridge.core.base.io.xml.DocumentOpXML.java

private void loadOperation(Element anElement) throws IOException {
    Attr nodeAttr;
    Node nodeItem;/* w  ww. jav a2 s  . c o m*/
    Document document;
    Element nodeElement;
    DocumentXML documentXML;
    DSCriteriaXML criteriaXML;
    String nodeName, nodeValue;

    mCriteria = null;
    mDocumentList.clear();
    mField.clearFeatures();

    String attrValue = anElement.getAttribute(Doc.FEATURE_OP_NAME);
    if (StringUtils.isNotEmpty(attrValue)) {
        mField.setName(attrValue);
        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, Doc.FEATURE_OP_NAME))
                        && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT)))
                    mField.addFeature(nodeName, nodeValue);
            }
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (nodeName.equalsIgnoreCase(IO.XML_CRITERIA_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            criteriaXML = new DSCriteriaXML();
            criteriaXML.load(nodeElement);
            mCriteria = criteriaXML.getCriteria();
        } else if (StringUtils.startsWithIgnoreCase(nodeName, IO.XML_DOCUMENT_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            documentXML = new DocumentXML();
            documentXML.load(nodeElement);
            document = documentXML.getDocument();
            if (document != null)
                mDocumentList.add(document);
        }
    }
}

From source file:com.nridge.core.base.io.xml.DataBagXML.java

/**
 * Parses an XML DOM element and loads it into a bag/table.
 *
 * @param anElement DOM element.//  w w w.  j a v  a  2  s. c  om
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void load(Element anElement) throws IOException {
    Node nodeItem;
    Attr nodeAttr;
    Element nodeElement;
    DataField dataField;
    String nodeName, nodeValue;

    String className = mBag.getClass().getName();
    String attrValue = anElement.getAttribute("type");
    if ((StringUtils.isNotEmpty(attrValue)) && (!IO.isTypesEqual(attrValue, className)))
        throw new IOException("Unsupported type: " + attrValue);

    attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue))
        mBag.setName(attrValue);
    attrValue = anElement.getAttribute("title");
    if (StringUtils.isNotEmpty(attrValue))
        mBag.setTitle(attrValue);

    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"))
                    || (StringUtils.equalsIgnoreCase(nodeName, "count"))
                    || (StringUtils.equalsIgnoreCase(nodeName, "title"))
                    || (StringUtils.equalsIgnoreCase(nodeName, "version")))
                continue;
            else
                mBag.addFeature(nodeName, nodeValue);
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (nodeName.equalsIgnoreCase(IO.XML_FIELD_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            dataField = mDataFieldXML.load(nodeElement);
            if (dataField != null)
                mBag.add(dataField);
        }
    }
}

From source file:com.nridge.core.base.io.xml.DocumentReplyXML.java

/**
 * Parses an XML DOM element and loads it into a document list.
 *
 * @param anElement DOM element.//ww w  .  ja  v  a  2 s.  c o  m
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void load(Element anElement) throws IOException {
    Attr nodeAttr;
    Node nodeItem;
    Document document;
    Element nodeElement;
    DocumentXML documentXML;
    String nodeName, nodeValue;

    nodeName = anElement.getNodeName();
    if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_REPLY_NODE_NAME)) {
        mField.clearFeatures();
        String attrValue = anElement.getAttribute(Doc.FEATURE_OP_STATUS_CODE);
        if (StringUtils.isNotEmpty(attrValue)) {
            mField.setName(Doc.FEATURE_OP_STATUS_CODE);
            mField.setValue(attrValue);
            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, Doc.FEATURE_OP_STATUS_CODE))
                            && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT)))
                        mField.addFeature(nodeName, nodeValue);
                }
            }
        }
        NodeList nodeList = anElement.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            nodeItem = nodeList.item(i);

            if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
                continue;

            // We really do not know how the node was named, so we will just accept it.

            nodeElement = (Element) nodeItem;
            documentXML = new DocumentXML();
            documentXML.load(nodeElement);
            document = documentXML.getDocument();
            if (document != null)
                mDocumentList.add(document);
        }
    }
}

From source file:com.nridge.core.base.io.xml.DocumentXML.java

private Document loadDocument(Element anElement) throws IOException {
    Node nodeItem;//w w  w  .  j a v a 2s  .  com
    Attr nodeAttr;
    Document document;
    Element nodeElement;
    String nodeName, nodeValue;

    String docName = anElement.getAttribute("name");
    String typeName = anElement.getAttribute("type");
    String docTitle = anElement.getAttribute("title");
    String schemaVersion = anElement.getAttribute("schemaVersion");
    if ((StringUtils.isNotEmpty(typeName)) && (StringUtils.isNotEmpty(schemaVersion)))
        document = new Document(typeName);
    else
        document = new Document("Unknown");
    if (StringUtils.isNotEmpty(docName))
        document.setName(docName);
    if (StringUtils.isNotEmpty(docTitle))
        document.setName(docTitle);

    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"))
                    || (StringUtils.equalsIgnoreCase(nodeName, "title"))
                    || (StringUtils.equalsIgnoreCase(nodeName, "schemaVersion")))
                continue;
            else
                document.addFeature(nodeName, nodeValue);
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_TABLE_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            DataTableXML dataTableXML = new DataTableXML();
            dataTableXML.load(nodeElement);
            document.setTable(dataTableXML.getTable());
        } else if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_RELATED_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            loadRelated(document, nodeElement);
        } else if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_ACL_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            loadACL(document, nodeElement);
        }
    }

    return document;
}

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

private DataField loadField(Element anElement) {
    Attr nodeAttr;
    DataField dataField;/*from  w  ww  . j  a v a  2 s. co  m*/
    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:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java

public List getNamespaceDeclarations() {
    Element element = null;//from w  w w.  j  a v a 2s.co  m
    if (cursor instanceof Element) {
        element = (Element) cursor;
    } else {
        return new ArrayList();
    }
    if (element == cacheNDKey) {
        return cacheND;
    }
    cacheNDKey = element;
    cacheND = new ArrayList();
    NamedNodeMap attrs = element.getAttributes();
    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            Attr attr = (Attr) attrs.item(i);
            String name = attr.getNodeName();
            if (name.startsWith("xmlns")) {
                String prefix = "";
                if (name.startsWith("xmlns:")) {
                    prefix = name.substring(6);
                }
                NamespaceDeclare nd = new NamespaceDeclare(prefix, attr.getNodeValue());
                cacheND.add(nd);
            }
        }
    }
    return cacheND;
}

From source file:org.apache.shindig.gadgets.templates.XmlTemplateLibrary.java

private void processTemplateDef(Builder<TagHandler> handlers, Element defElement)
        throws TemplateParserException {
    Attr tagAttribute = defElement.getAttributeNode(TAG_ATTRIBUTE);
    if (tagAttribute == null) {
        throw new TemplateParserException("Missing tag attribute on TemplateDef");
    }//from   ww  w. j av a 2s.  c  o m

    ImmutableSet.Builder<TemplateResource> resources = ImmutableSet.builder();

    Element scriptElement = (Element) DomUtil.getFirstNamedChildNode(defElement, JAVASCRIPT_TAG);
    if (scriptElement != null) {
        resources.add(TemplateResource.newJavascriptResource(scriptElement.getTextContent(), this));
    }

    Element styleElement = (Element) DomUtil.getFirstNamedChildNode(defElement, STYLE_TAG);
    if (styleElement != null) {
        resources.add(TemplateResource.newStyleResource(styleElement.getTextContent(), this));
    }

    Element templateElement = (Element) DomUtil.getFirstNamedChildNode(defElement, TEMPLATE_TAG);
    TagHandler handler = createHandler(tagAttribute.getNodeValue(), templateElement, resources.build());
    if (handler != null) {
        handlers.add(handler);
    }
}