Example usage for org.w3c.dom Element getAttributes

List of usage examples for org.w3c.dom Element getAttributes

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttributes.

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:com.ibm.soatf.component.soap.builder.SchemaUtils.java

/**
 * Returns a map mapping urls to corresponding XmlSchema XmlObjects for the
 * specified wsdlUrl/*ww w . ja  va  2s  . c o m*/
 */
public static void getSchemas(final String wsdlUrl, Map<String, XmlObject> existing, SchemaLoader loader,
        String tns) {
    if (existing.containsKey(wsdlUrl)) {
        return;
    }

    log.debug("Getting schema " + wsdlUrl);

    ArrayList<?> errorList = new ArrayList<>();

    Map<String, XmlObject> result = new HashMap<>();

    boolean common = false;

    try {
        XmlOptions options = new XmlOptions();
        options.setCompileNoValidation();
        options.setSaveUseOpenFrag();
        options.setErrorListener(errorList);
        options.setSaveSyntheticDocumentElement(new QName(Constants.XSD_NS, "schema"));

        XmlObject xmlObject = loader.loadXmlObject(wsdlUrl, options);
        if (xmlObject == null)
            throw new Exception("Failed to load schema from [" + wsdlUrl + "]");

        Document dom = (Document) xmlObject.getDomNode();
        Node domNode = dom.getDocumentElement();

        // is this an xml schema?
        if (domNode.getLocalName().equals("schema") && Constants.XSD_NS.equals(domNode.getNamespaceURI())) {
            // set targetNamespace (this happens if we are following an include
            // statement)
            if (tns != null) {
                Element elm = ((Element) domNode);
                if (!elm.hasAttribute("targetNamespace")) {
                    common = true;
                    elm.setAttribute("targetNamespace", tns);
                }

                // check for namespace prefix for targetNamespace
                NamedNodeMap attributes = elm.getAttributes();
                int c = 0;
                for (; c < attributes.getLength(); c++) {
                    Node item = attributes.item(c);
                    if (item.getNodeName().equals("xmlns"))
                        break;

                    if (item.getNodeValue().equals(tns) && item.getNodeName().startsWith("xmlns"))
                        break;
                }

                if (c == attributes.getLength())
                    elm.setAttribute("xmlns", tns);
            }

            if (common && !existing.containsKey(wsdlUrl + "@" + tns))
                result.put(wsdlUrl + "@" + tns, xmlObject);
            else
                result.put(wsdlUrl, xmlObject);
        } else {
            existing.put(wsdlUrl, null);

            XmlObject[] schemas = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:schema");

            for (int i = 0; i < schemas.length; i++) {
                XmlCursor xmlCursor = schemas[i].newCursor();
                String xmlText = xmlCursor.getObject().xmlText(options);
                // schemas[i] = XmlObject.Factory.parse( xmlText, options );
                schemas[i] = XmlUtils.createXmlObject(xmlText, options);
                schemas[i].documentProperties().setSourceName(wsdlUrl);

                result.put(wsdlUrl + "@" + (i + 1), schemas[i]);
            }

            XmlObject[] wsdlImports = xmlObject
                    .selectPath("declare namespace s='" + Constants.WSDL11_NS + "' .//s:import/@location");
            for (int i = 0; i < wsdlImports.length; i++) {
                String location = ((SimpleValue) wsdlImports[i]).getStringValue();
                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1)
                        location = joinRelativeUrl(wsdlUrl, location);

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] wadl10Imports = xmlObject.selectPath(
                    "declare namespace s='" + Constants.WADL10_NS + "' .//s:grammars/s:include/@href");
            for (int i = 0; i < wadl10Imports.length; i++) {
                String location = ((SimpleValue) wadl10Imports[i]).getStringValue();
                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1)
                        location = joinRelativeUrl(wsdlUrl, location);

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] wadlImports = xmlObject.selectPath(
                    "declare namespace s='" + Constants.WADL11_NS + "' .//s:grammars/s:include/@href");
            for (int i = 0; i < wadlImports.length; i++) {
                String location = ((SimpleValue) wadlImports[i]).getStringValue();
                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1)
                        location = joinRelativeUrl(wsdlUrl, location);

                    getSchemas(location, existing, loader, null);
                }
            }
        }

        existing.putAll(result);

        XmlObject[] schemas = result.values().toArray(new XmlObject[result.size()]);
        for (int c = 0; c < schemas.length; c++) {
            xmlObject = schemas[c];

            XmlObject[] schemaImports = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:import/@schemaLocation");
            for (int i = 0; i < schemaImports.length; i++) {
                String location = ((SimpleValue) schemaImports[i]).getStringValue();
                Element elm = ((Attr) schemaImports[i].getDomNode()).getOwnerElement();

                if (location != null && !defaultSchemas.containsKey(elm.getAttribute("namespace"))) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1)
                        location = joinRelativeUrl(wsdlUrl, location);

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] schemaIncludes = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:include/@schemaLocation");
            for (int i = 0; i < schemaIncludes.length; i++) {
                String location = ((SimpleValue) schemaIncludes[i]).getStringValue();
                if (location != null) {
                    String targetNS = getTargetNamespace(xmlObject);

                    if (!location.startsWith("file:") && location.indexOf("://") == -1)
                        location = joinRelativeUrl(wsdlUrl, location);

                    getSchemas(location, existing, loader, targetNS);
                }
            }
        }
    } catch (Exception e) {
        throw new SoapBuilderException(e);
    }
}

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

