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:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamDisplay object/* w w  w  .j  ava2 s  . c o m*/
 *
 * @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  av  a 2  s.c  om*/
 *
 * @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  av  a  2 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  . j  a 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:bridge.toolkit.commands.S1000DConverter.java

/**
 * Receive the node with the refdm, returns the dm file name
 * /* w w w  . j a  va  2  s  .  co m*/
 * @param e
 * @return
 */
public static String gettingDmfilename(Node theAncestor) {
    String dmc = "";
    String modelIdentCode = "";
    String systemDiffCode = "";
    String systemCode = "";
    String subSystemCode = "";
    String subSubSystemCode = "";
    String assyCode = "";
    String disassyCode = "";
    String disassyCodeVariant = "";
    String infoCode = "";
    String infoCodeVariant = "";
    String itemLocationCode = "";
    String learnCode = "";
    String learnEventCode = "";

    String countryIsoCode = "";
    String languageIsoCode = "";
    String issueinfo = "";
    String inwork = "";

    Node e = null;
    // looking for dmCode...
    for (int sons = 0; sons < theAncestor.getChildNodes().getLength(); sons++) {
        if (theAncestor.getChildNodes().item(sons) != null
                && theAncestor.getChildNodes().item(sons).getNodeName().equals("dmRefIdent")) {
            for (int sons2 = 0; sons2 < theAncestor.getChildNodes().item(sons).getChildNodes()
                    .getLength(); sons2++) {
                if (theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2) != null
                        && theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2).getNodeName()
                                .equals("dmCode")) {
                    e = theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2);
                    // building the file name structure
                    dmc = "DMC-";
                    NamedNodeMap atts = e.getAttributes();
                    for (int i = 0; i < atts.getLength(); i++) {
                        if (atts.item(i).getNodeName() == "modelIdentCode")
                            modelIdentCode = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "systemDiffCode")
                            systemDiffCode = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "systemCode")
                            systemCode = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "subSystemCode")
                            subSystemCode = atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "subSubSystemCode")
                            subSubSystemCode = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "assyCode")
                            assyCode = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "disassyCode")
                            disassyCode = atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "disassyCodeVariant")
                            disassyCodeVariant = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "infoCode")
                            infoCode = atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "infoCodeVariant")
                            infoCodeVariant = atts.item(i).getNodeValue() + "-";

                        if (atts.item(i).getNodeName() == "itemLocationCode")
                            if (atts.getLength() > 11)
                                itemLocationCode = atts.item(i).getNodeValue() + "-";
                            else
                                itemLocationCode = atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "learnCode")
                            learnCode = atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "learnEventCode")
                            learnEventCode = atts.item(i).getNodeValue();
                    }
                }

                if (theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2) != null
                        && theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2).getNodeName()
                                .equals("language")) {
                    e = theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2);
                    NamedNodeMap atts = e.getAttributes();
                    for (int i = 0; i < atts.getLength(); i++) {
                        if (atts.item(i).getNodeName() == "countryIsoCode")
                            countryIsoCode = "-" + atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "languageIsoCode")
                            languageIsoCode = "_" + atts.item(i).getNodeValue();
                    }

                }

                if (theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2) != null
                        && theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2).getNodeName()
                                .equals("issueInfo")) {
                    e = theAncestor.getChildNodes().item(sons).getChildNodes().item(sons2);
                    NamedNodeMap atts = e.getAttributes();
                    for (int i = 0; i < atts.getLength(); i++) {
                        if (atts.item(i).getNodeName() == "issueNumber")
                            issueinfo = "_" + atts.item(i).getNodeValue();

                        if (atts.item(i).getNodeName() == "inWork")
                            inwork = "-" + atts.item(i).getNodeValue();
                    }

                }

            }
            if (e != null)
                break;
        }
    }

    if (e == null)
        return "";
    return dmc + modelIdentCode + systemDiffCode + systemCode + subSystemCode + subSubSystemCode + assyCode
            + disassyCode + disassyCodeVariant + infoCode + infoCodeVariant + itemLocationCode + learnCode
            + learnEventCode + issueinfo + inwork + languageIsoCode + countryIsoCode;
}

From source file:AndroidUninstallStock.java

public static HashMap<String, String> getXmlAttributes(Node node) {
    HashMap<String, String> res = new HashMap<String, String>();
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null) {
        return res;
    }//ww  w  .  j  a  v a  2  s .  c o  m
    for (int x = attrs.getLength() - 1; x > -1; x--) {
        res.put(attrs.item(x).getNodeName(), attrs.item(x).getNodeValue());
    }
    return res;
}

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

/**
 * Creates LicenseParamEnum object/*from  w ww  . j  a v a  2s  .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;
}

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

/**
 * Creates List of LicenseModelGroup objects
 *
 * @param productGroupElementList - List of <ns:productGroup> elements
 * @return list of LicenseModelGroup objects
 *///w w  w.jav a  2 s  .  c om
