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.esri.geoevent.solutions.adapter.cot.CoTAdapter.java

public static String elementToString(Node n) {

    String name = n.getNodeName();
    short type = n.getNodeType();

    if (Node.CDATA_SECTION_NODE == type) {
        return "<![CDATA[" + n.getNodeValue() + "]]&gt;";
    }//from w  w w  .ja va2 s .  co  m

    if (name.startsWith("#")) {
        return "";
    }

    StringBuffer sb = new StringBuffer();
    sb.append('<').append(name);

    NamedNodeMap attrs = n.getAttributes();
    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            Node attr = attrs.item(i);
            sb.append(' ').append(attr.getNodeName()).append("=\"").append(attr.getNodeValue()).append("\"");
        }
    }

    String textContent = null;
    NodeList children = n.getChildNodes();

    if (children.getLength() == 0) {
        if ((textContent = n.getTextContent()) != null && !"".equals(textContent)) {
            sb.append(textContent).append("</").append(name).append('>');
        } else {
            sb.append("/>").append('\n');
        }
    } else {
        sb.append('>').append('\n');
        boolean hasValidChildren = false;
        for (int i = 0; i < children.getLength(); i++) {
            String childToString = elementToString(children.item(i));
            if (!"".equals(childToString)) {
                sb.append(childToString);
                hasValidChildren = true;
            }
        }

        if (!hasValidChildren && ((textContent = n.getTextContent()) != null)) {
            sb.append(textContent);
        }

        sb.append("</").append(name).append('>');
    }

    return sb.toString();
}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

@SuppressWarnings("unchecked")
private static <E> E coreOperations(final Map<String, Object> environment, final Node root, final String type,
        final RandomGenerator random) throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException {
    final NamedNodeMap atts = root.getAttributes();
    final Node nameNode = atts.getNamedItem(NAME);
    final String name = nameNode == null ? "" : nameNode.getNodeValue();
    if (!name.equals("") && atts.getLength() == 1 && environment.containsKey(name)) {
        return (E) environment.get(name);
    }/*w  w  w  .  j av a 2s. c  om*/
    final Class<?> objClass = (Class<?>) Class.forName(type);
    final List<Constructor<E>> consList = unsafeExtractConstructors(objClass);
    final ArrayList<String> params = new ArrayList<String>();
    int index = 0;
    for (Node param = atts.getNamedItem("p0"); param != null; param = atts.getNamedItem("p" + (++index))) {
        params.add(param.getNodeValue());
    }
    params.trimToSize();
    final E res = tryToBuild(consList, params, environment, random);
    environment.put(name, res);
    return res;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamInt object/*from www .java2  s  . com*/
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamInt createLicenseParamInt(Element parameterElement, String parameterClass) {
    LicenseParamInt lpInt = new LicenseParamInt();
    lpInt.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpInt.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpInt.setTitle(parameterTitleElement.getTextContent());
    }

    Element valueElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0);

    if (valueElement != null) {
        lpInt.setValue(Integer.parseInt(valueElement.getTextContent()));
    }

    return lpInt;
}

From source file:com.twinsoft.convertigo.engine.localbuild.BuildLocally.java

