1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.commsen.jwebthumb;
20
21 import java.io.Serializable;
22
23 import org.apache.commons.lang.Validate;
24 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
25 import org.apache.commons.lang.builder.ToStringBuilder;
26 import org.simpleframework.xml.Attribute;
27 import org.simpleframework.xml.Element;
28
29 /***
30 * This class represents the payload of webthumb's 'request' API call. See <a
31 * href="http://webthumb.bluga.net/apidoc#request">http://webthumb.bluga.net/apidoc#request</a> for
32 * details
33 *
34 * @author <a href="mailto:MilenDyankov@gmail.com">Milen Dyankov</a>
35 * @see http://webthumb.bluga.net/apidoc#request
36 *
37 */
38 public class WebThumbRequest implements Serializable {
39
40 private static final long serialVersionUID = 1L;
41
42 public static enum OutputType {
43 jpg, png, png8
44 };
45
46 /***
47 * The url to snapshot
48 */
49 @Element
50 private String url;
51
52 /***
53 * The image output type (jpg|png|png8)
54 */
55 @Element
56 private OutputType outputType = OutputType.jpg;
57
58 /***
59 * Width of the browser, 15 to 1280;
60 */
61 @Element(required = false)
62 private Integer width;
63
64 /***
65 * Height of the browser, 15 to 2048
66 */
67 @Element(required = false)
68 private Integer height;
69
70 /***
71 * Output a full sized snapshot
72 */
73 @Element(required = false)
74 private Integer fullthumb;
75
76 /***
77 * 2 attributes width, height (1 to browser height), width (1 to browser width)
78 */
79 @Element(required = false)
80 private CustomThumbnail customThumbnail;
81
82 /***
83 * Visual effect thumbnail to produce (mirror|dropshadow|border)
84 */
85 @Element(required = false)
86 private String effect;
87
88 /***
89 * Wait before taking the snapshot (1 to 15 seconds, 3 second default)
90 */
91 @Element(required = false)
92 private Integer delay;
93
94 /***
95 * Url to call when the thumbnail is complete
96 */
97 @Element(required = false)
98 private String notify;
99
100 /***
101 * Size and offset of the excerpt thumnbnail
102 */
103 @Element(required = false)
104 private Excerpt excerpt;
105
106
107 public WebThumbRequest(String url) {
108 Validate.notNull(url, "URL is NULL!");
109 this.url = url;
110 }
111
112
113 public WebThumbRequest(String url, OutputType outputType) {
114 Validate.notNull(url, "URL is NULL!");
115 Validate.notNull(outputType, "outputType is NULL!");
116 this.url = url;
117 this.outputType = outputType;
118 }
119
120 public static class Excerpt implements Serializable {
121 private static final long serialVersionUID = 1L;
122
123 @Element
124 private int x, y, width, height;
125
126
127 public Excerpt(int x, int y, int width, int height) {
128 super();
129 this.x = x;
130 this.y = y;
131 this.width = width;
132 this.height = height;
133 }
134
135
136 @Override
137 public String toString() {
138 return new ToStringBuilder(this).append("x", x).append("y", y).append("width", width).append("height", height).toString();
139 }
140
141 }
142
143 public static class CustomThumbnail implements Serializable {
144 private static final long serialVersionUID = 1L;
145
146 @Attribute
147 private int width, height;
148
149
150 public CustomThumbnail(int width, int height) {
151 super();
152 this.width = width;
153 this.height = height;
154 }
155
156
157 @Override
158 public String toString() {
159 return new ToStringBuilder(this).append("width", width).append("height", height).toString();
160 }
161 }
162
163
164 /***
165 * @return the url
166 */
167 public String getUrl() {
168 return this.url;
169 }
170
171
172 /***
173 * @param url the url to set
174 */
175 public void setUrl(String url) {
176 this.url = url;
177 }
178
179
180 /***
181 * @return the outputType
182 */
183 public OutputType getOutputType() {
184 return this.outputType;
185 }
186
187
188 /***
189 * @param outputType the outputType to set
190 */
191 public void setOutputType(OutputType outputType) {
192 this.outputType = outputType;
193 }
194
195
196 /***
197 * @return the width
198 */
199 public Integer getWidth() {
200 return this.width;
201 }
202
203
204 /***
205 * @param width the width to set
206 */
207 public void setWidth(Integer width) {
208 this.width = width;
209 }
210
211
212 /***
213 * @return the height
214 */
215 public Integer getHeight() {
216 return this.height;
217 }
218
219
220 /***
221 * @param height the height to set
222 */
223 public void setHeight(Integer height) {
224 this.height = height;
225 }
226
227
228 /***
229 * @return the fullthumb
230 */
231 public boolean getFullthumb() {
232 return this.fullthumb == 1 ? true : false;
233 }
234
235
236 /***
237 * @param fullthumb the fullthumb to set
238 */
239 public void setFullthumb(boolean fullthumb) {
240 this.fullthumb = fullthumb ? 1 : 0;
241 }
242
243
244 /***
245 * @return the customThumbnail
246 */
247 public CustomThumbnail getCustomThumbnail() {
248 return this.customThumbnail;
249 }
250
251
252 /***
253 * @param customThumbnail the customThumbnail to set
254 */
255 public void setCustomThumbnail(CustomThumbnail customThumbnail) {
256 this.customThumbnail = customThumbnail;
257 }
258
259
260 /***
261 * @return the effect
262 */
263 public String getEffect() {
264 return this.effect;
265 }
266
267
268 /***
269 * @param effect the effect to set
270 */
271 public void setEffect(String effect) {
272 this.effect = effect;
273 }
274
275
276 /***
277 * @return the delay
278 */
279 public Integer getDelay() {
280 return this.delay;
281 }
282
283
284 /***
285 * @param delay the delay to set
286 */
287 public void setDelay(Integer delay) {
288 this.delay = delay;
289 }
290
291
292 /***
293 * @return the notify
294 */
295 public String getNotify() {
296 return this.notify;
297 }
298
299
300 /***
301 * @param notify the notify to set
302 */
303 public void setNotify(String notify) {
304 this.notify = notify;
305 }
306
307
308 /***
309 * @return the excerpt
310 */
311 public Excerpt getExcerpt() {
312 return this.excerpt;
313 }
314
315
316 /***
317 * @param excerpt the excerpt to set
318 */
319 public void setExcerpt(Excerpt excerpt) {
320 this.excerpt = excerpt;
321 }
322
323
324
325
326
327
328 @Override
329 public String toString() {
330 return new ReflectionToStringBuilder(this).toString();
331 }
332 }