public String getElementStringValue(Object o) { return (o instanceof Node ? ((Node)o).getValue() : null); }
public Object getParentNode(Object o) { return (o instanceof Node ? ((Node)o).getParent() : null); }
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); } }
/** * <p> * Returns the first Attribute with name attrName from Document doc. Uses xPath "// * * @throws org.openbase.jul.extension.xml.exception.XMLParsingException * @param throwException flag set throw exception if no such Attribute can be found. <br> * @param attrName * @param doc * @return */ public static String extractAttributeValue(final String attrName, final Node doc, final boolean throwException) throws XMLParsingException { String xpath = "descendant-or-self::*/@" + attrName; Nodes nodes = doc.query(xpath); for (int i = 0; i < nodes.size(); i++) { if (nodes.get(i) instanceof Attribute) { return nodes.get(i).getValue(); } } if (throwException) { throw new XMLParsingException("No Attribute " + attrName + " in document:\n" + doc.toXML()); } else { return null; } }
/** * remeoves all whitespace-only text nodes. * * @param element * to strip whitespace from */ public static void removeWhitespaceNodes(Element element) { int nChild = element.getChildCount(); List<Node> nodeList = new ArrayList<Node>(); for (int i = 0; i < nChild; i++) { Node node = element.getChild(i); if (node instanceof Text) { if (node.getValue().trim().length() == 0) { nodeList.add(node); } } else if (node instanceof Element) { Element childElement = (Element) node; removeWhitespaceNodes(childElement); } else { } } for (Node node : nodeList) { node.detach(); } }
public static void deleteNode(Document doc , String entityType, String entityName) { Node node = getNode(doc, entityType, entityName); if (node != null) { node.detach(); } }
public static Node skipNlTabWs(final Node oldDoc) throws CouldNotProcessException { Node copy = oldDoc.copy(); try { String oldString = oldDoc.toXML(); String newString = oldString.replace("\n", ""); newString = newString.replace("\t", ""); newString = newString.trim(); return createDocumentFromString(newString); } catch (Exception ex) { throw new CouldNotProcessException("Couldn't skipNlTabWs. Returning old document.", ex); } }
/** * Converts a xom node into something readable by Saxon * @param node * @param config * @return */ static NodeInfo wrap(Node node, Configuration config) { if (node == null) throw new IllegalArgumentException("node must not be null"); //$NON-NLS-1$ if (node instanceof DocType) throw new IllegalArgumentException("DocType can't be queried by XQuery/XPath"); //$NON-NLS-1$ Node root = node; while (root.getParent() != null) { root = root.getParent(); } XOMDocumentWrapper docWrapper = new XOMDocumentWrapper(root, root.getBaseURI(), config); return docWrapper.wrap(node); }
@Override public ENext doStart(IContext context, IResultSet result) throws PluginException { Node node = context.getNode(); ParentNode parent = node.getParent(); int index = parent.indexOf(node); TableAdapter table = UtilTable.newTable(node); continue; TableAdapter copy = UtilTable.newTable(node.copy()); String alias = SRServices.get(IPluginFactory.class).getAlias(PluginJoined.class); copy.setAttribute(UtilNode.ATT_CSS, table.getAttribute(UtilNode.ATT_CSS).replace(alias, "")); copy.setAttribute(ATTR_ACTION, c.getAttribute(ATTR_ACTION)); } else { Element e = (Element) c.getNode().getParent(); if (e.getAttribute(ATTR_ACTION) != null) { copy.setAttribute(ATTR_ACTION, e.getAttributeValue(ATTR_ACTION));
/** * Get the Base URI for the node, that is, the URI used for resolving a * relative URI contained in the node. */ public String getBaseURI() { return node.getBaseURI(); }
/** copies children of element make subclasses when required * * @param element to copy from * @param to */ public static void copyChildrenFromTo(Element element, Element to) { for (int i = 0; i < element.getChildCount(); i++) { Node childNode = element.getChild(i); Node newNode = childNode.copy(); to.appendChild(newNode); } }
/** override insertChild. * if newNode has parent detach()es first * @param newNode * @param pos */ public void insertChild(Node newNode, int pos) { newNode.detach(); super.insertChild(newNode, pos); }
/** * Get the Base URI for the node, that is, the URI used for resolving a * relative URI contained in the node. */ public String getBaseURI() { return node.getBaseURI(); }
/** copies children of element make subclasses when required * * @param element to copy from */ public void copyChildrenFrom(Element element) { for (int i = 0; i < element.getChildCount(); i++) { Node childNode = element.getChild(i); Node newNode = childNode.copy(); this.appendChild(newNode); } }
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);
public Object getDocumentNode(Object o) { ParentNode parent = null; if (o instanceof ParentNode) { parent = (ParentNode)o; } else if (o instanceof Node) { parent = ((Node)o).getParent(); } return parent.getDocument(); }
/** * @see com.isotrol.impe3.idx.oc.IndexCommand#execute(nu.xom.Node) */ public String execute(Node value) { return value.toXML(); } /**
/** remove all arg childern from element. * * @param element to remove args from */ public static void removeArgs(CMLElement element) { if (element != null) { List<Node> args = CMLUtil.getQueryNodes(element, CMLArg.NS, CMLConstants.CML_XPATH); for (Node arg : args) { arg.detach(); } } }
/** * Get the Base URI for the node, that is, the URI used for resolving a * relative URI contained in the node. */ public String getBaseURI() { return node.getBaseURI(); }
/** clone content of element with CountExpression and append. * clones the element content and appends to original element content * @param element to process * @throws RuntimeException null element or bad attribute */ public static void cloneContentAndAppend(CMLElement element) throws RuntimeException { if (element == null) { throw new RuntimeException("Cannot process null element"); } Element parent = (Element) element.getParent(); if (parent == null) { throw new RuntimeException("Cannot process CountExpressionAttribute without parent"); } CountExpressionAttribute cea = (CountExpressionAttribute) element.getAttribute(CountExpressionAttribute.NAME); int count = cea.calculateCountExpression(); int nChild = element.getChildCount(); for (int i = 1; i < count; i++) { for (int j = 0; j < nChild; j++) { Node newChild = element.getChild(j).copy(); element.appendChild(newChild); } } }