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

Examples of org.waveprotocol.wave.model.document.operation.Nindo.Builder


    create(a);

    Element firstEl = (Element) doc.getFirstChild(doc.getDocumentElement());

    Builder b = at(0);
    Attributes attrs = attrs("x", "1", "y", "2");
    b.replaceAttributes(attrs);
    b.elementStart("x", attrs("a", "1"));
    b.characters("hello");
    b.elementStart("y", attrs("b", "2", "c", "3"));
    b.characters("yeah");
    b.elementEnd();
    b.elementEnd();
    String moreText = "more text";
    b.characters(moreText);
    consumeNindo(b.build());

    checkEvents(
        am(firstEl, pairs("x", null, "y", null), attrs),
        ci(doc.asElement(firstEl.getFirstChild())),
        ti(14, moreText));
View Full Code Here


    Node n1 = doc.getFirstChild(top);
    Node n2 = doc.getLastChild(top);
    List<Element> all = elementsInner(doc, top);
    List<Element> els = Arrays.asList(all.get(0), all.get(1));

    Builder b = at(0);
    Attributes attrs = attrs("x", "1", "y", "2");
    b.replaceAttributes(attrs);
    b.elementStart("x", attrs("a", "1"));
    b.characters("hello");
    b.elementStart("y", attrs("b", "2", "c", "3"));
    b.characters("yeah");
    b.elementEnd();
    b.elementEnd();
    String moreText = "more text";
    b.characters(moreText);
    b.deleteElementStart();
    b.deleteCharacters(3);
    b.deleteElementStart();
    b.deleteCharacters(3);
    b.deleteElementEnd();
    b.deleteElementEnd();
    String moreText2 = "more";
    b.characters(moreText2);
    consumeNindo(b.build());

    checkEvents(
        am(top, pairs("x", null, "y", null), attrs),
        ci(doc.asElement(top.getFirstChild())),
        ti(14, moreText),
View Full Code Here

  EventBundle<Node, Element, Text> getEvents() {
    return testNindoConsume ? events : events2;
  }

  private Builder at(int location) {
    Builder b = new Builder();
    if (location > 0) {
      b.skip(location);
    }
    return b;
  }
View Full Code Here

  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();
View Full Code Here

  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();
    }
  }
View Full Code Here

  // Helper DSL methods for building operations
  // at() creates a builder with cursor at the given location
  // Each other method does something convenient and returns the given builder

  private Builder at(int location) {
    Builder b = new Builder();
    if (location > 0) {
      b.skip(location);
    }
    return b;
  }
View Full Code Here

  }

  private Builder deleteRangeInternal(int startLocation, int endLocation) {
    // TODO(danilatos): Delete this method when deleting is redone efficiently

    Builder builder = at(startLocation);
    Point<N> start = doc.locate(startLocation);
    Point<N> end = doc.locate(endLocation);

    assert doc.isSameNode(
        Point.enclosingElement(doc, start.getContainer()),
        Point.enclosingElement(doc, end.getContainer()))
        : "Range must be within a single element";

    N node;
    if (start.isInTextNode()) {
      if (doc.isSameNode(start.getContainer(), end.getContainer())) {
        int size = end.getTextOffset() - start.getTextOffset();
        if (size > 0) {
          builder.deleteCharacters(size);
        }
        return builder;
      } else {
        int size = doc.getLength(doc.asText(start.getContainer())) - start.getTextOffset();
        node = doc.getNextSibling(start.getContainer());
        if (size > 0) {
          builder.deleteCharacters(size);
        }
      }
    } else {
      node = start.getNodeAfter();
    }

    N stop;
    if (end.isInTextNode()) {
      stop = end.getContainer();
    } else {
      stop = end.getNodeAfter();
    }

    while (node != stop) {
      N next = doc.getNextSibling(node);
      T text = doc.asText(node);
      if (text != null) {
        builder.deleteCharacters(doc.getData(text).length());
      } else {
        deleteElement(doc.asElement(node), builder);
      }
      node = next;
    }

    if (end.isInTextNode()) {
      int size = end.getTextOffset();
      if (size > 0) {
        builder.deleteCharacters(size);
      }
    }

    return builder;
  }
