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

/**
 * Creates LicenseParamInt object/*from   w w w.j  a va2s.  c  o  m*/
 *
 * @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:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamDisplay object/*from   w  w  w.  j  a v  a 2s .c  om*/
 *
 * @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  2s .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   w w  w .jav  a 2 s.c o m*/
 *
 * @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   www .ja va  2  s.  co  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:eu.elf.license.LicenseParser.java

/**
 * Creates List of LicenseModelGroup objects
 *
 * @param productGroupElementList - List of <ns:productGroup> elements
 * @return list of LicenseModelGroup objects
 *//*ww w.ja  v  a 2  s.  com*/
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:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamEnum object/*from  w ww . ja  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 LicenseConcludeResponseObject from the concludeLicense operation's response string
 * //from www  . j a v  a 2s.com
 * @param response
 * @return
 * @throws Exception
 */
public static LicenseConcludeResponseObject parseConcludeLicenseResponse(String response) throws Exception {
    LicenseConcludeResponseObject lcro = new LicenseConcludeResponseObject();

    try {
        Document xmlDoc = LicenseParser.createXMLDocumentFromString(response);
        NodeList LicenseReferenceNL = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2",
                "LicenseReference");

        for (int i = 0; i < LicenseReferenceNL.getLength(); i++) {
            Element attributeStatementElement = (Element) LicenseReferenceNL.item(i);

            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
                        .getElementsByTagName("AttributeValue").item(0);

                NamedNodeMap licenseReferenceElementAttributeMap = attributeElement.getAttributes();

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

                    if (attrs.getNodeName().equals("Name")) {
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:NotOnOrAfter")) {
                            lcro.setValidTo(AttributeValueElement.getTextContent());
                        }
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:ProductID")) {
                            lcro.setProductId(AttributeValueElement.getTextContent());
                        }
                        if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) {
                            lcro.setLicenseId(AttributeValueElement.getTextContent());
                        }
                    }

                }

            }

        }

    } catch (Exception e) {
        throw e;
    }

    return lcro;
}

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

/**
 * Creates list of license model parameters
 *
 * @param declarationListElement - XML element <x:declarationList>
 * @return List of LicenseParam objects//  ww  w .  j  a  v a 2 s  .c  o  m
 */
private static List<LicenseParam> createLicenseModelParamList(Element declarationListElement) {
    List<LicenseParam> paramList = new ArrayList<LicenseParam>();

    // Predefined Parameters - create as LicenseParamDisplay objects
    Element predefinedParametersElement = (Element) declarationListElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "predefinedParameters").item(0);

    if (predefinedParametersElement != null) {
        NodeList predefinedParametersParameterElementList = predefinedParametersElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter");

        for (int n = 0; n < predefinedParametersParameterElementList.getLength(); n++) {
            Element parameterElement = (Element) predefinedParametersParameterElementList.item(n);

            LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement,
                    "predefinedParameter");
            paramList.add(displayParam);

        }
    }

    // Configuration Parameters - might be LicenseParamDisplay || LicenseParamBln || LicenseParamEnum || LicenseParamInt || LicenseParamText
    Element configurationParametersElement = (Element) declarationListElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "configurationParameters").item(0);

    if (configurationParametersElement != null) {
        NodeList configurationParametersParameterElementList = configurationParametersElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter");

        for (int n = 0; n < configurationParametersParameterElementList.getLength(); n++) {
            Element parameterElement = (Element) configurationParametersParameterElementList.item(n);

            LicenseParam lp = null;
            Boolean isStringType = false;
            Boolean multiAttributeExists = false; // true for enumration type parameters
            //Boolean multiAttributeValue = false; // value of the multi attribute 
            //Boolean optionalAttribute = false;  // What does optional attribute signify???

            NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

            // Create appropriate subclass object based on the "type" and "multi" attributes
            for (int o = 0; o < parameterElementAttributeMap.getLength(); o++) {
                Attr attrs = (Attr) parameterElementAttributeMap.item(o);

                if (attrs.getNodeName().equals("type")) {
                    if (attrs.getNodeValue().equals("real")) {
                        lp = createLicenseParamInt(parameterElement, "configurationParameter");
                        paramList.add(lp);
                        //System.out.println("lp - name "+lpInt.getName());
                    } else if (attrs.getNodeValue().equals("string")) {
                        isStringType = true;
                    } else if (attrs.getNodeValue().equals("boolean")) {
                        lp = createLicenseParamBln(parameterElement, "configurationParameter");
                        paramList.add(lp);
                    }

                }
                if (attrs.getNodeName().equals("multi")) {
                    multiAttributeExists = true;
                    //if (attrs.getNodeValue().equals("true")) {

                    //multiAttributeValue = true;
                    //}
                    //else {
                    //multiAttributeExists = false;
                    //multiAttributeValue = false;
                    //}
                }
                // if (attrs.getNodeName().equals("optional")) {
                //    if (attrs.getNodeName().equals("true")) {
                //       optionalAttribute = true;
                //    }
                //    else {
                //       optionalAttribute = false;
                //    }
                // }

            }

            if (isStringType == true) {
                if (multiAttributeExists == true) {
                    lp = createLicenseParamEnum(parameterElement, "configurationParameter");
                    paramList.add(lp);

                    //if (optionalAttribute == true) {
                    //   
                    //    lp = createLicenseParamEnum(parameterElement, "configurationParameter");
                    //     paramList.add(lp);
                    //} 
                } else {
                    lp = createLicenseParamText(parameterElement, "configurationParameter");
                    paramList.add(lp);
                }
            }

        }
    }

    // Precalculated Parameters - create as LicenseParamDisplay objects
    Element precalculatedParametersElement = (Element) declarationListElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "precalculatedParameters").item(0);

    if (precalculatedParametersElement != null) {
        NodeList precalculatedParametersParameterElementList = precalculatedParametersElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter");

        for (int n = 0; n < precalculatedParametersParameterElementList.getLength(); n++) {
            Element parameterElement = (Element) precalculatedParametersParameterElementList.item(n);

            LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement,
                    "precalculatedParameter");
            paramList.add(displayParam);

        }
    }

    // Result Parameters - create as LicenseParamDisplay objects
    Element resultParametersElement = (Element) declarationListElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "resultParameters").item(0);

    if (resultParametersElement != null) {
        NodeList resultParametersParameterElementList = resultParametersElement
                .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter");

        for (int n = 0; n < resultParametersParameterElementList.getLength(); n++) {
            Element parameterElement = (Element) resultParametersParameterElementList.item(n);

            LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement, "resultParameter");
            paramList.add(displayParam);

        }
    }

    return paramList;
}

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

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

    try {//  w  w  w.j  a va 2 s .  c o  m
        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;
    }
}