List of usage examples for com.google.gwt.dom.client Text setData
@Override
public void setData(String data)
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.decorator.AnnoteaDecoratorVisitor.java
License:Apache License
private void processToFirstNode(Node node) { if (!(node.getNodeType() == Node.TEXT_NODE)) { return;//from w ww. j a va2s . c o m } Text text = (Text) node; String data = text.getData(); if (data.length() < offset) { offset -= data.length(); return; } decorating = true; Node parent = text.getParentNode(); if (data.endsWith(" ")) { lastCharIsSpace = true; } String notInData = data.substring(0, offset); text.setData(notInData); processDecoratedNode(node, data.substring(offset), parent); }
From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.decorator.NuxeoDecoratorVisitor.java
License:Apache License
protected void processToFirstNode() { Log.debug("Decorator -- processToFirstNode: " + currentNode.getNodeName()); if (!(currentNode.getNodeType() == Node.TEXT_NODE)) { return;//from ww w . j a va 2s .co m } Text text = (Text) currentNode; String data = text.getData(); Log.debug("Decorator -- text data before: " + data); data = Utils.removeWhitespaces(data, currentNode); Log.debug("Decorator -- text data after: " + data); if (data.length() < startOffset) { startOffset -= data.length(); if (startNode.equals(endNode)) { endOffset -= data.length(); } return; } decorating = true; String notInData = data.substring(0, startOffset); decorateText(data.substring(startOffset)); text.setData(notInData); }
From source file:org.vectomatic.svg.edit.client.model.svg.SVGNamedElementModel.java
License:Open Source License
/** * Ensures the specified element has a title and a desc. If * no title is found, a new title is set to specified value * @param element/*from w ww.j av a 2 s .c o m*/ * The element to control * @param name * The value of the title none pre-exists in the element * @return * The title value */ public static String createTitleDesc(SVGElement element, String name) { // Create the title child node if missing Document document = DOMHelper.getCurrentDocument(); SVGTitleElement title = DOMHelper.evaluateNodeXPath(element, "./svg:title", SVGPrefixResolver.INSTANCE); if (title == null) { title = DOMHelper.createElementNS(document, SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_TITLE_TAG) .cast(); Node firstChild = element.getFirstChild(); if (firstChild == null) { element.appendChild(title); } else { element.insertBefore(title, firstChild); } } Text titleText = DOMHelper.evaluateNodeXPath(element, "./svg:title/text()", SVGPrefixResolver.INSTANCE); if (titleText == null) { titleText = title.appendChild(document.createTextNode("")); } if (titleText.getData().length() == 0) { titleText.setData(name); } // Create the desc child node if missing SVGTitleElement desc = DOMHelper.evaluateNodeXPath(element, "./svg:desc", SVGPrefixResolver.INSTANCE); if (desc == null) { desc = DOMHelper.createElementNS(document, SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_DESC_TAG) .cast(); element.insertAfter(desc, title); } Text descText = DOMHelper.evaluateNodeXPath(element, "./svg:desc/text()", SVGPrefixResolver.INSTANCE); if (descText == null) { descText = desc.appendChild(document.createTextNode("")); } return titleText.getData(); }
From source file:org.vectomatic.svg.edit.client.model.XPathMetadata.java
License:Open Source License
@Override public T set(SVGElement element, T value) { T oldValue = null;// ww w . j av a 2 s.c om Node node = DOMHelper.evaluateNodeXPath(element, xpath, SVGPrefixResolver.INSTANCE); if (node != null) { switch (node.getNodeType()) { case Node.TEXT_NODE: { Text text = node.cast(); oldValue = (T) text.getData(); text.setData((String) value); } break; case 2: { Attr attr = node.cast(); oldValue = (T) attr.getValue(); attr.setValue((String) value); } break; default: assert (false); } } return oldValue; }
From source file:org.waveprotocol.wave.client.clipboard.Clipboard.java
License:Apache License
/** * Hijacks the paste fragment by hiding a span with metadata at the end of the * fragment./*from w w w . j av a 2s . c om*/ * * @param xmlInRange The xml string to pass into the magic span element * @param annotations The annotation string to pass into the magic span * element * @param origRange the current range. The span element will be inserted * before the start * * @return The new adjusted selection. The end will be adjusted such that it * encloses the original selection and the span with metadata */ private PointRange<Node> hijackFragment(String xmlInRange, String annotations, PointRange<Node> origRange) { Point<Node> origStart = origRange.getFirst(); Point<Node> origEnd = origRange.getSecond(); SpanElement spanForXml = Document.get().createSpanElement(); spanForXml.setAttribute(WAVE_XML_ATTRIBUTE, xmlInRange); spanForXml.setAttribute(WAVE_ANNOTATIONS_ATTRIBUTE, annotations); spanForXml.setClassName(MAGIC_CLASSNAME); LOG.trace().log("original point: " + origStart); // NOTE(user): An extra span is required at the end for Safari, otherwise // the span with the metadata may get discarded. SpanElement trailingSpan = Document.get().createSpanElement(); trailingSpan.setInnerHTML(" "); if (origEnd.isInTextNode()) { Text t = (Text) origEnd.getContainer(); t.setData(t.getData().substring(0, origEnd.getTextOffset())); origEnd.getContainer().getParentElement().insertAfter(spanForXml, t); origEnd.getContainer().getParentElement().insertAfter(trailingSpan, spanForXml); } else { origEnd.getContainer().insertAfter(spanForXml, origEnd.getNodeAfter()); origEnd.getContainer().insertAfter(trailingSpan, spanForXml); } Point<Node> newEnd = Point.<Node>inElement(spanForXml.getParentElement(), trailingSpan.getNextSibling()); LOG.trace().log("new point: " + newEnd); LOG.trace().logPlainText("parent: " + spanForXml.getParentElement().getInnerHTML()); assert newEnd.getNodeAfter() == null || newEnd.getNodeAfter().getParentElement() == newEnd.getContainer() : "inconsistent point"; return new PointRange<Node>(origStart, newEnd); }
From source file:org.waveprotocol.wave.client.clipboard.PasteBufferImplSafari.java
License:Apache License
private void maybeStripMarker(Node node, Element parent, boolean leading) { if (node == null) { logEndNotFound("node is null"); return;//from w w w . ja v a2s .c o m } if (DomHelper.isTextNode(node)) { Text textNode = node.cast(); String text = textNode.getData(); if (!text.isEmpty()) { if (leading) { if (text.charAt(0) == MARKER_CHAR) { textNode.setData(text.substring(1)); } } else { if (text.charAt(text.length() - 1) == MARKER_CHAR) { textNode.setData(text.substring(0, text.length() - 1)); } else { logEndNotFound("last character is not marker"); } } } else { logEndNotFound("text node is empty"); } if (textNode.getData().isEmpty()) { parent.removeChild(textNode); } } else { // In some cases, Safari will put the marker inside of a div, so this // traverses down the left or right side of the tree to find it. // For example: x<div><span>pasted</span>x</div> maybeStripMarker(leading ? node.getFirstChild() : node.getLastChild(), node.<Element>cast(), leading); } }
From source file:org.waveprotocol.wave.client.editor.content.ContentTextNode.java
License:Apache License
/** * Compacts the multiple impl text nodelets into one * @throws HtmlMissing// w w w . jav a 2 s . c o m */ public void normaliseImplThrow() throws HtmlMissing { // TODO(danilatos): Some code in line container depends on the isImplAttached() check, // but sometimes it might not be attached but should, and so should throw an exception. if (!isContentAttached() || !isImplAttached()) { simpleNormaliseImpl(); } Text first = getImplNodelet(); if (first.getLength() == getLength()) { return; } ContentNode next = checkNodeAndNeighbour(this); HtmlView filteredHtml = getFilteredHtmlView(); //String sum = ""; Node nextImpl = (next == null) ? null : next.getImplNodelet(); for (Text nodelet = first; nodelet != nextImpl && nodelet != null; nodelet = filteredHtml.getNextSibling(first).cast()) { //sum += nodelet.getData(); if (nodelet != first) { getExtendedContext().editing().textNodeletAffected(nodelet, -1000, -1000, TextNodeChangeType.REMOVE); nodelet.removeFromParent(); } } getExtendedContext().editing().textNodeletAffected(first, -1000, -1000, TextNodeChangeType.REPLACE_DATA); first.setData(getData()); }
From source file:org.waveprotocol.wave.client.editor.content.ContentTextNode.java
License:Apache License
/** * Same as {@link #normaliseImplThrow()}, but uses a repairer to fix problems * rather than throw an exception/*from w w w .j ava2 s . c o m*/ */ @Override public Text normaliseImpl() { Repairer repairer = getRepairer(); for (int i = 0; i < MAX_REPAIR_ATTEMPTS; i++) { try { normaliseImplThrow(); return getImplNodelet(); } catch (HtmlMissing e) { repairer.handle(e); } catch (RuntimeException e) { // Safe to catch runtime exception - no stateful code should be affected, // just browser DOM has been munged which we repair repairer.revert(Point.before(getRenderedContentView(), this), null); } } Text nodelet = getImplNodelet(); getExtendedContext().editing().textNodeletAffected(nodelet, -1000, -1000, TextNodeChangeType.REPLACE_DATA); nodelet.setData(getData()); return nodelet; }
From source file:org.waveprotocol.wave.client.editor.testing.FakeUser.java
License:Apache License
private void deleteText(int amount) { Point<Node> sel = getSelectionStart(); Text txt = sel == null ? null : sel.getContainer().<Text>cast(); int startIndex = sel.getTextOffset(), len; while (amount > 0) { if (txt == null || !DomHelper.isTextNode(txt)) { throw new RuntimeException("Action ran off end of text node"); }/*w w w .ja va 2 s. c o m*/ String data = txt.getData(); int remainingInNode = data.length() - startIndex; if (remainingInNode >= amount) { len = amount; } else { len = remainingInNode; } txt.setData(data.substring(0, startIndex) + data.substring(startIndex + len)); amount -= len; startIndex = 0; txt = htmlView.getNextSibling(txt).cast(); } moveCaret(0); }