public String getElementStringValue(Object o) { return (o instanceof Node ? ((Node)o).getValue() : null); }
CoreMap sentence = new ArrayCoreMap(); sentence.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, offset); Tree tree = Tree.valueOf(sentElem.getChild(0).getValue()); // XXX ms: is this the same as sentElem.getText() in JDOM? List<CoreLabel> tokens = new ArrayList<>(); List<Tree> preTerminals = preTerminals(tree);
/** * Return the string value of the node. The interpretation of this depends * on the type of node. For an element it is the accumulated character * content of the element, including descendant elements. * * @return the string value of the node */ public String getStringValue() { return node.getValue(); }
/** * Return the string value of the node. The interpretation of this depends * on the type of node. For an element it is the accumulated character * content of the element, including descendant elements. * * @return the string value of the node */ public String getStringValue() { return node.getValue(); }
/** * Get the value of the item as a CharSequence. This is in some cases more efficient than * the version of the method that returns a String. */ public CharSequence getStringValueCS() { return node.getValue(); }
/** * Return the string value of the node. The interpretation of this depends * on the type of node. For an element it is the accumulated character * content of the element, including descendant elements. * * @return the string value of the node */ public String getStringValue() { return node.getValue(); }
/** * Get the value of the item as a CharSequence. This is in some cases more efficient than * the version of the method that returns a String. */ public CharSequence getStringValueCS() { return node.getValue(); }
/** * Get the value of the item as a CharSequence. This is in some cases more efficient than * the version of the method that returns a String. */ public CharSequence getStringValueCS() { return node.getValue(); }
/** get array elements. * recalcuates each time so best cached for frequent use * @return elements as String */ public List<String> getStringValues() { List<Node> nodeList = CMLUtil.getQueryNodes(this, CMLConstants.S_STAR); List<String> stringList = new ArrayList<String>(); for (Node node : nodeList) { stringList.add(node.getValue()); } return stringList; } }
void createDocumentation() { List<Node> docs = CMLUtil.getQueryNodes(simpleType, "./" + XSD_ANNOTATION + CMLConstants.S_SLASH + XSD_DOCUMENTATION, XPATH_XSD); if (docs.size() == 0) { } else if (docs.size() == 1) { Element documentation = (Element) docs.get(0); List<Node> summarys = CMLUtil.getQueryNodes(documentation, ".//*[@class='summary']"); summary = (summarys.size() == 0) ? null : summarys.get(0) .getValue(); List<Node> descriptions = CMLUtil.getQueryNodes(documentation, ".//*[@class='description']"); description = (descriptions.size() == 0) ? null : descriptions.get( 0).getValue(); } }
/** * gets String content. only valid when there is a single Text child. not * checked against the schema, so use with care * * @return the XML text content or null */ public String getStringContent() { Node child = (this.getChildCount() == 0) ? null : this.getChild(0); String s = (child == null || !(child instanceof Text)) ? null : child .getValue(); return s; }
/** * * @param nodeName * @param doc * @param expectedNumberOfNodes * @return * @throws org.openbase.jul.extension.xml.exception.XMLParsingException */ public static HashSet<String> extractValues(final String nodeName, final Node doc, final NumberOfNodes expectedNumberOfNodes) throws XMLParsingException { HashSet<String> names = new HashSet<>(); Nodes nodes = extractNodesByNodeName(nodeName, doc, expectedNumberOfNodes); for (int i = 0; i < nodes.size(); i++) { names.add(nodes.get(i).getValue()); } return names; }
/** * Found more than one adjacent Text node; merge them. Appends forwards * and removes backwards to minimize memory copies of list elems. */ private void merge(ParentNode node, int i, int j) { int k = i; StringBuffer buf = new StringBuffer(node.getChild(k++).getValue()); while (k <= j) buf.append(node.getChild(k++).getValue()); k = j; while (k >= i) node.removeChild(k--); // replace run with compact merged Text node unless empty String norm = normalizeWhitespace(buf.toString()); if (norm.length() > 0) { node.insertChild(new Text(norm), i); } }
/** * Found more than one adjacent Text node; merge them. Appends forwards * and removes backwards to minimize memory copies of list elems. */ private void merge(ParentNode node, int i, int j) { int k = i; StringBuffer buf = new StringBuffer(node.getChild(k++).getValue()); while (k <= j) buf.append(node.getChild(k++).getValue()); k = j; while (k >= i) node.removeChild(k--); // replace run with compact merged Text node unless empty String norm = normalizeWhitespace(buf.toString()); if (norm.length() > 0) { node.insertChild(new Text(norm), i); } }
/** * * @param nodeName * @param doc * @param expectedNumberOfNodes * @param throwException * @return * @throws org.openbase.jul.extension.xml.exception.XMLParsingException */ public static HashSet<String> extractValues(final String nodeName, final Node doc, final int expectedNumberOfNodes, final boolean throwException) throws XMLParsingException { HashSet<String> names = new HashSet<>(); Nodes nodes = extractNodesByNodeName(nodeName, doc, expectedNumberOfNodes, throwException); for (int i = 0; i < nodes.size(); i++) { names.add(nodes.get(i).getValue()); } return names; }
/** * convenience method to extract value of exactly one node. * uses element.query(xpath, xPathContext); * @param element * @param xpath * @param xPathContext defines prefix/namespace used in query * @return value if exactly 1 node (0 or many returns null) */ public static String getSingleValue(Element element, String xpath, XPathContext xPathContext) { String s = null; if (element == null) { LOG.warn("Null element"); } else { Nodes nodes = element.query(xpath, xPathContext); s = (nodes.size() == 1) ? nodes.get(0).getValue() : null; } return s; } /**
@Override public boolean apply(final BroadcastMessage broadcastMessage) { Document doc = broadcastMessage.signedBroadcastMessage.parsedBroadcastMessage.broadcastMessageDocument; for (UserIdentity identity : identityStore.getIdentitiesWithLabel(TrConstants.OWN)){ for(int docCount = 0; docCount<doc.query("//"+TrConstants.FormatInfo.MENTION).size(); docCount++){ if(identity.getNick().equals(doc.query("//"+TrConstants.FormatInfo.MENTION).get(docCount).getValue())){ return true; } } } return false; } }
@Test public void updateWithClassifier() throws ValidityException, ParsingException, IOException, MojoExecutionException { Document pom = new Builder() .build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml")))); Artifact artifact = new DefaultArtifact( "net.stickycode", "sticky-coercion", "jar", "", "[2.6,3)"); new StickyBoundsUpgradeMojo().updateDependency(pom, artifact, "[2.1,3)"); XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0"); Nodes versions = pom.query("//mvn:version", context); assertThat(versions.size()).isEqualTo(4); Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context); assertThat(nodes.size()).isEqualTo(1); Node node = nodes.get(0); assertThat(node.getValue()).isEqualTo("[2.6,3)"); }
@Test public void updateTheClassifier() throws ValidityException, ParsingException, IOException, MojoExecutionException { Document pom = new Builder() .build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml")))); Artifact artifact = new DefaultArtifact( "net.stickycode", "sticky-coercion", "jar", "test-jar", "[2.6,3)"); new StickyBoundsUpgradeMojo().updateDependency(pom, artifact, "[2.6,3)"); XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0"); Nodes versions = pom.query("//mvn:version", context); assertThat(versions.size()).isEqualTo(4); Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context); assertThat(nodes.size()).isEqualTo(1); Node node = nodes.get(0); assertThat(node.getValue()).isEqualTo("[2.6,3)"); }
@Test public void updateTheClassifier() throws ValidityException, ParsingException, IOException, MojoExecutionException { Document pom = new Builder() .build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml")))); Artifact artifact = new DefaultArtifact( "net.stickycode", "sticky-coercion", "jar", "test-jar", "[2.6,3)"); new StickyBoundsMojo().updateDependency(pom, artifact, "[2.1,3)"); XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0"); Nodes versions = pom.query("//mvn:version", context); assertThat(versions.size()).isEqualTo(4); Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context); assertThat(nodes.size()).isEqualTo(1); Node node = nodes.get(0); assertThat(node.getValue()).isEqualTo("[2.6,3)"); }