List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:org.craftercms.cstudio.alfresco.dm.util.impl.DmImportServiceImpl.java
License:Open Source License
/** * create folders/*from w w w . jav a 2 s .c o m*/ * * @param name * site name * @param importedFiles * a list of imported files * @param importedFullPaths * @param nodes * nodes representing folders * @param fileRoot * the root location of files/folders being imported * @param parentRef * the parent nodeRef * @param targetRoot * the target location root * @param parentPath * the target location to import to * @param overWrite * overwrite contents? * @param channels * @param user * */ @SuppressWarnings("unchecked") private void createFolders(String site, Set<String> importedPaths, List<String> importedFullPaths, List<Node> nodes, String fileRoot, NodeRef parentRef, String targetRoot, String parentPath, boolean overWrite, List<PublishingChannel> channels, String user) { if (LOGGER.isInfoEnabled()) { LOGGER.info( "[IMPORT] createFolders : site[" + site + "] " + "] fileRoot [" + fileRoot + "] targetRoot [ " + targetRoot + "] parentPath [" + parentPath + "] overwrite[" + overWrite + "]"); } if (nodes != null) { for (Node node : nodes) { String name = node.valueOf("@name"); String value = node.valueOf("@over-write"); boolean folderOverWrite = (StringUtils.isEmpty(value)) ? overWrite : ContentFormatUtils.getBooleanValue(value); if (!StringUtils.isEmpty(name)) { String currentFilePath = fileRoot + "/" + name; String currentPath = parentPath + "/" + name; // check if the parent node exists and create the folder if // not NodeRef currentRef = findChildByName(parentRef, name); if (currentRef == null) { currentRef = createDirectory(parentRef, name); } boolean importAll = ContentFormatUtils.getBooleanValue(node.valueOf("@import-all")); if (importAll) { importRootFileList(site, importedPaths, importedFullPaths, fileRoot + "/" + name, currentRef, targetRoot, currentPath, folderOverWrite, channels, user); } else { // create child folders List<Node> childFolders = node.selectNodes("folder"); createFolders(site, importedPaths, importedFullPaths, childFolders, currentFilePath, currentRef, targetRoot, currentPath, folderOverWrite, channels, user); // create child fiimportedPathsles List<Node> childFiles = node.selectNodes("file"); createFiles(site, importedPaths, importedFullPaths, childFiles, currentFilePath, currentRef, targetRoot, currentPath, folderOverWrite, channels, user); } } } } }
From source file:org.craftercms.cstudio.alfresco.service.impl.ContentTypesConfigImpl.java
License:Open Source License
/** * load search configuration/* ww w. ja v a2 s. c om*/ * * @param node */ @SuppressWarnings("unchecked") public SearchConfigTO loadSearchConfig(Node node) { SearchConfigTO searchConfig = new SearchConfigTO(); if (node != null) { // get the maximum number of results to search for String maxCount = node.valueOf("max-count"); if (!StringUtils.isEmpty(maxCount)) { int max = ContentFormatUtils.getIntValue(node.valueOf("max-count")); searchConfig.setMaxCount((max <= 0) ? 100 : max); } else { searchConfig.setMaxCount(100); } // get wcm searchPath String wcmSearchPath = node.valueOf("wcm-search-path"); searchConfig.setWcmSearchPath(wcmSearchPath); // set base search filters List<Node> propNodes = node.selectNodes("base-searchable-properties/property"); if (propNodes != null && propNodes.size() > 0) { List<SearchColumnTO> columns = new FastList<SearchColumnTO>(propNodes.size()); for (Node propNode : propNodes) { String key = propNode.valueOf("@name"); if (!StringUtils.isEmpty(key)) { SearchColumnTO column = new SearchColumnTO(); column.setName(key); column.setTitle(propNode.valueOf("@title")); String useWildCard = propNode.valueOf("@use-wild-card"); column.setUseWildCard(ContentFormatUtils.getBooleanValue(useWildCard)); column.setSearchable(true); columns.add(column); } } searchConfig.setBaseSearchableColumns(columns); } // set searchable content-types List<Node> ctypeNodes = node.selectNodes("searchable-content-types/searchable-content-type"); if (ctypeNodes != null && ctypeNodes.size() > 0) { List<String> ctypes = new FastList<String>(ctypeNodes.size()); for (Node ctypeNode : ctypeNodes) { String s = ctypeNode.getText(); if (!StringUtils.isEmpty(s)) { ctypes.add(ctypeNode.getText()); } } searchConfig.setSearchableContentTypes(ctypes); } // set extractable metadata qnames Map<QName, String> extractableMetadata = getConfigMapWithStringValue( node.selectNodes("extractable-properties/property")); searchConfig.setExtractableMetadata(extractableMetadata); loadSearchColumnConfig(searchConfig, node.selectNodes("search-result/column")); } return searchConfig; }
From source file:org.craftercms.cstudio.alfresco.service.impl.NotificationServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") protected void loadConfiguration(final String key) { NodeRef configRef = getConfigRef(key); PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class); Document document = persistenceManagerService.loadXml(configRef); if (document != null) { Element root = document.getRootElement(); NotificationConfigTO config = new NotificationConfigTO(); Node configNode = root.selectSingleNode("/notification-config"); if (configNode != null) { loadCannedMessages(config, configNode.selectNodes("canned-messages/messages")); loadEmailMessageTemplates(config, configNode.selectNodes("email-message-templates/email-message-template")); Map<String, String> completeMessages = loadMessages( configNode.selectNodes("complete-messages/message")); Map<String, String> errorMessages = loadMessages(configNode.selectNodes("error-messages/message")); config.setCompleteMessages(completeMessages); config.setErrorMessages(errorMessages); Map<String, String> generalMessages = loadMessages( configNode.selectNodes("general-messages/message")); config.setMessages(generalMessages); Map<String, Boolean> noticeMapping = loadSendNoticeMapping( configNode.selectSingleNode("send-notifications")); config.setSendNoticeMapping(noticeMapping); config.setSite(key);// w ww.j a v a 2 s.co m config.setLastUpdated(new Date()); _notificationConfigMap.put(key, config); } else { LOGGER.error("Notification config is not found for " + key); } } }
From source file:org.craftercms.cstudio.alfresco.service.impl.NotificationServiceImpl.java
License:Open Source License
/** * load canned messages from the configuration file * * @param config/*from w w w .j a v a 2 s. c o m*/ * notification config to store messages * @param nodes * canned messages nodes * @return a list of canned messages */ @SuppressWarnings("unchecked") protected void loadCannedMessages(final NotificationConfigTO config, final List<Node> nodes) { if (nodes != null) { Map<String, List<MessageTO>> messageMap = new HashMap<String, List<MessageTO>>(); for (Node listNode : nodes) { String name = listNode.valueOf("@name"); if (!StringUtils.isEmpty(name)) { List<Node> messageNodes = listNode.selectNodes("message"); if (messageNodes != null) { List<MessageTO> messages = new ArrayList<MessageTO>(messageNodes.size()); for (Node messageNode : messageNodes) { MessageTO message = new MessageTO(); message.setTitle(messageNode.valueOf("title")); message.setBody(messageNode.valueOf("body")); messages.add(message); } messageMap.put(name, messages); } } } config.setCannedMessages(messageMap); } }
From source file:org.craftercms.cstudio.alfresco.service.impl.PermissionServiceImpl.java
License:Open Source License
/** * populate user permissions/* ww w. j av a 2 s. co m*/ * * @param site * @param path * @param roles * @param permissionsConfig */ protected Set<String> populateUserPermissions(String site, String path, Set<String> roles, PermissionsConfigTO permissionsConfig) { Set<String> permissions = new FastSet<String>(); if (roles != null && !roles.isEmpty()) { for (String role : roles) { Map<String, Map<String, List<Node>>> permissionsMap = permissionsConfig.getPermissions(); Map<String, List<Node>> siteRoles = permissionsMap.get(site); if (siteRoles == null || siteRoles.isEmpty()) { siteRoles = permissionsMap.get("*"); } if (siteRoles != null && !siteRoles.isEmpty()) { List<Node> ruleNodes = siteRoles.get(role); if (ruleNodes == null || ruleNodes.isEmpty()) { ruleNodes = siteRoles.get("*"); } if (ruleNodes != null && !ruleNodes.isEmpty()) { for (Node ruleNode : ruleNodes) { String regex = ruleNode.valueOf(CStudioXmlConstants.DOCUMENT_ATTR_REGEX); if (path.matches(regex)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Permissions found by matching " + regex + " for " + role + " in " + site); } List<Node> permissionNodes = ruleNode .selectNodes(CStudioXmlConstants.DOCUMENT_ELM_ALLOWED_PERMISSIONS); for (Node permissionNode : permissionNodes) { String permission = permissionNode.getText().toLowerCase(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding permissions " + permission + " to " + path + " for " + role + " in " + site); } permissions.add(permission); } } } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No default role is set. adding default permission: " + CStudioConstants.PERMISSION_VALUE_READ); } // If no default role is set permissions.add(CStudioConstants.PERMISSION_VALUE_READ); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No default site is set. adding default permission: " + CStudioConstants.PERMISSION_VALUE_READ); } // If no default site is set permissions.add(CStudioConstants.PERMISSION_VALUE_READ); } } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No user or group matching found. adding default permission: " + CStudioConstants.PERMISSION_VALUE_READ); } // If user or group did not match the roles-mapping file permissions.add(CStudioConstants.PERMISSION_VALUE_READ); } return permissions; }
From source file:org.craftercms.cstudio.alfresco.service.impl.PermissionServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") protected Map<String, List<String>> getRoles(List<Node> nodes, Map<String, List<String>> rolesMap) { for (Node node : nodes) { String name = node.valueOf(CStudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME); if (!StringUtils.isEmpty(name)) { List<Node> roleNodes = node.selectNodes(CStudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE); List<String> roles = new FastList<String>(); for (Node roleNode : roleNodes) { roles.add(roleNode.getText()); }//w w w. j ava 2s . co m rolesMap.put(name, roles); } } return rolesMap; }
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 . ja va 2 s.c om*/ permissionsMap.put(siteId, rules); } } config.setPermissions(permissionsMap); } }
From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java
License:Open Source License
/** * load services configuration//from w w w . j a v a2s .c o 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 the web-project configuration// www. j a v a 2s.c o m * * @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 common prototype configuration/*from w ww . ja v a2 s . c o m*/ * * @param repoConfig * @param node */ protected void loadTemplateConfig(RepositoryConfigTO repoConfig, Node node) { TemplateConfigTO templateConfig = new TemplateConfigTO(); if (node != null) { List<String> excludedPaths = getStringList( node.selectNodes("excluded-on-convert-paths/excluded-on-convert-path")); List<String> multiValuedPaths = getStringList( node.selectNodes("multi-valued-on-convert-paths/multi-valued-on-convert-path")); templateConfig.setExcludedPathsOnConvert(excludedPaths); templateConfig.setMultiValuedPathsOnConvert(multiValuedPaths); } repoConfig.setTemplateConfig(templateConfig); }