List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.collectionspace.chain.csp.persistence.services.vocab.ConfiguredVocabStorage.java
License:Educational Community License
/** * Returns JSON containing pagenumber, pagesize, itemsinpage, totalitems and the list of items itself *///from w w w.j a v a 2 s.co m @SuppressWarnings("unchecked") public JSONObject getPathsJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String rootPath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException { try { JSONObject out = new JSONObject(); List<String> list = new ArrayList<String>(); String url; if (rootPath.isEmpty()) { url = "/" + r.getServicesURL() + ALL_VOCAB_ITEMS; } else { String vocab = RefName.shortIdToPath(rootPath); url = "/" + r.getServicesURL() + "/" + vocab + ITEMS_SUFFIX; } String path = getRestrictedPath(url, restrictions, r.getServicesSearchKeyword(), "", true, getDisplayNameKey()); boolean excludeSoftDeleted = true; if (restrictions.has("deleted")) { excludeSoftDeleted = !restrictions.getBoolean("deleted"); } if (excludeSoftDeleted && r.hasSoftDeleteMethod()) { path = softpath(path); } ReturnedDocument data = conn.getXMLDocument(RequestMethod.GET, path, null, creds, cache); Document doc = data.getDocument(); if (doc == null) throw new UnderlyingStorageException("Could not retrieve vocabulary items", data.getStatus(), path); String[] tag_parts = r.getServicesListPath().split(",", 2); JSONObject pagination = new JSONObject(); String[] allfields = null; String fieldsReturnedName = r.getServicesFieldsPath(); List<Node> nodes = doc.selectNodes("/" + tag_parts[1].split("/")[0] + "/*"); for (Node node : nodes) { if (node.matches("/" + tag_parts[1])) { // Risky hack - assumes displayName must be at root. Really should // understand that the list results are a different schema from record GET. String dnName = getDisplayNameKey(); String csid = node.selectSingleNode("csid").getText(); list.add(csid); String urlPlusCSID = url + "/" + csid; List<Node> nameNodes = node.selectNodes(dnName); String nameListValue = null; for (Node nameNode : nameNodes) { String name = nameNode.getText(); if (nameListValue == null) { nameListValue = name; } else { nameListValue = JSONUtils.appendWithArraySeparator(nameListValue, name); } } if (nameListValue == null) { throw new JSONException("No displayNames found!"); } else { String json_name = view_map.get(dnName); setGleanedValue(cache, urlPlusCSID, json_name, nameListValue); } List<Node> fields = node.selectNodes("*[(name()!='" + dnName + "')]"); for (Node field : fields) { String json_name = view_map.get(field.getName()); if (json_name != null) { String value = field.getText(); // XXX hack to cope with multi values if (value == null || "".equals(value)) { List<Node> inners = field.selectNodes("*"); for (Node n : inners) { value += n.getText(); } } setGleanedValue(cache, urlPlusCSID, json_name, value); } } if (allfields == null || allfields.length == 0) { log.warn("Missing fieldsReturned value - may cause fan-out!"); } else { // Mark all the fields not yet found as gleaned - for (String s : allfields) { String gleaned = getGleanedValue(cache, urlPlusCSID, s); if (gleaned == null) { setGleanedValue(cache, urlPlusCSID, s, ""); } } } } else if (fieldsReturnedName.equals(node.getName())) { String myfields = node.getText(); allfields = myfields.split("\\|"); } else { pagination.put(node.getName(), node.getText()); } } out.put("pagination", pagination); out.put("listItems", list.toArray(new String[0])); return out; } catch (ConnectionException e) { throw new UnderlyingStorageException("Connection exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e); } catch (UnsupportedEncodingException e) { throw new UnderlyingStorageException("UTF-8 not supported!?" + e.getLocalizedMessage()); } catch (JSONException e) { throw new UnderlyingStorageException("Error parsing JSON" + e.getLocalizedMessage()); } }
From source file:org.craftercms.core.processors.impl.IncludeDescriptorsProcessor.java
License:Open Source License
protected boolean isIncludeDisabled(Element includeElement) { Node disabledIncludeNode = includeElement.selectSingleNode(disabledIncludeNodeXPathQuery); return disabledIncludeNode != null && BooleanUtils.toBoolean(disabledIncludeNode.getText()); }
From source file:org.craftercms.core.processors.impl.template.TemplateProcessor.java
License:Open Source License
/** * Processes the content of certain nodes (found by the {@code NodeScanner} in the item's descriptor as templates, * by compiling the node text templates through the {@code templateCompiler} and then processing the compiled * template with a model returned by {@code modelFactory}. * * @throws ItemProcessingException if an error occurred while processing a template *//*from ww w . j a v a 2 s .c o m*/ public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException { String descriptorUrl = item.getDescriptorUrl(); Document descriptorDom = item.getDescriptorDom(); if (descriptorDom != null) { List<Node> templateNodes = templateNodeScanner.scan(descriptorDom); if (CollectionUtils.isNotEmpty(templateNodes)) { for (Node templateNode : templateNodes) { String templateNodePath = templateNode.getUniquePath(); if (logger.isDebugEnabled()) { logger.debug("Template found in " + descriptorUrl + " at " + templateNodePath); } String templateId = templateNodePath + "@" + descriptorUrl; String template = templateNode.getText(); IdentifiableStringTemplateSource templateSource = new IdentifiableStringTemplateSource( templateId, template); Object model = modelFactory.getModel(item, templateNode, template); StringWriter output = new StringWriter(); try { CompiledTemplate compiledTemplate = templateCompiler.compile(templateSource); compiledTemplate.process(model, output); } catch (TemplateException e) { throw new ItemProcessingException("Unable to process the template " + templateId, e); } templateNode.setText(output.toString()); } } } return item; }
From source file:org.craftercms.core.util.XmlUtils.java
License:Open Source License
/** * Executes the specified XPath query as a single node query, returning the text value of the resulting single node. *///from w w w . j ava 2 s . c o m public static String selectSingleNodeValue(Node node, String xpathQuery) { Node resultNode = node.selectSingleNode(xpathQuery); if (resultNode != null) { return resultNode.getText(); } else { return null; } }
From source file:org.craftercms.core.util.XmlUtils.java
License:Open Source License
/** * Executes the specified namespace aware XPath query as a single node query, * returning the text value of the resulting single node. *//*from w ww . ja v a 2 s. c o m*/ public static String selectSingleNodeValue(Node node, String xpathQuery, Map<String, String> namespaceUris) { Node resultNode = selectSingleNode(node, xpathQuery, namespaceUris); if (resultNode != null) { return resultNode.getText(); } else { return null; } }
From source file:org.craftercms.core.util.XmlUtils.java
License:Open Source License
private static List<String> extractNodeValues(List<Node> nodes) { if (CollectionUtils.isNotEmpty(nodes)) { List<String> nodeValues = new ArrayList<String>(nodes.size()); for (Node resultNode : nodes) { nodeValues.add(resultNode.getText()); }/* w ww . j av a 2 s. co m*/ return nodeValues; } else { return Collections.emptyList(); } }
From source file:org.craftercms.core.xml.mergers.impl.resolvers.MetaDataMergeStrategyResolver.java
License:Open Source License
/** * Returns a {@link DescriptorMergeStrategy} for a given descriptor. The strategy chosen is the one defined * in the descriptor document.//from ww w . j ava 2 s .c om * * @param descriptorUrl the URL that identifies the descriptor * @param descriptorDom the XML DOM of the descriptor * @return the {@link DescriptorMergeStrategy} for the descriptor, or null if the DOM is null or if there's no * element in the DOM that defines the merge strategy to use. * @throws XmlException if the element value doesn't refer to an existing strategy */ public DescriptorMergeStrategy getStrategy(String descriptorUrl, Document descriptorDom) throws XmlException { if (descriptorDom != null) { Node element = descriptorDom.selectSingleNode(mergeStrategyElementXPathQuery); if (element != null) { DescriptorMergeStrategy strategy = elementValueToStrategyMappings.get(element.getText()); if (strategy != null) { return strategy; } else { throw new XmlException("Element value \"" + element.getText() + "\" doesn't refer to an " + "registered strategy"); } } else { return null; } } else { return null; } }
From source file:org.craftercms.cstudio.alfresco.action.GenericImportActionExecutor.java
License:Open Source License
/** * load configuration/*www . j a v a 2 s .c o m*/ */ @SuppressWarnings("unchecked") protected synchronized void loadConfiguration() { LOGGER.debug("Start loadConfiguration"); if (_configRef == null) { _configRef = _searchService.findNodeFromPath(CStudioConstants.STORE_REF, _configPath, _configFileName, true); } Document document = loadXml(_configRef); LOGGER.debug("Loaded Configuration document: " + document.asXML()); _configTimeStamp = new Date(); Element root = document.getRootElement(); _site = root.valueOf("//site"); _namespace = root.valueOf("//namespace"); _contentPath = root.valueOf("//content-path"); String publish = root.valueOf("//publish-to-cstudio"); _publishToCStudio = (!StringUtils.isEmpty(publish) && publish.equalsIgnoreCase("true")) ? true : false; // get processed paths Map<String, NodeRef> paths = new HashMap<String, NodeRef>(); List<Node> pathNodes = document.selectNodes("//paths/path"); if (pathNodes != null) { for (Node node : pathNodes) { String name = node.valueOf("@name"); String path = node.getText(); NodeRef pathRef = _searchService.findNode(CStudioConstants.STORE_REF, "PATH:\"" + path + "\""); paths.put(name, pathRef); } } this._paths = paths; }
From source file:org.craftercms.cstudio.alfresco.dm.service.impl.DmClipboardServiceImpl.java
License:Open Source License
/** * get the duplicated content// w w w .j av a 2 s . c o m * * @param site * @param sub * @param path * @param name * @param contentAsFolder * @return duplicated content * @throws org.alfresco.repo.security.permissions.AccessDeniedException * @throws ContentNotFoundException */ protected InputStream getDuplicatedContent(String site, String user, String sub, String path, String name, boolean contentAsFolder) throws AccessDeniedException, ContentNotFoundException { // if it is XML, change the internal name with the next number DmContentService dmContentService = getService(DmContentService.class); if (path.endsWith(DmConstants.XML_PATTERN)) { Document document = dmContentService.getContentXml(site, sub, path); 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(CStudioConstants.DATE_PATTERN_MODEL); String date = ContentFormatUtils.formatDate(format, new Date()); String formDate = ContentFormatUtils.convertToFormDate(date); ((Element) modifiedDateNode).setText(formDate); } } return ContentUtils.convertDocumentToStream(document, CStudioConstants.CONTENT_ENCODING); } else { // otherwise, return the content as is return dmContentService.getContent(site, path, false, false); } }
From source file:org.craftercms.cstudio.alfresco.dm.service.impl.DmContentServiceImpl.java
License:Open Source License
/** * get WCM content item order metadata/*from w w w. j a va2 s . c om*/ * * @param nodes * @return */ protected List<DmOrderTO> getItemOrders(List<Node> nodes) { if (nodes != null) { List<DmOrderTO> orders = new FastList<DmOrderTO>(nodes.size()); for (Node node : nodes) { //String orderName = node.valueOf(DmXmlConstants.ELM_ORDER_NAME); //String orderStr = node.valueOf(DmXmlConstants.ELM_ORDER_VALUE); String orderName = DmConstants.JSON_KEY_ORDER_DEFAULT; String orderStr = node.getText(); addOrderValue(orders, orderName, orderStr); } return orders; } else { return null; } }