List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:org.craftercms.studio.impl.v1.service.configuration.ServicesConfigImpl.java
License:Open Source License
/** * load the web-project configuration// w w w. jav a2s .com * * @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")); loadFolderConfiguration(siteConfig, repoConfigTO, node.selectNodes("folders/folder")); loadPatterns(siteConfig, repoConfigTO, node.selectNodes("patterns/pattern-group")); List<String> displayPatterns = getStringList( node.selectNodes("display-in-widget-patterns/display-in-widget-pattern")); repoConfigTO.setDisplayPatterns(displayPatterns); siteConfig.setRepositoryConfig(repoConfigTO); }
From source file:org.craftercms.studio.impl.v1.service.content.ImportServiceImpl.java
License:Open Source License
@Override public void importSite(String configLocation) { Document document = loadConfiguration(configLocation); if (document != null) { Element root = document.getRootElement(); List<Node> siteNodes = root.selectNodes("site"); if (siteNodes != null) { for (Node siteNode : siteNodes) { String name = siteNode.valueOf("name"); String buildDataLocation = siteNode.valueOf("build-data-location"); String publishingChannelGroup = siteNode.valueOf("publish-channel-group"); String publishStr = siteNode.valueOf("publish"); boolean publish = (!StringUtils.isEmpty(publishStr) && publishStr.equalsIgnoreCase("true")); String publishSize = siteNode.valueOf("publish-chunk-size"); int chunkSize = (!StringUtils.isEmpty(publishSize) && StringUtils.isNumeric(publishSize)) ? Integer.valueOf(publishSize) : -1;//ww w . j a v a 2s . co m Node foldersNode = siteNode.selectSingleNode("folders"); String sourceLocation = buildDataLocation + "/" + name; String delayIntervalStr = siteNode.valueOf("delay-interval"); int delayInterval = (!StringUtils.isEmpty(delayIntervalStr) && StringUtils.isNumeric(delayIntervalStr)) ? Integer.valueOf(delayIntervalStr) : -1; String delayLengthStr = siteNode.valueOf("delay-length"); int delayLength = (!StringUtils.isEmpty(delayLengthStr) && StringUtils.isNumeric(delayLengthStr)) ? Integer.valueOf(delayLengthStr) : -1; importFromConfigNode(name, publishingChannelGroup, foldersNode, sourceLocation, "/", publish, chunkSize, delayInterval, delayLength); } } } }
From source file:org.craftercms.studio.impl.v1.service.content.ImportServiceImpl.java
License:Open Source License
private void importFromConfigNode(final String site, String publishChannelGroup, final Node node, final String fileRoot, final String targetRoot, boolean publish, int chunkSize, int delayInterval, int delayLength) { if (!inProgress) { inProgress = true;//from w w w . j a va 2s. c om if (delayInterval > 0) pauseEanbeld = true; this.currentDelayInterval = delayInterval * 1000; this.currentDelayLength = delayLength * 1000; final Set<String> importedPaths = new HashSet<String>(); final List<String> importedFullPaths = new ArrayList<String>(); logger.info("[IMPORT] started importing in " + site + ", pause enabled: " + pauseEanbeld + ", delay interval: " + this.currentDelayInterval + ", delay length: " + this.currentDelayLength); boolean overWrite = ContentFormatUtils.getBooleanValue(node.valueOf("@over-write")); final List<Node> folderNodes = node.selectNodes("folder"); if (publish) { PublishingChannelGroupConfigTO configTO = siteService.getPublishingChannelGroupConfigs(site) .get(publishChannelGroup); String user = securityService.getCurrentUser(); List<PublishingChannel> channels = getChannels(site, configTO); logger.debug( "[IMPORT] publishing user: " + user + ", publishing channel config: " + configTO.getName()); this.nextStop = System.currentTimeMillis() + this.currentDelayInterval; createFolders(site, importedPaths, importedFullPaths, folderNodes, fileRoot, targetRoot, "", overWrite, channels, user); logger.info("Starting Publish of Imported Files (Total " + importedFullPaths.size() + " On chunkSize of " + chunkSize + " )"); publish(site, publishChannelGroup, targetRoot, importedFullPaths, chunkSize); } else { this.nextStop = System.currentTimeMillis() + this.currentDelayInterval; createFolders(site, importedPaths, importedFullPaths, folderNodes, fileRoot, targetRoot, "", overWrite, null, null); } inProgress = false; } else { logger.info("[IMPORT] an import process is currently running."); } }
From source file:org.craftercms.studio.impl.v1.service.content.ImportServiceImpl.java
License:Open Source License
/** * create folders/* w ww . j a v a 2s . c o m*/ * * @param site * site name * @param importedPaths * a list of imported files * @param importedFullPaths * @param nodes * nodes representing folders * @param fileRoot * the root location of files/folders being imported * @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, String targetRoot, String parentPath, boolean overWrite, List<PublishingChannel> channels, String user) { 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 boolean folderExists = contentService.contentExists(site, currentPath); if (!folderExists) { contentService.createFolder(site, parentPath, name); } boolean importAll = ContentFormatUtils.getBooleanValue(node.valueOf("@import-all")); if (importAll) { importRootFileList(site, importedPaths, importedFullPaths, fileRoot + "/" + name, targetRoot, currentPath, folderOverWrite, channels, user); } else { // create child folders List<Node> childFolders = node.selectNodes("folder"); createFolders(site, importedPaths, importedFullPaths, childFolders, currentFilePath, targetRoot, currentPath, folderOverWrite, channels, user); // create child fiimportedPathsles List<Node> childFiles = node.selectNodes("file"); createFiles(site, importedPaths, importedFullPaths, childFiles, currentFilePath, targetRoot, currentPath, folderOverWrite, channels, user); } } } } }
From source file:org.craftercms.studio.impl.v1.service.content.ImportServiceImpl.java
License:Open Source License
/** * create files from a list/*from w w w. j a va2 s . c o m*/ * * @param site * @param importedPaths * @param importedFullPaths * @param nodes * @param fileRoot * @param targetRoot * the target location root * @param parentPath * the target location to import to * @param overWrite * @param channels * @param user */ protected void createFiles(String site, Set<String> importedPaths, List<String> importedFullPaths, List<Node> nodes, String fileRoot, String targetRoot, String parentPath, boolean overWrite, List<PublishingChannel> channels, String user) { logger.info("[IMPORT] createFiles: fileRoot [" + fileRoot + "] parentFullPath [" + parentPath + "] overwrite[" + overWrite + "]"); if (nodes != null) { for (Node node : nodes) { String name = node.valueOf("@name"); String value = node.valueOf("@over-write"); boolean fileOverwrite = (StringUtils.isEmpty(value)) ? overWrite : ContentFormatUtils.getBooleanValue(value); if (!StringUtils.isEmpty(name)) { writeContentInTransaction(site, importedPaths, importedFullPaths, fileRoot, targetRoot, parentPath, name, fileOverwrite, channels, user); } } } }
From source file:org.craftercms.studio.impl.v1.service.notification.NotificationServiceImpl.java
License:Open Source License
/** * load canned messages from the configuration file * * @param config/*ww w . j a v a2s . 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")); message.setKey(((Element) messageNode).attributeValue("key", "")); messages.add(message); } messageMap.put(name, messages); } } } config.setCannedMessages(messageMap); } }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
protected Set<String> populateUserGlobalPermissions(String path, Set<String> roles, PermissionsConfigTO permissionsConfig) { Set<String> permissions = new HashSet<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("###GLOBAL###"); if (siteRoles == null || siteRoles.isEmpty()) { siteRoles = permissionsMap.get("*"); }/* ww w. j a v a 2 s .c om*/ 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(StudioXmlConstants.DOCUMENT_ATTR_REGEX); if (path.matches(regex)) { logger.debug("Global permissions found by matching " + regex + " for " + role); List<Node> permissionNodes = ruleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_ALLOWED_PERMISSIONS); for (Node permissionNode : permissionNodes) { String permission = permissionNode.getText().toLowerCase(); logger.debug("adding global permissions " + permission + " to " + path + " for " + role); permissions.add(permission); } } } } else { logger.debug("No default role is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default role is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } else { logger.debug("No default site is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default site is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } } else { logger.debug("No user or group matching found. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If user or group did not match the roles-mapping file permissions.add(StudioConstants.PERMISSION_VALUE_READ); } return permissions; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
/** * populate user permissions// w w w .ja va 2 s.c o 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 HashSet<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(StudioXmlConstants.DOCUMENT_ATTR_REGEX); if (path.matches(regex)) { logger.debug( "Permissions found by matching " + regex + " for " + role + " in " + site); List<Node> permissionNodes = ruleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_ALLOWED_PERMISSIONS); for (Node permissionNode : permissionNodes) { String permission = permissionNode.getText().toLowerCase(); logger.debug("adding permissions " + permission + " to " + path + " for " + role + " in " + site); permissions.add(permission); } } } } else { logger.debug("No default role is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default role is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } else { logger.debug("No default site is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default site is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } } else { logger.debug("No user or group matching found. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If user or group did not match the roles-mapping file permissions.add(StudioConstants.PERMISSION_VALUE_READ); } return permissions; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.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(StudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME); if (!StringUtils.isEmpty(name)) { List<Node> roleNodes = node.selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE); List<String> roles = new ArrayList<String>(); for (Node roleNode : roleNodes) { roles.add(roleNode.getText()); }//from w w w .j av a2 s .com rolesMap.put(name, roles); } } return rolesMap; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") protected void loadPermissions(Element root, PermissionsConfigTO config) { if (root.getName().equals(StudioXmlConstants.DOCUMENT_PERMISSIONS)) { Map<String, Map<String, List<Node>>> permissionsMap = new HashMap<String, Map<String, List<Node>>>(); List<Node> siteNodes = root.selectNodes(StudioXmlConstants.DOCUMENT_ELM_SITE); for (Node siteNode : siteNodes) { String siteId = siteNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_SITE_ID); if (!StringUtils.isEmpty(siteId)) { List<Node> roleNodes = siteNode.selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE); Map<String, List<Node>> rules = new HashMap<String, List<Node>>(); for (Node roleNode : roleNodes) { String roleName = roleNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME); List<Node> ruleNodes = roleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_RULE); rules.put(roleName, ruleNodes); }/* w w w . jav a 2 s. c o m*/ permissionsMap.put(siteId, rules); } } config.setPermissions(permissionsMap); } }