/**
 * Creates LicenseParamInt object//from  w w w.  j  ava  2s  . c om
 *
 * @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 LicenseParamText object//from   www .j  a v a2 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  w  ww.  j  ava2  s  . co  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

/**
 * Creates LicenseParamDisplay object// w  ww  . 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:com.centeractive.ws.legacy.SchemaUtils.java

/**
 * Returns a map mapping urls to corresponding XmlSchema XmlObjects for the specified wsdlUrl
 *///  w w w.j av  a2 s . co m
public static void getSchemas(String wsdlUrl, Map<String, XmlObject> existing, SchemaLoader loader,
        String tns) {
    if (existing.containsKey(wsdlUrl)) {
        return;
    }

    log.debug("Getting schema " + wsdlUrl);

    ArrayList<?> errorList = new ArrayList<Object>();

    Map<String, XmlObject> result = new HashMap<String, XmlObject>();

    boolean common = false;

    try {
        XmlOptions options = new XmlOptions();
        options.setCompileNoValidation();
        options.setSaveUseOpenFrag();
        options.setErrorListener(errorList);
        options.setSaveSyntheticDocumentElement(new QName(Constants.XSD_NS, "schema"));

        XmlObject xmlObject = loader.loadXmlObject(wsdlUrl, options);
        if (xmlObject == null) {
            throw new Exception("Failed to load schema from [" + wsdlUrl + "]");
        }

        Document dom = (Document) xmlObject.getDomNode();
        Node domNode = dom.getDocumentElement();

        // is this an xml schema?
        if (domNode.getLocalName().equals("schema") && Constants.XSD_NS.equals(domNode.getNamespaceURI())) {
            // set targetNamespace (this happens if we are following an include
            // statement)
            if (tns != null) {
                Element elm = ((Element) domNode);
                if (!elm.hasAttribute("targetNamespace")) {
                    common = true;
                    elm.setAttribute("targetNamespace", tns);
                }

                // check for namespace prefix for targetNamespace
                NamedNodeMap attributes = elm.getAttributes();
                int c = 0;
                for (; c < attributes.getLength(); c++) {
                    Node item = attributes.item(c);
                    if (item.getNodeName().equals("xmlns")) {
                        break;
                    }

                    if (item.getNodeValue().equals(tns) && item.getNodeName().startsWith("xmlns")) {
                        break;
                    }
                }

                if (c == attributes.getLength()) {
                    elm.setAttribute("xmlns", tns);
                }
            }

            if (common && !existing.containsKey(wsdlUrl + "@" + tns)) {
                result.put(wsdlUrl + "@" + tns, xmlObject);
            } else {
                result.put(wsdlUrl, xmlObject);
            }
        } else {
            existing.put(wsdlUrl, null);

            XmlObject[] schemas = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:schema");

            for (int i = 0; i < schemas.length; i++) {

                XmlCursor xmlCursor = schemas[i].newCursor();
                String xmlText = xmlCursor.getObject().xmlText(options);
                // schemas[i] = XmlObject.Factory.parse( xmlText, options );
                schemas[i] = XmlUtils.createXmlObject(xmlText, options);
                schemas[i].documentProperties().setSourceName(wsdlUrl);

                result.put(wsdlUrl + "@" + (i + 1), schemas[i]);
            }

            XmlObject[] wsdlImports = xmlObject
                    .selectPath("declare namespace s='" + Constants.WSDL11_NS + "' .//s:import/@location");
            for (int i = 0; i < wsdlImports.length; i++) {

                String location = ((SimpleValue) wsdlImports[i]).getStringValue();

                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1) {
                        location = joinRelativeUrl(wsdlUrl, location);
                    }

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] wadl10Imports = xmlObject.selectPath(
                    "declare namespace s='" + Constants.WADL10_NS + "' .//s:grammars/s:include/@href");
            for (int i = 0; i < wadl10Imports.length; i++) {
                String location = ((SimpleValue) wadl10Imports[i]).getStringValue();
                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1) {
                        location = joinRelativeUrl(wsdlUrl, location);
                    }

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] wadlImports = xmlObject.selectPath(
                    "declare namespace s='" + Constants.WADL11_NS + "' .//s:grammars/s:include/@href");
            for (int i = 0; i < wadlImports.length; i++) {
                String location = ((SimpleValue) wadlImports[i]).getStringValue();
                if (location != null) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1) {
                        location = joinRelativeUrl(wsdlUrl, location);
                    }

                    getSchemas(location, existing, loader, null);
                }
            }

        }

        existing.putAll(result);

        XmlObject[] schemas = result.values().toArray(new XmlObject[result.size()]);

        for (int c = 0; c < schemas.length; c++) {
            xmlObject = schemas[c];

            XmlObject[] schemaImports = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:import/@schemaLocation");
            for (int i = 0; i < schemaImports.length; i++) {
                String location = ((SimpleValue) schemaImports[i]).getStringValue();
                Element elm = ((Attr) schemaImports[i].getDomNode()).getOwnerElement();

                if (location != null && !defaultSchemas.containsKey(elm.getAttribute("namespace"))) {
                    if (!location.startsWith("file:") && location.indexOf("://") == -1) {
                        location = joinRelativeUrl(wsdlUrl, location);
                    }

                    getSchemas(location, existing, loader, null);
                }
            }

            XmlObject[] schemaIncludes = xmlObject
                    .selectPath("declare namespace s='" + Constants.XSD_NS + "' .//s:include/@schemaLocation");
            for (int i = 0; i < schemaIncludes.length; i++) {
                String location = ((SimpleValue) schemaIncludes[i]).getStringValue();
                if (location != null) {
                    String targetNS = getTargetNamespace(xmlObject);

                    if (!location.startsWith("file:") && location.indexOf("://") == -1) {
                        location = joinRelativeUrl(wsdlUrl, location);
                    }

                    getSchemas(location, existing, loader, targetNS);
                }
            }
        }
    } catch (Exception e) {
        throw new SoapBuilderException(e);
    }
}

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