private static Element cloneNode(Node node, String newNodeName) {

    Element newElement = node.getOwnerDocument().createElement(newNodeName);

    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        newElement.setAttribute(attr.getName(), attr.getValue());
    }/*www  .  j a  v  a  2 s .  co  m*/

    return newElement;

}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamDisplay object//from w ww  .  j  av a  2s. com
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamDisplay createLicenseParamDisplay(Element parameterElement, String parameterClass) {
    LicenseParamDisplay lpd = new LicenseParamDisplay();
    lpd.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpd.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpd.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        lpd.addValue(valueElement.getTextContent());

    }

    return lpd;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamText object//from   w w  w.j  a  v  a 2  s  .c  o m
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamText createLicenseParamText(Element parameterElement, String parameterClass) {
    LicenseParamText lpt = new LicenseParamText();
    lpt.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpt.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpt.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        lpt.addValue(valueElement.getTextContent());

    }

    return lpt;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamBln object//from   www .j  a v  a2  s. c om
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamBln createLicenseParamBln(Element parameterElement, String parameterClass) {
    LicenseParamBln lpbln = new LicenseParamBln();
    lpbln.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpbln.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpbln.setTitle(parameterTitleElement.getTextContent());
    }

    Element parameterValueElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0);

    if (parameterValueElement != null) {
        if (parameterValueElement.getTextContent().equals("true")) {
            lpbln.setValue(true);
        } else {
            lpbln.setValue(false);
        }
    }

    return lpbln;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Parses a list of active licenses from GetLicenseReferences response string
 * //from  w  w w  . ja  v a 2  s. c o m
 * @param xml   - xml response
 * @return      - ArrayList of license identifiers that are active
 * @throws Exception
 */
public static ArrayList<String> parseActiveLicensesFromGetLicenseReferencesResponse(String xml)
        throws Exception {
    ArrayList<String> activeLicenses = new ArrayList<String>();

    try {
        Document xmlDoc = createXMLDocumentFromString(xml);

        NodeList licenseReferenceList = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2",
                "LicenseReference");

        for (int i = 0; i < licenseReferenceList.getLength(); i++) {
            Element licenseReferenceElement = (Element) licenseReferenceList.item(i);

            NodeList attributeElementList = licenseReferenceElement
                    .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");

            for (int j = 0; j < attributeElementList.getLength(); j++) {
                Element attributeElement = (Element) attributeElementList.item(j);
                Element attributeValueElement = (Element) attributeElement
                        .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue")
                        .item(0);

                NamedNodeMap attributeMap = attributeElement.getAttributes();

                for (int k = 0; k < attributeMap.getLength(); k++) {
                    Attr attrs = (Attr) attributeMap.item(k);
                    if (attrs.getNodeName().equals("Name")) {

                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) {
                            activeLicenses.add(attributeValueElement.getTextContent());
                        }
                    }

                }

            }

        }

    } catch (Exception e) {
        throw e;
    }

    return activeLicenses;
}

From source file:be.ibridge.kettle.core.XMLHandler.java

/**
 * Get all the attributes in a certain node (on the root level)
 * @param node The node to examine//from  w  w w  .  j av a2 s . c  o m
 * @return an array of strings containing the names of the attributes.
 */
public static String[] getNodeAttributes(Node node) {
    NamedNodeMap nnm = node.getAttributes();
    if (nnm != null) {
        String attributes[] = new String[nnm.getLength()];
        for (int i = 0; i < nnm.getLength(); i++) {
            Node attr = nnm.item(i);
            attributes[i] = attr.getNodeName();
        }
        return attributes;
    }
    return null;

}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamEnum object//from w  ww  .j  av  a 2  s .  c o m
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamEnum createLicenseParamEnum(Element parameterElement, String parameterClass) {

    Boolean multiAttributeValue = false;
    LicenseParamEnum lpEnum = new LicenseParamEnum();
    lpEnum.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpEnum.setName(attrs.getNodeValue());
        }

        if (attrs.getNodeName().equals("multi")) {

            if (attrs.getNodeValue().equals("true")) {
                multiAttributeValue = true;
            } else {
                multiAttributeValue = false;
            }
        }

    }

    lpEnum.setMulti(multiAttributeValue);

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpEnum.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        NamedNodeMap valueElementAttributeMap = valueElement.getAttributes();

        for (int k = 0; k < valueElementAttributeMap.getLength(); k++) {
            Attr attrs = (Attr) valueElementAttributeMap.item(k);

            if (attrs.getNodeName().equals("selected")) {
                if (attrs.getNodeValue().equals("true")) {
                    lpEnum.setDefaultValue(valueElement.getTextContent());
                    lpEnum.addSelection(valueElement.getTextContent());
                }
            }

        }

        lpEnum.addOption(valueElement.getTextContent());
    }

    return lpEnum;
}