Adding a HTML Anchor to a Wave via the Robot Protocol.

1 view
Skip to first unread message

EntropyFails

unread,
Oct 6, 2009, 5:47:04 PM10/6/09
to Google Wave API
Hello,

I've been playing around a bit with wave bots on the app engine
architecture and I was wondering if anyone knows how to add a direct
anchor link without using a wavelet?

For example, if I have a blip named "blip", obviously doing something
like

blip.getDocument().append("<a href=\"http://www.google.com\"> To
Google </a>");

will not work as that will only insert the escaped text of the anchor
instead of the anchor itself.

Now I would assume that I would use something like

blip.getDocument().appendElement(?)

but there is no element type for anchors defined at

http://wave-robot-java-client.googlecode.com/svn/trunk/doc/com/google/wave/api/ElementType.html

This seems strange to me as the native widget bar has an anchor
element in it. (Also, the documentation for ElementType is terrible.)

Hopefully I'm missing something obvious.

Thanks for any help you can give.

--
Entropyfails

Austin Chau (Google employee)

unread,
Oct 7, 2009, 1:25:00 AM10/7/09
to google-...@googlegroups.com
Hi,

If you just append the straight URL, Wave will automatically linkify into an anchor link with the URL as its anchor text.  But it seems like you would like to have customized anchor text, you would need annotation to do that.  The annotation name for anchor link is "link/manual", this is an example how this is done - 

          TextView textView = yourBlip.getDocument();
          String content = textView.getText();
          String anchorText = "click here";
          textView.insert(content.length(), anchorText);
          
          int start = content.length();
          int end = start + anchorText.length();
          
          textView.setAnnotation(new Range(start, end), "link/manual", "http://www.google.com");

This snippet above would add an anchor text at the end of a blip and annotate it with the URL http://www.google.com.

Austin

EntropyFails

unread,
Oct 7, 2009, 2:58:58 PM10/7/09
to Google Wave API
Absolutely perfect. Thank you so much!

Here is the documentation for setAnnotation in TextView. I believe
that is insufficient for me to have discovered this on my own. Is
there a list of acceptable annotations anywhere? Can we get proper
links to these in the documentation?

void setAnnotation(Range range,
java.lang.String name,
java.lang.String value)
Sets an annotation affecting the specified range of the document.
Parameters:
range - The range over the document affected by this operation.
name - The name of the annotation.
value - The value of the annotation.

Thanks again for your help!

---
Entropyfails

On Oct 7, 12:25 am, "Austin Chau (Google employee)"
<api.aus...@google.com> wrote:
> Hi,
> If you just append the straight URL, Wave will automatically linkify into an
> anchor link with the URL as its anchor text.  But it seems like you would
> like to have customized anchor text, you would need annotation to do that.
>  The annotation name for anchor link is "link/manual", this is an example
> how this is done -
>
>           TextView textView = yourBlip.getDocument();
>           String content = textView.getText();
>           String anchorText = "click here";
>           textView.insert(content.length(), anchorText);
>
>           int start = content.length();
>           int end = start + anchorText.length();
>
>           textView.setAnnotation(new Range(start, end), "link/manual", "http://www.google.com");
>
> This snippet above would add an anchor text at the end of a blip and
> annotate it with the URLhttp://www.google.com.
>
> Austin
>
>
>
> On Tue, Oct 6, 2009 at 2:47 PM, EntropyFails <entropyfa...@gmail.com> wrote:
>
> > Hello,
>
> > I've been playing around a bit with wave bots on the app engine
> > architecture and I was wondering if anyone knows how to add a direct
> > anchor link without using a wavelet?
>
> > For example, if I have a blip named "blip", obviously doing something
> > like
>
> > blip.getDocument().append("<a href=\"http://www.google.com\"> To
> > Google </a>");
>
> > will not work as that will only insert the escaped text of the anchor
> > instead of the anchor itself.
>
> > Now I would assume that I would use something like
>
> > blip.getDocument().appendElement(?)
>
> > but there is no element type for anchors defined at
>
> >http://wave-robot-java-client.googlecode.com/svn/trunk/doc/com/google...

Austin Chau (Google employee)

unread,
Oct 7, 2009, 3:42:17 PM10/7/09
to google-...@googlegroups.com
Glad to help :)

Can you file a feature request to my documentation to include list of native annotation names?


Thanks,
Austin

GH

unread,
Oct 7, 2009, 4:58:49 PM10/7/09
to Google Wave API
I just came across something in the Java API that I thought might be
useful in your situation. It seems like the following may be a
slightly more elegant solution:

blip.getDocument().appendMarkup("<a href=\"http://www.google.com\">To
Google </a>");

I haven't used appendMarkup() before, so I am making an educated
guess.

On Oct 7, 2:42 pm, "Austin Chau (Google employee)"
<api.aus...@google.com> wrote:
> Glad to help :)
> Can you file a feature request to my documentation to include list of native
> annotation names?
>
> http://code.google.com/p/google-wave-resources/issues/list
>
> Thanks,
> Austin
>

Austin Chau (Google employee)

unread,
Oct 7, 2009, 5:24:17 PM10/7/09
to google-...@googlegroups.com
Thanks Greg, that would also work nicely without having to deal with annotation :)

Austin

EntropyFails

unread,
Oct 7, 2009, 8:56:55 PM10/7/09
to Google Wave API
Greetings,

appendMarkup() does work. I just tested it. Thank you for that!
However, I'll be using Austin's approach because it allows in-place
updating.

Consider this as a request for Feature 76 please. I've added a comment
there on adding replaceMarkup function as well. As a short aside, I
personally vote for the maximum expressive power inside of the blips.
I'll expand on this in another post.

Also, do you have any word on the annotation documentation? Is it out
there anywhere?

Thank you so very much for all of your help!

---
Entropyfails

On Oct 7, 4:24 pm, "Austin Chau (Google employee)"

masouras

unread,
Oct 8, 2009, 2:43:58 AM10/8/09
to Google Wave API
I can inject a link to the blip using SetAnnotation() but then the
WYSIWIG editor keeps the link going for any text that is typed after
the link. DeleteAnnotations() won't work since the blip text ends
right at the end of the link. Is there a way to signify the end of the
link to the editor so it won't keep including subsequent text within
the link?

Austin Chau (Google employee)

unread,
Oct 8, 2009, 4:24:53 AM10/8/09
to google-...@googlegroups.com
You can try to add a trailing space at the end of the anchor text and annotate the text just before the trailing space.  This should prevent the autolinking to continue on.

Austin

frak

unread,
Nov 25, 2009, 12:49:51 AM11/25/09
to Google Wave API
If I try to use the following code to add a link:

tv.appendMarkup("And example of a link <a href=\"http://www.example/"+
m.group(1) + "\">Example</a>");

Then all text I append after this is made into the same hyperlink,
until I add a new hyperlink to somewhere else, which then is used to
make all text into a link... any ideas?

On Oct 8, 7:24 pm, "Austin Chau (Google employee)"
Reply all
Reply to author
Forward
0 new messages