View Full Code Here

    if (useSemanticCopyPaste && waveXml != null) {
      if (!waveXml.isEmpty()) {
        instrumentor.record(Action.CLIPBOARD_PASTE_FROM_WAVE);

        // initialise the XML:
        Builder builder = at(pos);
        XmlStringBuilder createdFromXmlString =
            XmlStringBuilder.createFromXmlStringWithContraints(waveXml,
                PermittedCharacters.BLIP_TEXT);

        // Strip annotations based on behaviour:
        StringMap<String> modified = annotationLogic.stripKeys(
            destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

        double startTime = Duration.currentTimeMillis();
        // apply xml change
        MutableDocumentImpl.appendXmlToBuilder(createdFromXmlString, builder);
        double timeTaken = Duration.currentTimeMillis() - startTime;
        LOG.trace().log("time taken: " + timeTaken);

        // handle the end of annotations
        annotationLogic.unstripKeys(builder, modified.keySet(), CollectionUtils.createStringSet());
        builder.finish();
        Nindo nindo = builder.build();

        try {
          validator.maybeThrowOperationExceptionFor(nindo);

          int locationAfter = destDoc.getLocation(insertAt) + createdFromXmlString.getLength();
          destOperationSequencer.begin();
          destOperationSequencer.consume(nindo);
          destOperationSequencer.end();
          aggressiveSelectionHelper.setCaret(locationAfter);

          LOG.trace().log("annotations: " + String.valueOf(annotations));
          if (annotations != null && !annotations.isEmpty()) {
            List<RangedAnnotation<String>> deserialize =
                AnnotationSerializer.deserialize(annotations);
            for (RangedAnnotation<String> ann : deserialize) {
              destDoc.setAnnotation(pos + ann.start(), pos + ann.end(), ann.key(), ann.value());
              LOG.trace().log(
                  "pos: " + pos + "start: " + (pos + ann.start()) + " end: " + (pos + ann.end())
                      + " key: " + ann.key() + " value: " + ann.value());
            }
          }
        } catch (OperationException e) {
          LOG.error().log("Semantic paste failed");
          // Restore caret
          aggressiveSelectionHelper.setCaret(insertAt);
        }
      }
    } else {
      instrumentor.record(Action.CLIPBOARD_PASTE_FROM_OUTSIDE);

      // initialize tokenizer and builder
      RichTextTokenizer tokenizer = createTokenizer(srcContainer);
      Builder builder = at(pos);

      // handle annotation starts
      StringMap<String> modified = annotationLogic.stripKeys(
          destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

      // parse the tokens and apply ops
      RichTextMutationBuilder mutationBuilder = new RichTextMutationBuilder(modified);
      ReadableStringSet affectedKeys =
          mutationBuilder.applyMutations(tokenizer, builder, destDoc, insertAt.getContainer());

      // close annotations and finish
      annotationLogic.unstripKeys(builder, modified.keySet(), affectedKeys);
      builder.finish();
      Nindo nindo = builder.build();

      try {
        validator.maybeThrowOperationExceptionFor(nindo);

        destOperationSequencer.begin();
View Full Code Here

    if (useSemanticCopyPaste && waveXml != null) {
      if (!waveXml.isEmpty()) {
        instrumentor.record(Action.CLIPBOARD_PASTE_FROM_WAVE);

        // initialise the XML:
        Builder builder = at(pos);
        XmlStringBuilder createdFromXmlString =
            XmlStringBuilder.createFromXmlStringWithContraints(waveXml,
                PermittedCharacters.BLIP_TEXT);

        // Strip annotations based on behaviour:
        StringMap<String> modified = annotationLogic.stripKeys(
            destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

        double startTime = Duration.currentTimeMillis();
        // apply xml change
        MutableDocumentImpl.appendXmlToBuilder(createdFromXmlString, builder);
        double timeTaken = Duration.currentTimeMillis() - startTime;
        LOG.trace().log("time taken: " + timeTaken);

        // handle the end of annotations
        annotationLogic.unstripKeys(builder, modified.keySet(), CollectionUtils.createStringSet());
        builder.finish();
        Nindo nindo = builder.build();

        try {
          validator.maybeThrowOperationExceptionFor(nindo);

          int locationAfter = destDoc.getLocation(insertAt) + createdFromXmlString.getLength();
          destOperationSequencer.begin();
          destOperationSequencer.consume(nindo);
          destOperationSequencer.end();
          aggressiveSelectionHelper.setCaret(locationAfter);

          LOG.trace().log("annotations: " + String.valueOf(annotations));
          if (annotations != null && !annotations.isEmpty()) {
            List<RangedAnnotation<String>> deserialize =
                AnnotationSerializer.deserialize(annotations);
            for (RangedAnnotation<String> ann : deserialize) {
              destDoc.setAnnotation(pos + ann.start(), pos + ann.end(), ann.key(), ann.value());
              LOG.trace().log(
                  "pos: " + pos + "start: " + (pos + ann.start()) + " end: " + (pos + ann.end())
                      + " key: " + ann.key() + " value: " + ann.value());
            }
          }
        } catch (OperationException e) {
          LOG.error().log("Semantic paste failed");
          // Restore caret
          aggressiveSelectionHelper.setCaret(insertAt);
        }
      }
    } else {
      instrumentor.record(Action.CLIPBOARD_PASTE_FROM_OUTSIDE);

      // initialize tokenizer and builder
      RichTextTokenizer tokenizer = createTokenizer(srcContainer);
      Builder builder = at(pos);

      // handle annotation starts
      StringMap<String> modified = annotationLogic.stripKeys(
          destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

      // parse the tokens and apply ops
      RichTextMutationBuilder mutationBuilder = new RichTextMutationBuilder(modified);
      ReadableStringSet affectedKeys =
          mutationBuilder.applyMutations(tokenizer, builder, destDoc, insertAt.getContainer());

      // close annotations and finish
      annotationLogic.unstripKeys(builder, modified.keySet(), affectedKeys);
      builder.finish();
      Nindo nindo = builder.build();

      try {
        validator.maybeThrowOperationExceptionFor(nindo);

        destOperationSequencer.begin();
View Full Code Here

  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();
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.Nindo.Builder

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.