Example usage for org.dom4j Element getStringValue

List of usage examples for org.dom4j Element getStringValue

Introduction

In this page you can find the example usage for org.dom4j Element getStringValue.

Prototype

String getStringValue();

Source Link

Document

Returns the XPath string-value of this node.

Usage

From source file:org.infoglue.cms.controllers.kernel.impl.simple.GroupPropertiesController.java

License:Open Source License

/**
 * Parses siteNodes from an XML within a transaction
 * @param qualifyerXML/*from   w  w w.  j  a va 2 s .  com*/
 * @return
 */

private List getRelatedSiteNodesFromXML(Database db, String qualifyerXML) {
    List siteNodes = new ArrayList();

    if (qualifyerXML == null || qualifyerXML.length() == 0)
        return siteNodes;

    try {
        org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML);

        String entity = document.getRootElement().attributeValue("entity");

        List children = document.getRootElement().elements();
        Iterator i = children.iterator();
        while (i.hasNext()) {
            Element child = (Element) i.next();
            String id = child.getStringValue();

            SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(new Integer(id), db);
            siteNodes.add(siteNode);
        }
    } catch (Exception e) {
        logger.warn("An error getting related site nodes:" + e.getMessage(), e);
    }

    return siteNodes;
}

From source file:org.infoglue.cms.controllers.kernel.impl.simple.GroupPropertiesController.java

License:Open Source License

/**
 * Parses siteNodes from an XML within a transaction
 * @param qualifyerXML/*  w  w w .  ja  va 2  s.  co m*/
 * @return
 */

private List getReadOnlyRelatedSiteNodesFromXML(Database db, String qualifyerXML) {
    List siteNodes = new ArrayList();

    if (qualifyerXML == null || qualifyerXML.length() == 0)
        return siteNodes;

    try {
        org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML);

        String entity = document.getRootElement().attributeValue("entity");

        List children = document.getRootElement().elements();
        Iterator i = children.iterator();
        while (i.hasNext()) {
            Element child = (Element) i.next();
            String id = child.getStringValue();

            SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(new Integer(id), db, true);
            siteNodes.add(siteNode);
        }
    } catch (Exception e) {
        logger.warn("An error getting related pages:" + e.getMessage());
        logger.info("An error getting related pages:" + e.getMessage(), e);
    }

    return siteNodes;
}

From source file:org.infoglue.cms.controllers.kernel.impl.simple.GroupPropertiesController.java

License:Open Source License

private List<SiteNodeVO> getReadOnlyRelatedSiteNodeVOListFromXML(Database db, String qualifyerXML) {
    List<SiteNodeVO> siteNodes = new ArrayList<SiteNodeVO>();

    if (qualifyerXML == null || qualifyerXML.length() == 0)
        return siteNodes;

    try {/*  w  w w  .  jav  a 2s.  co  m*/
        org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML);

        String entity = document.getRootElement().attributeValue("entity");

        List children = document.getRootElement().elements();
        Iterator i = children.iterator();
        while (i.hasNext()) {
            Element child = (Element) i.next();
            String id = child.getStringValue();

            SiteNodeVO siteNode = SiteNodeController.getController().getSiteNodeVOWithId(new Integer(id), db);
            siteNodes.add(siteNode);
        }
    } catch (Exception e) {
        logger.warn("An error getting related pages:" + e.getMessage());
        logger.info("An error getting related pages:" + e.getMessage(), e);
    }

    return siteNodes;
}

From source file:org.infoglue.cms.controllers.kernel.impl.simple.RolePropertiesController.java

License:Open Source License

/**
 * Parses contents from an XML within a transaction
 * @param qualifyerXML/* ww  w  .  j av  a  2s .  c o m*/
 * @return
 */

