This tutorial shows how to build a Wave Robot using Dailydev Wave Robot library and Spring MVC Robot's sources can be downloaded from Download/Examples section. Robot is also deployed so you can try it from your Wave. It's address is: calendar-robot@appspot.com This tutorial assumes that the reader has a basic knowledge of Google's Wave Java Client Library Requirements for Java 6, currently defined by Google, are valid here also. For more information read Google's Tutorial This tutorial also assumes that you already registered your
application with Google App Engine (GAE) and has your Eclipse set and
standard GAE project is created. For more information read Setting Up App Engine LibrariesTo update standard GAE application into DailyDev Wave Robot Application with Spring support you should add following libraries into${project.dir}/war/WEB-INF/lib folder.
First three libraries are standard Google Wave libraries To make libraries available on classpath of the project do Refresh and add libraries through project Properties > Java Build Path > Libraries. Event Handlingpackage org.dailydev.wave.calendar;
For concrete implementation of the method check source code repository of spring-wave-calendar example project: CalendarRobotHandler.javaimport static com.google.wave.api.EventType.*; import java.util.List; import java.util.regex.Pattern; import org.dailydev.wave.robot.EventHandlerOperation; import org.dailydev.wave.robot.filter.ContentMatch; import com.google.wave.api.Blip; import com.google.wave.api.Event; import com.google.wave.api.RobotMessageBundle; public class CalendarRobotHandler { private static final String DATE_PATTERN = "((19|20)\\d\\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])"; private static final Pattern datePattern = Pattern.compile(DATE_PATTERN); @EventHandlerOperation(eventTypes = { BLIP_SUBMITTED, DOCUMENT_CHANGED }, content = true) @ContentMatch(DATE_PATTERN) public void handleDateInDocument(Event event, RobotMessageBundle bundle) throws UnsupportedEncodingException { Blip blip = event.getBlip(); handleBlip(blip); } @EventHandlerOperation(eventTypes = { WAVELET_SELF_ADDED }, content = true) @ContentMatch(DATE_PATTERN) public void handleDateInWavelet(Event event, Wavelet wavelet) throws UnsupportedEncodingException { Blip rootBlip = wavelet.getRootBlip(); handleBlipRecursive(rootBlip); } protected void handleBlipRecursive(Blip blip) { handleBlip(blip); List<Blip> children = blip.getChildren(); for (Blip child : children) { handleBlipRecursive(child); } } protected void handleBlip(Blip blip) { // for concrete implementation of the method check source code repository // of spring-wave-calendar example project: CalendarRobotHandler.java } } Servlet MappingSince the robot is based on Spring MVC framework, it's servlet mapping is standard for such case. It means that we have to simply map just Spring'sDispatcherServlet to the context under which every robot lives.<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <servlet> <servlet-name>robot</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>robot</servlet-name> <url-pattern>/_wave/*</url-pattern> </servlet-mapping> </web-app> Application Context
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean name="calendarHandler" class="org.dailydev.wave.calendar.CalendarRobotHandler" /> <bean name="robot" class="org.dailydev.wave.robot.Robot"> <property name="robotName" value="Calendar Robot" /> <property name="robotVersion" value="2.0" /> <property name="robotAvatar" value="/images/calendar.gif" /> <property name="handlers"> <set> <ref bean="calendarHandler" /> </set> </property> <property name="filterManager" ref="filterManager" /> </bean> <bean name="filterManager" class="org.dailydev.wave.robot.filter.SimpleFilterManager"> <property name="filters"> <bean class="org.dailydev.wave.robot.filter.ContentMatchFilter" /> </property> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /robot/jsonrpc=robotController /capabilities.xml=capabilitiesController /robot/profile=profileController </value> </property> </bean> <bean name="robotController" class="org.dailydev.wave.robot.spring.RobotController"> <property name="robot" ref="robot" /> </bean> <bean name="capabilitiesController" class="org.dailydev.wave.robot.spring.CapabilitiesController"> <property name="robot" ref="robot" /> </bean> <bean name="profileController" class="org.dailydev.wave.robot.spring.ProfileController"> <property name="robot" ref="robot" /> </bean> </beans> |