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.craftercms.studio.impl.v1.service.dependency.RegexDependencyResolver.java

License:Open Source License

@SuppressWarnings("unchecked")
private DependencyResolverConfigTO getConfiguraion(String site) {
    DependencyResolverConfigTO config = null;
    String configLocation = getConfigLocation(site);
    Document document = null;/*from  w w  w  .j av  a  2 s  .  c  o m*/
    try {
        document = contentService.getContentAsDocument(site, configLocation);
    } catch (DocumentException e) {
        logger.error("Failed to load dependency resolver configuration from location: " + configLocation, e);
    }
    if (document != null) {
        Element root = document.getRootElement();
        config = new DependencyResolverConfigTO();

        Element itemTypesEl = root.element("item-types");
        if (itemTypesEl != null) {
            Map<String, DependencyResolverConfigTO.ItemType> itemTypes = new HashMap<String, DependencyResolverConfigTO.ItemType>();
            Iterator<Element> iterItemTypes = itemTypesEl.elementIterator("item-type");
            while (iterItemTypes.hasNext()) {
                DependencyResolverConfigTO.ItemType itemType = new DependencyResolverConfigTO.ItemType();
                List<String> itemTypeIncludes = new ArrayList<String>();
                Map<String, DependencyResolverConfigTO.DependencyType> dependencyTypes = new HashMap<String, DependencyResolverConfigTO.DependencyType>();
                Element itemTypeEl = iterItemTypes.next();
                String typeName = itemTypeEl.valueOf("name");
                Element includesIT = itemTypeEl.element("includes");
                Iterator<Element> iterPathPatterns = includesIT.elementIterator("path-pattern");
                while (iterPathPatterns.hasNext()) {
                    Element pathPattern = iterPathPatterns.next();
                    String pathPatternValue = pathPattern.getStringValue();
                    itemTypeIncludes.add(pathPatternValue);
                }
                itemType.setIncludes(itemTypeIncludes);
                Element dependencyTypesEl = itemTypeEl.element("dependency-types");
                Iterator<Element> iterDependencyTypes = dependencyTypesEl.elementIterator("dependency-type");
                while (iterDependencyTypes.hasNext()) {
                    Element dependencyTypeEl = iterDependencyTypes.next();
                    DependencyResolverConfigTO.DependencyType dependencyType = new DependencyResolverConfigTO.DependencyType();
                    List<DependencyResolverConfigTO.DependencyExtractionPattern> patterns = new ArrayList<DependencyResolverConfigTO.DependencyExtractionPattern>();
                    String dependencyTypeName = dependencyTypeEl.valueOf("name");
                    dependencyType.setName(dependencyTypeName);
                    Element dependencyTypeIncludesEl = dependencyTypeEl.element("includes");
                    Iterator<Element> iterDependencyTypeIncludes = dependencyTypeIncludesEl
                            .elementIterator("pattern");
                    while (iterDependencyTypeIncludes.hasNext()) {
                        DependencyResolverConfigTO.DependencyExtractionPattern pattern = new DependencyResolverConfigTO.DependencyExtractionPattern();
                        List<DependencyResolverConfigTO.DependencyExtractionTransform> transforms = new ArrayList<DependencyResolverConfigTO.DependencyExtractionTransform>();
                        Element patternEl = iterDependencyTypeIncludes.next();
                        Element findRegexEl = patternEl.element("find-regex");
                        pattern.setFindRegex(findRegexEl.getStringValue());
                        Element transformsEl = patternEl.element("transforms");
                        if (transformsEl != null) {
                            Iterator<Element> iterTransformEl = transformsEl.elementIterator("transform");
                            while (iterTransformEl.hasNext()) {
                                Element transformEl = iterTransformEl.next();
                                DependencyResolverConfigTO.DependencyExtractionTransform transform = new DependencyResolverConfigTO.DependencyExtractionTransform();
                                Element matchEl = transformEl.element("match");
                                Element replaceEl = transformEl.element("replace");
                                transform.setMatch(matchEl.getStringValue());
                                transform.setReplace(replaceEl.getStringValue());
                                transforms.add(transform);
                            }
                        }
                        pattern.setTransforms(transforms);
                        patterns.add(pattern);
                    }
                    dependencyType.setIncludes(patterns);
                    dependencyTypes.put(dependencyTypeName, dependencyType);
                }
                itemType.setDependencyTypes(dependencyTypes);
                itemTypes.put(typeName, itemType);
            }
            config.setItemTypes(itemTypes);
        }
    }

    return config;
}

From source file:org.craftercms.studio.impl.v1.service.site.SiteServiceImpl.java

License:Open Source License

private Map<String, Object> createMap(Element element) {
    Map<String, Object> map = new HashMap<String, Object>();
    for (int i = 0, size = element.nodeCount(); i < size; i++) {
        Node currentNode = element.node(i);
        if (currentNode instanceof Element) {
            Element currentElement = (Element) currentNode;
            String key = currentElement.getName();
            Object toAdd = null;/*from ww  w.java2  s  . c om*/
            if (currentElement.isTextOnly()) {
                toAdd = currentElement.getStringValue();
            } else {
                toAdd = createMap(currentElement);
            }
            if (map.containsKey(key)) {
                Object value = map.get(key);
                List listOfValues = new ArrayList<Object>();
                if (value instanceof List) {
                    listOfValues = (List<Object>) value;
                } else {
                    listOfValues.add(value);
                }
                listOfValues.add(toAdd);
                map.put(key, listOfValues);
            } else {
                map.put(key, toAdd);
            }
        }
    }
    return map;
}

