Example usage for org.w3c.dom NamedNodeMap item

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

Introduction

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

Prototype

public Node item(int index);

Source Link

Document

Returns the indexth item in the map.

Usage

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;//  ww  w.  jav  a  2s .c  o  m
    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 w ww .j  a  v  a 2  s .c o  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: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);
    }//from  w w  w  .j  av 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:com.francelabs.datafari.servlets.admin.FieldWeight.java

private Node run(final NodeList child, final String type) {
    for (int i = 0; i < child.getLength(); i++) {
        String name = "";
        if (child.item(i).hasAttributes()) {
            final NamedNodeMap map = child.item(i).getAttributes();
            for (int j = 0; j < map.getLength(); j++) {
                if (map.item(j).getNodeName().equals("name")) {
                    name = map.item(j).getNodeValue();
                }//from  w w w .  j  a  va  2 s.  c o  m
            }
            if (name.equals(type)) {
                return child.item(i);
            }
        }
        if (child.item(i).hasChildNodes()) {
            if (run(child.item(i).getChildNodes(), type) != null) {
                return run(child.item(i).getChildNodes(), type);
            }
        }
    }
    return null;
}

From source file:com.francelabs.datafari.servlets.admin.FieldWeight.java

/**
 * Retrieve the default search handler '/select' from a list of request
 * handlers/*from   www. j  av a 2 s  .  com*/
 *
 * @param requestHandlers
 * @return the search handler or null if not found
 */
private Node getSearchHandler(final NodeList requestHandlers) {
    for (int i = 0; i < requestHandlers.getLength(); i++) {

        final Node rh = requestHandlers.item(i);
        if (rh.hasAttributes()) {
            final NamedNodeMap rhAttributes = rh.getAttributes();
            for (int j = 0; j < rhAttributes.getLength(); j++) {
                if (rhAttributes.item(j).getNodeName().equals("name")
                        && rhAttributes.item(j).getNodeValue().equals("/select")) {
                    return rh;
                }
            }
        }

    }
    return null;
}

From source file:com.portfolio.data.attachment.XSLService.java

public Connection getConnection()
        throws ParserConfigurationException, SAXException, IOException, SQLException, ClassNotFoundException {
    // Open META-INF/context.xml
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document doc = documentBuilder.parse(sc.getRealPath("/") + "/META-INF/context.xml");
    NodeList res = doc.getElementsByTagName("Resource");
    Node dbres = res.item(0);/*from  w  w  w .ja v  a  2 s . c o  m*/

    Properties info = new Properties();
    NamedNodeMap attr = dbres.getAttributes();
    String url = "";
    for (int i = 0; i < attr.getLength(); ++i) {
        Node att = attr.item(i);
        String name = att.getNodeName();
        String val = att.getNodeValue();
        if ("url".equals(name))
            url = val;
        else if ("username".equals(name)) // username (context.xml) -> user (properties)
            info.put("user", val);
        else if ("driverClassName".equals(name))
            Class.forName(val);
        else
            info.put(name, val);
    }

    return DriverManager.getConnection(url, info);
}

From source file:org.dasein.cloud.terremark.Terremark.java

private Organization toOrg(Document doc) throws CloudException {
    Logger logger = getLogger(Terremark.class);
    Organization org = new Organization();
    NodeList blocks = doc.getElementsByTagName("Organization");
    if (blocks == null) {
        throw new CloudException("Did not find any organizations");
    } else if (blocks.getLength() > 1) {
        logger.warn(//  www.  j  a v  a 2  s.c o  m
                "There is more than one organization in this account. This must be a reseller account. Only using the first organization.");
    }

    Node organization = blocks.item(0);
    NamedNodeMap attributes = organization.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node node = attributes.item(i);
        if (node.getNodeName().equals(Terremark.HREF)) {
            org.setId(hrefToId(node.getNodeValue()));
        } else if (node.getNodeName().equals(Terremark.NAME)) {
            org.setName(node.getNodeValue());
        }
    }

    return org;
}

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

private DataField loadField(Element anElement) {
    Attr nodeAttr;// w  ww.  j  ava  2 s  .c om
    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:de.bayern.gdi.services.Atom.java

private ArrayList<String> getCRS(Node entry) {
    ArrayList<String> crs = new ArrayList<>();
    //Predefined in ATOM Service
    String getCategories = "category";
    NodeList cL = (NodeList) XML.xpath(entry, getCategories, XPathConstants.NODESET, this.nscontext);
    for (int i = 0; i < cL.getLength(); i++) {
        Node cat = cL.item(i);//from  ww  w.  jav  a2s  .com
        NamedNodeMap catAttributes = cat.getAttributes();
        String epsg = null;
        for (int j = 0; j < catAttributes.getLength(); j++) {
            Node catAttr = catAttributes.item(j);
            if (catAttr.getNodeName().equals("label")) {
                epsg = catAttr.getTextContent();
                crs.add(epsg);
            }
        }
    }
    return crs;
}

From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java

private void gothroughPlaceHolders(Document templateDocument, TemplateContext templateContext)
        throws Exception {
    Element templteViewElement = ViewConfigParserUtils.findViewElement(templateDocument.getDocumentElement(),
            templateContext.getResource());

    Document document = templateContext.getSourceDocument();
    Element viewElement = ViewConfigParserUtils.findViewElement(document.getDocumentElement(),
            templateContext.getSourceContext().getResource());

    NamedNodeMap attributes = viewElement.getAttributes();
    int len = attributes.getLength();
    for (int i = 0; i < len; i++) {
        Node item = attributes.item(i);
        String nodeName = item.getNodeName();
        if (!specialMergeProperties.contains(nodeName)) {
            templteViewElement.setAttribute(nodeName, item.getNodeValue());
        }//from  w  w w .ja  v  a  2 s.co  m
    }

    List<Element> viewProperties = DomUtils.getChildrenByTagName(viewElement, XmlConstants.PROPERTY);
    for (Element propertyElement : viewProperties) {
        String propertyName = propertyElement.getAttribute(XmlConstants.ATTRIBUTE_NAME);
        if (!specialMergeProperties.contains(propertyName)) {
            Element clonedElement = (Element) templateDocument.importNode(propertyElement, true);
            templteViewElement.appendChild(clonedElement);
        }
    }

    mergeMetaData(templateDocument, templteViewElement, viewElement);
    mergeTemplateProperty(templteViewElement, viewElement, ViewXmlConstants.ATTRIBUTE_PACKAGES);
    mergeTemplateProperty(templteViewElement, viewElement, ViewXmlConstants.ATTRIBUTE_JAVASCRIPT_FILE);
    mergeTemplateProperty(templteViewElement, viewElement, ViewXmlConstants.ATTRIBUTE_STYLESHEET_FILE);

    for (Element element : DomUtils.getChildElements(viewElement)) {
        String nodeName = element.getNodeName();
        if (nodeName.equals(XmlConstants.PROPERTY) || nodeName.equals(XmlConstants.GROUP_START)
                || nodeName.equals(XmlConstants.GROUP_END) || nodeName.equals(XmlConstants.IMPORT)
                || nodeName.equals(XmlConstants.GROUP_END) || nodeName.equals(XmlConstants.PLACE_HOLDER_START)
                || nodeName.equals(XmlConstants.PLACE_HOLDER_END)) {
            continue;
        }
        if (componentTypeRegistry.getRegisterInfo(nodeName) == null) {
            Element clonedElement = (Element) templateDocument.importNode(element, true);
            templteViewElement.appendChild(clonedElement);
        }
    }

    processPlaceHolders(templteViewElement, templateContext);
}