Example usage for org.dom4j Node valueOf

List of usage examples for org.dom4j Node valueOf

Introduction

In this page you can find the example usage for org.dom4j Node valueOf.

Prototype

String valueOf(String xpathExpression);

Source Link

Document

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.

Usage

From source file:org.craftercms.cstudio.alfresco.service.impl.PermissionServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void loadPermissions(Element root, PermissionsConfigTO config) {
    if (root.getName().equals(CStudioXmlConstants.DOCUMENT_PERMISSIONS)) {
        Map<String, Map<String, List<Node>>> permissionsMap = new FastMap<String, Map<String, List<Node>>>();
        List<Node> siteNodes = root.selectNodes(CStudioXmlConstants.DOCUMENT_ELM_SITE);
        for (Node siteNode : siteNodes) {
            String siteId = siteNode.valueOf(CStudioXmlConstants.DOCUMENT_ATTR_SITE_ID);
            if (!StringUtils.isEmpty(siteId)) {
                List<Node> roleNodes = siteNode.selectNodes(CStudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE);
                Map<String, List<Node>> rules = new FastMap<String, List<Node>>();
                for (Node roleNode : roleNodes) {
                    String roleName = roleNode.valueOf(CStudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME);
                    List<Node> ruleNodes = roleNode
                            .selectNodes(CStudioXmlConstants.DOCUMENT_ELM_PERMISSION_RULE);
                    rules.put(roleName, ruleNodes);
                }// ww  w. j a  va2 s. co  m
                permissionsMap.put(siteId, rules);
            }
        }
        config.setPermissions(permissionsMap);
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ProfileServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void loadConfiguration(String key) {
    // key is the site type
    NodeRef configRef = getConfigRef(key);
    PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
    Document document = persistenceManagerService.loadXml(configRef);
    if (document != null) {
        Element root = document.getRootElement();
        RolesConfigTO rolesConfig = new RolesConfigTO();
        String topGroup = root.valueOf("@name");
        rolesConfig.setTopGroup(topGroup);
        List<Node> groupNodes = root.selectNodes("group");
        Map<String, RoleConfigTO> roles = new FastMap<String, RoleConfigTO>();
        for (Node groupNode : groupNodes) {
            String groupName = groupNode.valueOf("@name");
            if (!StringUtils.isEmpty(groupName)) {
                RoleConfigTO roleConfig = new RoleConfigTO();
                roleConfig.setName(groupName);
                roleConfig.setLabel(groupNode.valueOf("@label"));
                roleConfig.setRole(groupNode.valueOf("@role"));
                int weight = ContentFormatUtils.getIntValue(groupNode.valueOf("@weight"));
                roleConfig.setWeight(weight);
                roles.put(groupName, roleConfig);
            }/*from   w w  w.  java2s  .  co  m*/
        }
        rolesConfig.setRoles(roles);
        rolesConfig.setLastUpdated(new Date());
        _rolesMapping.put(key, rolesConfig);
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load services configuration//w w w.j  a v  a2s. co m
 * 
 */
@SuppressWarnings("unchecked")
protected void loadConfiguration(String site) {
    String siteConfigPath = _configPath.replaceFirst(CStudioConstants.PATTERN_SITE, site);
    PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
    Document document = persistenceManagerService.loadXml(siteConfigPath + "/" + _configFileName);
    if (document != null) {
        Element root = document.getRootElement();
        Node configNode = root.selectSingleNode("/site-config");
        String name = configNode.valueOf("display-name");
        SiteConfigTO siteConfig = new SiteConfigTO();
        siteConfig.setName(name);
        siteConfig.setSiteName(configNode.valueOf("name"));
        siteConfig.setWemProject(configNode.valueOf("wem-project"));
        siteConfig.setDefaultContentType(configNode.valueOf("default-content-type"));
        String assetUrl = configNode.valueOf("assets-url");
        siteConfig.setTimezone(configNode.valueOf("default-timezone"));
        siteConfig.setAssetUrl(assetUrl);
        loadNamespaceToTypeMap(siteConfig, configNode.selectNodes("namespace-to-type-map/namespace"));
        loadModelConfig(siteConfig, configNode.selectNodes("models/model"));
        SearchConfigTO searchConfig = _contentTypesConfig
                .loadSearchConfig(configNode.selectSingleNode("search"));
        siteConfig.setDefaultSearchConfig(searchConfig);
        loadSiteRepositoryConfiguration(siteConfig, configNode.selectSingleNode("repository"));
        // set the last updated date
        siteConfig.setLastUpdated(new Date());
        _siteMapping.put(site, siteConfig);
    } else {
        LOGGER.error("No site configuration found for " + site + " at " + siteConfigPath);
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load namespaces to types mapping//from  w w  w . j  a v  a  2 s.c o m
 * 
 * @param siteConfig
 * @param nodes
 */
protected void loadNamespaceToTypeMap(SiteConfigTO siteConfig, List<Node> nodes) {
    if (nodes != null && nodes.size() > 0) {
        Map<String, QName> namespaceToTypeMap = new FastMap<String, QName>();
        PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
        for (Node node : nodes) {
            String namespace = node.valueOf("@name");
            QName type = persistenceManagerService.createQName(node.getText());
            if (!StringUtils.isEmpty(namespace) && type != null) {
                namespaceToTypeMap.put(namespace, type);
            }
        }
        siteConfig.setNamespaceToTypeMap(namespaceToTypeMap);
    } else {
        siteConfig.setNamespaceToTypeMap(new FastMap<String, QName>(0));
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load the web-project configuration//from w w  w. ja  v a  2 s .c  om
 *
 * @param siteConfig
 * @param node
 */
@SuppressWarnings("unchecked")
protected void loadSiteRepositoryConfiguration(SiteConfigTO siteConfig, Node node) {
    RepositoryConfigTO repoConfigTO = new RepositoryConfigTO();
    repoConfigTO.setRootPrefix(node.valueOf("@rootPrefix"));
    repoConfigTO.setLevelDescriptorName(node.valueOf("level-descriptor"));
    repoConfigTO.setIndexRepository(ContentFormatUtils.getBooleanValue(node.valueOf("index-repository")));
    String timeValue = node.valueOf("index-time-to-live");
    if (!StringUtils.isEmpty(timeValue)) {
        long indexTimeToLive = ContentFormatUtils.getLongValue(timeValue);
        if (indexTimeToLive > 0) {
            repoConfigTO.setIndexTimeToLive(indexTimeToLive);
        }
    }
    repoConfigTO.setCheckForRenamed(ContentFormatUtils.getBooleanValue(node.valueOf("check-for-renamed")));
    loadFolderConfiguration(siteConfig, repoConfigTO, node.selectNodes("folders/folder"));
    loadPatterns(siteConfig, repoConfigTO, node.selectNodes("patterns/pattern-group"));
    List<String> excludePaths = getStringList(node.selectNodes("exclude-paths/exclude-path"));
    repoConfigTO.setExcludePaths(excludePaths);
    List<String> displayPatterns = getStringList(
            node.selectNodes("display-in-widget-patterns/display-in-widget-pattern"));
    repoConfigTO.setDisplayPatterns(displayPatterns);
    loadTemplateConfig(repoConfigTO, node.selectSingleNode("common-prototype-config"));
    siteConfig.setRepositoryConfig(repoConfigTO);
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load models from the given nodes/*from w w  w  . ja  v  a 2  s.c om*/
 * 
 * @param nodes
 * @return model configuration
 */
protected void loadModelConfig(SiteConfigTO config, List<Node> nodes) {
    Map<QName, ModelConfigTO> models = new FastMap<QName, ModelConfigTO>();
    if (nodes != null && nodes.size() > 0) {
        PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
        for (Node node : nodes) {
            String name = node.valueOf(ATTR_NAME);
            QName type = persistenceManagerService.createQName(name);
            if (type != null) {
                int depth = 1;
                try {
                    depth = Integer.parseInt(node.valueOf(ATTR_DEPTH));
                } catch (NumberFormatException e) {
                    // do nothing
                }
                String path = node.valueOf(ATTR_PATH);
                String displayName = node.valueOf(ATTR_DISPLAY_NAME);
                String namespace = node.valueOf(ATTR_NAMESPACE);
                models.put(type, new ModelConfigTO(path, depth, displayName, namespace));
            }
        }
    }
    config.setModelConfig(models);
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load page/component/assets patterns configuration
 *
 * @param site/*  w w  w  .j a v a  2  s  .  co m*/
 * @param nodes
 */
@SuppressWarnings("unchecked")
protected void loadPatterns(SiteConfigTO site, RepositoryConfigTO repo, List<Node> nodes) {
    if (nodes != null) {
        for (Node node : nodes) {
            String patternKey = node.valueOf(ATTR_NAME);
            if (!StringUtils.isEmpty(patternKey)) {
                List<Node> patternNodes = node.selectNodes(ELM_PATTERN);
                if (patternNodes != null) {
                    List<String> patterns = new FastList<String>(patternNodes.size());
                    for (Node patternNode : patternNodes) {
                        String pattern = patternNode.getText();
                        if (!StringUtils.isEmpty(pattern)) {
                            patterns.add(pattern);
                        }
                    }
                    if (patternKey.equals(PATTERN_PAGE)) {
                        repo.setPagePatterns(patterns);
                    } else if (patternKey.equals(PATTERN_COMPONENT)) {
                        repo.setComponentPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_ASSET)) {
                        repo.setAssetPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_DOCUMENT)) {
                        repo.setDocumentPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_RENDERING_TEMPLATE)) {
                        repo.setRenderingTemplatePatterns(patterns);
                    } else if (patternKey.equals(PATTERN_LEVEL_DESCRIPTOR)) {
                        repo.setLevelDescriptorPatterns(patterns);
                    } else if (patternKey.equals(PATTERN_PREVIEWABLE_MIMETYPES)) {
                        repo.setPreviewableMimetypesPaterns(patterns);
                    } else {
                        LOGGER.error(
                                "Unknown pattern key: " + patternKey + " is provided in " + site.getName());
                    }
                }
            } else {
                LOGGER.error("no pattern key provided in " + site.getName()
                        + " configuration. Skipping the pattern.");
            }
        }
    } else {
        LOGGER.warn(site.getName() + " does not have any pattern configuration.");
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java

License:Open Source License

/**
 * load top level folder configuration//from  w  w w.j  a va 2  s  . c o  m
 *
 * @param site
 * @param folderNodes
 */
protected void loadFolderConfiguration(SiteConfigTO site, RepositoryConfigTO repo, List<Node> folderNodes) {
    if (folderNodes != null) {
        List<DmFolderConfigTO> folders = new FastList<DmFolderConfigTO>(folderNodes.size());
        for (Node folderNode : folderNodes) {
            DmFolderConfigTO folderConfig = new DmFolderConfigTO();
            folderConfig.setName(folderNode.valueOf(ATTR_NAME));
            folderConfig.setPath(folderNode.valueOf(ATTR_PATH));
            folderConfig.setReadDirectChildren(
                    ContentFormatUtils.getBooleanValue(folderNode.valueOf(ATTR_READ_DIRECT_CHILDREN)));
            folderConfig.setAttachRootPrefix(
                    ContentFormatUtils.getBooleanValue(folderNode.valueOf(ATTR_ATTACH_ROOT_PREFIX)));
            folders.add(folderConfig);
        }
        repo.setFolders(folders);
    } else {
        LOGGER.warn(site.getName() + " does not have any folder configuration.");
    }
}

From source file:org.craftercms.cstudio.alfresco.service.impl.SiteServiceImpl.java

License:Open Source License

/**
 * create a map from the given list of nodes
 * //from   w w w .  j a v  a  2 s  . com
 * @param nodes
 * @return a map of key and value pairs
 */
protected Map<String, String> loadMap(List<Node> nodes) {
    if (nodes != null && nodes.size() > 0) {
        Map<String, String> mapping = new HashMap<String, String>();
        for (Node node : nodes) {
            String key = node.valueOf("@key");
            String value = node.getText();
            mapping.put(key, value);
        }
        return mapping;
    } else {
        return new HashMap<String, String>(0);
    }
}

From source file:org.craftercms.cstudio.alfresco.util.impl.ImportServiceImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void setupRepository(Document document, boolean importFromFilePath, String buildDataLocation) {
    if (LOGGER.isInfoEnabled())
        LOGGER.info("[IMPORTSERVICE] starting DM repository setup.");
    PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class);
    Element root = document.getRootElement();
    Node node = root.selectSingleNode("//repository/folders");
    String rootPath = node.valueOf("@root");
    String fileRootPath = node.valueOf("@file-root");
    NodeRef rootRef = persistenceManagerService.getNodeRef(rootPath);
    String basePath = buildDataLocation + "/" + fileRootPath;
    if (LOGGER.isInfoEnabled())
        LOGGER.info("[IMPORTSERVICE] importing from " + basePath + " to " + rootPath);

    if (rootRef != null) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(CStudioConstants.DATE_PATTERN_WORKFLOW);
        dateFormat.setTimeZone(TimeZone.getTimeZone(_timezone));
        createChildren(basePath, importFromFilePath, rootRef, node.selectNodes("folder"), true, dateFormat);
        createChildren(basePath, importFromFilePath, rootRef, node.selectNodes("file"), false, dateFormat);
    } else {/*from   w w w. java2s. co  m*/
        LOGGER.error("[IMPORTSERVICE] Cannot locate the root folder: " + rootPath);
    }
    List<String> groups = createGroups(root.selectNodes("groups/group"), null);
    for (String group : groups) {
        String groupName = persistenceManagerService.getName(AuthorityType.GROUP, group);
        persistenceManagerService.setPermission(rootRef, groupName, PermissionService.COORDINATOR, true);
    }
}