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

Examples of org.waveprotocol.wave.model.document.operation.DocOpCursor


  public static DocOpCursor createScrubber(final DocOpCursor target) {
    final ScrubCache attrNames = new ScrubCache(attrNameScrubber);
    final ScrubCache annotationNames = new ScrubCache(annotationKeyScrubber);

    return new DocOpCursor() {
      @Override
      public void deleteCharacters(String chars) {
        target.deleteCharacters(scrubString(chars));
      }
View Full Code Here


   * @param inputOp document operation to serialize
   * @return serialized protocol buffer document operation
   */
  public static ProtocolDocumentOperation serialize(DocOp inputOp) {
    final ProtocolDocumentOperation output = ProtocolDocumentOperationJsoImpl.create();
    inputOp.apply(new DocOpCursor() {

      private Component addComponent() {
        ComponentJsoImpl component = ComponentJsoImpl.create();
        output.addComponent(component);
        return component;
View Full Code Here

    op.apply(createConciseStringBuilder(op, b));
    return b.toString();
  }

  public static DocOpCursor createConciseStringBuilder(DocOp op, final StringBuilder b) {
    return new DocOpCursor() {
      @Override
      public void deleteCharacters(String chars) {
        b.append("--" + literalString(chars) + "; ");
      }
View Full Code Here

   * Computes the number of items of the document that an op applies to, prior
   * to its application.
   */
  public static int initialDocumentLength(DocOp op) {
    final int[] size = { 0 };
    op.apply(new DocOpCursor() {
      @Override
      public void deleteCharacters(String chars) {
        size[0] += chars.length();
      }

View Full Code Here

   * Computes the number of items of the document that an op produces when
   * applied.
   */
  public static int resultingDocumentLength(DocOp op) {
    final int[] size = { 0 };
    op.apply(new DocOpCursor() {
      @Override
      public void deleteCharacters(String chars) {
      }

      @Override
View Full Code Here

    final DocInitialization exploded = ExplodedDocOp.explode(doc);

    final int numDocComponents = exploded.size();

    final DocOpCursor opStringifier = createConciseStringBuilder(op, opB);

    final DocInitializationBuffer target = new DocInitializationBuffer();
    new Runnable() {
      int index = 0;
      int docItem = 0;

      private void runTarget(int itemCount) {
        indicesB.append(docItem);
        docItem += itemCount;
        while (index < numDocComponents && itemCount > 0) {
          exploded.applyComponent(index, target);
          if (exploded.getType(index) != DocOpComponentType.ANNOTATION_BOUNDARY) {
            itemCount--;
          }
          index++;
        }
      }

      private void matchUp() {
        int max = 0;
        for (StringBuilder b : builders) {
          max = Math.max(max, b.length());
        }
        for (StringBuilder b : builders) {
          while (b.length() < max) {
            b.append(' ');
          }
        }
      }

      @Override
      public void run() {
        op.apply(new DocOpCursor() {

          @Override
          public void deleteCharacters(String chars) {
            opStringifier.deleteCharacters(chars);
            runTarget(chars.length());
            matchUp();
          }

          @Override
          public void deleteElementEnd() {
            opStringifier.deleteElementEnd();
            runTarget(1);
            matchUp();
          }

          @Override
          public void deleteElementStart(String type, Attributes attrs) {
            opStringifier.deleteElementStart(type, attrs);
            runTarget(1);
            matchUp();
          }

          @Override
          public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) {
            opStringifier.replaceAttributes(oldAttrs, newAttrs);
            runTarget(1);
            matchUp();
          }

          @Override
          public void retain(int itemCount) {
            opStringifier.retain(itemCount);
            runTarget(itemCount);
            matchUp();
          }

          @Override
          public void updateAttributes(AttributesUpdate attrUpdate) {
            opStringifier.updateAttributes(attrUpdate);
            runTarget(1);
            matchUp();
          }

          @Override
          public void annotationBoundary(AnnotationBoundaryMap map) {
            opStringifier.annotationBoundary(map);
            matchUp();
          }

          @Override
          public void characters(String chars) {
            opStringifier.characters(chars);
            matchUp();
          }

          @Override
          public void elementEnd() {
            opStringifier.elementEnd();
            matchUp();
          }

          @Override
          public void elementStart(String type, Attributes attrs) {
            opStringifier.elementStart(type, attrs);
          }

        });
        runTarget(1);
      }
View Full Code Here

      schema = DocumentSchema.NO_SCHEMA_CONSTRAINTS;
    }
    final DocOpAutomaton a = new DocOpAutomaton(doc, schema);
    final ValidationResult[] accu = new ValidationResult[] { ValidationResult.VALID };
    try {
      op.apply(new DocOpCursor() {
        void abortIfIllFormed() {
          if (accu[0].isIllFormed()) {
            throw ILL_FORMED;
          }
        }
View Full Code Here

  public ExplodedDocOp(DocOp source) {
    this.source = source;
  }

  private void apply(final DocOpCursor target) {
    source.apply(new DocOpCursor() {
      @Override
      public void deleteCharacters(String chars) {
        for (int i = 0; i < chars.length(); i++) {
          target.deleteCharacters(chars.substring(i, i + 1));
        }
View Full Code Here

    final ListIterator<Item> iterator = items.listIterator();
    try {
      // In theory, the above call to the validator makes the error checking in
      // this DocOpCursor redundant.  We check for errors anyway in case the
      // validator is incorrect.
      m.apply(new DocOpCursor() {

        Item current = null;

        AnnotationMap inherited = AnnotationMapImpl.EMPTY_MAP;
View Full Code Here

   * @return serialized protocol buffer document operation
   */
  public static ProtocolDocumentOperation serialize(DocOp inputOp) {
    final ProtocolDocumentOperation.Builder output = ProtocolDocumentOperation.newBuilder();

    inputOp.apply(new DocOpCursor() {
      private ProtocolDocumentOperation.Component.Builder newComponentBuilder() {
        return ProtocolDocumentOperation.Component.newBuilder();
      }

      @Override public void retain(int itemCount) {
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.DocOpCursor

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.