Refine search
public void outputPretty(PrintWriter out, Annotation annotation) throws ServletException { try { Document input = XMLOutputter.annotationToDoc(annotation, pipeline); Nodes output = corenlpTransformer.transform(input); for (int i = 0; i < output.size(); i++) { out.print(output.get(i).toXML()); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new ServletException(e); } }
/** Wraps each item in the result sequence into a decorated element wrapper. */ private static Document wrapSequence(Nodes nodes) { // make a copy of the template for sequences: Element items = (Element) TEMPLATES.get(Nodes.class.getName()); items = new Element(items); int size = nodes.size(); for (int i=0; i < size; i++) { items.appendChild(wrap(nodes.get(i))); } return new Document(items); }
void updateProperty(Document pom, String propertyName, String newVersion) throws MojoExecutionException { XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0"); Nodes nodes = pom.query("//mvn:properties", context); if (nodes.size() > 0) { final Element propertiesElement = (Element) nodes.get(0); Elements properties = propertiesElement.getChildElements(); for (int i = 0; i < properties.size(); i++) { Element property = properties.get(i); if (property.getLocalName().equals(propertyName)) { Element newRange = new Element(propertyName, "http://maven.apache.org/POM/4.0.0"); newRange.appendChild(newVersion); propertiesElement.replaceChild(property, newRange); } } } }
/** * convenience method to get exactly one element. * uses element.query(xpath, xPathContext); * @param element * @param xpath * @param xPathContext defines prefix/namespace used in query * @return value if exactly 1 element (0 or many returns null) */ public static Element getSingleElement(Element element, String xpath, XPathContext xPathContext) { Nodes nodes = element.query(xpath, xPathContext); return (nodes.size() == 1) ? (Element) nodes.get(0) : null; }
for (int i = 0; i < contentElements.size(); i++) { final Element contentElement = (Element) contentElements.get(i); final String typeName = contentElement.getAttributeValue("name"); final String typeId = contentElement.getAttributeValue("id"); final boolean isContent = Boolean.parseBoolean(contentElement.getAttributeValue("content"));
@Override protected void appendChildrenToNewParent(Element oldParent, Element newParent) throws SAXException { try { Nodes children = oldParent.removeChildren(); for (int i = 0; i < children.size(); i++) { newParent.appendChild(children.get(i)); } } catch (XMLException e) { fatal(e); } }
private static void appendNodes(Element elem, Nodes nodes) { if (nodes != null) { int size = nodes.size(); for (int i=0; i < size; i++) { Node node = nodes.get(i); if (node instanceof Attribute) { elem.addAttribute((Attribute) node); } else { elem.insertChild(node, elem.getChildCount()); } } } }
current.insertChild(elem, current.getChildCount()); continue; // skip element ParentNode parent = elem.getParent(); if (parent == null) throwTamperedWithParent(); if (parent instanceof Document) { if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case) continue; // optimization: no need to remove and then readd same element
final CoverageResult.Type type = (CoverageResult.Type) TAG_2_TYPE.get( elem.getLocalName() ); if ( type == null ) name = elem.getAttributeValue( "name" ); final Nodes coverageNodes = elem.query( "coverage" ); final int len = coverageNodes.size(); for ( int i = 0; i < len; ++i ) final Element coverageElem = (Element) coverageNodes.get( i ); final String coverageType = coverageElem.getAttributeValue( "type" ); if ( StringUtils.isEmpty( coverageType ) )
Nodes resourceNodes = yourDoc.query("//*[local-name()='resource']"); for (int i = 0; i < resourceNodes .size(); i++) { Element resource = (Element) resourceNodes .get(i); Elements childElements = resource.getChildElements(); // .. etc }
/** process all arg/@substitute in element. * * @param element to edit */ public static void substituteTextContent(CMLElement element) { Nodes textContentArgs = element.query(".//"+CMLArg.NS+"[@substitute[.='.']]", CMLConstants.CML_XPATH); for (int i = 0; i < textContentArgs.size(); i++) { CMLArg textContentArg = (CMLArg) textContentArgs.get(i); String value = textContentArg.getValue(); if (value.startsWith(START_CHARS) && value.endsWith(END_CHARS)) { // unsubstituted arg } else { Element parent = (Element) textContentArg.getParent(); parent.appendChild(new Text(value)); } textContentArg.detach(); } }
@Override public ISource transform(ISource source) throws SourceException { Document d = source.getDocument(); Nodes tables = d.query("//table"); for (int i = 0; i < tables.size(); i++) { Element table = (Element) tables.get(i); table.addAttribute(new Attribute("class", getValue())); } return source; }
if (nodes.size() > 0) { Attribute attr = ((Element) nodes.get(0)).getAttribute("srsName"); if (attr != null) { crs = attr.getValue(); if (nodes.size() > 0) { double[] xy = splitDoubles(nodes.get(0).getValue()); minx = xy[0]; miny = xy[1]; if (nodes.size() > 0) { double[] xy = splitDoubles(nodes.get(0).getValue()); maxx = xy[0]; maxy = xy[1]; if (nodes.size() > 0) { double[] xy = splitDoubles(nodes.get(0).getValue()); xcells = (int) xy[0]; ycells = (int) xy[1];
private void removeIrrelevantFooter(Element rootElement) { Element body = rootElement.getFirstChildElement("body"); body.removeChild(rootElement.query("//div[@class='footer']").get(0)); } }
private String categorize(Element row) { String cssClass = row.getAttributeValue("class"); if (cssClass == null) { Element cell = (Element) row.query("td").get(0); cssClass = cell.getAttributeValue("class"); } Check.notNull(cssClass, "cssClass is null"); return cssClass.toUpperCase(); }
/** * Does nothing if only one of nodes1, nodes2 or nodes3 contains more than zero nodes. Throws InvalidCfgDocException otherwise. * * * @param nodes1 * @param nodes2 * @param nodes3 * @param nodeTypeForDebugging * @throws org.openbase.jul.extension.xml.exception.XMLParsingException */ public static void xorCheck(final Nodes nodes1, final Nodes nodes2, final Nodes nodes3, final String nodeTypeForDebugging) throws XMLParsingException { if (nodes1.size() > 0 && nodes2.size() > 0 && nodes3.size() > 0) { throw new XMLParsingException("Message contains more than one " + nodeTypeForDebugging + " node. Only one permitted."); } }
//WRITER document (odt) Nodes odtScriptNodes = document.query("//text:script[translate(@script:language, 'CIJOPRST', 'cijoprst')='jooscript']", XPATH_CONTEXT); Nodes scriptNodes = odtScriptNodes; //CALC document (ods) Nodes odsPotentialScriptNodes = document.query("//table:table-cell", XPATH_CONTEXT); for(int nodeIndex = 0; nodeIndex < odsPotentialScriptNodes.size(); nodeIndex++){ Element tableCellElement = (Element) odsPotentialScriptNodes.get(nodeIndex); Elements textElements = tableCellElement.getChildElements(); if(textElements.size() > 0 && textElements.get(0).getValue().toLowerCase().startsWith("--!jooscript:")){ String fullScript = textElements.get(0).getValue().substring("--!jooscript:".length()); for(int elementIndex = 1; elementIndex < textElements.size(); elementIndex++){ fullScript += System.getProperty("line.separator") + textElements.get(elementIndex).getValue(); } for(int elementIndex = textElements.size()-1; elementIndex > 0; elementIndex--){ tableCellElement.removeChild(elementIndex); } Element firstTextElement = (Element) tableCellElement.getChild(0); firstTextElement.removeChildren(); firstTextElement.appendChild(fullScript); scriptNodes.append(firstTextElement); } }
public static Element extractOneChildElementByXPath(final String xPath, Node node) throws MissingNodeException, OverissueNodeException, NotOneNodeException { return (Element) extractNodesByXpath(xPath, node, NumberOfNodes.EXACT_ONE).get(0); }