Package com.google.wave.api

Examples of com.google.wave.api.Element


   * Test that the passed xml string deserializes into exactly two elements and
   * that the second element is the one we're after and serialized back to the
   * passed xml.
   */
  private void convertBackAndForth(String xml) {
    Element element = createApiElementFromXml(xml);
    String resultXml = ElementSerializer.apiElementToXml(element).getXmlString();
    assertEquals(xml, resultXml);
  }
View Full Code Here


      Arrays.asList(Attachment.MIME_TYPE, Attachment.DATA, Attachment.ATTACHMENT_URL));

  @Override
  public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) {
    if (src.getType() == ElementType.ATTACHMENT) {
      src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties()));
    }
    return super.serialize(src, typeOfSrc, context);
  }
View Full Code Here

  private static final String PROPERTIES_TAG = "properties";

  @Override
  public Element deserialize(JsonElement json, Type typeOfT,
      JsonDeserializationContext context) throws JsonParseException {
    Element result = null;
    ElementType type = ElementType.valueOfIgnoreCase(
        json.getAsJsonObject().get(TYPE_TAG).getAsString());

    Type mapType = new TypeToken<Map<String, String>>(){}.getType();
    Map<String, String> properties = context.deserialize(
        json.getAsJsonObject().get(PROPERTIES_TAG), mapType);

    if (FormElement.getFormElementTypes().contains(type)) {
      result = new FormElement(type, properties);
    } else if (type == ElementType.GADGET) {
      result = new Gadget(properties);
    } else if (type == ElementType.IMAGE) {
      result = new Image(properties);
    } else if (type == ElementType.LINE) {
      result = new Line(properties);
    } else {
      result = new Element(type, properties);
    }
    return result;
  }
View Full Code Here

    BlipData blipData = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_DATA);
    String parentBlipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID);
    ConversationBlip parentBlip = context.getBlip(conversation, parentBlipId);

    Element element = OperationUtil.getRequiredParameter(operation, ParamsProperty.ELEMENT);

    // view.locateElement will tell where the element actually is.
    ApiView view = new ApiView(parentBlip.getContent(), wavelet);
    int elementApiLocation = view.locateElement(element);
View Full Code Here

          setDocumentAnnotation(operation, doc, annotationStart, annotationEnd, ia.key, ia.value);
        }
      }
      return toInsert.length();
    } else {
      Element element = modifyAction.getElement(valueIndex);
      if (element != null) {
        if (element.isGadget()) {
          Gadget gadget = (Gadget) element;
          XmlStringBuilder xml =
              GadgetXmlUtil.constructXml(gadget.getUrl(), "", gadget.getAuthor(), null,
                  gadget.getProperties());
          // TODO (Yuri Z.) Make it possible to specify a location to insert the
View Full Code Here

  private void updateElement(OperationRequest operation, Document doc, ApiView view,
      DocumentHitIterator hitIterator, DocumentModifyAction modifyAction)
      throws InvalidRequestException {
    Range range = null;
    for (int index = 0; ((range = hitIterator.next()) != null); ++index) {
      Element element = modifyAction.getElement(index);
      if (element != null) {
        if (element.isGadget()) {
          int xmlStart = view.transformToXmlOffset(range.getStart());
          Doc.E docElem = Point.elementAfter(doc, doc.locate(xmlStart));
          updateExistingGadgetElement(doc, docElem, element);
        } else {
          // TODO (Yuri Z.) Updating other elements.
View Full Code Here

      Arrays.asList(Attachment.MIME_TYPE, Attachment.DATA, Attachment.ATTACHMENT_URL));

  @Override
  public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) {
    if (src.getType() == ElementType.ATTACHMENT) {
      src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties()));
    }
    return super.serialize(src, typeOfSrc, context);
  }
View Full Code Here

      node = doc.getFirstChild(node);
    }
    while (node != null) {
      E element = doc.asElement(node);
      if (element != null) {
        Element apiElement = xmlToApiElement(doc, element, wavelet);
        if (apiElement != null) {
          result.put(apiView.transformToTextOffset(doc.getLocation(element)), apiElement);
        }
      }
      node = doc.getNextSibling(node);
View Full Code Here

        if (asText != null) {
          bits.add(new Bit(doc.getData(asText), xmlPos));
        } else {
          E xmlElement = doc.asElement(child);
          if (xmlElement != null) {
            Element element = ElementSerializer.xmlToApiElement(doc, xmlElement, wavelet);
            // element can be null, but we still want to note that there
            // was something unknown.
            N next = doc.getNextSibling(child);
            int xmlSize;
            if (next != null) {
View Full Code Here

  protected static final String PROPERTIES_TAG = "properties";

  @Override
  public Element deserialize(JsonElement json, Type typeOfT,
      JsonDeserializationContext context) throws JsonParseException {
    Element result = null;
    ElementType type = ElementType.valueOfIgnoreCase(
        json.getAsJsonObject().get(TYPE_TAG).getAsString());

    Map<String, String> properties = context.deserialize(
        json.getAsJsonObject().get(PROPERTIES_TAG), GsonFactory.STRING_MAP_TYPE);

    if (FormElement.getFormElementTypes().contains(type)) {
      result = new FormElement(type, properties);
    } else if (type == ElementType.GADGET) {
      result = new Gadget(properties);
    } else if (type == ElementType.IMAGE) {
      result = new Image(properties);
    } else if (type == ElementType.ATTACHMENT) {
      byte[] data = null;
      String encodedData = properties.get(Attachment.DATA);
      if (encodedData != null) {
        try {
          data = Base64.decodeBase64(encodedData.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
          throw new JsonParseException("Couldn't convert to utf-8", e);
        }
      }
      result = new Attachment(properties, data);
    } else if (type == ElementType.LINE) {
      result = new Line(properties);
    } else {
      result = new Element(type, properties);
    }
    return result;
  }
View Full Code Here

TOP

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

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.