KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > webservices > adminapi > sdk > WeblogEntry


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.webservices.adminapi.sdk;
19 /*
20  * WeblogEntry.java
21  *
22  * Created on January 17, 2006, 12:44 PM
23  */

24
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Locale JavaDoc;
29 import java.util.TimeZone JavaDoc;
30 import org.jdom.Document;
31 import org.jdom.Element;
32 import org.jdom.JDOMException;
33 import org.jdom.Text;
34 import org.jdom.input.SAXBuilder;
35 import org.apache.roller.webservices.adminapi.sdk.Entry.Attributes;
36 import org.apache.roller.webservices.adminapi.sdk.Entry.Types;
37
38 /**
39  * This class describes a weblog entry.
40  */

41 public class WeblogEntry extends Entry {
42     static interface Tags {
43         public static final String JavaDoc WEBLOG = "weblog";
44         public static final String JavaDoc HANDLE = "handle";
45         public static final String JavaDoc NAME = "name";
46         public static final String JavaDoc DESCRIPTION = "description";
47         public static final String JavaDoc LOCALE = "locale";
48         public static final String JavaDoc TIMEZONE = "timezone";
49         public static final String JavaDoc DATE_CREATED = "date-created";
50         public static final String JavaDoc CREATING_USER = "creating-user";
51         public static final String JavaDoc EMAIL_ADDRESS = "email-address";
52         public static final String JavaDoc APP_ENTRIES_URL = "app-entries-url";
53         public static final String JavaDoc APP_RESOURCES_URL = "app-resources-url";
54     }
55     
56     private String JavaDoc handle;
57     private String JavaDoc name;
58     private String JavaDoc description;
59     private Locale JavaDoc locale;
60     private TimeZone JavaDoc timezone;
61     private Date JavaDoc dateCreated;
62     private String JavaDoc creatingUser;
63     private String JavaDoc emailAddress;
64     private String JavaDoc appEntriesUrl;
65     private String JavaDoc appResourcesUrl;
66     
67     public WeblogEntry(Element e, String JavaDoc urlPrefix) throws MissingElementException {
68         populate(e, urlPrefix);
69     }
70     
71     public WeblogEntry(InputStream JavaDoc stream, String JavaDoc urlPrefix) throws JDOMException, IOException JavaDoc, MissingElementException {
72         SAXBuilder sb = new SAXBuilder();
73         Document d = sb.build(stream);
74         Element e = d.detachRootElement();
75         
76         populate(e, urlPrefix);
77     }
78     
79     private void populate(Element e, String JavaDoc urlPrefix) throws MissingElementException {
80         // handle
81
Element handleElement = e.getChild(Tags.HANDLE, Service.NAMESPACE);
82         if (handleElement == null) {
83             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.HANDLE);
84         }
85         setHandle(handleElement.getText());
86         
87         // href
88
String JavaDoc href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + getHandle();
89         setHref(href);
90         
91         // name
92
Element nameElement = e.getChild(Tags.NAME, Service.NAMESPACE);
93         if (nameElement == null) {
94             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.NAME);
95         }
96         setName(nameElement.getText());
97         
98         // description
99
Element descElement = e.getChild(Tags.DESCRIPTION, Service.NAMESPACE);
100         if (descElement == null) {
101             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.DESCRIPTION);
102         }
103         setDescription(descElement.getText());
104         
105         // locale
106
Element localeElement = e.getChild(Tags.LOCALE, Service.NAMESPACE);
107         if (localeElement == null) {
108             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.LOCALE);
109         }
110         setLocale(localeElement.getText());
111         
112         // timezone
113
Element tzElement = e.getChild(Tags.TIMEZONE, Service.NAMESPACE);
114         if (tzElement == null) {
115             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.TIMEZONE);
116         }
117         setTimezone(tzElement.getText());
118         
119         // creator
120
Element creatorElement = e.getChild(Tags.CREATING_USER, Service.NAMESPACE);
121         if (creatorElement == null) {
122             throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.CREATING_USER);
123         }
124         setCreatingUser(creatorElement.getText());
125         
126         // email address
127
Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
128         if (emailElement == null) {
129             throw new MissingElementException("ERROR: Missing element: ", e.getName(), Tags.EMAIL_ADDRESS);
130         }
131         setEmailAddress(emailElement.getText());
132         
133         // created (optional)
134
Element createdElement = e.getChild(Tags.DATE_CREATED, Service.NAMESPACE);
135         if (createdElement != null) {
136             setDateCreated(new Date JavaDoc(Long.valueOf(createdElement.getText()).longValue()));
137         }
138         
139         // APP entries URL (optional)
140
Element appEntriesUrlElement = e.getChild(Tags.APP_ENTRIES_URL, Service.NAMESPACE);
141         if (appEntriesUrlElement != null) {
142             setAppEntriesUrl(appEntriesUrlElement.getText());
143         }
144         
145         // APP resources URL (optional)
146
Element appResourcesUrlElement = e.getChild(Tags.APP_RESOURCES_URL, Service.NAMESPACE);
147         if (appResourcesUrlElement != null) {
148             setAppResourcesUrl(appResourcesUrlElement.getText());
149         }
150     }
151     
152     
153     public WeblogEntry(String JavaDoc handle, String JavaDoc urlPrefix) {
154         String JavaDoc href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + handle;
155         setHref(href);
156         setHandle(handle);
157     }
158     
159     public String JavaDoc getType() {
160         return Types.WEBLOG;
161     }
162     
163     public Document toDocument() {
164         Element weblog = new Element(Tags.WEBLOG, Service.NAMESPACE);
165         Document doc = new Document(weblog);
166         
167         // link
168
weblog.setAttribute(Attributes.HREF, getHref());
169         
170         // handle
171
Element handle = new Element(Tags.HANDLE, Service.NAMESPACE);
172         Text handleText = new Text(getHandle());
173         handle.addContent(handleText);
174         weblog.addContent(handle);
175         
176         // name
177
Element name = new Element(Tags.NAME, Service.NAMESPACE);
178         Text nameText = new Text(getName());
179         name.addContent(nameText);
180         weblog.addContent(name);
181         
182         // description
183
Element desc = new Element(Tags.DESCRIPTION, Service.NAMESPACE);
184         Text descText = new Text(getDescription());
185         desc.addContent(descText);
186         weblog.addContent(desc);
187         
188         // locale
189
Element locale = new Element(Tags.LOCALE, Service.NAMESPACE);
190         Text localeText = new Text(getLocale().toString());
191         locale.addContent(localeText);
192         weblog.addContent(locale);
193         
194         // timezone
195
Element tz = new Element(Tags.TIMEZONE, Service.NAMESPACE);
196         Text tzText = new Text(getTimezone().getID());
197         tz.addContent(tzText);
198         weblog.addContent(tz);
199         
200         // creating user
201
Element creator = new Element(Tags.CREATING_USER, Service.NAMESPACE);
202         Text creatorText = new Text(String.valueOf(getCreatingUser()));
203         creator.addContent(creatorText);
204         weblog.addContent(creator);
205         
206         // email address
207
Element email = new Element(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
208         Text emailText = new Text(String.valueOf(getEmailAddress()));
209         email.addContent(emailText);
210         weblog.addContent(email);
211         
212         // creation date (optional)
213
Element created = new Element(Tags.DATE_CREATED, Service.NAMESPACE);
214         Date JavaDoc datedCreated = getDateCreated();
215         if (dateCreated != null) {
216             Text createdText = new Text(String.valueOf(dateCreated.getTime()));
217             created.addContent(createdText);
218             weblog.addContent(created);
219         }
220
221         // APP entries URL (optional)
222
Element appEntriesUrlElement = new Element(Tags.APP_ENTRIES_URL, Service.NAMESPACE);
223         String JavaDoc appEntriesUrl = getAppEntriesUrl();
224         if (appEntriesUrl != null) {
225             Text appEntriesUrlText = new Text(appEntriesUrl);
226             appEntriesUrlElement.addContent(appEntriesUrlText);
227             weblog.addContent(appEntriesUrlElement);
228         }
229
230         // APP entries URL (optional)
231
Element appResourcesUrlElement = new Element(Tags.APP_RESOURCES_URL, Service.NAMESPACE);
232         String JavaDoc appResourcesUrl = getAppResourcesUrl();
233         if (appResourcesUrl != null) {
234             Text appResourcesUrlText = new Text(appResourcesUrl);
235             appResourcesUrlElement.addContent(appResourcesUrlText);
236             weblog.addContent(appResourcesUrlElement);
237         }
238         
239         return doc;
240     }
241
242     /** Test if a user entry is equal to this user entry. */
243     public boolean equals(Object JavaDoc o) {
244         if ( o == null || o.getClass() != this.getClass()) {
245             return false;
246         }
247         
248         WeblogEntry other = (WeblogEntry)o;
249         
250         if (!areEqual(getEmailAddress(), other.getEmailAddress())) {
251             return false;
252         }
253         if (!areEqual(getHandle(), other.getHandle())) {
254             return false;
255         }
256         if (!areEqual(getLocale(), other.getLocale())) {
257             return false;
258         }
259         if (!areEqual(getName(), other.getName())) {
260             return false;
261         }
262         if (!areEqual(getDescription(), other.getDescription())) {
263             return false;
264         }
265         if (!areEqual(getTimezone(), other.getTimezone())) {
266             return false;
267         }
268         
269         return super.equals(o);
270     }
271     
272     public String JavaDoc getHandle() {
273         return handle;
274     }
275     
276     public void setHandle(String JavaDoc handle) {
277         this.handle = handle;
278     }
279     
280     public String JavaDoc getDescription() {
281         return description;
282     }
283     
284     public void setDescription(String JavaDoc description) {
285         this.description = description;
286     }
287     
288     public Locale JavaDoc getLocale() {
289         return locale;
290     }
291     
292     public void setLocale(Locale JavaDoc locale) {
293         this.locale = locale;
294     }
295     
296     public void setLocale(String JavaDoc localeString) {
297         this.locale = new LocaleString(localeString).getLocale();
298     }
299     
300     
301     public TimeZone JavaDoc getTimezone() {
302         return timezone;
303     }
304     
305     public void setTimezone(TimeZone JavaDoc timezone) {
306         this.timezone = timezone;
307     }
308
309     public void setTimezone(String JavaDoc timezoneString) {
310         this.timezone = TimeZone.getTimeZone(timezoneString);
311     }
312     
313     public String JavaDoc getName() {
314         return name;
315     }
316     
317     public void setName(String JavaDoc name) {
318         this.name = name;
319     }
320     
321     public Date JavaDoc getDateCreated() {
322         return dateCreated;
323     }
324     
325     public void setDateCreated(Date JavaDoc dateCreated) {
326         this.dateCreated = dateCreated;
327     }
328     
329     public String JavaDoc getCreatingUser() {
330         return creatingUser;
331     }
332     
333     public void setCreatingUser(String JavaDoc creatingUser) {
334         this.creatingUser = creatingUser;
335     }
336
337     public String JavaDoc getEmailAddress() {
338         return emailAddress;
339     }
340
341     public void setEmailAddress(String JavaDoc emailAddress) {
342         this.emailAddress = emailAddress;
343     }
344
345     public String JavaDoc getAppEntriesUrl() {
346         return appEntriesUrl;
347     }
348
349     public void setAppEntriesUrl(String JavaDoc appEntriesUrl) {
350         this.appEntriesUrl = appEntriesUrl;
351     }
352
353     public String JavaDoc getAppResourcesUrl() {
354         return appResourcesUrl;
355     }
356
357     public void setAppResourcesUrl(String JavaDoc appResourcesUrl) {
358         this.appResourcesUrl = appResourcesUrl;
359     }
360 }
361
Popular Tags