private List getRelatedContentsFromXML(Database db, String qualifyerXML) {
    List contents = new ArrayList();

    if (qualifyerXML == null || qualifyerXML.length() == 0)
        return contents;

    try {
        org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML);

        String entity = document.getRootElement().attributeValue("entity");

        List children = document.getRootElement().elements();
        Iterator i = children.iterator();
        while (i.hasNext()) {
            Element child = (Element) i.next();
            String id = child.getStringValue();

            Content content = ContentController.getContentController().getContentWithId(new Integer(id), db);
            contents.add(content);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return contents;
}

From source file:org.infoglue.cms.controllers.kernel.impl.simple.RolePropertiesController.java

License:Open Source License

/**
 * Parses siteNodes from an XML within a transaction
 * @param qualifyerXML//from w w  w.  j av  a 2s .co m
 * @return
 */

private List getRelatedSiteNodesFromXML(Database db, String qualifyerXML) {
    List siteNodes = new ArrayList();

    if (qualifyerXML == null || qualifyerXML.length() == 0)
        return siteNodes;

    try {
        org.dom4j.Document document = new DOMBuilder().getDocument(qualifyerXML);

        String entity = document.getRootElement().attributeValue("entity");

        List children = document.getRootElement().elements();
        Iterator i = children.iterator();
        while (i.hasNext()) {
            Element child = (Element) i.next();
            String id = child.getStringValue();

            SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(new Integer(id), db);
            siteNodes.add(siteNode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return siteNodes;
}

From source file:org.jivesoftware.openfire.net.ComponentStanzaHandler.java

License:Open Source License

@Override
boolean processUnknowPacket(Element doc) throws UnauthorizedException {
    String tag = doc.getName();//from w w  w  .j a  v a  2s .co  m
    if ("handshake".equals(tag)) {
        // External component is trying to authenticate
        if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) {
            session.close();
        }
        return true;
    } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
        session.close();
        return true;
    } else if ("bind".equals(tag)) {
        // Handle subsequent bind packets
        LocalComponentSession componentSession = (LocalComponentSession) session;
        // Get the external component of this session
        ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
        String initialDomain = component.getInitialSubdomain();
        String extraDomain = doc.attributeValue("name");
        String allowMultiple = doc.attributeValue("allowMultiple");
        if (extraDomain == null || "".equals(extraDomain)) {
            // No new bind domain was specified so return a bad_request error
            Element reply = doc.createCopy();
            reply.add(new PacketError(PacketError.Condition.bad_request).getElement());
            connection.deliverRawText(reply.asXML());
        } else if (extraDomain.equals(initialDomain)) {
            // Component is binding initial domain that is already registered
            // Send confirmation that the new domain has been registered
            connection.deliverRawText("<bind/>");
        } else if (extraDomain.endsWith(initialDomain)) {
            // Only accept subdomains under the initial registered domain
            if (allowMultiple != null && component.getSubdomains().contains(extraDomain)) {
                // Domain already in use so return a conflict error
                Element reply = doc.createCopy();
                reply.add(new PacketError(PacketError.Condition.conflict).getElement());
                connection.deliverRawText(reply.asXML());
            } else {
                try {
                    // Get the requested subdomain
                    String subdomain = extraDomain;
                    int index = extraDomain.indexOf(serverName);
                    if (index > -1) {
                        subdomain = extraDomain.substring(0, index - 1);
                    }
                    InternalComponentManager.getInstance().addComponent(subdomain, component);
                    // Send confirmation that the new domain has been registered
                    connection.deliverRawText("<bind/>");
                } catch (ComponentException e) {
                    Log.error("Error binding extra domain: " + extraDomain + " to component: " + component, e);
                    // Return internal server error
                    Element reply = doc.createCopy();
                    reply.add(new PacketError(PacketError.Condition.internal_server_error).getElement());
                    connection.deliverRawText(reply.asXML());
                }
            }
        } else {
            // Return forbidden error since we only allow subdomains of the intial domain
            // to be used by the same external component
            Element reply = doc.createCopy();
            reply.add(new PacketError(PacketError.Condition.forbidden).getElement());
            connection.deliverRawText(reply.asXML());
        }
        return true;
    }
    return false;
}

From source file:org.jivesoftware.openfire.net.MultiplexerStanzaHandler.java

License:Open Source License

@Override
boolean processUnknowPacket(Element doc) {
    String tag = doc.getName();/*  w  w w . ja  v  a2  s . c om*/
    if ("route".equals(tag)) {
        // Process stanza wrapped by the route packet
        processRoute(new Route(doc));
        return true;
    } else if ("handshake".equals(tag)) {
        if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) {
            session.close();
        }
        return true;
    } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
        session.close();
        return true;
    }
    return false;
}