/**
 * Creates LicenseParamEnum object//  ww w.  j  ava2  s  .co  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:com.microsoft.tfs.core.clients.versioncontrol.workspacecache.WorkspaceInfo.java

/**
 * Creates an instance from the XML representation used in the cache file.
 *
 * @param serverINfo//  ww w. ja v  a2 s.  c  om
 *        the workspace's host server
 * @param workspaceInfoNode
 *        the {@value #XML_WORKSPACE_INFO} node to load from
 * @return an instance of a {@link WorkspaceInfo} created from the XML
 */
public static WorkspaceInfo loadFromXML(final InternalServerInfo serverInfo, final Element workspaceInfoNode) {
    final WorkspaceInfo workspaceInfo = new WorkspaceInfo();
    workspaceInfo.serverInfo = serverInfo;

    final NamedNodeMap attributes = workspaceInfoNode.getAttributes();
    Check.notNull(attributes, "attributes"); //$NON-NLS-1$

    workspaceInfo.name = getStringValue(attributes.getNamedItem(XML_NAME));
    workspaceInfo.ownerName = getStringValue(attributes.getNamedItem(XML_OWNER_NAME));
    workspaceInfo.ownerDisplayName = getStringValue(attributes.getNamedItem(XML_OWNER_DISPLAY_NAME));

    // The "ownerDisplayName" attribute was absent for some users.
    // Expecting it to always exist was causing a NullPointerException.
    // Now, use the "ownerName" if the "ownerDisplayName" is missing.
    if (StringUtil.isNullOrEmpty(workspaceInfo.ownerDisplayName)) {
        workspaceInfo.ownerDisplayName = workspaceInfo.getOwnerName();
    }

    workspaceInfo.computer = getStringValue(attributes.getNamedItem(XML_COMPUTER));
    workspaceInfo.comment = getStringValue(attributes.getNamedItem(XML_COMMENT));
    workspaceInfo.securityToken = getStringValue(attributes.getNamedItem(XML_SECURITY_TOKEN), null);
    workspaceInfo.isLocalWorkspace = getBooleanValue(attributes.getNamedItem(XML_IS_LOCAL_WORKSPACE));
    workspaceInfo.lastSavedCheckinTimeStamp = getTimeStampValue(
            attributes.getNamedItem(XML_LAST_SAVED_CHECKIN_TIME_STAMP));
    workspaceInfo.options = getWorkspaceOptionsValue(attributes.getNamedItem(OPTIONS_NAME));

    for (final Element child : DOMUtils.getChildElements(workspaceInfoNode)) {
        final String name = child.getNodeName();

        if (name.equals(XML_MAPPED_PATHS)) {
            final Element[] mappedPathElements = DOMUtils.getChildElements(child, XML_MAPPED_PATH);
            workspaceInfo.mappedPaths = new String[mappedPathElements.length];

            for (int i = 0; i < mappedPathElements.length; i++) {
                workspaceInfo.mappedPaths[i] = getStringValue(
                        mappedPathElements[i].getAttributes().getNamedItem(XML_PATH));
            }
        } else if (name.equals(XML_WORKING_FOLDERS)) {
            // Backwards compatibility with PDC build of Dev11 (and
            // earlier).
            final Element[] mapElements = DOMUtils.getChildElements(child, XML_MAP);
            workspaceInfo.mappedPaths = new String[mapElements.length];

            for (int i = 0; i < mapElements.length; i++) {
                workspaceInfo.mappedPaths[i] = getStringValue(
                        mapElements[i].getAttributes().getNamedItem(XML_LOCAL_PATH));
            }

            workspaceInfo.state = LocalWorkspaceState.MODIFIED;
        } else if (name.equals(XML_LAST_SAVED_CHECKIN)) {
            Check.isTrue(DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length == 1,
                    MessageFormat.format("Wrong number of LastSavedCheckin children: {0}", //$NON-NLS-1$
                            DOMUtils.getChildElements(child, SavedCheckin.XML_SAVED_CHECKIN).length));
            workspaceInfo.lastSavedCheckin = SavedCheckin
                    .loadFromXML(DOMUtils.getFirstChildElement(child, SavedCheckin.XML_SAVED_CHECKIN));
        } else if (name.equals(XML_OWNER_ALIASES)) {
            final Element[] aliasNodes = DOMUtils.getChildElements(child, XML_OWNER_ALIAS);
            final List<String> aliases = new ArrayList<String>(aliasNodes.length);

            for (int i = 0; i < aliasNodes.length; i++) {
                final String alias = getStringValue(
                        aliasNodes[i].getAttributes().getNamedItem(XML_OWNER_ALIAS));

                if (!StringUtil.isNullOrEmpty(alias)) {
                    aliases.add(alias);
                } else {
                    log.error(MessageFormat.format("Owner alias loaded from cache was null or empty: {0}", //$NON-NLS-1$
                            workspaceInfo));
                }
            }

            workspaceInfo.ownerAliases = aliases.toArray(new String[aliases.size()]);
        } else {
            log.warn(MessageFormat.format("Unknown workspace child node: {0}", name)); //$NON-NLS-1$
        }
    }

    if (workspaceInfo.ownerAliases == null) {
        workspaceInfo.ownerAliases = new String[0];
    }

    // Since we've just loaded the workspace, make sure it is marked as
    // clean.
    workspaceInfo.markClean();

    return workspaceInfo;
}

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

