public void hackConsume(Nindo op) { begin(); try { consume(op); } finally { end(); } }
@Override public void setElementAttribute(E element, String name, String value) { String currentValue = getAttribute(element, name); if ((value == null && currentValue == null) || (value != null && value.equals(currentValue))) { // Redundant. Do nothing, no operation. return; } try { begin(); consume(setAttribute(name, value, at(Locator.before(doc, element)))); } finally { end(); } }
/** * Deletes a content element. Executes the delete in this document, and * places the caret in the deleted element's spot. Finally triggers * a single operation event matching the executed delete. * * @param element the element to delete */ public void deleteNode(E element) { try { begin(); consume(deleteElement(element, at(Locator.before(doc, element)))); } finally { end(); } }
/** * Deletes all children of a content element. Executes the delete in * this document, and places the caret in the emptied element. Finally * triggers a single operation event matching the executed delete. * * @param element the element to delete */ public void emptyElement(E element) { try { begin(); // Construct and apply delete operation consume(emptyElement(element, at(Locator.start(doc, element)))); } finally { end(); } }
@Override public void insertText(int location, String text) { Preconditions.checkPositionIndex(location, size()); // TODO(danilatos): Get the schema constraints from the document // and use the corresponding permitted characters from there. // text = getPermittedCharactersForPoint(point).convertString(text); try { begin(); consume(insertText(text, at(location))); } finally { end(); } }
@Override public void setAnnotation(int start, int end, String key, String value) { Annotations.checkPersistentKey(key); Preconditions.checkPositionIndexes(start, end, doc.size()); if (start == end) { return; } try { begin(); consume(Nindo.setAnnotation(start, end, key, value)); } finally { end(); } }
@Override public void setElementAttributes(E element, Attributes attrs) { Preconditions.checkArgument(element != getDocumentElement(), "Cannot touch root element"); try { begin(); consume(setAttributes(attrs, at(Locator.before(doc, element)))); } finally { end(); } }
@Override public void updateElementAttributes(E element, Map<String, String> attrs) { Preconditions.checkArgument(element != getDocumentElement(), "Cannot touch root element"); try { begin(); consume(updateAttributes(attrs, at(Locator.before(doc, element)))); } finally { end(); } }
@Override public E insertXml(Point<N> point, XmlStringBuilder xml) { Point.checkPoint(this, point, "MutableDocumentImpl.insertXml"); try { begin(); int where = doc.getLocation(point); Builder builder = at(where); appendXmlToBuilder(xml, builder); consume(builder); return Point.elementAfter(this, doc.locate(where)); } finally { end(); } }
begin(); consume(ab.build()); } finally {
@Override public E createElement(Point<N> point, String tagName, Map<String, String> attributes) { // TODO(danilatos): Validate point is in document. indexed doc should throw an exception // when calling getLocation anyway. Preconditions.checkNotNull(tagName, "createElement: tagName must not be null"); Point.checkPoint(this, point, "MutableDocumentImpl.createElement"); try { begin(); int location = doc.getLocation(point); consume(createElement(tagName, new AttributesImpl(attributes), at(location))); Point<N> result = doc.locate(location); return doc.asElement(result.isInTextNode() ? doc.getNextSibling(result.getContainer()) : result.getNodeAfter()); } finally { end(); } }
@Override public void resetAnnotation(int start, int end, String key, String value) { Annotations.checkPersistentKey(key); Preconditions.checkPositionIndexes(start, end, doc.size()); try { begin(); Builder b = new Builder(); if (start > 0) { b.startAnnotation(key, null); b.skip(start); } if (start != end) { b.startAnnotation(key, value); b.skip(end - start); } if (doc.size() != end) { b.startAnnotation(key, null); b.skip(doc.size() - end); } b.endAnnotation(key); consume(b.build()); } finally { end(); } }