Package com.google.wave.api

Examples of com.google.wave.api.Range


  public void testFailOnMultipleWhereParams() throws Exception {
    OperationRequest operation =
        operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId,
            Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction()),
            Parameter.of(ParamsProperty.RANGE, new Range(0, 1)),
            Parameter.of(ParamsProperty.INDEX, 0));

    try {
      service.execute(operation, helper.getContext(), ALEX);
      fail("Expected InvalidRequestException");
View Full Code Here


        operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId,
            Parameter.of(ParamsProperty.MODIFY_ACTION,
                new DocumentModifyAction(ModifyHow.REPLACE, Collections.singletonList(replacement),
                    NO_ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)),
            Parameter.of(ParamsProperty.RANGE,
                new Range(CONTENT_START_TEXT, CONTENT_START_TEXT + INITIAL_CONTENT.length())));

    service.execute(operation, helper.getContext(), ALEX);

    // Cut off the /n
    String after = getApiView().apiContents().substring(1);
View Full Code Here

  public static void copyBlipContents(Blip fromBlip, Blip toBlip) {
    for (BlipContent blipContent: fromBlip.all().values()) {
      toBlip.append(blipContent);
    }
    for (Annotation annotation : fromBlip.getAnnotations()) {
      Range range = annotation.getRange();
      toBlip.range(range.getStart() + 1, range.getEnd() + 1).annotate(annotation.getName(),
          annotation.getValue());
    }
  }
View Full Code Here

    List<Annotation> result = Lists.newArrayList();
    for (RangedAnnotation<String> annotation : doc.rangedAnnotations(0, doc.size(), null)) {
      if (annotation.key() != null && annotation.value() != null) {
        int start = apiView.transformToTextOffset(annotation.start());
        int end = apiView.transformToTextOffset(annotation.end());
        result.add(new Annotation(annotation.key(), annotation.value(), new Range(start, end)));
      }
    }
    return result;
  }
View Full Code Here

   * @throws InvalidRequestException if more than one "where" parameter is
   *         specified.
   */
  private DocumentHitIterator getDocumentHitIterator(OperationRequest operation, ApiView view)
      throws InvalidRequestException {
    Range range = OperationUtil.getOptionalParameter(operation, ParamsProperty.RANGE);
    Integer index = OperationUtil.getOptionalParameter(operation, ParamsProperty.INDEX);
    DocumentModifyQuery query =
        OperationUtil.getOptionalParameter(operation, ParamsProperty.MODIFY_QUERY);

    DocumentHitIterator hitIterator;
    if (range != null) {
      if (index != null || query != null) {
        throw new InvalidRequestException(
            "At most one parameter out of RANGE, INDEX and MODIFY_QUERY must be specified",
            operation);
      }
      // Use the specified range
      hitIterator = new DocumentHitIterator.Singleshot(range);
    } else if (index != null) {
      if (query != null) { // range is null.
        throw new InvalidRequestException(
            "At most one parameter out of RANGE, INDEX and MODIFY_QUERY must be specified",
            operation);
      }
      // Use exactly the location of the index
      hitIterator = new DocumentHitIterator.Singleshot(new Range(index, index + 1));
    } else if (query != null) { // range and index are both null.
      // Use the query
      hitIterator = new DocumentHitIterator.ElementMatcher(
          view, query.getElementMatch(), query.getRestrictions(), query.getMaxRes());
    } else {
      // Take entire document since nothing appropriate was specified
      hitIterator = new DocumentHitIterator.Singleshot(new Range(0, view.apiContents().length()));
    }
    return hitIterator;
  }
View Full Code Here

        modifyAction.getModifyHow() == ModifyHow.ANNOTATE, "This method only supports ANNOTATE");

    String annotationKey = modifyAction.getAnnotationKey();

    int valueIndex = 0;
    Range range = hitIterator.next();
    while (range != null) {
      int start = view.transformToXmlOffset(range.getStart());
      int end = view.transformToXmlOffset(range.getEnd());
      setDocumentAnnotation(
          operation, doc, start, end, annotationKey, modifyAction.getValue(valueIndex));

      valueIndex++;
      range = hitIterator.next();
View Full Code Here

    Preconditions.checkArgument(modifyAction.getModifyHow() == ModifyHow.CLEAR_ANNOTATION,
        "This method only supports CLEAR_ANNOTATION");

    String annotationKey = modifyAction.getAnnotationKey();

    Range range = hitIterator.next();
    while (range != null) {
      int start = view.transformToXmlOffset(range.getStart());
      int end = view.transformToXmlOffset(range.getEnd());
      setDocumentAnnotation(operation, doc, start, end, annotationKey, null);

      range = hitIterator.next();
    }
  }
View Full Code Here

   * @param hitIterator iterates over the ranges of elements to delete.
   * @throws InvalidRequestException if the specified range was invalid.
   */
  private void delete(OperationRequest operation, ApiView view, DocumentHitIterator hitIterator)
      throws InvalidRequestException {
    Range range = hitIterator.next();
    while (range != null) {
      int start = range.getStart();
      int end = range.getEnd();

      if (start == 0) {
        // Can't delete the first new line.
        start = 1;
      }
View Full Code Here

   */
  private void insert(OperationRequest operation, Document doc, ApiView view,
      DocumentHitIterator hitIterator, DocumentModifyAction modifyAction)
      throws InvalidRequestException {
    int valueIndex = 0;
    Range range = hitIterator.next();
    while (range != null) {
      int insertAt = range.getStart();

      int inserted = insertInto(operation, doc, view, insertAt, modifyAction, valueIndex);
      hitIterator.shift(insertAt, inserted);

      valueIndex++;
View Full Code Here

   */
  private void insertAfter(OperationRequest operation, Document doc, ApiView view,
      DocumentHitIterator hitIterator, DocumentModifyAction modifyAction)
      throws InvalidRequestException {
    int valueIndex = 0;
    Range range = hitIterator.next();
    while (range != null) {
      int insertAt = range.getEnd();

      int inserted = insertInto(operation, doc, view, insertAt, modifyAction, valueIndex);
      hitIterator.shift(insertAt, inserted);

      valueIndex++;
View Full Code Here

TOP

Related Classes of com.google.wave.api.Range

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.