Package com.google.walkaround.proto

Examples of com.google.walkaround.proto.ProtocolDocumentOperation


   * @param blipId
   * @param mutationOp
   * @return MutateDocument
   */
  public static MutateDocument createMutateDocumentMessage(String blipId, DocOp mutationOp) {
    final ProtocolDocumentOperation mutation = createMutationOp(mutationOp);

    MutateDocument operation = MessageFactoryHelper.createBlipContentMutation();

    operation.setDocumentId(blipId);
    operation.setDocumentOperation(mutation);
View Full Code Here


   * Convert the given document mutation op into a mutation op message
   * @param docOp
   * @return DocumentMutation
   */
  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);
        mutation.addComponent(component);
      }

      @Override
      public void characters(String characters) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setCharacters(characters);
        mutation.addComponent(component);
      }

      @Override
      public void elementStart(String type, Attributes attributes) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setElementStart(createElementStart(type, attributes));
        mutation.addComponent(component);
      }

      @Override
      public void elementEnd() {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setElementEnd(true);
        mutation.addComponent(component);
      }

      @Override
      public void deleteCharacters(String characters) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setDeleteCharacters(characters);
        mutation.addComponent(component);
      }

      @Override
      public void deleteElementStart(String type, Attributes attributes) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setDeleteElementStart(createElementStart(type, attributes));
        mutation.addComponent(component);
      }

      @Override
      public void deleteElementEnd() {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        component.setDeleteElementEnd(true);
        mutation.addComponent(component);
      }

      @Override
      public void replaceAttributes(Attributes oldAttributes, Attributes newAttributes) {
        Component component =
            MessageFactoryHelper.createDocumentOperationComponent();
        ReplaceAttributes replace =
            MessageFactoryHelper.createDocumentReplaceAttributes();
        if (oldAttributes.isEmpty() && newAttributes.isEmpty()) {
          replace.setEmpty(true);
        } else {
          for (Map.Entry<String, String> e : oldAttributes.entrySet()) {
            replace.addOldAttribute(createKeyValuePair(e.getKey(), e.getValue()));
          }
          for (Map.Entry<String, String> e : newAttributes.entrySet()) {
            replace.addNewAttribute(createKeyValuePair(e.getKey(), e.getValue()));
          }
        }
        component.setReplaceAttributes(replace);
        mutation.addComponent(component);
      }

      @Override
      public void updateAttributes(AttributesUpdate update) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        UpdateAttributes updateAttributes =
            MessageFactoryHelper.createDocumentUpdateAttributes();
        int n = update.changeSize();
        if (n == 0) {
          updateAttributes.setEmpty(true);
        } else {
          for (int i = 0; i < n; i++) {
          updateAttributes.addAttributeUpdate(createKeyValueUpdate(
              update.getChangeKey(i), update.getOldValue(i), update.getNewValue(i)));
          }
        }
        component.setUpdateAttributes(updateAttributes);
        mutation.addComponent(component);
      }

      @Override
      public void annotationBoundary(AnnotationBoundaryMap map) {
        Component component = MessageFactoryHelper.createDocumentOperationComponent();
        AnnotationBoundary boundary =
            MessageFactoryHelper.createDocumentAnnotationBoundary();
        int endSize = map.endSize();
        int changeSize = map.changeSize();
        if (endSize == 0 && changeSize == 0) {
          boundary.setEmpty(true);
        } else {
          for (int i = 0; i < endSize; i++) {
            boundary.addEnd(map.getEndKey(i));
          }
          for (int i = 0; i < changeSize; i++) {
            boundary.addChange(createKeyValueUpdate(map.getChangeKey(i),
                map.getOldValue(i), map.getNewValue(i)));
          }
        }
        component.setAnnotationBoundary(boundary);
        mutation.addComponent(component);
      }
    });
    return mutation;
  }
View Full Code Here

    document.setAuthor(blip.getAuthor().getAddress());
    document.setLastModifiedTime(blip.getLastModifiedTime());
    document.setLastModifiedVersion(blip.getLastModifiedVersion());
    document.addAllContributor(listOfParticipantAddresses(blip.getContributors()));

    ProtocolDocumentOperation documentOperation =
        OperationSerializer.createMutationOp(blip.getContent().asOperation());

    document.setContent(documentOperation);

    return document;
View Full Code Here

TOP

Related Classes of com.google.walkaround.proto.ProtocolDocumentOperation

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.