List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
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()); }/*from w w w . j ava 2 s . c o m*/ rolesMap.put(name, roles); } } return rolesMap; }
From source file:org.craftercms.cstudio.alfresco.service.impl.ServicesConfigImpl.java
License:Open Source License
/** * load namespaces to types mapping//from ww w . j a va2s. 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
/** * get a list of string values//from w w w.ja va2 s. c o m * * @param nodes * @return a list of string values */ protected List<String> getStringList(List<Node> nodes) { List<String> items = null; if (nodes != null && nodes.size() > 0) { items = new FastList<String>(nodes.size()); for (Node node : nodes) { items.add(node.getText()); } } else { items = new FastList<String>(0); } return items; }
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 va 2 s. c o 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.SiteEnvironmentConfigImpl.java
License:Open Source License
protected void loadConfiguration(String key) { NodeRef configRef = getConfigRef(key); PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class); if (configRef != null) { String configPath = persistenceManagerService.getNodePath(configRef); LOGGER.info("Loading environment configuration for " + key + "; Path: " + configPath); }//from w w w . j ava2 s . c om Document document = persistenceManagerService.loadXml(configRef); if (document != null) { Element root = document.getRootElement(); EnvironmentConfigTO 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()); 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."); } } } config.getPublishingChannelGroupConfigs().put(pcgConfigTo.getName(), pcgConfigTo); } config.setLastUpdated(new Date()); _siteMapping.put(key, config); } }
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 2s .c om * @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
/** * get a map of properties from the given nodes * * @param nodes//from w ww. j a v a 2 s. c om * @param dateFormat * @return */ protected Map<QName, Serializable> getProperties(List<Node> nodes, SimpleDateFormat dateFormat) { Map<QName, Serializable> properties = null; if (nodes != null && nodes.size() > 0) { properties = new HashMap<QName, Serializable>(); NamespaceService namespaceService = getService(NamespaceService.class); PersistenceManagerService persistenceManagerService = getService(PersistenceManagerService.class); for (Node propNode : nodes) { String propName = propNode.valueOf("@name"); String value = propNode.getText(); QName propType = namespaceService.createQName(propName); if (propType != null) { PropertyDefinition propDef = persistenceManagerService.getProperty(propType); if (propDef != null) { String className = propDef.getDataType().getJavaClassName(); Serializable convertedValue = ContentFormatUtils.convertType(namespaceService, propType, className, value, dateFormat); properties.put(propType, convertedValue); } } } } return properties; }
From source file:org.craftercms.cstudio.impl.service.translation.provider.demo.DemoTranslationProvider.java
License:Open Source License
@Override public InputStream getTranslatedContentForItem(String siteName, String targetLanguage, String path) { InputStream retTranslatedContent = null; byte[] contentBytes = _content.get(path); if (contentBytes != null) { if (path.endsWith(".xml") || path.endsWith(".XML")) { try { InputStream docInputStream = new ByteArrayInputStream(contentBytes); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(docInputStream); for (String element : _translateElements) { List<Node> valueEls = document.selectNodes("//" + element); if (valueEls != null && valueEls.size() > 0) { // translate each value String translation = ""; Node valueEl = valueEls.get(0); String value = valueEl.getText(); translation = value; Pattern contentPattern = Pattern.compile(">(.*?)<"); Matcher regexMatcher = contentPattern.matcher(value); while (regexMatcher.find()) { String content = regexMatcher.group(1); if (!".".equals(content.trim())) { translation = translation.replaceAll(content, new StringBuffer(content).reverse().toString()); }/*from www . j a v a 2 s .c o m*/ } // put it back in the xml document (but translated) valueEl.setText(translation); } } // get the entire translation and return as bytes String translatedDocument = document.asXML(); retTranslatedContent = new ByteArrayInputStream(translatedDocument.getBytes("UTF-8")); } catch (Exception err) { // log error logger.error("issue during translation", err); } } else { retTranslatedContent = new ByteArrayInputStream(contentBytes); } } return retTranslatedContent; }
From source file:org.craftercms.studio.impl.v1.repository.alfresco.AlfrescoContentRepository.java
License:Open Source License
@Override public String authenticate(String username, String password) { InputStream retStream = null; String toRet = null;//from w w w . ja v a 2s . co m try { // construct and execute url to download result String downloadURI = "/api/login?u={u}&pw={pw}"; Map<String, String> lookupContentParams = new HashMap<String, String>(); lookupContentParams.put("u", username); lookupContentParams.put("pw", password); retStream = this.alfrescoGetRequest(downloadURI, lookupContentParams); SAXReader reader = new SAXReader(); Document response = reader.read(retStream); Node ticketNode = response.selectSingleNode("//ticket"); toRet = ticketNode.getText(); this.storeSessionTicket(toRet); this.storeSessionUsername(username); } catch (Exception err) { logger.error("err getting content: ", err); } return toRet; }
From source file:org.craftercms.studio.impl.v1.service.clipboard.ClipboardServiceImpl.java
License:Open Source License
/** * get the duplicated content// w w w.jav a 2 s. c o m * * @param site * @param path * @param name * @param contentAsFolder * @return duplicated content * @throws ContentNotFoundException */ protected InputStream getDuplicatedContent(String site, String user, String path, String name, boolean contentAsFolder) throws ContentNotFoundException { // if it is XML, change the internal name with the next number if (path.endsWith(DmConstants.XML_PATTERN)) { Document document = null; try { document = contentService.getContentAsDocument(site, path); } catch (DocumentException e) { logger.error("Error getting xml document for following site: " + site + " path: " + path); } if (document != null) { Pattern pattern = (contentAsFolder) ? FOLDER_PATTERN : FILE_PATTERN; final Matcher m = pattern.matcher(name); if (m.matches()) { String number = m.group(2); Element root = document.getRootElement(); // set internal name to be the same as duplicate content Node nameNode = root.selectSingleNode("//" + DmXmlConstants.ELM_INTERNAL_NAME); if (nameNode != null) { String nameValue = nameNode.getText(); ((Element) nameNode).setText(nameValue + " " + number); } Node fileNameNode = root.selectSingleNode("//" + DmXmlConstants.ELM_FILE_NAME); if (fileNameNode != null) { String fileName = (contentAsFolder) ? DmConstants.INDEX_FILE : name; ((Element) fileNameNode).setText(fileName); } // set content history - modifier Node modifierNode = root.selectSingleNode("//" + DmXmlConstants.ELM_LAST_MODIFIED_BY); if (modifierNode != null) { ((Element) modifierNode).setText(user); } // set content history - modified date Node modifiedDateNode = root.selectSingleNode("//" + DmXmlConstants.ELM_LAST_MODIFIED_DATE); if (modifiedDateNode != null) { SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_MODEL); String date = ContentFormatUtils.formatDate(format, new Date()); String formDate = ContentFormatUtils.convertToFormDate(date); ((Element) modifiedDateNode).setText(formDate); } } return ContentUtils.convertDocumentToStream(document, StudioConstants.CONTENT_ENCODING); } else { return null; } } else { // otherwise, return the content as is return contentService.getContent(site, path); } }