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

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


   */
  public static String collateTextForOps(Iterable<? extends DocOp> documentops,
      final Function<StringBuilder, Void> func) {
    final StringBuilder resultBuilder = new StringBuilder();
    for (DocOp docOp : documentops) {
      docOp.apply(InitializationCursorAdapter.adapt(new DocOpCursor() {
        @Override
        public void characters(String s) {
          resultBuilder.append(s);
        }

View Full Code Here


   */
  public static ProtocolDocumentOperation createMutationOp(DocOp docOp) {
    final ProtocolDocumentOperation mutation =
        MessageFactoryHelper.createDocumentOperation();

    docOp.apply(new DocOpCursor() {

      @Override
      public void retain(int itemCount) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setRetainItemCount(itemCount);
View Full Code Here

          @Override public void visitAddParticipant(AddParticipant op) {}
          @Override public void visitRemoveParticipant(RemoveParticipant op) {}
          @Override public void visitWaveletBlipOperation(final WaveletBlipOperation waveletOp) {
            waveletOp.getBlipOp().acceptVisitor(new BlipOperationVisitor() {
                @Override public void visitBlipContentOperation(BlipContentOperation blipOp) {
                  blipOp.getContentOp().apply(new DocOpCursor() {
                    @Override public void annotationBoundary(AnnotationBoundaryMap m) {}
                    @Override public void characters(String chars) {}
                    @Override public void elementEnd() {}
                    @Override public void deleteCharacters(String chars) {}
                    @Override public void deleteElementEnd() {}
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

   * @return A String containing the characters from the operations.
   */
  public static String collateTextForOps(Iterable<DocOp> documentops) {
    final StringBuilder resultBuilder = new StringBuilder();
    for (DocOp docOp : documentops) {
      docOp.apply(InitializationCursorAdapter.adapt(new DocOpCursor() {
        @Override
        public void characters(String s) {
          resultBuilder.append(s);
        }

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

    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

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.