rave 0.1.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ module Rave
2
+ module Models
3
+ class Document # :nodoc:
4
+
5
+ #TODO
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,113 @@
1
+ module Rave
2
+ module Models
3
+ # An element within a document.
4
+ # (abstract factory)
5
+ class Element < Component
6
+ include Rave::Mixins::ObjectFactory
7
+
8
+ JAVA_CLASS = "com.google.wave.api.FormElement"
9
+
10
+ def initialize(properties = {})
11
+ super(:id => '') # TODO: Don't actually have IDs, as such. Bad inheritance from Component?
12
+ @properties = properties
13
+ end
14
+
15
+ # Gets the value of an element property.
16
+ def get(key, default = nil)
17
+ if @properties.has_key? key
18
+ @properties[key]
19
+ else
20
+ default
21
+ end
22
+ end
23
+
24
+ # Sets the value of an element property.
25
+ def set(key, value)
26
+ @properties[key] = value
27
+ end
28
+
29
+ # Alias for #set(key, value)
30
+ alias_method :[]=, :set
31
+
32
+ # Alias for #get(key)
33
+ alias_method :[], :get
34
+
35
+ def to_json # :nodoc:
36
+ {
37
+ 'javaClass' => JAVA_CLASS,
38
+ 'properties' => @properties,
39
+ 'type' => type,
40
+ }.to_json
41
+ end
42
+
43
+ # A Google Gadget element within a document.
44
+ class Gadget < Element
45
+ factory_register 'GADGET'
46
+
47
+ def initialize(fields = {})
48
+ # Gadget has 'fields' rather than 'properties'.
49
+ super(fields)
50
+ end
51
+ end
52
+
53
+ # An image element within a document.
54
+ class Image < Element
55
+ factory_register 'IMAGE'
56
+ end
57
+
58
+ # An inline blip within a document.
59
+ class InlineBlip < Element
60
+ factory_register 'INLINE_BLIP'
61
+
62
+ # The blip contained within the element [Blip].
63
+ def blip # :nodoc:
64
+ @context.blips[@properties['blipId']]
65
+ end
66
+ end
67
+
68
+ # A form element within a document.
69
+ # (Abstract)
70
+ class Form < Element
71
+ # A button form element within a document.
72
+ class Button < Form
73
+ factory_register 'BUTTON'
74
+ end
75
+
76
+ # A check form element within a document.
77
+ class Check < Form
78
+ factory_register 'CHECK'
79
+ end
80
+
81
+ # A input form element within a document.
82
+ class Input < Form
83
+ factory_register 'INPUT'
84
+ end
85
+
86
+ # A password form element within a document.
87
+ class Password < Form
88
+ factory_register 'PASSWORD'
89
+ end
90
+
91
+ # A label form element within a document.
92
+ class Label < Form
93
+ factory_register 'LABEL'
94
+ end
95
+
96
+ # A radio button form element within a document.
97
+ class RadioButton < Form
98
+ factory_register 'RADIO_BUTTON'
99
+ end
100
+
101
+ # A radio button group form element within a document.
102
+ class RadioButtonGroup < Form
103
+ factory_register 'RADIO_BUTTON_GROUP'
104
+ end
105
+
106
+ # A text-area form element within a document.
107
+ class TextArea < Form
108
+ factory_register 'TEXTAREA'
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,230 @@
1
+ module Rave
2
+ module Models
3
+ # Represents an event received from the server.
4
+ class Event
5
+ include Rave::Mixins::TimeUtils
6
+ include Rave::Mixins::ObjectFactory
7
+
8
+ BLIP_ID = 'blipId' # :nodoc:
9
+
10
+ # Time at which the event was created [Time]
11
+ def timestamp # :nodoc:
12
+ @timestamp.dup
13
+ end
14
+
15
+ # ID of the blip that caused the event, or root blip of the wavelet that caused the event [String]
16
+ def blip_id # :nodoc:
17
+ @properties[BLIP_ID].dup
18
+ end
19
+
20
+ # Wavelet that caused the event, or wavelet containing the blip that caused the event [Wavelet]
21
+ def wavelet # :nodoc:
22
+ @context.primary_wavelet
23
+ end
24
+
25
+ # The user that caused this event to be generated [User]
26
+ def modified_by # :nodoc:
27
+ @context.users[@modified_by_id]
28
+ end
29
+
30
+ # Blip that caused the event, or wavelet's root blip for wavelet events [Blip]
31
+ def blip # :nodoc:
32
+ @context.blips[@properties[BLIP_ID]]
33
+ end
34
+
35
+ #Options include:
36
+ # - :timestamp
37
+ # - :modified_by
38
+ # - :properties
39
+ # - :context
40
+ # Do not use Event.new from outside; instead use Event.create
41
+ def initialize(options = {}) # :nodoc:
42
+ @timestamp = time_from_json(options[:timestamp]) || Time.now
43
+ @modified_by_id = options[:modified_by] || User::NOBODY_ID
44
+ @properties = options[:properties] || {}
45
+ @context = options[:context]
46
+
47
+ raise ArgumentError.new(":context option required") if @context.nil?
48
+
49
+ add_user_ids([@modified_by_id])
50
+ end
51
+
52
+ protected
53
+ # Add a series of user ids to the context, if they don't already exist.
54
+ def add_user_ids(user_ids) # :nodoc:
55
+ user_ids.each do |id|
56
+ @context.add_user(:id => id) unless @context.users[id]
57
+ end
58
+ end
59
+
60
+ # Wavelet events
61
+
62
+ public
63
+ class WaveletBlipCreated < Event
64
+ factory_register 'WAVELET_BLIP_CREATED'
65
+
66
+ # Newly created blip [Blip]
67
+ def new_blip # :nodoc:
68
+ @context.blips[@properties['newBlipId']]
69
+ end
70
+ end
71
+
72
+ class WaveletBlipRemoved < Event
73
+ factory_register 'WAVELET_BLIP_REMOVED'
74
+
75
+ # ID for blip which has now been removed [String]
76
+ def removed_blip_id # :nodoc:
77
+ @properties['removedBlipId'].dup
78
+ end
79
+ end
80
+
81
+ class WaveletParticipantsChanged < Event
82
+ factory_register 'WAVELET_PARTICIPANTS_CHANGED'
83
+
84
+ ADDED = 'participantsAdded' # :nodoc:
85
+ REMOVED = 'participantsRemoved' # :nodoc:
86
+
87
+ def initialize(options = {}) # :nodoc:
88
+ super(options)
89
+
90
+ add_user_ids(@properties[ADDED]) if @properties[ADDED]
91
+ add_user_ids(@properties[REMOVED]) if @properties[REMOVED]
92
+ end
93
+
94
+ # Array of participants added to the wavelet [Array of User]
95
+ def participants_added # :nodoc:
96
+ @properties[ADDED].map { |id| @context.users[id] }
97
+ end
98
+
99
+ # Array of participants removed from the wavelet [Array of User].
100
+ def participants_removed # :nodoc:
101
+ @properties[REMOVED].map { |id| @context.users[id] }
102
+ end
103
+ end
104
+
105
+ class WaveletSelfAdded < Event
106
+ factory_register 'WAVELET_SELF_ADDED'
107
+ end
108
+
109
+ class WaveletSelfRemoved < Event
110
+ factory_register 'WAVELET_SELF_REMOVED'
111
+ end
112
+
113
+ class WaveletTimestampChanged < Event
114
+ factory_register 'WAVELET_TIMESTAMP_CHANGED'
115
+
116
+ # Time that the wavelet was changed [Time]
117
+ def new_timestamp # :nodoc:
118
+ @properties['timestamp'].dup
119
+ end
120
+ end
121
+
122
+ class WaveletTitleChanged < Event
123
+ factory_register 'WAVELET_TITLE_CHANGED'
124
+
125
+ def new_title # :nodoc:
126
+ @properties['title'].dup
127
+ end
128
+ end
129
+
130
+ class WaveletVersionChanged < Event
131
+ factory_register 'WAVELET_VERSION_CHANGED'
132
+
133
+ def new_version # :nodoc:
134
+ @properties['version'].dup
135
+ end
136
+ end
137
+
138
+ # Blip events
139
+
140
+ class BlipContributorsChanged < Event
141
+ factory_register 'BLIP_CONTRIBUTORS_CHANGED'
142
+
143
+ ADDED = 'contributorsAdded' # :nodoc:
144
+ REMOVED = 'contributorsRemoved' # :nodoc:
145
+
146
+ def initialize(options = {}) # :nodoc:
147
+ super(options)
148
+
149
+ add_user_ids(@properties[ADDED]) if @properties[ADDED]
150
+ add_user_ids(@properties[REMOVED]) if @properties[REMOVED]
151
+ end
152
+
153
+ # Array of contributors added to the wavelet [Array of User].
154
+ def contributors_added # :nodoc:
155
+ @properties[ADDED].map { |id| @context.users[id] }
156
+ end
157
+
158
+ # Array of contributors removed from the wavelet [Array of User].
159
+ def contributors_removed # :nodoc:
160
+ @properties[REMOVED].map { |id| @context.users[id] }
161
+ end
162
+ end
163
+
164
+ class BlipSubmitted < Event
165
+ factory_register 'BLIP_SUBMITTED'
166
+ end
167
+
168
+ # #blip will be nil, but #blip_id will give a sensible value.
169
+ class BlipDeleted < Event
170
+ factory_register 'BLIP_DELETED'
171
+
172
+ # ID of the blip that was deleted [String]
173
+ #-- This dummy method just added for the purposes of rdoc.
174
+ def blip_id # :nodoc:
175
+ super
176
+ end
177
+
178
+ def initialize(options = {}) # :nodoc:
179
+ super(options)
180
+
181
+ # Ensure a referenced blip is properly deleted. Destroyed blip won't exist.
182
+ blip.delete_me(false) if @properties[BLIP_ID] and blip
183
+ end
184
+ end
185
+
186
+ # General events.
187
+
188
+ class DocumentChanged < Event
189
+ factory_register 'DOCUMENT_CHANGED'
190
+ end
191
+
192
+ class FormButtonClicked < Event
193
+ factory_register 'FORM_BUTTON_CLICKED'
194
+
195
+ # Name of button that was clicked.
196
+ def button # :nodoc:
197
+ @properties['button'].dup
198
+ end
199
+ end
200
+
201
+ # Generated when someone in the current wave creates a new wavelet (in a new wave).
202
+ class WaveletCreated < Event
203
+ factory_register 'WAVELET_CREATED'
204
+ end
205
+
206
+ class OperationError < Event
207
+ factory_register 'OPERATION_ERROR'
208
+
209
+ # Message describing what caused the error [String]
210
+ def message # :nodoc:
211
+ @properties['errorMessage'].dup
212
+ end
213
+
214
+ # Operation type that caused the error [String]
215
+ def operation_type # :nodoc:
216
+ # Format is "document.appendMarkup1260632282946" (number is timestamp)
217
+ @properties['operationId'] =~ /^(.+?)\d+$/
218
+ "#{$1.split(/(?=[A-Z])|\./).join('_').upcase}"
219
+ end
220
+
221
+ # Time of the err [String]
222
+ def operation_timestamp # :nodoc:
223
+ # Format is "document.appendMarkup1260632282946" (number is timestamp)
224
+ @properties['operationId'] =~ /(\d+)$/
225
+ time_from_json($1)
226
+ end
227
+ end
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,79 @@
1
+ module Rave
2
+ module Models
3
+ # Represents an operation to be applied on the server.
4
+ class Operation # :nodoc:
5
+ attr_reader :index, :property
6
+
7
+ def type; @type.dup; end
8
+ def wave_id; @wave_id.dup; end
9
+ def wavelet_id; @wavelet_id.dup; end
10
+ def blip_id; @blip_id.dup; end
11
+
12
+ JAVA_CLASS = 'com.google.wave.api.impl.OperationImpl' # :nodoc:
13
+
14
+ #Constants
15
+ # Types of operations
16
+ WAVELET_APPEND_BLIP = 'WAVELET_APPEND_BLIP'
17
+ WAVELET_ADD_PARTICIPANT = 'WAVELET_ADD_PARTICIPANT'
18
+ WAVELET_REMOVE_PARTICIPANT = 'WAVELET_REMOVE_PARTICIPANT'
19
+ WAVELET_CREATE = 'WAVELET_CREATE'
20
+ WAVELET_REMOVE_SELF = 'WAVELET_REMOVE_SELF'
21
+ WAVELET_DATADOC_SET = 'WAVELET_DATADOC_SET'
22
+ WAVELET_SET_TITLE = 'WAVELET_SET_TITLE'
23
+ BLIP_CREATE_CHILD = 'BLIP_CREATE_CHILD'
24
+ BLIP_DELETE = 'BLIP_DELETE'
25
+ DOCUMENT_ANNOTATION_DELETE = 'DOCUMENT_ANNOTATION_DELETE'
26
+ DOCUMENT_ANNOTATION_SET = 'DOCUMENT_ANNOTATION_SET'
27
+ DOCUMENT_ANNOTATION_SET_NORANGE = 'DOCUMENT_ANNOTATION_SET_NORANGE'
28
+ DOCUMENT_APPEND = 'DOCUMENT_APPEND' # Plain text
29
+ DOCUMENT_APPEND_MARKUP = 'DOCUMENT_APPEND_MARKUP' # HTML
30
+ DOCUMENT_APPEND_STYLED_TEXT = 'DOCUMENT_APPEND_STYLED_TEXT'
31
+ DOCUMENT_INSERT = 'DOCUMENT_INSERT'
32
+ DOCUMENT_DELETE = 'DOCUMENT_DELETE'
33
+ DOCUMENT_REPLACE = 'DOCUMENT_REPLACE'
34
+ DOCUMENT_ELEMENT_APPEND = 'DOCUMENT_ELEMENT_APPEND'
35
+ DOCUMENT_ELEMENT_DELETE = 'DOCUMENT_ELEMENT_DELETE'
36
+ DOCUMENT_ELEMENT_INSERT = 'DOCUMENT_ELEMENT_INSERT'
37
+ DOCUMENT_ELEMENT_INSERT_AFTER = 'DOCUMENT_ELEMENT_INSERT_AFTER'
38
+ DOCUMENT_ELEMENT_INSERT_BEFORE = 'DOCUMENT_ELEMENT_INSERT_BEFORE'
39
+ DOCUMENT_ELEMENT_REPLACE = 'DOCUMENT_ELEMENT_REPLACE'
40
+ DOCUMENT_INLINE_BLIP_APPEND = 'DOCUMENT_INLINE_BLIP_APPEND'
41
+ DOCUMENT_INLINE_BLIP_DELETE = 'DOCUMENT_INLINE_BLIP_DELETE'
42
+ DOCUMENT_INLINE_BLIP_INSERT = 'DOCUMENT_INLINE_BLIP_INSERT'
43
+ DOCUMENT_INLINE_BLIP_INSERT_AFTER_ELEMENT = 'DOCUMENT_INLINE_BLIP_INSERT_AFTER_ELEMENT'
44
+
45
+ #Options include:
46
+ # - :type
47
+ # - :wave_id
48
+ # - :wavelet_id
49
+ # - :blip_id
50
+ # - :index
51
+ # - :property
52
+ def initialize(options = {})
53
+ @type = options[:type]
54
+ @wave_id = options[:wave_id]
55
+ @wavelet_id = options[:wavelet_id] || ''
56
+ @blip_id = options[:blip_id] || ''
57
+ @index = options[:index] || -1
58
+ @property = options[:property]
59
+ end
60
+
61
+ #Serialize the operation to json
62
+ def to_json
63
+ hash = {
64
+ 'blipId' => @blip_id,
65
+ 'index' => @index,
66
+ 'waveletId' => @wavelet_id,
67
+ 'waveId' => @wave_id,
68
+ 'type' => @type,
69
+ 'javaClass' => JAVA_CLASS
70
+ }
71
+
72
+ hash['property'] = @property unless @property.nil?
73
+
74
+ hash.to_json
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,14 @@
1
+ # Extend a standard Range so that it can be serialized easily
2
+
3
+ class Range # :nodoc:
4
+ JAVA_CLASS = 'com.google.wave.api.Range'
5
+
6
+ # Convert to a hash for sending in an operation.
7
+ def to_json
8
+ {
9
+ 'javaClass' => JAVA_CLASS,
10
+ 'start' => min,
11
+ 'end' => max
12
+ }.to_json
13
+ end
14
+ end