List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
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);//from w ww. j ava 2 s. com 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.ServicesConfigImpl.java
License:Open Source License
/** * load services configuration/*from www . java 2 s . 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// ww w . ja va 2 s .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.util.impl.ImportServiceImpl.java
License:Open Source License
/** * create rules for the space associated with the nodeRef * * @param nodeRef// www . j a v a 2 s . com * @param nodes */ protected void createRules(String name, NodeRef nodeRef, List<Node> nodes) { if (nodes != null) { PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class); for (Node node : nodes) { // clean up persistenceManagerService.removeAllRules(nodeRef); // create an action for the rule Action action = createAction(name, node.selectSingleNode("action")); if (action != null) { Rule rule = new Rule(); rule.setRuleType(node.valueOf("@ruleType")); rule.setDescription(node.valueOf("@description")); rule.setTitle(node.valueOf("@title")); boolean executeAsynchronously = Boolean.parseBoolean(node.valueOf("@executeAsynchronously")); rule.setExecuteAsynchronously(executeAsynchronously); boolean applyToChildren = Boolean.parseBoolean(node.valueOf("@applyToChildren")); rule.applyToChildren(applyToChildren); rule.setAction(action); persistenceManagerService.saveRule(nodeRef, rule); } } } }
From source file:org.craftercms.studio.impl.v1.service.cmis.CmisServiceImpl.java
License:Open Source License
private String getPropertyValue(Node repositoryNode, String property) { Node propertyNode = repositoryNode.selectSingleNode(property); if (propertyNode != null) { return propertyNode.getStringValue(); }/*from w w w . java2s . co m*/ return StringUtils.EMPTY; }
From source file:org.craftercms.studio.impl.v1.service.configuration.ContentTypesConfigImpl.java
License:Open Source License
/** * load delete dependencies mapping//from w ww. ja v a 2 s. c om * * @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
/** * * @param config// w w w . j av a 2 s. 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.ServicesConfigImpl.java
License:Open Source License
/** * load services configuration//from w w w .ja v a 2 s . c o m * */ @SuppressWarnings("unchecked") protected SiteConfigTO loadConfiguration(String site) { String siteConfigPath = getConfigPath().replaceFirst(StudioConstants.PATTERN_SITE, site); Document document = null; SiteConfigTO siteConfig = null; try { document = contentService.getContentAsDocument(site, siteConfigPath + "/" + getConfigFileName()); } catch (DocumentException e) { LOGGER.error("Error while loading configuration for " + site + " at " + siteConfigPath, e); } if (document != null) { Element root = document.getRootElement(); Node configNode = root.selectSingleNode("/site-config"); String name = configNode.valueOf("display-name"); 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()); } else { LOGGER.error("No site configuration found for " + site + " at " + siteConfigPath); } return siteConfig; }
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;//from ww w.ja v a2 s .c om 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.notification.NotificationServiceImpl.java
License:Open Source License
protected NotificationConfigTO loadConfiguration(final String site) { String configFullPath = getConfigPath().replaceFirst(StudioConstants.PATTERN_SITE, site); configFullPath = configFullPath + "/" + getConfigFileName(); NotificationConfigTO config = null;/* w ww . j av a2s . co m*/ try { Document document = contentService.getContentAsDocument(site, configFullPath); if (document != null) { Element root = document.getRootElement(); 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); Map<String, String> submitNotificationRules = loadSubmitNotificationRules( configNode.selectSingleNode("submit-notifications")); config.setSubmitNotificationsMapping(submitNotificationRules); List<String> deploymentFailureNotifications = loadDeploymentFailureNotifications( configNode.selectSingleNode("deployment-failure")); config.setDeploymentFailureNotifications(deploymentFailureNotifications); config.setSite(site); config.setLastUpdated(new Date()); } else { logger.error("Notification config is not found for " + site); } } } catch (Exception ex) { logger.error("Notification config is not found for " + site, ex); } return config; }