/** * {@inheritDoc} */ @Override public DomText splitText(final int offset) { if (offset < 0 || offset > getLength()) { throw new IllegalArgumentException("offset: " + offset + " data.length: " + getLength()); } // split text into two separate nodes final DomText newText = createSplitTextNode(offset); setData(getData().substring(0, offset)); // insert new text node if (getParentNode() != null) { getParentNode().insertBefore(newText, getNextSibling()); } return newText; }
/** * {@inheritDoc} */ @Override public String getWholeText() { // I couldn't find a way to have a nearby EntityReference node (either sibling or parent) // if this is found, have a look at xerces TextImpl. return getNodeValue(); }
/** * Creates a new text node split from another text node. This method allows * the derived type of the new text node to match the original node type. * * @param offset the character position at which to split the DomText node * @return the newly created Text node */ protected DomText createSplitTextNode(final int offset) { return new DomText(getPage(), getData().substring(offset)); }
/** * Process {@link DomText}. * * @param builder the StringBuilder to add to * @param domText the target to process */ protected void appendText(final StringBuilder builder, final DomText domText) { final DomNode parent = domText.getParentNode(); if (parent == null || parent instanceof HtmlTitle || isVisible(parent)) { builder.append(domText.getData()); } }
/** * Recursively writes the XML data for the node tree starting at <code>node</code>. * * @param indent white space to indent child nodes * @param printWriter writer where child nodes are written */ @Override protected void printXml(final String indent, final PrintWriter printWriter) { if (getData().trim().length() != 0) { printWriter.print(indent); String data = getData(); if (!(getParentNode() instanceof HtmlStyle) || !data.startsWith("<!--") || !data.endsWith("-->")) { data = StringUtils.escapeXmlChars(data); } printWriter.println(data); } printChildrenAsXml(indent, printWriter); }
private String readValue() { final StringBuilder builder = new StringBuilder(); for (final DomNode node : getChildren()) { if (node instanceof DomText) { builder.append(((DomText) node).getData()); } } // if content starts with new line, it is ignored (=> for the parser?) if (builder.length() != 0 && builder.charAt(0) == '\n') { builder.deleteCharAt(0); } return builder.toString(); }
/** * {@inheritDoc} */ @Override public Text createTextNode(final String data) { return new DomText(this, data); }
/** * Allows the text value for the title element be replaced. * {@inheritDoc} */ @Override public void setNodeValue(final String message) { final DomNode child = getFirstChild(); if (child == null) { final DomNode textNode = new DomText(getPage(), message); appendChild(textNode); } else if (child instanceof DomText) { ((DomText) child).setData(message); } else { throw new IllegalStateException("For title tag, this should be a text node"); } }
/** * Performs the effective type action, called after the keyPress event and before the keyUp event. * @param c the character you with to simulate typing * @param htmlElement the element in which typing occurs * @param lastType is this the last character to type */ protected void doType(final char c, final HtmlElement htmlElement, final boolean lastType) { initDoTypeProcessor(); doTypeProcessor_.doType(getData(), selectionDelegate_, c, htmlElement, lastType); }
/** * {@inheritDoc} */ @Override public Node jsxGet_lastChild() { if (getBrowserVersion().isFirefox()) { final DomText text = new DomText(getDomNodeOrDie().getPage(), jsxGet_nodeValue()); return (Node) text.getScriptObject(); } return null; } }
/** * Splits this text node into two text nodes at the specified offset and inserts the new text node into the tree * as a sibling that immediately follows this node. * @param offset the number of characters at which to split this text node into two nodes, starting from zero * @return the new text node */ @JsxFunction public Object splitText(final int offset) { if (offset < 0) { throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data."); } final DomText domText = getDomNodeOrDie(); if (offset > domText.getLength()) { throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data."); } return getScriptableFor(domText.splitText(offset)); }
private void initTextNode() { if (textNode_ == null) { final String value = getValue(); if (!org.apache.commons.lang3.StringUtils.isEmpty(value)) { final DomText text = new DomText(getDomNodeOrDie().getPage(), value); getDomNodeOrDie().appendChild(text); textNode_ = text.getScriptableObject(); } } }
/** * Gives a simple representation to facilitate debugging. * @return a simple representation */ @Override public String toString() { return asText(); }
/** * Recursively writes the XML data for the node tree starting at <code>node</code>. * * @param indent white space to indent child nodes * @param printWriter writer where child nodes are written */ @Override protected void printXml(final String indent, final PrintWriter printWriter) { if (getData().trim().length() != 0) { printWriter.print(indent); String data = getData(); if (!(getParentNode() instanceof HtmlStyle) || !data.startsWith("<!--") || !data.endsWith("-->")) { data = StringUtils.escapeXmlChars(data); } printWriter.println(data); } printChildrenAsXml(indent, printWriter); }
private String readValueIE() { final StringBuilder builder = new StringBuilder(); for (final DomNode node : getDescendants()) { if (node instanceof DomText) { builder.append(((DomText) node).getData()); } } // if content starts with new line, it is ignored (=> for the parser?) if (builder.length() != 0 && builder.charAt(0) == '\n') { builder.deleteCharAt(0); } return builder.toString(); }
/** * Process {@link DomText}. * * @param builder the StringBuilder to add to * @param domText the target to process */ protected void appendText(final StringBuilder builder, final DomText domText) { final DomNode parent = domText.getParentNode(); if (parent == null || parent instanceof HtmlTitle || isVisible(parent)) { builder.append(domText.getData()); } }
/** * {@inheritDoc} */ public Text createTextNode(final String data) { return new DomText(this, data); }
private void setTextInternal(final String newValue) { initDefaultValue(); final DomText child = (DomText) getFirstChild(); if (child == null) { final DomText newChild = new DomText(getPage(), newValue); appendChild(newChild); } else { child.setData(newValue); } setSelectionStart(newValue.length()); setSelectionEnd(newValue.length()); }
/** * Performs the effective type action, called after the keyPress event and before the keyUp event. * * @param keyCode the key code wish to simulate typing * @param htmlElement the element in which typing occurs * @param lastType is this the last character to type */ protected void doType(final int keyCode, final HtmlElement htmlElement, final boolean lastType) { initDoTypeProcessor(); doTypeProcessor_.doType(getData(), selectionDelegate_, keyCode, htmlElement, lastType); }
/** * {@inheritDoc} */ @Override public Node jsxGet_lastChild() { if (getBrowserVersion().isFirefox()) { final DomText text = new DomText(getDomNodeOrDie().getPage(), jsxGet_nodeValue()); return (Node) text.getScriptObject(); } return null; } }