Package com.google.wave.api

Examples of com.google.wave.api.Blip


 
  @Override
  public void processEvents(RobotMessageBundle robotMessageBundle) {
    Wavelet wavelet = robotMessageBundle.getWavelet();
    for (Event event : robotMessageBundle.getEvents()) {
      Blip currentBlip = event.getBlip();
      switch(event.getType()) {
        case WAVELET_SELF_ADDED:
          wavelet.setTitle(WELCOME);    
          addButton(event.getBlip());
          break;
        case BLIP_SUBMITTED:         
          if (!isRoot(currentBlip, wavelet)) {
            String text = currentBlip.getDocument().getText();
            wavelet.appendBlip().getDocument().append("[echo] " + text);            
          }                  
          break;
        case WAVELET_PARTICIPANTS_CHANGED:
          for (String participant : event.getAddedParticipants()) {           
            if (!participant.equals(BOT_NAME) &&
                !participant.equals(wavelet.getCreator())) {
              wavelet.appendBlip().getDocument().append("Hi " + participant + "!");
            }                       
          }         
          break;           
        case FORM_BUTTON_CLICKED:
          if (event.getButtonName().equals("my_button")) {
            String clicker = event.getModifiedBy();
            wavelet.appendBlip().getDocument().append(clicker + " has clicked the button!");
          }
          FormView formView = currentBlip.getDocument().getFormView();         
          if (formView.getFormElement("my_button") != null) {
           
          }         
          break;            
      }     
View Full Code Here


  @Override
  public void onBlipSubmitted(BlipSubmittedEvent e) {
    // Invoked when any blip we are interested in is submitted.
    LOG.info("onBlipSubmitted");
    Blip blip = e.getBlip();

    String gadgetUrl = "http://jkitchensinky.appspot.com/public/embed.xml";
    Gadget gadget = Gadget.class.cast(blip.first(ElementType.GADGET,
        Gadget.restrictByUrl(gadgetUrl)).value());
    if (gadget != null &&
        gadget.getProperty("loaded", "no").equals("yes") &&
        gadget.getProperty("seen", "no").equals("no")) {
      // Elements should always be updated through a BlipContentRefs to
      // correspond the matching operations for the wire.
      blip.first(ElementType.GADGET, Gadget.restrictByUrl(gadgetUrl)).updateElement(
          ImmutableMap.of("seen", "yes"));
      blip.append("\nSeems all to have worked out.");
      blip.first(ElementType.IMAGE).updateElement(
          ImmutableMap.of("url", "http://www.google.com/logos/poppy09.gif"));
    }

    // Update installer either way.
    String extensionInstallerUrl = "http://google-wave-resources.googlecode.com/svn/trunk/" +
        "samples/extensions/gadgets/mappy/installer.xml";
    blip.first(ElementType.INSTALLER).updateElement(
        ImmutableMap.of("manifest", extensionInstallerUrl));
  }
View Full Code Here

  @Capability(contexts = {Context.SELF})
  @Override
  public void onWaveletSelfAdded(WaveletSelfAddedEvent e) {
    // Invoked when any participants have been added/removed from the wavelet.
    LOG.info("onWaveletSelfAdded");
    Blip blip = e.getBlip();
    Wavelet wavelet = e.getWavelet();

    // Test setting wavelet title.
    wavelet.setTitle("A wavelet title");

    // Test inserting image.
    blip.append(new Image("http://www.google.com/logos/clickortreat1.gif", 320, 118,
        "Click or treat"));

    // Test inserting list.
    Line line = new Line();
    line.setLineType("li");
    line.setIndent("2");
    blip.append(line);
    blip.append("bulleted!");

    // Test inserting extension installer.
    String installerUrl = "http://wave-skynet.appspot.com/public/extensions/areyouin/manifest.xml";
    blip.append(new Installer(installerUrl));

    // Test adding a proxied reply. The reply will be posted by
    // jkitchensinky+proxy@appspot.com. Note that as a side effect this will
    // also add this participant to the wave.
    wavelet.proxyFor("proxy").reply("\n").append("Douwe says Java rocks!");

    // Test inserting inline blip.
    Blip inlineBlip = blip.insertInlineBlip(5);
    inlineBlip.append("Hello again!");

    // Test creating a new wave. The new wave will have its own operation queue.
    // {@link AbstractRobot#newWave(String, Set, String, String)} takes a
    // {@code message} parameter which can be set to an arbitrary string. By
    // setting it to the serialized version of the current wave, we can
    // reconstruct the current wave when the other wave is constructed and
    // update the current wave.
    JsonElement waveletJson = SERIALIZER.toJsonTree(wavelet.serialize());
    JsonElement blipJson = SERIALIZER.toJsonTree(blip.serialize());
    JsonObject json = new JsonObject();
    json.add("wavelet", waveletJson);
    json.add("blip", blipJson);
    Wavelet newWave = this.newWave(wavelet.getDomain(), wavelet.getParticipants(),
        SERIALIZER.toJson(json), null);
    newWave.getParticipants().setParticipantRole(wavelet.getCreator(), Participants.Role.READ_ONLY);
   
    newWave.getRootBlip().append("A new day and a new wave");
    newWave.getRootBlip().appendMarkup("<p>Some stuff!</p><p>Not the <b>beautiful</b></p>");

    // Since the new wave has its own operation queue, we need to submit it
    // explicitly through the active gateway, or, as in this case, submit it
    // together with wavelet, which will handle the submit automatically.
    newWave.submitWith(wavelet);

    // Test inserting a form element.
    blip.append(new FormElement(ElementType.CHECK, "My Label", "true", "false"));

    // Test inserting replies with image.
    String imgUrl = "http://upload.wikimedia.org/wikipedia/en/thumb/c/cc/Googlewave.svg/" +
        "200px-Googlewave.svg.png";
    Blip replyBlip = blip.reply();
    replyBlip.append("Hello");
    replyBlip.append(new Image(imgUrl, 50, 50, "caption"));
    replyBlip.append("\nHello");
    replyBlip.append(new Image(imgUrl, 50, 50, "caption"));
    replyBlip.append("\nHello");
    replyBlip.append(new Image(imgUrl, 50, 50, "caption"));
  }
View Full Code Here

    OperationQueue operationQueue = new OperationQueue();

    Map<String, Blip> blips = new HashMap<String, Blip>();
    Wavelet originalWavelet = Wavelet.deserialize(operationQueue, blips, waveletData);

    Blip rootBlip = Blip.deserialize(operationQueue, originalWavelet, blipData);
    blips.put(rootBlip.getBlipId(), rootBlip);

    // Add a gadget that embeds the newly created wave to the original wavelet.
    Gadget gadget = new Gadget("http://jkitchensinky.appspot.com/public/embed.xml");
    gadget.setProperty("waveid", e.getWavelet().getWaveId().serialise());
    originalWavelet.getRootBlip().append(gadget);
View Full Code Here

  public void onDocumentChanged(DocumentChangedEvent event) {
    if (WHITELIST_ONLY && !whitelist.contains(event.getModifiedBy())) {
      return; // Ignore non-whitelisted actions
    }

    Blip blip = event.getBlip();

    Annotations annotations = event.getBlip().getAnnotations();
    for (Annotation annotation : annotations.asList()) {
      String name = annotation.getName();
      String value = annotation.getValue();
      if (name.equals("stocky") && value.equals("_new_")) {
        int startIndex = annotation.getRange().getStart();

        BlipContentRefs blipContentRefs = blip.range(annotation.getRange().getStart(), annotation
            .getRange().getEnd());
        blipContentRefs.annotate("stocky", "_done_");

        String annotatedContent = blipContentRefs.value().getText();
        LOG.info("annotatedContent = " + annotatedContent);
       
        //String symbol = annotatedContent.substring(1, annotatedContent.length() - 1).toUpperCase();
        String symbol = annotatedContent.toUpperCase();
        LOG.info("stocky finds new symbol: " + symbol);

        // Replace the content with new and delete the "stocky" annotation.
        String price = String.format("$%.2f", util.getStockPrice(symbol));
        String newContent = String.format("%s[%s] ", symbol, price);
        blipContentRefs = blipContentRefs.replace(newContent);

        BlipContentRefs symbolContentRef = blip.range(startIndex, startIndex + symbol.length());
        symbolContentRef.annotate("style/color", "rgb(50,205,50)");
        symbolContentRef.annotate("style/fontWeight", "bold");

        BlipContentRefs priceContentRef = blip.range(startIndex + symbol.length() + 1, startIndex
            + symbol.length() + 1 + price.length());
        priceContentRef.annotate("style/color", "rgb(50,205,50)");
        priceContentRef.annotate("style/fontSize", "0.8em");
        priceContentRef.annotate("style/color", "rgb(255,0,0)");
      }
View Full Code Here

  @Override
  public void processEvents(RobotMessageBundle robotMessageBundle) {

    final Wavelet wavelet = robotMessageBundle.getWavelet();
    final Blip rootBlip = wavelet.getRootBlip();
    // Construct an oauthService with the user key and Twitter OAuth info.
    final String authUserId = wavelet.getCreator() + "@" + wavelet.getWaveId();
    final TwitterService twitterService = new TwitterService(authUserId, getRobotAddress());
    final PopupLoginFormHandler loginForm = new PopupLoginFormHandler(getRobotAddress());
       
    // Handle the flow when Tweety was just added to a new wave.
    if (robotMessageBundle.wasSelfAdded()) {
      rootBlip.getDocument().setAuthor(TWEETY_ID);
      wavelet.setTitle("Sign into Twitter");

      // Checks if the user is authorized with the service provider.
      // If not, fetches the request token and authorizes it.
      if (!twitterService.checkAuthorization(wavelet, loginForm)) {
View Full Code Here

    String content = blip.getDocument().getText();

    // If the parent blip is a tweet, set the parent tweet id and prepend
    // the content with @<author>.
    Blip parent = blip.getParent();
    String parentTweetId = null;
    List<Annotation> annotations = parent.getDocument().getAnnotations(TWEET_ID_ANNOTATION_KEY);
    if (!annotations.isEmpty()) {
      parentTweetId = annotations.get(0).getValue();
      String author = parent.getDocument().getAuthor();
      if (author != null) {
        content = "@" + author.substring(0, author.indexOf("@")) + " " + content;
      }
    }
View Full Code Here

    wavelet.setTitle(CONTENTS_TITLE);
    TextView contentsDocument = wavelet.getRootBlip().getDocument();
    contentsDocument.append("\n\n(Write Introduction Here)");
   
    // Create New Post button in new blip.
    Blip blip = wavelet.appendBlip();
    contentsDocument = blip.getDocument();
    contentsDocument.appendElement(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID,
        LOGIN_BUTTON_CAPTION));
   
    // Create new blip for TOC and save blip ID.
    String blipKey = String.valueOf(Math.random());
View Full Code Here

    String waveletId = postWavelet.getDataDocument(WAVELET_ID);
    String blipId = postWavelet.getDataDocument(BLIP_ID);
    String postTitle = postWavelet.getTitle();
   
    // Get access to table of contents blip by using the stored information.
    Blip blip = bundle.getBlip(waveId, waveletId, blipId);
    TextView contentsDocument = blip.getDocument();
    Wavelet contentsWavelet = blip.getWavelet();
       
    // Add and linkify the title of the new blog post.
    String postWaveId = postWavelet.getWaveId();
    contentsDocument.insert(0, "\n" + postTitle);
    int upperIndex = postTitle.length() + 1;
View Full Code Here

        + " -help\" on a new line and hit \"Enter\".");
  }

  @Override
  public void onDocumentChanged(DocumentChangedEvent event) {
    Blip blip = event.getBlip();
    String modifiedBy = event.getModifiedBy();
    CommandLine commandLine = null;
    try {
      commandLine = preprocessCommand(blip.getContent());
    } catch (IllegalArgumentException e) {
      appendLine(blip, e.getMessage());
    }
    if (commandLine != null) {
      if (commandLine.hasOption("help")
View Full Code Here

TOP

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

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.