From source file:org.localmatters.serializer.config.SerializationElementHandler.java

License:Apache License

/**
 * Handles a complex element//from w ww  .j av a  2s .c o  m
 * @param element The element
 * @param attributes The map of attributes consumed for this element
 * @return The serialization for this element
 */
@SuppressWarnings("unchecked")
protected ComplexSerialization handleComplex(Element element, Map<String, String> attributes) {
    ComplexSerialization ser = new ComplexSerialization();

    List<Element> children = element.elements();
    if (CollectionUtils.isNotEmpty(children)) {
        for (Element child : children) {
            String type = child.getName();
            if (TYPE_COMMENT.equalsIgnoreCase(type)) {
                ser.addComment(child.getStringValue());
            } else {
                Serialization childSerialization = handleId(child);
                if (TYPE_ATTRIBUTE.equalsIgnoreCase(type) || TYPE_NAMESPACE.equalsIgnoreCase(type)) {
                    ser.addAttribute(childSerialization);
                } else {
                    ser.addElement(childSerialization);
                }
            }
        }
    }

    if (attributes.containsKey(ATTRIBUTE_ID)) {
        getComplexWithIds().put(attributes.get(ATTRIBUTE_ID), ser);
    }
    if (attributes.containsKey(ATTRIBUTE_PARENT)) {
        getExtensions().put(ser, attributes.get(ATTRIBUTE_PARENT));
    }

    return ser;
}

From source file:org.localmatters.serializer.config.SerializationElementHandler.java

License:Apache License

/**
 * Handles a list/*from  ww w.j a va2 s. c om*/
 * @param element The element
 * @param attributes The map of attributes consumed for this element
 * @return The serialization for this element
 */
@SuppressWarnings("unchecked")
protected IteratorSerialization handleList(Element element, Map<String, String> attributes) {
    IteratorSerialization serialization = new IteratorSerialization();

    boolean foundElement = false;
    List<Element> children = element.elements();
    if (CollectionUtils.isNotEmpty(children)) {
        for (Element child : children) {
            String type = child.getName();
            if (TYPE_COMMENT.equalsIgnoreCase(type)) {
                serialization.addComment(child.getStringValue());
            } else if (foundElement) {
                throw new ConfigurationException(INVALID_LIST_FORMAT, element.getPath());
            } else {
                foundElement = true;
                Serialization elem = handleId(child);
                serialization.setElement(elem);
            }
        }
    }

    if (!foundElement) {
        serialization.setElement(new ValueSerialization());
    }
    return serialization;
}

From source file:org.localmatters.serializer.config.SerializationElementHandler.java

License:Apache License

/**
 * Handles a map/*from   w  ww .ja  v  a  2  s .  com*/
 * @param element The element
 * @param attributes The map of attributes consumed for this element
 * @return The serialization for this element
 */
@SuppressWarnings("unchecked")
protected MapSerialization handleMap(Element element, Map<String, String> attributes) {
    MapSerialization serialization = new MapSerialization();

    boolean foundElement = false;
    List<Element> children = element.elements();
    if (CollectionUtils.isNotEmpty(children)) {
        for (Element child : children) {
            String type = child.getName();
            if (TYPE_COMMENT.equalsIgnoreCase(type)) {
                serialization.addComment(child.getStringValue());
            } else if (foundElement) {
                throw new ConfigurationException(INVALID_MAP_FORMAT, element.getPath());
            } else {
                if (StringUtils.isNotBlank(child.attributeValue(ATTRIBUTE_NAME))) {
                    throw new ConfigurationException(NAME_NOT_ALLOWED_FORMAT, element.getPath());
                }
                foundElement = true;
                Serialization elem = handleId(child);
                serialization.setValue(elem);
            }
        }
    }

    if (!foundElement) {
        serialization.setValue(new ValueSerialization());
    }

    String key = element.attributeValue(ATTRIBUTE_KEY);
    if (StringUtils.isNotBlank(key)) {
        serialization.setKey(key);
        attributes.put(ATTRIBUTE_KEY, key);
    }

    return serialization;
}