Example usage for org.w3c.dom Node getLocalName

List of usage examples for org.w3c.dom Node getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Node getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Context element// www  .  jav  a 2s .co  m
 * 
 * @param element the Context element
 * @param definitions the definitions data object to resolve the reference attributes
 * @return Context data object
 * @throws InkMLException
 */
protected Context getContext(final Element element, final Definitions definitions) throws InkMLException {
    final Context context = new Context();
    // set value of the object from the value of the DOM element
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        context.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }
    final NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        final Node node = list.item(i);
        if (!(node instanceof Element)) {
            continue;
        }
        final Element child = (Element) node;
        this.addToContextChildrenList(child, context, definitions);
    }
    return context;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Channel element/*  w ww  . j  a  va 2s  .  co m*/
 * 
 * @param channelElement Channel element
 * @return Channel data object
 * @throws InkMLException
 */
protected Channel getChannel(final Element channelElement) throws InkMLException {
    Channel channel = null;
    final String chnName = channelElement.getAttribute("name");
    if ("".equals(chnName)) {
        throw new InkMLException("Channel element must have value for 'name' attribute");
    } else {
        channel = new Channel(chnName);
    }
    // checking for intermittend channel
    if ("intermittentChannels".equalsIgnoreCase(channelElement.getParentNode().getLocalName())) {
        channel.setIntermittent(true);
    }

    // Extract and set Attribute values
    final NamedNodeMap attrMap = channelElement.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        channel.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }
    return channel;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind Trace element//from w w  w .  j  a v a 2  s. c om
 * 
 * @param element the Trace element
 * @return Trace data object
 * @throws InkMLException
 */
protected Trace getTrace(final Element element) throws InkMLException {
    final Trace trace = new Trace();
    // set value of the object from the value of the DOM element
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        trace.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }
    // get trace data
    String traceText = "";
    final NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
            traceText += nl.item(i).getNodeValue();
        }
    }
    final Ink ink = this.inkMLProcessor.getInk();
    final Context currCtx = ink.getCurrentContext();
    final Definitions defs = ink.getDefinitions();
    trace.resolveAssociatedContext(currCtx, defs);
    trace.processTraceElement(traceText, currCtx, defs);

    return trace;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind InkSource.ActiveArea element
 * //from ww w  .  j a v a 2  s .co  m
 * @param element the InkSource.ActiveArea element
 * @param inkSrc the enclosing InkSource data object
 * @return InkSource.ActiveArea data object
 * @throws InkMLException
 */
protected InkSource.ActiveArea getActiveArea(final Element element, final InkSource inkSrc)
        throws InkMLException {
    final InkSource.ActiveArea activeArea = inkSrc.new ActiveArea();
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        final String attrName = attr.getLocalName();
        if ("size".equals(attrName)) {
            activeArea.setSize(attr.getNodeValue());
        }
        if ("height".equals(attrName)) {
            activeArea.setHegiht(Double.valueOf(attr.getNodeValue()).doubleValue());
        }
        if ("width".equals(attrName)) {
            activeArea.setWidth(Double.valueOf(attr.getNodeValue()).doubleValue());
        }
        if ("units".equals(attrName)) {
            activeArea.setUnits(attr.getNodeValue());
        }
    }
    return activeArea;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind CanvasTransform element
 * /*from w w w  . ja va2 s .c  o  m*/
 * @param element the CanvasTransform element
 * @return CanvasTransform data object
 * @throws InkMLException
 */
protected CanvasTransform getCanvasTransform(final Element element) throws InkMLException {
    final CanvasTransform canvasTransform = new CanvasTransform();
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        canvasTransform.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }

    final NodeList list = element.getElementsByTagName("mapping");
    final int nMappingChildren = list.getLength();
    if (nMappingChildren == 2) {
        canvasTransform.setForwardMapping(this.getMapping((Element) list.item(0)));
        canvasTransform.setReverseMapping(this.getMapping((Element) list.item(1)));
    } else if (nMappingChildren == 1) {
        canvasTransform.setForwardMapping(this.getMapping((Element) list.item(0)));
    }
    return canvasTransform;
}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/**
 * Method to bind InkSource element/*from   w  ww.  j a v a 2  s. c o  m*/
 * 
 * @param element the InkSource element
 * @param definitions the definitions data object to resolve the reference attributes
 * @return InkSource data object
 * @throws InkMLException
 */
protected InkSource getInkSource(final Element element, final Definitions definitions) throws InkMLException {
    final InkSource inkSrc = new InkSource();
    // Extract and set Attribute values
    final NamedNodeMap attrMap = element.getAttributes();
    final int length = attrMap.getLength();
    for (int i = 0; i < length; i++) {
        final Node attr = attrMap.item(i);
        inkSrc.setAttribute(attr.getLocalName(), attr.getNodeValue());
    }

    NodeList list = element.getElementsByTagName("traceFormat");
    if (list.getLength() != 0) {
        inkSrc.setTraceFormat(this.getTraceFormat((Element) list.item(0), definitions));
    }

    list = element.getElementsByTagName("sampleRate");
    if (list.getLength() != 0) {
        inkSrc.setSampleRate(this.getSampleRate((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("latency");
    if (list.getLength() != 0) {
        inkSrc.setLatency(this.getLatency((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("activeArea");
    if (list.getLength() != 0) {
        inkSrc.setActiveArea(this.getActiveArea((Element) list.item(0), inkSrc));
    }
    list = element.getElementsByTagName("srcProperty");
    for (int i = 0; i < list.getLength(); i++) {
        inkSrc.addSourceProperty(this.getSourceProperty((Element) list.item(i), inkSrc));
    }
    list = element.getElementsByTagName("channelProperties");
    if (list.getLength() != 0) {
        inkSrc.setChannelProperties(this.getChannelProperties((Element) list.item(0), inkSrc));
    }
    return inkSrc;
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private SOAPElement addSoapElement(Context context, SOAPEnvelope se, SOAPElement soapParent, Node node)
        throws Exception {
    String prefix = node.getPrefix();
    String namespace = node.getNamespaceURI();
    String nodeName = node.getNodeName();
    String localName = node.getLocalName();
    String value = node.getNodeValue();

    boolean includeResponseElement = true;
    if (context.sequenceName != null) {
        includeResponseElement = ((Sequence) context.requestedObject).isIncludeResponseElement();
    }/*from w w w . j  av a 2 s.co m*/

    SOAPElement soapElement = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;

        boolean toAdd = true;
        if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
            toAdd = false;
        }
        if ("http://schemas.xmlsoap.org/soap/envelope/".equals(element.getParentNode().getNamespaceURI())
                || "http://schemas.xmlsoap.org/soap/envelope/".equals(namespace)
                || nodeName.toLowerCase().endsWith(":envelope") || nodeName.toLowerCase().endsWith(":body")
        //element.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 ||
        //nodeName.toUpperCase().indexOf("NS0:") != -1
        ) {
            toAdd = false;
        }

        if (toAdd) {
            if (prefix == null || prefix.equals("")) {
                soapElement = soapParent.addChildElement(nodeName);
            } else {
                soapElement = soapParent.addChildElement(se.createName(localName, prefix, namespace));
            }
        } else {
            soapElement = soapParent;
        }

        if (soapElement != null) {
            if (soapParent.equals(se.getBody()) && !soapParent.equals(soapElement)) {
                if (XsdForm.qualified == context.project.getSchemaElementForm()) {
                    if (soapElement.getAttribute("xmlns") == null) {
                        soapElement.addAttribute(se.createName("xmlns"), context.project.getTargetNamespace());
                    }
                }
            }

            if (element.hasAttributes()) {
                String attrType = element.getAttribute("type");
                if (("attachment").equals(attrType)) {
                    if (context.requestedObject instanceof AbstractHttpTransaction) {
                        AttachmentDetails attachment = AttachmentManager.getAttachment(element);
                        if (attachment != null) {
                            byte[] raw = attachment.getData();
                            if (raw != null)
                                soapElement.addTextNode(Base64.encodeBase64String(raw));
                        }

                        /* DON'T WORK YET *\
                        AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), element.getAttribute("content-type"));
                        ap.setContentId(key);
                        ap.setContentLocation(element.getAttribute("url"));
                        responseMessage.addAttachmentPart(ap);
                        \* DON'T WORK YET */
                    }
                }

                if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
                    // do not add attributes
                } else {
                    NamedNodeMap attributes = element.getAttributes();
                    int len = attributes.getLength();
                    for (int i = 0; i < len; i++) {
                        Node item = attributes.item(i);
                        addSoapElement(context, se, soapElement, item);
                    }
                }
            }

            if (element.hasChildNodes()) {
                NodeList childNodes = element.getChildNodes();
                int len = childNodes.getLength();
                for (int i = 0; i < len; i++) {
                    Node item = childNodes.item(i);
                    switch (item.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        addSoapElement(context, se, soapElement, item);
                        break;
                    case Node.CDATA_SECTION_NODE:
                    case Node.TEXT_NODE:
                        String text = item.getNodeValue();
                        text = (text == null) ? "" : text;
                        soapElement.addTextNode(text);
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
        if (prefix == null || prefix.equals("")) {
            soapElement = soapParent.addAttribute(se.createName(nodeName), value);
        } else {
            soapElement = soapParent.addAttribute(se.createName(localName, prefix, namespace), value);
        }
    }
    return soapElement;
}

From source file:dk.statsbiblioteket.doms.central.connectors.fedora.FedoraRest.java

@Override
public List<FedoraRelation> getNamedRelations(String pid, String predicate, Long asOfTime)
        throws BackendMethodFailedException, BackendInvalidCredsException, BackendInvalidResourceException {
    ArrayList<FedoraRelation> result = new ArrayList<FedoraRelation>();
    try {/*from  w  w  w .j  a v  a2  s. c  o m*/
        //TODO handle RELS-INT
        pid = cleanInfo(pid);
        XPathSelector xpath = DOM.createXPathSelector("rdf", Constants.NAMESPACE_RDF);

        Document relsDoc = DOM.stringToDOM(getXMLDatastreamContents(pid, "RELS-EXT", asOfTime), true);

        NodeList relationNodes = xpath.selectNodeList(relsDoc, "/rdf:RDF/rdf:Description/*");
        if (predicate != null) {
            predicate = getAbsoluteURIAsString(predicate);
        }
        for (int i = 0; i < relationNodes.getLength(); i++) {
            Node relationNode = relationNodes.item(i);
            final String nodeName = relationNode.getNamespaceURI() + relationNode.getLocalName();
            if (predicate == null || nodeName.equals(predicate)) {

                final Node resource = relationNode.getAttributes().getNamedItemNS(Constants.NAMESPACE_RDF,
                        "resource");
                //The resource will have the info:fedora/ prefix if not literal
                if (resource != null) {
                    result.add(new FedoraRelation(toUri(pid), nodeName, resource.getNodeValue()));
                } else {
                    final FedoraRelation fedoraRelation = new FedoraRelation(toUri(pid), nodeName,
                            relationNode.getTextContent());
                    fedoraRelation.setLiteral(true);
                    result.add(fedoraRelation);
                }

            }
        }
    } catch (BackendInvalidResourceException e) {
        if (exists(pid, asOfTime)) {
            //does not have a RELS-EXT datastream. This is not really an error
            return result;
        } else {
            throw new BackendInvalidResourceException("Object '" + pid + "' does not exist", e);
        }
    }
    return result;

}

From source file:javax.microedition.ims.core.xdm.XDMServiceImpl.java

private URIListData handleListNode(Node listNode) {

    URIListDataBean retValue;//www .  j ava  2 s  .  c om

    if (listNode != null) {

        if (!LIST_NODE_NAME.equalsIgnoreCase(listNode.getLocalName())) {
            throw new IllegalArgumentException("Must be 'list' listNode");
        }

        if (listNode.getNodeType() == Node.ELEMENT_NODE) {
            Element listElement = (Element) listNode;

            NodeList displayNameNode = listElement.getElementsByTagNameNS("*", "display-name");
            String displayName = /* "" */null;

            for (int entrIndex = 0; entrIndex < displayNameNode.getLength(); entrIndex++) {
                if (displayNameNode.item(entrIndex).getNodeType() == Node.ELEMENT_NODE) {

                    Element entryElement = (Element) displayNameNode.item(entrIndex);
                    if (LIST_NODE_NAME.equalsIgnoreCase(entryElement.getParentNode().getLocalName())) {

                        final Node firstChildNode = entryElement.getFirstChild();
                        if (firstChildNode != null) {
                            displayName = firstChildNode.getNodeValue();
                        }
                        break;
                    }
                }
            }

            String name = listElement.getAttribute("name");

            List<ListEntryData> listEntryData = new ArrayList<ListEntryData>();

            // extracts single user URI
            {
                NodeList entryNode = listElement.getElementsByTagNameNS("*", "entry");
                for (int entrIndex = 0; entrIndex < entryNode.getLength(); entrIndex++) {
                    if (entryNode.item(entrIndex).getNodeType() == Node.ELEMENT_NODE) {
                        Element entryElement = (Element) entryNode.item(entrIndex);
                        if (LIST_NODE_NAME.equalsIgnoreCase(entryElement.getParentNode().getLocalName())) {
                            String entryURI = entryElement.getAttribute("uri");
                            NodeList entryDisplayNameNode = entryElement.getElementsByTagNameNS("*",
                                    "display-name");
                            String entryDisplayName = null/* "" */;
                            if (entryDisplayNameNode.getLength() > 0) {
                                Node node = entryDisplayNameNode.item(0);
                                final Node firstChildNode = node.getFirstChild();
                                if (firstChildNode != null) {
                                    entryDisplayName = firstChildNode.getNodeValue();
                                }
                            }

                            listEntryData.add(
                                    new ListEntryDataBean(ListEntryData.URI_ENTRY, entryDisplayName, entryURI));
                        }
                    }
                }
            }

            // extracts references to an already existing URI list
            {
                NodeList externalsNode = listElement.getElementsByTagNameNS("*", "external");
                for (int entrIndex = 0; entrIndex < externalsNode.getLength(); entrIndex++) {
                    if (externalsNode.item(entrIndex).getNodeType() == Node.ELEMENT_NODE) {
                        Element externalElement = (Element) externalsNode.item(entrIndex);
                        if (LIST_NODE_NAME.equalsIgnoreCase(externalElement.getParentNode().getLocalName())) {
                            String anchorURI = externalElement.getAttribute("anchor");
                            NodeList anchorDisplayNameNode = externalElement.getElementsByTagNameNS("*",
                                    "display-name");
                            String anchorDisplayName = null/* "" */;
                            if (anchorDisplayNameNode.getLength() > 0) {
                                Node node = anchorDisplayNameNode.item(0);
                                final Node firstChildNode = node.getFirstChild();
                                if (firstChildNode != null) {
                                    anchorDisplayName = firstChildNode.getNodeValue();
                                }
                            }

                            listEntryData.add(new ListEntryDataBean(ListEntryData.URI_LIST_ENTRY,
                                    anchorDisplayName, anchorURI));
                        }
                    }
                }
            }

            retValue = new URIListDataBean(displayName, name, listEntryData);

        } else {
            throw new IllegalArgumentException(
                    "only " + Node.ELEMENT_NODE + " is allowed as parameter. Passed " + listNode.getNodeType());
        }
    } else {
        throw new NullPointerException("listNode is null. Null is not allowed here.");
    }

    return retValue;
}

From source file:ch.entwine.weblounge.common.impl.site.SiteImpl.java

/**
 * Initializes this site from an XML node that was generated using
 * {@link #toXml()}./*  w w  w .  j  a v  a  2  s  .  c  o m*/
 * 
 * @param config
 *          the site node
 * @param xpathProcessor
 *          xpath processor to use
 * @throws IllegalStateException
 *           if the site cannot be parsed
 * @see #toXml()
 */
public static Site fromXml(Node config, XPath xpathProcessor) throws IllegalStateException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    // identifier
    String identifier = XPathHelper.valueOf(config, "@id", xpathProcessor);
    if (identifier == null)
        throw new IllegalStateException("Unable to create sites without identifier");

    // class
    Site site = null;
    String className = XPathHelper.valueOf(config, "ns:class", xpathProcessor);
    if (className != null) {
        try {
            Class<? extends Site> c = (Class<? extends Site>) classLoader.loadClass(className);
            site = c.newInstance();
            site.setIdentifier(identifier);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException(
                    "Implementation " + className + " for site '" + identifier + "' not found", e);
        } catch (InstantiationException e) {
            throw new IllegalStateException(
                    "Error instantiating impelementation " + className + " for site '" + identifier + "'", e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Access violation instantiating implementation " + className
                    + " for site '" + identifier + "'", e);
        } catch (Throwable t) {
            throw new IllegalStateException(
                    "Error loading implementation " + className + " for site '" + identifier + "'", t);
        }

    } else {
        site = new SiteImpl();
        site.setIdentifier(identifier);
    }

    // name
    String name = XPathHelper.valueOf(config, "ns:name", xpathProcessor);
    if (name == null)
        throw new IllegalStateException("Site '" + identifier + " has no name");
    site.setName(name);

    // domains
    NodeList urlNodes = XPathHelper.selectList(config, "ns:domains/ns:url", xpathProcessor);
    if (urlNodes.getLength() == 0)
        throw new IllegalStateException("Site '" + identifier + " has no hostname");
    String url = null;
    try {
        for (int i = 0; i < urlNodes.getLength(); i++) {
            Node urlNode = urlNodes.item(i);
            url = urlNode.getFirstChild().getNodeValue();
            boolean defaultUrl = ConfigurationUtils.isDefault(urlNode);
            Environment environment = Environment.Production;
            Node environmentAttribute = urlNode.getAttributes().getNamedItem("environment");
            if (environmentAttribute != null && environmentAttribute.getNodeValue() != null)
                environment = Environment.valueOf(StringUtils.capitalize(environmentAttribute.getNodeValue()));

            SiteURLImpl siteURL = new SiteURLImpl(new URL(url));
            siteURL.setDefault(defaultUrl);
            siteURL.setEnvironment(environment);

            site.addHostname(siteURL);
        }
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Site '" + identifier + "' defines malformed url: " + url);
    }

    // languages
    NodeList languageNodes = XPathHelper.selectList(config, "ns:languages/ns:language", xpathProcessor);
    if (languageNodes.getLength() == 0)
        throw new IllegalStateException("Site '" + identifier + " has no languages");
    for (int i = 0; i < languageNodes.getLength(); i++) {
        Node languageNode = languageNodes.item(i);
        Node defaultAttribute = languageNode.getAttributes().getNamedItem("default");
        String languageId = languageNode.getFirstChild().getNodeValue();
        try {
            Language language = LanguageUtils.getLanguage(languageId);
            if (ConfigurationUtils.isTrue(defaultAttribute))
                site.setDefaultLanguage(language);
            else
                site.addLanguage(language);
        } catch (UnknownLanguageException e) {
            throw new IllegalStateException(
                    "Site '" + identifier + "' defines unknown language: " + languageId);
        }
    }

    // templates
    NodeList templateNodes = XPathHelper.selectList(config, "ns:templates/ns:template", xpathProcessor);
    PageTemplate firstTemplate = null;
    for (int i = 0; i < templateNodes.getLength(); i++) {
        PageTemplate template = PageTemplateImpl.fromXml(templateNodes.item(i), xpathProcessor);
        boolean isDefault = ConfigurationUtils.isDefault(templateNodes.item(i));
        if (isDefault && site.getDefaultTemplate() != null) {
            logger.warn("Site '{}' defines more than one default templates", site.getIdentifier());
        } else if (isDefault) {
            site.setDefaultTemplate(template);
            logger.debug("Site '{}' uses default template '{}'", site.getIdentifier(),
                    template.getIdentifier());
        } else {
            site.addTemplate(template);
            logger.debug("Added template '{}' to site '{}'", template.getIdentifier(), site.getIdentifier());
        }
        if (firstTemplate == null)
            firstTemplate = template;
    }

    // Make sure we have a default template
    if (site.getDefaultTemplate() == null) {
        if (firstTemplate == null)
            throw new IllegalStateException(
                    "Site '" + site.getIdentifier() + "' does not specify any page templates");
        logger.warn("Site '{}' does not specify a default template. Using '{}'", site.getIdentifier(),
                firstTemplate.getIdentifier());
        site.setDefaultTemplate(firstTemplate);
    }

    // security
    String securityConfiguration = XPathHelper.valueOf(config, "ns:security/ns:configuration", xpathProcessor);
    if (securityConfiguration != null) {
        URL securityConfig = null;

        // If converting the path into a URL fails, we are assuming that the
        // configuration is part of the bundle
        try {
            securityConfig = new URL(securityConfiguration);
        } catch (MalformedURLException e) {
            logger.debug("Security configuration {} is pointing to the bundle", securityConfiguration);
            securityConfig = SiteImpl.class.getResource(securityConfiguration);
            if (securityConfig == null) {
                throw new IllegalStateException("Security configuration " + securityConfig + " of site '"
                        + site.getIdentifier() + "' cannot be located inside of bundle", e);
            }
        }
        site.setSecurity(securityConfig);
    }

    // administrator
    Node adminNode = XPathHelper.select(config, "ns:security/ns:administrator", xpathProcessor);
    if (adminNode != null) {
        site.setAdministrator(SiteAdminImpl.fromXml(adminNode, site, xpathProcessor));
    }

    // digest policy
    Node digestNode = XPathHelper.select(config, "ns:security/ns:digest", xpathProcessor);
    if (digestNode != null) {
        site.setDigestType(DigestType.valueOf(digestNode.getFirstChild().getNodeValue()));
    }

    // role definitions
    NodeList roleNodes = XPathHelper.selectList(config, "ns:security/ns:roles/ns:*", xpathProcessor);
    for (int i = 0; i < roleNodes.getLength(); i++) {
        Node roleNode = roleNodes.item(i);
        String roleName = roleNode.getLocalName();
        String localRoleName = roleNode.getFirstChild().getNodeValue();
        if (Security.SITE_ADMIN_ROLE.equals(roleName))
            site.addLocalRole(Security.SITE_ADMIN_ROLE, localRoleName);
        if (Security.PUBLISHER_ROLE.equals(roleName))
            site.addLocalRole(Security.PUBLISHER_ROLE, localRoleName);
        if (Security.EDITOR_ROLE.equals(roleName))
            site.addLocalRole(Security.EDITOR_ROLE, localRoleName);
        if (Security.GUEST_ROLE.equals(roleName))
            site.addLocalRole(Security.GUEST_ROLE, localRoleName);
    }

    // options
    Node optionsNode = XPathHelper.select(config, "ns:options", xpathProcessor);
    OptionsHelper.fromXml(optionsNode, site, xpathProcessor);

    return site;
}