List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.mindquarry.desktop.model.task.TaskTransformer.java
License:Open Source License
@Path("people/item") public void people(Node node) { Node personID = node.selectSingleNode("./person"); //$NON-NLS-1$ Node role = node.selectSingleNode("./role"); //$NON-NLS-1$ task.addPerson(personID.getText(), role.getText()); }
From source file:com.mindquarry.desktop.model.task.TaskTransformer.java
License:Open Source License
@Path("dependencies/item") public void dependencies(Node node) { Node taskID = node.selectSingleNode("./task"); //$NON-NLS-1$ Node role = node.selectSingleNode("./role"); //$NON-NLS-1$ task.addDependency(taskID.getText(), role.getText()); }
From source file:com.mirth.connect.connectors.jdbc.JdbcUtils.java
License:Open Source License
public static Object[] getParams(UMOEndpointURI uri, List<String> paramNames, Object root) throws Exception { Object[] params = new Object[paramNames.size()]; for (int i = 0; i < paramNames.size(); i++) { String param = paramNames.get(i); String name = param.substring(2, param.length() - 1); Object value = null;/* w w w.ja va 2 s .c o m*/ if ("NOW".equalsIgnoreCase(name)) { value = new Timestamp(Calendar.getInstance().getTimeInMillis()); } else if ("payload".equals(name)) { value = root; } else if (root instanceof MessageObject) { TemplateValueReplacer parser = new TemplateValueReplacer(); value = parser.replaceValues(param, (MessageObject) root); } else if (root instanceof Map) { value = ((Map) root).get(name); } else if (root instanceof org.w3c.dom.Document) { org.w3c.dom.Document x3cDoc = (org.w3c.dom.Document) root; org.dom4j.Document dom4jDoc = new DOMReader().read(x3cDoc); try { Node node = dom4jDoc.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else if (root instanceof org.dom4j.Document) { org.dom4j.Document dom4jDoc = (org.dom4j.Document) root; try { Node node = dom4jDoc.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else if (root instanceof org.dom4j.Node) { org.dom4j.Node dom4jNode = (org.dom4j.Node) root; try { Node node = dom4jNode.selectSingleNode(name); if (node != null) { value = node.getText(); } } catch (Exception ignored) { value = null; } } else { try { value = BeanUtils.getProperty(root, name); } catch (Exception ignored) { value = null; } } if (value == null) { value = uri.getParams().getProperty(name); } if (value == null) { throw new IllegalArgumentException("Can not retrieve argument " + name); } params[i] = value; } return params; }
From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java
License:Apache License
@SuppressWarnings("unchecked") private Map<Date, PollResults> getPage(final String after, final int pageNumber) { final Map<Date, PollResults> pageMap = new LinkedHashMap<Date, PollResults>(); HttpClientResponse httpResponse = null; try {/*from w w w . jav a 2 s . co m*/ final URL url = new URL(String.format(BASE_URL, after, pageNumber)); httpResponse = NetworkingUtil.get(url, null, null); final SAXReader saxReader = new SAXReader(); org.dom4j.Document document; try { document = saxReader.read(httpResponse.getInputStream()); } catch (DocumentException e) { throw new IOException(e); } finally { httpResponse.close(); } final SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD); final List<Node> questions = document.selectNodes(XPATH_QUESTIONS); for (final Node question : questions) { final Date endDate; final Node poll = question.selectSingleNode(ANCESTOR_POLL); final Node endDateNode = poll.selectSingleNode(END_DATE); try { endDate = format.parse(endDateNode.getText()); logger.debug(String.format("%s: %s", END_DATE, format.format(endDate))); } catch (final ParseException e) { throw new RuntimeException(e); } final List<Node> responses = question.selectNodes(XPATH_RESPONSE_FROM_QUESTION); for (final Node response : responses) { final Node choiceNode = response.selectSingleNode(CHOICE); final String choice = choiceNode.getText(); if (President2012DataSetImporter.CANDIDATE_OPTIONS.contains(choice)) { final Node valueNode = response.selectSingleNode(VALUE); final Double value = Double.valueOf(valueNode.getText()); append(pageMap, endDate, choice, value); } } } httpResponse.close(); httpResponse = null; } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (httpResponse != null) { httpResponse.close(); } } return pageMap; }
From source file:com.msg.wmTestHelper.metaModel.AbstractExtractor.java
License:Apache License
/** * Extracts a <code><value></code> element where the attribute name is like elementName. * * @param element the XML element./*from ww w . j ava2 s . c om*/ * @param elementName the name attribute value. * @return */ protected String extractPlainValue(Element element, String elementName) { Node nodeStepLabel = element.selectSingleNode(".//value[@name='" + elementName + "']"); if (nodeStepLabel != null && StringUtils.isNotEmpty(nodeStepLabel.getText())) { return nodeStepLabel.getText(); } log.warn("Value '{}' not given for element {} {}", elementName, element.getUniquePath(), element.getDocument().getName()); return StringUtils.EMPTY; }
From source file:com.nokia.helium.ant.data.AntComment.java
License:Open Source License
/** * Clean the whitespace of the doc text. * Trim the whole string and also remove a consistent indent from the start * of each line.//from w w w .j ava 2 s .c o m */ static String getCleanedDocNodeText(Node docNode) { Node preceedingWhitespaceNode = docNode.selectSingleNode("preceding-sibling::text()"); int indent = 0; if (preceedingWhitespaceNode != null) { String text = preceedingWhitespaceNode.getText(); String[] lines = text.split("\n"); if (lines.length > 0) { indent = lines[lines.length - 1].length(); } } String text = docNode.getText(); text = text.trim(); String[] docLines = text.split("\n"); // Do not remove from the first line, it is already trimmed. text = docLines[0] + "\n"; for (int i = 1; i < docLines.length; i++) { String line = docLines[i].replaceFirst("^[ \t]{" + indent + "}", ""); text += line + "\n"; } return text; }
From source file:com.nokia.helium.ant.data.ProjectMeta.java
License:Open Source License
@SuppressWarnings("unchecked") public List<PropertyCommentMeta> getPropertyCommentBlocks() { ArrayList<PropertyCommentMeta> objects = new ArrayList<PropertyCommentMeta>(); List<Node> nodes = getNode().selectNodes("//comment()"); for (Node node : nodes) { String text = node.getText().trim(); if (text.startsWith(DOC_COMMENT_MARKER + " @property")) { PropertyCommentMeta propertyCommentMeta = new PropertyCommentMeta(this, (Comment) node); propertyCommentMeta.setRuntimeProject(getRuntimeProject()); if (propertyCommentMeta.matchesScope(getScopeFilter())) { objects.add(propertyCommentMeta); }// w w w . j a va2s . co m } } return objects; }
From source file:com.nokia.helium.antlint.checks.CheckScriptDef.java
License:Open Source License
/** * Check against the given node./*from w w w . ja va 2 s . c o m*/ * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDef(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } if (!statements.isEmpty() && !props.isEmpty()) { for (Node statement : statements) { if (!props.contains(statement.valueOf("@name"))) { // for (String x : props) // log(x); log("Scriptdef " + name + " does not use " + statement.valueOf("@name")); } } } }
From source file:com.nokia.helium.antlint.checks.CheckScriptDefNameAttributes.java
License:Open Source License
/** * Check against the given node./*from w ww . java2 s . c om*/ * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDefNameAttributes(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } ArrayList<String> attributes = new ArrayList<String>(); for (Node statement : statements) { attributes.add(statement.valueOf("@name")); } for (String x : props) { if (!attributes.contains(x)) { log("Scriptdef " + name + " does not have attribute " + x); } } }
From source file:com.nokia.helium.antlint.checks.CheckScriptDefStyle.java
License:Open Source License
/** * Check against the given node./*from ww w . j av a2 s.c o m*/ * * @param node * is the node to check. */ @SuppressWarnings("unchecked") public void checkScriptDefStyle(String name, Node node) { List<Node> statements = node.selectNodes("//scriptdef[@name='" + name + "']/attribute"); Pattern p1 = Pattern.compile("attributes.get\\([\"']([^\"']*)[\"']\\)"); Matcher m1 = p1.matcher(node.getText()); ArrayList<String> props = new ArrayList<String>(); while (m1.find()) { props.add(m1.group(1)); } ArrayList<String> attributes = new ArrayList<String>(); for (Node statement : statements) { attributes.add(statement.valueOf("@name")); } if (!statements.isEmpty() && props.isEmpty()) { log("Scriptdef " + name + " doesn't reference attributes directly, poor style"); } }