Skip to content

Instantly share code, notes, and snippets.

@MoriTanosuke
Created October 7, 2010 16:53
Show Gist options
  • Save MoriTanosuke/615441 to your computer and use it in GitHub Desktop.
Save MoriTanosuke/615441 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
<w:capabilities>
<w:capability name="WAVELET_PARTICIPANTS_CHANGED"
content="true" />
<w:capability name="BLIP_SUBMITTED" content="true" />
</w:capabilities>
<w:version>3</w:version>
</w:robot>
package de.kopis.wave.robot;
import java.util.logging.Logger;
import com.google.wave.api.AbstractRobotServlet;
import com.google.wave.api.Blip;
import com.google.wave.api.Event;
import com.google.wave.api.RobotMessageBundle;
import com.google.wave.api.TextView;
import com.google.wave.api.Wavelet;
@SuppressWarnings("serial")
public class WaveRobot1Servlet extends AbstractRobotServlet {
private static final Logger LOG = Logger.getLogger(WaveRobot1Servlet.class
.getName());
@Override
public void processEvents(final RobotMessageBundle bundle) {
Wavelet wavelet = bundle.getWavelet();
LOG.info("Receiving events.");
if (bundle.wasSelfAdded()) {
LOG.info("Adding myself to wave.");
final Blip blip = wavelet.appendBlip();
reply(blip, "Here I am.");
}
for (Event e : bundle.getBlipSubmittedEvents()) {
LOG.info("A blip was submitted. Reversing it and replying.");
Blip blip = e.getBlip();
replyWithReversedText(blip);
}
}
private void replyWithReversedText(final Blip blip) {
TextView textView = blip.getDocument();
StringBuffer text = new StringBuffer(textView.getText());
reply(blip, text.reverse().toString());
}
private void reply(final Blip blip, final String text) {
if (text.length() > 0) {
Blip newBlip = blip.createChild();
TextView newTextView = newBlip.getDocument();
newTextView.append(text);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>WaveRobot1</servlet-name>
<servlet-class>de.kopis.wave.robot.WaveRobot1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WaveRobot1</servlet-name>
<url-pattern>/_wave/robot/jsonrpc</url-pattern>
</servlet-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment