List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.danann.cernunnos.runtime.XmlGrammar.java
License:Apache License
public Phrase newPhrase(Node n) { // Assertions... if (n == null) { String msg = "Argument 'n [Node]' cannot be null."; throw new IllegalArgumentException(msg); }//from w ww . j a va 2 s. c o m List<String> chunks = new LinkedList<String>(); String chunkMe = n.getText(); while (chunkMe.length() != 0) { if (chunkMe.startsWith(Phrase.OPEN_PHRASE_DELIMITER)) { chunks.add(Phrase.OPEN_PHRASE_DELIMITER); chunkMe = chunkMe.substring(2); } else { chunks.add(chunkMe.substring(0, 1)); chunkMe = chunkMe.substring(1); } } List<Phrase> children = new LinkedList<Phrase>(); StringBuffer buffer = new StringBuffer(); int openCount = 0; for (String chunk : chunks) { switch (openCount) { case 0: if (chunk.equals(Phrase.OPEN_PHRASE_DELIMITER)) { if (buffer.length() > 0) { children.add(new LiteralPhrase(buffer.toString())); buffer.setLength(0); } ++openCount; } else { buffer.append(chunk); } break; default: if (chunk.equals(Phrase.OPEN_PHRASE_DELIMITER)) { ++openCount; buffer.append(chunk); } else if (chunk.equals(Phrase.CLOSE_PHRASE_DELIMITER)) { --openCount; if (openCount == 0) { // Time to create a dynamic component... String expression = buffer.toString(); String name = null; // Name of the phrase to use... String nested = null; // Content passed to the phrase // Determine if a Phrase impl was specified or if we should use the default... int openParenIndex = expression.indexOf("("); if (openParenIndex != -1 && expression.endsWith(")")) { // A phrase impl was specified -- use it! try { name = expression.substring(0, openParenIndex); nested = expression.substring(expression.indexOf("(") + 1, expression.length() - 1); } catch (Throwable t) { String msg = "The specified expression is not well formed: " + expression; throw new RuntimeException(msg, t); } } else { // Use the default phrase impl... name = Grammar.DEFAULT_PHRASE_IMPL.getName(); nested = expression; } Entry y = getEntry(name, Entry.Type.PHRASE); Phrase p = null; try { // Create & bootstrap the phrase... EntityConfig config = prepareEntryConfig(y, fac.createText(nested), n.getUniquePath()); Phrase enclosed = (Phrase) y.getFormula().getImplementationClass().newInstance(); enclosed.init(config); p = new RuntimePhraseDecorator(enclosed, config); } catch (Throwable t) { String msg = "Unable to create the specified phrase: " + name; throw new RuntimeException(msg, t); } children.add(p); buffer.setLength(0); } else { buffer.append(chunk); } } else { buffer.append(chunk); } break; } } if (buffer.length() > 0) { // Add anything that's left... children.add(new LiteralPhrase(buffer.toString())); } return new ConcatenatingPhrase(children); }
From source file:org.danann.cernunnos.xml.NodeProcessor.java
License:Apache License
public static void evaluatePhrases(Node n, Grammar g, TaskRequest req, TaskResponse res) { // Assertions... if (n == null) { String msg = "Argument 'n [Node]' cannot be null."; throw new IllegalArgumentException(msg); }/* w w w . j a v a 2 s . c o m*/ if (g == null) { String msg = "Argument 'g [Grammar]' cannot be null."; throw new IllegalArgumentException(msg); } if (n instanceof Branch) { ((Branch) n).normalize(); } final XPath xpath = XPATH_LOCAL.get(); for (Iterator<?> it = xpath.selectNodes(n).iterator(); it.hasNext();) { Node d = (Node) it.next(); if (d.getText().trim().length() != 0) { Phrase p = g.newPhrase(d); Object o = p.evaluate(req, res); String value = o != null ? o.toString() : "null"; d.setText(value); } } }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
public static String readChildTag(String xml, String tagFather, String tag, String root) throws WDSException { try {/*w w w . j a v a 2 s.c o m*/ Document document = parse(xml); String xPathExpression = buildXPathExpression(tagFather, tag, root); Node node = document.selectSingleNode(xPathExpression); return node.getText(); } catch (NullPointerException e) { return null; } }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
public static String readTag(String xml, String tag, String root) throws WDSException { try {/*from w w w .ja v a2s . co m*/ Document document = parse(xml); String xPathExpression = buildXPathExpression(tag, root); Node node = document.selectSingleNode(xPathExpression); return node.getText(); } catch (Exception e) { e.printStackTrace(); throw new WDSException(e.getMessage()); } }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
@SuppressWarnings("unchecked") public static Map<String, String> readCollection(String xml, String[] tags, String nameTag, String valueTag, String root) throws WDSException { Map<String, String> m = new HashMap<String, String>(); try {/* w w w . ja v a 2s.co m*/ Document document = parse(xml); List l = document.selectNodes(buildXPathExpression(tags, root)); for (int i = 0; i < l.size(); i++) { Node parameters = (Node) l.get(i); Node name = parameters.selectSingleNode(nameTag); Node value = parameters.selectSingleNode(valueTag); m.put(name.getText(), value.getText()); } } catch (Exception e) { throw new WDSException(e.getMessage()); } return m; }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
@SuppressWarnings("unchecked") public static Map<String, String> readCollection(String xml, String[] tags, String valueTag, String root) throws WDSException { Map<String, String> m = new HashMap<String, String>(); try {//from w ww. jav a 2s. c o m Document document = parse(xml); List l = document.selectNodes(buildXPathExpression(tags, root)); for (int i = 0; i < l.size(); i++) { Node parameters = (Node) l.get(i); Node value = parameters.selectSingleNode(valueTag); m.put(valueTag, value.getText()); } } catch (Exception e) { throw new WDSException(e.getMessage()); } return m; }
From source file:org.foxbpm.bpmn.converter.util.BpmnXMLUtil.java
License:Apache License
/** * ??//from ww w .j a v a2 s .c om * * @param element * ? * @return ? */ @SuppressWarnings("rawtypes") public static String parseExpression(Element element) { Node node = null; if (element == null) { return null; } for (Iterator iterator = element.nodeIterator(); iterator.hasNext();) { node = (Node) iterator.next(); if (Element.CDATA_SECTION_NODE == node.getNodeType()) { return node.getText(); } } return null; }
From source file:org.gbif.portal.util.mhf.message.impl.xml.XMLMessage.java
License:Open Source License
/** * Gets a list of Strings for the multiple values that will be * returned from the XPath/* w ww .j a v a2s . c o m*/ * * @param location Xpath to evaluate * @return The List of Node */ @SuppressWarnings("unchecked") public List<String> getPartsAsString(Object location) throws MessageAccessException { if (!(location instanceof XPath)) { throw new MessageAccessException("Only XPath location's are supported for accessing XMLMessage parts - " + "received: " + location.getClass()); } XPath xpath = (XPath) location; String key = GET_PARTS_AS_STRING_KEY_PREFIX + xpath.getText(); if (getCache().containsKey(key)) { return (List<String>) getCache().get(key); } else { List<Node> result = (List<Node>) xpath.selectNodes(getDocument()); List<String> resultsAsString = new LinkedList<String>(); for (Node node : result) { resultsAsString.add(node.getText()); } getCache().put(key, resultsAsString); return resultsAsString; } }
From source file:org.geolatte.featureserver.config.FeatureServerConfiguration.java
License:Open Source License
/** * Reparses the configurationfile//from w w w. j av a 2 s . com * * @throws ConfigurationException if something went wrong parsing the file */ protected void reparse() throws ConfigurationException { error = true; setProperties(); includeRules = new ArrayList<String>(); excludeRules = new ArrayList<String>(); try { SAXReader reader = new SAXReader(); Document document = reader.read(propertyFileName); if (document == null) { throw new ConfigurationException( String.format("No such properties file found: %s", propertyFileName)); } List includes = document.selectNodes("//FeatureServerConfig/Mapping/Tables/Include/Item"); List excludes = document.selectNodes("//FeatureServerConfig/Mapping/Tables/Exclude/Item"); for (int i = 0; i < includes.size(); i++) { Element el = (Element) includes.get(i); includeRules.add(el.getTextTrim()); LOGGER.info(String.format("Include rule added: \"%s\"", el.getTextTrim())); } for (int i = 0; i < excludes.size(); i++) { Element el = (Element) includes.get(i); excludeRules.add(el.getTextTrim()); LOGGER.info(String.format("Exclude rule added: %s", el.getTextTrim())); } List hibernateConfigProps = document .selectNodes("//FeatureServerConfig/HibernateConfiguration/property"); hibernateProperties.clear(); for (int i = 0; i < hibernateConfigProps.size(); i++) { Element el = (Element) hibernateConfigProps.get(i); String propertyName = el.attributeValue("name"); if (!propertyName.startsWith("hibernate")) { propertyName = "hibernate." + propertyName; } String propertyValue = el.getTextTrim(); hibernateProperties.put(propertyName, propertyValue); } Node schema = document.selectSingleNode("//FeatureServerConfig/Mapping/Tables/Schema"); if (schema != null) { dbaseSchema = schema.getText(); LOGGER.info(String.format("Schema is: %s", dbaseSchema)); } else { dbaseSchema = null; LOGGER.info(String.format("No schema specified.")); } errorMessage = null; error = false; } catch (DocumentException e) { LOGGER.error("Error reading configuration file: ", e); errorMessage = e.getMessage(); throw new ConfigurationException("Error parsing the configurationfile: " + e.getMessage(), e); } }
From source file:org.hibernate.ogm.type.AbstractGenericBasicType.java
License:Open Source License
public final Object fromXMLNode(Node xml, Mapping factory) { return fromString(xml.getText()); }