My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package org.wadael.waverobotfrmwrk.utils;

import org.wadael.waverobotfrmwrk.WadRobot;
import org.wadael.waverobotfrmwrk.advanced.Command;
import org.wadael.waverobotfrmwrk.advanced.WithDelimitedCommandsRobot;

import com.google.wave.api.Blip;
import com.google.wave.api.BlipContentRefs;
import com.google.wave.api.Wavelet;
import com.google.wave.api.event.Event;

/**
* Collection of methods to manipulate blips. Mainly static methods. Mostly
* convenience methods to avoid repeating in one's code.
*
* @author jerome (wadael)
*
*/
public class BlipUtils {

/**
* Replaces the content of a blip
*
* @param event
* a BLipSubmittedEvent or .... instance
* @param nextContent
*/
public static void replaceBlipContent(Blip bleep, String nextContent) {
BlipContentRefs bcr = bleep.all();
if (bcr != null) {
bcr.delete();
bleep.append(nextContent);
}
}

/**
*
* @param event
* @param nextContent
*/
public static void replaceBlipContent(Event event, String nextContent) {
Blip blee = event.getBlip();
replaceBlipContent(blee, nextContent);
}

/**
* Appends a new blip after the blip of the event, with the given string as
* content
*
* @param event
* @param newContent
*/
public static void appendNewBlipWithContent(Event event, String newContent) {
// BlipContentRefs bcrs =
// event.getBlip().getParentBlip().append(newContent);
// event.getBundle().
if (event != null)
event.getBlip().reply().append(newContent);
}

/**
* Returns the text of the blip that triggered the event passed as
* parameter.
*
* @param event
* @return
*/
public static String getEventBlipText(Event event) {
if (event != null)
return event.getBlip().getContent();
else
return null;
// TODO are NPE possible ?
}

/**
* Removes the command after usage. Nice.
*
* @param c
* @param blip
* @param rw
* RobotWorker
*/
@SuppressWarnings("deprecation")
public static void removeCommandFromBlip(Command c, Blip blip,
WithDelimitedCommandsRobot rw) {
replaceCommandFromBlip(c, blip, rw, "");
}

/**
* Opens the way to commands that get replaced by a value (after
* validation).
*
* @param c
* @param blip
* @param rw
* @param replacingText
* the text that will replace the command
*/
public static void replaceCommandFromBlip(Command c, Blip blip,
WithDelimitedCommandsRobot rw, String replacingText) {
String toRemove = rw.getStartCommandDelimiter() + c.getAcronym()
+ rw.getAcronymAndCommandSeparator() + c.getInstruction()
+ ((c.getParameters() == null) ? "" : c.getParameters())
+ rw.getEndCommandDelimiter();
String nextContent = blip.getContent().replace(toRemove, replacingText);
replaceBlipContent(blip, nextContent);
}

/**
* Creates a child blip with content.
*
* TODO correct : is not a child : how to add a child ?
*
* @param blip
* @param childContent
*/
public static void createChildBlip(Blip blip, String childContent) {
Blip shild = blip.reply();
replaceBlipContent(shild, childContent);
}

/**
*
* @param wavelet
* @param user
* @return
*/
public static boolean isWaveletCreator(Wavelet wavelet, String user) {
if (wavelet == null || user == null) return false;
return wavelet.getCreator().equals(user);
}

/**
* Returns true if the blip given as paremeter is issued by the wavelet creator
* @param blip
* @return
*/
public static boolean isFromWaveletCreator(Event event) {
if( event==null) return false;
else{
return event.getWavelet().getCreator().equals(event.getModifiedBy() ) ;
}
}

/**
* Returns true if the user that triggered the event is an authorized user of the wadrobot
* @param event
* @param robot
* @return
*/
public static boolean isUserAnAuthorizedUser(Event event, WadRobot robot) {
if( event == null || robot == null) return false;
return robot.getAuthorisedUsers().contains(event.getModifiedBy());
}

}

Change log

r102 by wadael on May 27, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r93 by wadael on May 6, 2010   Diff
NEw feature : limited obedience, new
example workers
r88 by wadael on Apr 9, 2010   Diff
srcv2
All revisions of this file

File info

Size: 3994 bytes, 157 lines

File properties

svn:mime-type
text/plain
svn:executable
*
Powered by Google Project Hosting