private static List<LicenseModelGroup> createLicenseModelGroupList(NodeList productGroupElementList) {
    List<LicenseModelGroup> lmgList = new ArrayList<LicenseModelGroup>();

    for (int i = 0; i < productGroupElementList.getLength(); i++) {
        LicenseModelGroup tempLMG = new LicenseModelGroup();
        Boolean isAccountGroup = false;

        Element productGroupElement = (Element) productGroupElementList.item(i);

        NamedNodeMap productGroupElementAttributeMap = productGroupElement.getAttributes();

        for (int j = 0; j < productGroupElementAttributeMap.getLength(); j++) {
            Attr attrs = (Attr) productGroupElementAttributeMap.item(j);

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

                if (attrs.getNodeValue().equals("ACCOUNTING_SUMMARY_GROUP")) { // Skip element with id="ACCOUNTING_SUMMARY_GROUP" -  do not add to the list
                    isAccountGroup = true;
                }

                if (attrs.getNodeName() != null) {
                    tempLMG.setId(attrs.getNodeValue());
                }
            }
            if (attrs.getNodeName().equals("name")) {
                if (attrs.getNodeName() != null) {
                    tempLMG.setUrl(attrs.getNodeValue());
                }
            }
        }

        if (isAccountGroup == true) {
            continue; // Skip element with id="ACCOUNTING_SUMMARY_GROUP" -  do not add to the list
        }

        Element abstractElement = (Element) productGroupElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "abstract").item(0);
        if (abstractElement != null) {
            tempLMG.setDescription(abstractElement.getTextContent());
        }

        Element titleElement = (Element) productGroupElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);
        if (titleElement != null) {
            tempLMG.setName(titleElement.getTextContent());
        }

        NodeList productElementList = productGroupElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "product");
        tempLMG.setLicenseModels(createLicenseModelList(productElementList));

        lmgList.add(tempLMG);
    }

    return lmgList;
}

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  ww  w.  j  av  a2s.co  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

public static UserLicenses parseUserLicensesAsLicenseModelGroupList(String xml, String userid)
        throws Exception {
    UserLicenses userLicenses = new UserLicenses();

    try {/*from w ww .  jav a2 s . c om*/
        Document xmlDoc = createXMLDocumentFromString(xml);

        Element ordersElement = (Element) xmlDoc
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "orders").item(0);
        NodeList orderList = ordersElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "order");

        for (int i = 0; i < orderList.getLength(); i++) {
            UserLicense userLicense = new UserLicense();
            try {
                Element orderElement = (Element) orderList.item(i);
                Element productionElement = (Element) orderElement
                        .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "production").item(0);
                Element productionItemElement = (Element) productionElement
                        .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productionItem").item(0);
                Element LicenseReferenceElement = (Element) productionItemElement
                        .getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference")
                        .item(0);
                Element attributeStatementElement = (Element) LicenseReferenceElement
                        .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeStatement")
                        .item(0);

                NodeList attributeElementList = attributeStatementElement
                        .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 ("Name".equals(attrs.getNodeName())) {

                            if ("urn:opengeospatial:ows4:geodrm:NotOnOrAfter".equals(attrs.getNodeValue())) {
                                userLicense.setValidTo(AttributeValueElement.getTextContent());
                            }
                            if ("urn:opengeospatial:ows4:geodrm:LicenseID".equals(attrs.getNodeValue())) {
                                userLicense.setLicenseId(AttributeValueElement.getTextContent());
                            }
                        }
                    }
                    userLicense.setSecureServiceURL("/httpauth/licid-" + userLicense.getLicenseId());
                }

                Element orderContentElement = (Element) orderElement
                        .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "orderContent").item(0);
                Element catalogElement = (Element) orderContentElement
                        .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "catalog").item(0);
                NodeList productGroupElementList = catalogElement
                        .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productGroup");

                // setup user license flags in models
                List<LicenseModelGroup> list = createLicenseModelGroupList(productGroupElementList);
                for (LicenseModelGroup group : list) {
                    group.setUserLicense(true);
                }
                userLicense.setLmgList(list);

                String WSS_URL = findWssUrlFromUserLicenseParamList(userLicense.getLmgList());

                //Remove WSS from the WSS-url string
                WSS_URL = WSS_URL.substring(0, WSS_URL.lastIndexOf("/"));

                userLicense.setSecureServiceURL(WSS_URL + userLicense.getSecureServiceURL());

                userLicenses.addUserLicense(userLicense);
            } catch (Exception e) {
                // Sometimes we get results without LicenseReference element: order/production/productionItem/LicenseReference
                // there might be valid results in the same response. Skipping the invalid ones.
                LOG.warn("Error while parsing user licenses");
            }

        }

        return userLicenses;

    } catch (Exception e) {
        throw e;
    }
}