Package org.waveprotocol.wave.model.document.operation.impl

Examples of org.waveprotocol.wave.model.document.operation.impl.DocOpBuffer


      addPosition -= removeSize; // new insert should shift down
    }
    int remainder = doc.size() - removeSize - addPosition; // remainder after the insert

    // step 1: initialise the operations for the DOM and annotations:
    DocOpBuffer domOp = new DocOpBuffer();
    final AnnotationsNormalizer<DocOp> annotOp =
      new AnnotationsNormalizer<DocOp>(new UncheckedDocOpBuffer());
    if (addPosition > 0) {
      annotOp.retain(addPosition);
      domOp.retain(addPosition);
    }

    // step 2: fill in the DOM operations:
    for (N at = from; at != toExcl; at = doc.getNextSibling(at)) {
      DomOperationUtil.buildDomInitializationFromSubtree(doc, at, domOp);
    }

    // step 3: form the annotatinos
    AnnotationInterval<String> last = null;
    doc.knownKeys().each(new Proc() { // start all the keys
        @Override public void apply(String key) {
          annotOp.startAnnotation(key, null, doc.getAnnotation(removeStart, key));
        }
      });
    for (AnnotationInterval<String> interval : // update along the way
        doc.annotationIntervals(removeStart, removeEnd, null)) {
      interval.diffFromLeft().each(new ProcV<Object>() {
        @Override public void apply(String key, Object value) {
          assert value == null || value instanceof String;
          if (value != null) {
            annotOp.startAnnotation(key, null, (String) value);
          } else {
            annotOp.endAnnotation(key);
          }
        }
      });
      annotOp.retain(interval.length());
      last = interval;
    }
    doc.knownKeys().each(new Proc() { // close all the keys
      @Override public void apply(String key) {
        annotOp.endAnnotation(key);
      }
    });

    // step 4: close them out:
    if (remainder > 0) {
      domOp.retain(remainder);
      annotOp.retain(remainder);
    }

    // step 5: remove the entire range
    deleteRange(removeStart, removeEnd);

    // step 6: compose then consume the insertion op:
    DocOp atomicInsert;
    try {
      atomicInsert = Composer.compose(domOp.finish(), annotOp.finish());
      hackConsume(Nindo.fromDocOp(atomicInsert, true));
    } catch (OperationException e) {
      // should never happen, we constructed composable ops
    }
  }
View Full Code Here


    int position = DocHelper.getFilteredLocation(persistedLocations,
        persistedView, Point.end(localNode));
    int remainder = persistedLocations.size() - position;

    // create op, wrapping the tree operations within retains.
    DocOpBuffer opBuffer = new DocOpBuffer();
    safeRetain(opBuffer, position);
    DomOperationUtil.buildDomInitializationFromSubtree(localDoc, localNode, opBuffer);
    safeRetain(opBuffer, remainder);
    DocOp op = opBuffer.finish();

    // fake out the node creation, and consume:
    nodeCreationDelegate =
      new ReadableTreeWalker<ContentNode, ContentElement, ContentTextNode>(localDoc, localNode);
    sink.consume(op);
View Full Code Here

    int position = DocHelper.getFilteredLocation(persistedLocations,
        persistedView, Point.end(localNode));
    int remainder = persistedLocations.size() - position;

    // create op, wrapping the tree operations within retains.
    DocOpBuffer opBuffer = new DocOpBuffer();
    safeRetain(opBuffer, position);
    DomOperationUtil.buildDomInitializationFromSubtree(localDoc, localNode, opBuffer);
    safeRetain(opBuffer, remainder);
    DocOp op = opBuffer.finish();

    // fake out the node creation, and consume:
    nodeCreationDelegate =
      new ReadableTreeWalker<ContentNode, ContentElement, ContentTextNode>(localDoc, localNode);
    sink.consume(op);
View Full Code Here

    apply(cursor);
    return cursor.finish();
  }

  public static DocOp explode(DocOp op) {
    return new ExplodedDocOp(op).explodeWith(new DocOpBuffer());
  }
View Full Code Here

    boolean didSomethingOtherThanDeletionSinceAnnotationBoundary = false;

    private void begin2() {
      beginChange();
      builder = new AnnotationsNormalizer<DocOp>(
          performValidation ? new DocOpBuffer() : new UncheckedDocOpBuffer());
      sizeDiffSoFar = 0;
      deletionValues.clear();
    }
View Full Code Here

   * Scrubs the given operation. Ill-formed input is permitted but may lead to
   * ill-formed output. Invalid characters will be clearly noted.
   */
  public static DocOp scrub(final DocOp op) {
    try {
      DocOpBuffer b = new DocOpBuffer();
      op.apply(createScrubber(b));
      return b.finishUnchecked();
    } catch (RuntimeException e) {
      // This should not really happen unless perhaps the input operation has some
      // diabolically broken implementation of apply ofr of attribute or annotation datastructures.
      return new DocOpBuilder().characters("Scrub exploded: " + e).build();
    }
View Full Code Here

public class TestOperations {

  // The test case for the message-based implementation should also use this.
  public static DocOp getBasicTestOp() {
    DocOpBuffer b = new DocOpBuffer();

    // The operation starts with characters/deleteCharacters of various lengths
    // and case, mixed with some retains and nested element start/end with
    // different mixes of attributes.
    b.characters("hello");
    b.characters("z");
    b.retain(1);
    b.deleteCharacters("ab");
    b.characters("world");
    b.retain(2);
    b.deleteCharacters("cd");
    b.elementStart("a", Attributes.EMPTY_MAP);
    b.characters("hEllo");
    b.elementStart("b", new AttributesImpl("a", "1"));
    b.characters("world");
    b.elementStart("B", new AttributesImpl("A", "1", "b", "abc12"));
    b.elementEnd();
    // A non-ASCII Unicode character.
    b.characters("\u2603");
    b.elementEnd();
    b.elementEnd();
    b.deleteElementStart("a", new AttributesImpl("a", "2", "c", ""));
    b.deleteCharacters("asdf");
    b.deleteElementEnd();

    // Now some replaceAttributes with different size and case.
    b.replaceAttributes(new AttributesImpl("a", "b"), new AttributesImpl("b", "c", "c", "d"));
    b.replaceAttributes(Attributes.EMPTY_MAP, new AttributesImpl("Aa", "aA"));
    b.replaceAttributes(new AttributesImpl("B", "A"), new AttributesImpl());
    // Try both a fresh empty AttributesImpl() instance and the preallocated
    // EMPTY_MAP.
    b.replaceAttributes(new AttributesImpl(), Attributes.EMPTY_MAP);
    // Now we add similar cases for annotation boundaries.  Since consecutive annotation
    // boundaries would make the operation ill-formed, we interleave them with further
    // updateAttributes tests.
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder().build());
    b.updateAttributes(new AttributesUpdateImpl());
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .updateValues("b", "XZ", "yz", "f-", null, null,
            "g-", "a", null, "k-", "b", "", "r", "", "2")
        .build());
    b.updateAttributes(new AttributesUpdateImpl("a", null, "1"));
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .initializationEnd("b", "g-", "k-", "r")
        .updateValues("e", "166", null, "f-", null, null)
        .build());
    b.updateAttributes(new AttributesUpdateImpl("P", null, "", ":wq", "ZZ", null));
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .initializationEnd("e", "f-")
        .build());

    return b.finish();
  }
View Full Code Here

    target.modifyDocument(documentId, operation);
  }

  @Override
  public CoreWaveletOperation getInverse() {
    DocOpInverter<DocOp> inverse = new DocOpInverter<DocOp>(new DocOpBuffer());
    operation.apply(inverse);
    return new CoreWaveletDocumentOperation(documentId, inverse.finish());
  }
View Full Code Here

  private static final class InsertionTarget extends Target {

    NoninsertionTarget otherTarget;

    InsertionTarget(RelativePosition relativePosition) {
      super(new RangeNormalizer<DocOp>(new DocOpBuffer()), relativePosition);
    }
View Full Code Here

    private int depth = 0;

    private InsertionTarget otherTarget;

    NoninsertionTarget(RelativePosition relativePosition) {
      super(OperationNormalizer.createNormalizer(new DocOpBuffer()), relativePosition);
    }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.impl.DocOpBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.