List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.craftercms.studio.impl.v1.service.configuration.ContentTypesConfigImpl.java
License:Open Source License
/** * load delete dependencies mapping/* w w w .j a va 2 s . c o m*/ * * @param contentTypeConfig * @param nodes */ protected void loadDeleteDependencies(ContentTypeConfigTO contentTypeConfig, List<Node> nodes) { List<DeleteDependencyConfigTO> deleteConfigs = new ArrayList<>(); if (nodes != null) { for (Node node : nodes) { Node patternNode = node.selectSingleNode("pattern"); Node removeFolderNode = node.selectSingleNode("remove-empty-folder"); if (patternNode != null) { String pattern = patternNode.getText(); String removeEmptyFolder = removeFolderNode.getText(); boolean isRemoveEmptyFolder = false; if (removeEmptyFolder != null) { isRemoveEmptyFolder = Boolean.valueOf(removeEmptyFolder); } if (StringUtils.isNotEmpty(pattern)) { DeleteDependencyConfigTO deleteConfigTO = new DeleteDependencyConfigTO(pattern, isRemoveEmptyFolder); deleteConfigs.add(deleteConfigTO); } } } contentTypeConfig.setDeleteDependencies(deleteConfigs); } }
From source file:org.craftercms.studio.impl.v1.service.configuration.ContentTypesConfigImpl.java
License:Open Source License
/** * get paths/* w ww. j ava 2s. co m*/ * * @param root * @param path * @return */ private List<String> getPaths(Element root, String path) { List<String> paths = null; List<Node> nodes = root.selectNodes(path); if (nodes != null && nodes.size() > 0) { paths = new ArrayList<String>(nodes.size()); for (Node node : nodes) { String role = node.getText(); if (!StringUtils.isEmpty(role)) { paths.add(role); } } } else { paths = new ArrayList<String>(); } return paths; }
From source file:org.craftercms.studio.impl.v1.service.configuration.ContentTypesConfigImpl.java
License:Open Source License
/** * load a list of allowed roles//from w w w. ja va 2s. c o m * @param config * @param nodes */ protected void loadRoles(ContentTypeConfigTO config, List<Node> nodes) { Set<String> roles = null; if (nodes != null && nodes.size() > 0) { roles = new HashSet<String>(nodes.size()); for (Node node : nodes) { String role = node.getText(); if (!StringUtils.isEmpty(role)) { roles.add(role); } } } else { roles = new HashSet<String>(); } config.setAllowedRoles(roles); }
From source file:org.craftercms.studio.impl.v1.service.configuration.ContentTypesConfigImpl.java
License:Open Source License
/** * * @param config/*from w w w . j av a 2s .co m*/ * @param copyDependencyNodes * @return */ protected void loadCopyDependencyPatterns(ContentTypeConfigTO config, List<Node> copyDependencyNodes) { List<CopyDependencyConfigTO> copyConfig = new ArrayList<CopyDependencyConfigTO>(); if (copyDependencyNodes != null) { for (Node copyDependency : copyDependencyNodes) { Node patternNode = copyDependency.selectSingleNode("pattern"); Node targetNode = copyDependency.selectSingleNode("target"); if (patternNode != null && targetNode != null) { String pattern = patternNode.getText(); String target = targetNode.getText(); if (StringUtils.isNotEmpty(pattern) && StringUtils.isNotEmpty(target)) { CopyDependencyConfigTO copyDependencyConfigTO = new CopyDependencyConfigTO(pattern, target); copyConfig.add(copyDependencyConfigTO); } } } } config.setCopyDepedencyPattern(copyConfig); }
From source file:org.craftercms.studio.impl.v1.service.configuration.SiteEnvironmentConfigImpl.java
License:Open Source License
protected EnvironmentConfigTO loadConfiguration(String key) { String configLocation = getConfigPath().replaceFirst(StudioConstants.PATTERN_SITE, key) .replaceFirst(StudioConstants.PATTERN_ENVIRONMENT, getEnvironment()); configLocation = configLocation + "/" + getConfigFileName(); EnvironmentConfigTO config = null;//from w w w. ja v a 2 s . c o m Document document = null; try { document = contentService.getContentAsDocument(key, configLocation); } catch (DocumentException e) { e.printStackTrace(); } if (document != null) { Element root = document.getRootElement(); config = new EnvironmentConfigTO(); String previewServerUrl = root.valueOf("preview-server-url"); config.setPreviewServerUrl(previewServerUrl); String openDropdown = root.valueOf("open-site-dropdown"); config.setOpenDropdown((openDropdown != null) ? Boolean.valueOf(openDropdown) : false); String previewServerUrlPattern = root.valueOf("preview-server-url-pattern"); config.setPreviewServerUrlPattern(previewServerUrlPattern); String orbeonServerUrlPattern = root.valueOf("form-server-url"); config.setFormServerUrlPattern(orbeonServerUrlPattern); String authoringServerUrl = root.valueOf("authoring-server-url"); config.setAuthoringServerUrl(authoringServerUrl); String authoringServerUrlPattern = root.valueOf("authoring-server-url-pattern"); config.setAuthoringServerUrlPattern(authoringServerUrlPattern); String liveServerUrl = root.valueOf("live-server-url"); config.setLiveServerUrl(liveServerUrl); String adminEmailAddress = root.valueOf("admin-email-address"); config.setAdminEmailAddress(adminEmailAddress); String cookieDomain = root.valueOf("cookie-domain"); config.setCookieDomain(cookieDomain); List<Element> channelGroupList = root.selectNodes("publishing-channels/channel-group"); for (Element element : channelGroupList) { PublishingChannelGroupConfigTO pcgConfigTo = new PublishingChannelGroupConfigTO(); Node node = element.selectSingleNode("label"); if (node != null) pcgConfigTo.setName(node.getText()); List<Element> channels = element.selectNodes("channels/channel"); for (Element channel : channels) { PublishingChannelConfigTO pcConfigTO = new PublishingChannelConfigTO(); pcConfigTO.setName(channel.getText()); if (!checkEndpointConfigured(key, pcConfigTO.getName())) { logger.error("Deployment endpoint \"" + pcConfigTO.getName() + "\" is not configured for site " + key); } pcgConfigTo.getChannels().add(pcConfigTO); } node = element.selectSingleNode("live-environment"); if (node != null) { String isLiveEnvStr = node.getText(); boolean isLiveEnvVal = (StringUtils.isNotEmpty(isLiveEnvStr)) && Boolean.valueOf(isLiveEnvStr); pcgConfigTo.setLiveEnvironment(isLiveEnvVal); if (isLiveEnvVal) { if (config.getLiveEnvironmentPublishingGroup() == null) { config.setLiveEnvironmentPublishingGroup(pcgConfigTo); } else { pcgConfigTo.setLiveEnvironment(false); logger.warn( "Multiple publishing groups assigned as live environment. Only one publishing group can be live environment. " + config.getLiveEnvironmentPublishingGroup().getName() + " is already set as live environment."); } } } node = element.selectSingleNode("order"); if (node != null) { String orderStr = node.getText(); if (StringUtils.isNotEmpty(orderStr)) { try { int orderVal = Integer.parseInt(orderStr); pcgConfigTo.setOrder(orderVal); } catch (NumberFormatException exc) { logger.info( String.format("Order not defined for publishing group (%s) config [path: %s]", pcgConfigTo.getName(), configLocation)); logger.info( String.format("Default order value (%d) will be used for publishing group [%s]", pcgConfigTo.getOrder(), pcgConfigTo.getName())); } } } List<Element> roles = element.selectNodes("roles/role"); Set<String> rolesStr = new HashSet<String>(); for (Element role : roles) { rolesStr.add(role.getTextTrim()); } pcgConfigTo.setRoles(rolesStr); config.getPublishingChannelGroupConfigs().put(pcgConfigTo.getName(), pcgConfigTo); } String previewDeploymentEndpoint = root.valueOf("preview-deployment-endpoint"); config.setPreviewDeploymentEndpoint(previewDeploymentEndpoint); config.setLastUpdated(new Date()); } return config; }
From source file:org.craftercms.studio.impl.v1.service.content.ContentServiceImpl.java
License:Open Source License
/** * get WCM content item order metadata/*from ww w.ja v a2 s. com*/ * * @param nodes * @return */ protected List<DmOrderTO> getItemOrders(List<Node> nodes) { // TODO: SJ: Rewrite this and the whole order/sort system; 2.7.x if (nodes != null) { List<DmOrderTO> orders = new ArrayList<DmOrderTO>(nodes.size()); for (Node node : nodes) { String orderName = DmConstants.JSON_KEY_ORDER_DEFAULT; String orderStr = node.getText(); addOrderValue(orders, orderName, orderStr); } return orders; } else { return null; } }
From source file:org.craftercms.studio.impl.v1.service.notification.NotificationServiceImpl.java
License:Open Source License
protected Map<String, String> loadSubmitNotificationRules(Node node) { Map<String, String> submitNotificationMapping = new HashMap<String, String>(); if (node != null) { Element element = (Element) node; List<Element> childElements = element.elements(); if (childElements != null && childElements.size() > 0) { for (Element childElement : childElements) { String regex = childElement.attributeValue("regex"); Node addressNode = childElement.selectSingleNode("email"); String value = addressNode.getText(); // default to true if (!StringUtils.isEmpty(regex) && !StringUtils.isEmpty(value)) { submitNotificationMapping.put(regex, value); }/*from ww w . j a v a2s . c o m*/ } } } return submitNotificationMapping; }
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("*"); }//from w w w . j a va 2 s.co m 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/*from ww w. j ava 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()); }// w w w . ja va 2 s. com rolesMap.put(name, roles); } } return rolesMap; }