@Override public String getData(T textNode) { return inner.getData(textNode); }
private void getInnerTextOfText(T text, StringBuilder builder) { builder.append(document.getData(text)); }
/** * Writes a text node's information out to an initialization cursor. * NOTE(patcoleman): does not include annotations. * * @param doc Document the node resides within. * @param textNode Text node containing information to be written * @param cursor Cursor to write results out to. */ public static <N, E extends N, T extends N> void buildDomInitializationFromTextNode( ReadableDocument<N, E, T> doc, T textNode, DocInitializationCursor cursor) { cursor.characters(doc.getData(textNode)); }
/** * Construct a point at the end of either an element or text node. * @param doc Document containing the node * @param node The node to get the start of * @return The Point.El end if node is an element, otherwise the position at the last text offset. */ public static <N, E extends N, T extends N> Point<N> textOrElementEnd( ReadableDocument<N,E,T> doc, N node) { E elt = doc.asElement(node); return elt == null ? inText(node, doc.getData(doc.asText(node)).length()) : end(node); }
/** * Useful argument checking method for validating that an offset lies * within a text node * * @param doc * @param textNode * @param offset * @param msgPrefix string to prepend to exception, if thrown */ public static <N, T extends N> void checkOffset( ReadableDocument<N, ?, T> doc, T textNode, int offset, String msgPrefix) { Preconditions.checkNotNull(textNode, "Container must not be null"); if (offset < 0 || offset > doc.getLength(textNode)) { throw new IllegalArgumentException( msgPrefix + ": offset '" + offset + "' is not inside text node, " + "length " + doc.getLength(textNode) + ", text: '" + doc.getData(textNode) + "'"); } }
/** * Checks whether the current walk is a text node with the right data. * @throws IllegalStateException if the text node does not match the expected state. * @return the checked text node */ public T checkTextNode(String data) { Preconditions.checkState(nodeWalker.hasNext(), "Tree Walker: no more nodes to walk, text node expected"); progress(); T textNode = document.asText(currentNode); Preconditions.checkState(textNode != null, "Tree Walker: At element, text node expected"); Preconditions.checkState(document.getData(textNode).equals(data), "Tree Walker: Incorrect text node data"); return textNode; }
String value = displayWhitespace(doc.getData(text));
/** * Worker for appendNode * @param node * @return item length of node */ private int addNode(N node) { E element = view.asElement(node); if (element != null) { boolean selfClosing = isSelfClosing(element) && view.getFirstChild(element) == null; builder.append(startTag(element, selfClosing)); int len = 2; if (!selfClosing) { len += addChildXmlFragment(element); builder.append(endTag(element)); } return len; } else { String data = view.getData(view.asText(node)); return addText(permittedChars.coerceString(data)); } }
/** Performs a walk against an iterable collection of nodes, returns true if all checks pass. */ public boolean checkWalk(ReadableDocument<N, E, T> doc, Iterable<N> nodes) { try { for (N node : nodes) { E elt = doc.asElement(node); if (elt != null) { checkElement(doc.getTagName(elt), doc.getAttributes(elt)); } else { checkTextNode(doc.getData(doc.asText(node))); } } return checkComplete(); } catch (IllegalStateException e) { return false; // assertion failed. } }
private static <N, E extends N, T extends N> Tx<N> findCharacterInNode( ReadableDocument<N, E, T> doc, Tx<N> start, CharacterLocator locator, boolean forward) { assert start.getContainer() != null && doc.asText(start.getContainer()) != null; String data = doc.getData(doc.asText(start.getContainer())); int index = locator.indexOf(data, start.getTextOffset(), forward); if (index != -1) { return Point.inText(start.getContainer(), index); } else { return null; } }