/**
 * Creates LicenseConcludeResponseObject from the concludeLicense operation's response string
 * /*from   www  . j a va  2  s .c o  m*/
 * @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:net.di2e.ecdr.search.transform.atom.security.impl.XmlMetadataSecurityMarkingHandler.java

@Override
public SecurityData getSecurityData(Metacard metacard) {
    String metadata = metacard.getMetadata();
    if (StringUtils.isNotBlank(metadata)) {
        XPathHelper helper = new XPathHelper(metacard.getMetadata());
        Document document = helper.getDocument();
        NodeList nodeList = document.getElementsByTagNameNS("*", "security");
        if (nodeList != null && nodeList.getLength() > 0) {
            Element element = (Element) nodeList.item(0);
            NamedNodeMap nodeNameMap = element.getAttributes();
            int length = nodeNameMap.getLength();

            Map<String, List<String>> securityProps = new HashMap<String, List<String>>();
            String securityNamespace = null;
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr) nodeNameMap.item(i);
                String value = attr.getValue();
                if (!attr.getName().startsWith(XMLNS_PREFIX) && StringUtils.isNotBlank(value)) {
                    securityProps.put(attr.getLocalName(), SecurityMarkingParser.getValues(value));
                    if (securityNamespace == null) {
                        securityNamespace = attr.getNamespaceURI();
                    }//from   ww w  .  java  2 s  .c om
                }
            }
            if (!securityProps.isEmpty()) {
                return new SecurityDataImpl(securityProps, securityNamespace);
            }
        }
    }
    return null;
}