From source file:org.infoglue.cms.applications.contenttool.actions.MoveMultipleContentAction.java

License:Open Source License

private List parseContentsFromXML(String qualifyerXML) {
    List contents = new ArrayList();

    try {/*from  ww w .jav  a 2 s .c  o m*/
        Document document = new DOMBuilder().getDocument(qualifyerXML);

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

        Map addedContents = new HashMap();

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

            if (!addedContents.containsKey(id)) {
                ContentVO contentVO = ContentController.getContentController()
                        .getContentVOWithId(new Integer(id));
                contents.add(contentVO);
                addedContents.put(id, contentVO);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return contents;
}

From source file:org.infoglue.cms.applications.contenttool.actions.ViewContentVersionAction.java

License:Open Source License

private List parseQualifyersFromXML(String qualifyerXML, String currentEntityIdentifyer) {
    List qualifyers = new ArrayList();

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

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

            QualifyerVO qualifyerVO = new QualifyerVO();
            qualifyerVO.setName(currentEntityIdentifyer);
            qualifyerVO.setValue(id);
            qualifyerVO.setPath(this.getQualifyerPath(entity, id));
            //qualifyerVO.setSortOrder(new Integer(i));
            qualifyers.add(qualifyerVO);
        }
    } catch (Exception e) {
        logger.error("Error in parseQualifyersFromXML:" + e.getMessage());
        logger.error("qualifyerXML:\n" + qualifyerXML);
    }

    return qualifyers;
}

From source file:org.infoglue.cms.applications.contenttool.actions.ViewRelationEditorAction.java

License:Open Source License

private List parseQualifyersFromXML(String qualifyerXML) {
    List qualifyers = new ArrayList();

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

            QualifyerVO qualifyerVO = new QualifyerVO();
            qualifyerVO.setName(this.getCurrentEntityIdentifyer());
            qualifyerVO.setValue(id);
            qualifyerVO.setPath(this.getQualifyerPath(id));
            //qualifyerVO.setSortOrder(new Integer(i));
            qualifyers.add(qualifyerVO);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return qualifyers;
}

From source file:org.infoglue.cms.applications.managementtool.actions.ViewEntityPropertiesAction.java

License:Open Source License

/**
 * Parses qualifyers from an XML//from ww w.  j  a va  2s.c o  m
 * @param qualifyerXML
 * @return
 */

private List parseQualifyersFromXML(String qualifyerXML, String currentEntityIdentifyer) {
    List qualifyers = new ArrayList();

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

    try {
        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();

            QualifyerVO qualifyerVO = new QualifyerVO();
            qualifyerVO.setName(currentEntityIdentifyer);
            qualifyerVO.setValue(id);
            qualifyerVO.setPath(this.getQualifyerPath(entity, id));
            //qualifyerVO.setSortOrder(new Integer(i));
            qualifyers.add(qualifyerVO);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return qualifyers;
}

From source file:org.infoglue.cms.applications.structuretool.actions.CopyMultipleSiteNodeAction.java

License:Open Source License

private List parseSiteNodesFromXML(String qualifyerXML) {
    List siteNodes = new ArrayList();

    try {/*from   w w  w  .j a v  a 2s  . c o  m*/
        Document document = new DOMBuilder().getDocument(qualifyerXML);

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

        Map addedSiteNodes = new HashMap();

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

            if (!addedSiteNodes.containsKey(id)) {
                SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(new Integer(id));
                siteNodes.add(siteNodeVO);
                addedSiteNodes.put(id, siteNodeVO);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return siteNodes;
}

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

License:Open Source License

/**
 * Parses contents from an XML within a transaction
 * @param qualifyerXML//from  ww  w . ja  va  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) {
        logger.warn("An error getting related contents:" + e.getMessage(), e);
    }

    return contents;
}

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

License:Open Source License

private List<ContentVO> getRelatedContentVOListFromXML(Database db, String qualifyerXML) {
    List<ContentVO> contents = new ArrayList<ContentVO>();

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

    try {/*from   w w w  .j av  a2 s  . 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();

            ContentVO content = ContentController.getContentController().getContentVOWithId(new Integer(id),
                    db);
            contents.add(content);
        }
    } catch (Exception e) {
        logger.warn("An error getting related contents:" + e.getMessage());
    }

    return contents;
}

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

License:Open Source License

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

private List getReadOnlyRelatedContentsFromXML(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().getReadOnlyContentWithId(new Integer(id),
                    db);
            contents.add(content);
        }
    } catch (Exception e) {
        logger.warn("An error getting related contents:" + e.getMessage());
        logger.info("An error getting related contents:" + e.getMessage(), e);
    }

    return contents;
}