File Source: WeblogEntry.java
/*
P/P * Method: org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry__static_init
*/
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.weblogger.webservices.adminprotocol.sdk;
19 /*
20 * WeblogEntry.java
21 *
22 * Created on January 17, 2006, 12:44 PM
23 */
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Date;
28 import java.util.Locale;
29 import java.util.TimeZone;
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.weblogger.webservices.adminprotocol.sdk.Entry.Attributes;
36 import org.apache.roller.weblogger.webservices.adminprotocol.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 WEBLOG = "weblog";
44 public static final String HANDLE = "handle";
45 public static final String NAME = "name";
46 public static final String DESCRIPTION = "description";
47 public static final String LOCALE = "locale";
48 public static final String TIMEZONE = "timezone";
49 public static final String DATE_CREATED = "date-created";
50 public static final String CREATING_USER = "creating-user";
51 public static final String EMAIL_ADDRESS = "email-address";
52 public static final String APP_ENTRIES_URL = "app-entries-url";
53 public static final String APP_RESOURCES_URL = "app-resources-url";
54 public static final String ENABLED = "enabled";
55 }
56
57 private String handle;
58 private String name;
59 private String description;
60 private Locale locale;
61 private TimeZone timezone;
62 private Date dateCreated;
63 private String creatingUser;
64 private String emailAddress;
65 private String appEntriesUrl;
66 private String appResourcesUrl;
67 private Boolean enabled;
68
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry(Element, String)
*
* Preconditions:
* e != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* possibly_updated(this.appEntriesUrl)
* possibly_updated(this.appResourcesUrl)
* possibly_updated(this.creatingUser)
* this.dateCreated == One-of{undefined, &new Date(populate#2)}
* this.dateCreated in Addr_Set{null,&new Date(populate#2)}
* possibly_updated(this.description)
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* init'ed(this.handle)
* ...
*/
69 public WeblogEntry(Element e, String urlPrefix) {
70 populate(e, urlPrefix);
71 }
72
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry(InputStream, String)
*
* Presumptions:
* org.jdom.Document:detachRootElement(...)@76 != null
* org.jdom.input.SAXBuilder:build(...)@75 != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* possibly_updated(this.appEntriesUrl)
* possibly_updated(this.appResourcesUrl)
* possibly_updated(this.creatingUser)
* this.dateCreated == One-of{undefined, &new Date(populate#2)}
* this.dateCreated in Addr_Set{null,&new Date(populate#2)}
* possibly_updated(this.description)
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* init'ed(this.handle)
* ...
*/
73 public WeblogEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException {
74 SAXBuilder sb = new SAXBuilder();
75 Document d = sb.build(stream);
76 Element e = d.detachRootElement();
77
78 populate(e, urlPrefix);
79 }
80
81 private void populate(Element e, String urlPrefix) {
82 // handle (required)
/*
P/P * Method: void populate(Element, String)
*
* Preconditions:
* e != null
* (soft) init'ed(this.handle)
*
* Presumptions:
* java.lang.Long:valueOf(...)@131 != null
* org.jdom.Element:getText(...)@107 == null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* possibly_updated(this.appEntriesUrl)
* possibly_updated(this.appResourcesUrl)
* possibly_updated(this.creatingUser)
* this.dateCreated == One-of{old this.dateCreated, &new Date(populate#2)}
* possibly_updated(this.description)
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* init'ed(this.handle)
* this.href == &java.lang.StringBuilder:toString(...)
* ...
*
* Test Vectors:
* org.jdom.Element:getChild(...)@105: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@111: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@117: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@123: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@129: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@135: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@141: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@147: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@83: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@93: Addr_Set{null}, Inverse{null}
* ...
*/
83 Element handleElement = e.getChild(Tags.HANDLE, Service.NAMESPACE);
84 if (handleElement != null) {
85 setHandle(handleElement.getText());
86 }
87
88 // href
89 String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + getHandle();
90 setHref(href);
91
92 // name
93 Element nameElement = e.getChild(Tags.NAME, Service.NAMESPACE);
94 if (nameElement != null) {
95 setName(nameElement.getText());
96 }
97
98 // description
99 Element descElement = e.getChild(Tags.DESCRIPTION, Service.NAMESPACE);
100 if (descElement != null) {
101 setDescription(descElement.getText());
102 }
103
104 // locale
105 Element localeElement = e.getChild(Tags.LOCALE, Service.NAMESPACE);
106 if (localeElement != null) {
107 setLocale(localeElement.getText());
108 }
109
110 // timezone
111 Element tzElement = e.getChild(Tags.TIMEZONE, Service.NAMESPACE);
112 if (tzElement != null) {
113 setTimezone(tzElement.getText());
114 }
115
116 // creator
117 Element creatorElement = e.getChild(Tags.CREATING_USER, Service.NAMESPACE);
118 if (creatorElement != null) {
119 setCreatingUser(creatorElement.getText());
120 }
121
122 // email address
123 Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
124 if (emailElement != null) {
125 setEmailAddress(emailElement.getText());
126 }
127
128 // created
129 Element createdElement = e.getChild(Tags.DATE_CREATED, Service.NAMESPACE);
130 if (createdElement != null) {
131 setDateCreated(new Date(Long.valueOf(createdElement.getText()).longValue()));
132 }
133
134 // APP entries URL
135 Element appEntriesUrlElement = e.getChild(Tags.APP_ENTRIES_URL, Service.NAMESPACE);
136 if (appEntriesUrlElement != null) {
137 setAppEntriesUrl(appEntriesUrlElement.getText());
138 }
139
140 // APP resources URL
141 Element appResourcesUrlElement = e.getChild(Tags.APP_RESOURCES_URL, Service.NAMESPACE);
142 if (appResourcesUrlElement != null) {
143 setAppResourcesUrl(appResourcesUrlElement.getText());
144 }
145
146 // enabled
147 Element enabledElement = e.getChild(Tags.ENABLED, Service.NAMESPACE);
148 if (enabledElement != null) {
149 setEnabled(Boolean.valueOf(enabledElement.getText()));
150 }
151 }
152
153
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry(String, String)
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == urlPrefix._tainted | handle._tainted
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.handle == handle
* init'ed(this.handle)
* this.href == &java.lang.StringBuilder:toString(...)
*/
154 public WeblogEntry(String handle, String urlPrefix) {
155 String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + handle;
156 setHref(href);
157 setHandle(handle);
158 }
159
160 public String getType() {
/*
P/P * Method: String getType()
*
* Postconditions:
* return_value == &"weblog"
*/
161 return Types.WEBLOG;
162 }
163
164 public Document toDocument() {
/*
P/P * Method: Document toDocument()
*
* Preconditions:
* init'ed(this.appEntriesUrl)
* init'ed(this.appResourcesUrl)
* init'ed(this.creatingUser)
* init'ed(this.dateCreated)
* init'ed(this.description)
* init'ed(this.emailAddress)
* init'ed(this.enabled)
* init'ed(this.handle)
* init'ed(this.href)
* init'ed(this.locale)
* ...
*
* Postconditions:
* return_value == &new Document(toDocument#2)
* new Document(toDocument#2) num objects == 1
*
* Test Vectors:
* this.appEntriesUrl: Addr_Set{null}, Inverse{null}
* this.appResourcesUrl: Addr_Set{null}, Inverse{null}
* this.creatingUser: Addr_Set{null}, Inverse{null}
* this.dateCreated: Addr_Set{null}, Inverse{null}
* this.description: Addr_Set{null}, Inverse{null}
* this.emailAddress: Addr_Set{null}, Inverse{null}
* this.enabled: Addr_Set{null}, Inverse{null}
* this.handle: Addr_Set{null}, Inverse{null}
* this.locale: Addr_Set{null}, Inverse{null}
* this.name: Addr_Set{null}, Inverse{null}
* ...
*/
165 Element weblog = new Element(Tags.WEBLOG, Service.NAMESPACE);
166 Document doc = new Document(weblog);
167
168 // link
169 weblog.setAttribute(Attributes.HREF, getHref());
170
171 // handle (required)
172 String handle = getHandle();
173 if (handle != null && handle.length() > 0) {
174 Element handleElement = new Element(Tags.HANDLE, Service.NAMESPACE);
175 Text handleText = new Text(handle);
176 handleElement.addContent(handleText);
177 weblog.addContent(handleElement);
178 }
179
180 // name
181 String name = getName();
182 if (name != null) {
183 Element nameElement = new Element(Tags.NAME, Service.NAMESPACE);
184 Text nameText = new Text(name);
185 nameElement.addContent(nameText);
186 weblog.addContent(nameElement);
187 }
188
189 // description
190 String desc = getDescription();
191 if (desc != null) {
192 Element descElement = new Element(Tags.DESCRIPTION, Service.NAMESPACE);
193 Text descText = new Text(desc);
194 descElement.addContent(descText);
195 weblog.addContent(descElement);
196 }
197
198 // locale
199 Locale locale = getLocale();
200 if (locale != null) {
201 Element localeElement = new Element(Tags.LOCALE, Service.NAMESPACE);
202 Text localeText = new Text(locale.toString());
203 localeElement.addContent(localeText);
204 weblog.addContent(localeElement);
205 }
206
207 // timezone
208 TimeZone tz = getTimezone();
209 if (tz != null) {
210 Element tzElement = new Element(Tags.TIMEZONE, Service.NAMESPACE);
211 Text tzText = new Text(tz.getID());
212 tzElement.addContent(tzText);
213 weblog.addContent(tzElement);
214 }
215
216 // creating user
217 String creator = getCreatingUser();
218 if (creator != null) {
219 Element creatorElement = new Element(Tags.CREATING_USER, Service.NAMESPACE);
220 Text creatorText = new Text(creator);
221 creatorElement.addContent(creatorText);
222 weblog.addContent(creatorElement);
223 }
224
225 // email address
226 String email = getEmailAddress();
227 if (email != null) {
228 Element emailElement = new Element(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
229 Text emailText = new Text(email);
230 emailElement.addContent(emailText);
231 weblog.addContent(emailElement);
232 }
233
234 // creation date
235 Element dateCreatedElement = new Element(Tags.DATE_CREATED, Service.NAMESPACE);
+ 236 Date datedCreated = getDateCreated();
237 if (dateCreated != null) {
238 Text createdText = new Text(String.valueOf(dateCreated.getTime()));
239 dateCreatedElement.addContent(createdText);
240 weblog.addContent(dateCreatedElement);
241 }
242
243 // APP entries URL
244 Element appEntriesUrlElement = new Element(Tags.APP_ENTRIES_URL, Service.NAMESPACE);
245 String appEntriesUrl = getAppEntriesUrl();
246 if (appEntriesUrl != null) {
247 Text appEntriesUrlText = new Text(appEntriesUrl);
248 appEntriesUrlElement.addContent(appEntriesUrlText);
249 weblog.addContent(appEntriesUrlElement);
250 }
251
252 // APP entries URL
253 Element appResourcesUrlElement = new Element(Tags.APP_RESOURCES_URL, Service.NAMESPACE);
254 String appResourcesUrl = getAppResourcesUrl();
255 if (appResourcesUrl != null) {
256 Text appResourcesUrlText = new Text(appResourcesUrl);
257 appResourcesUrlElement.addContent(appResourcesUrlText);
258 weblog.addContent(appResourcesUrlElement);
259 }
260
261 // enabled
262 Element enabledElement = new Element(Tags.ENABLED, Service.NAMESPACE);
263 Boolean enabled = getEnabled();
264 if (enabled != null) {
265 Text enabledText = new Text(getEnabled().toString());
266 enabledElement.addContent(enabledText);
267 weblog.addContent(enabledElement);
268 }
269
270 return doc;
271 }
272
273 /** Test if a user entry is equal to this user entry. */
274 public boolean equals(Object o) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) init'ed(o.description)
* (soft) init'ed(o.emailAddress)
* (soft) init'ed(o.enabled)
* (soft) init'ed(o.handle)
* (soft) init'ed(o.href)
* (soft) init'ed(o.locale)
* (soft) init'ed(o.name)
* (soft) init'ed(o.timezone)
* (soft) init'ed(this.description)
* (soft) init'ed(this.emailAddress)
* ...
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* o: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@281: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@284: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@287: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@290: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@293: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@296: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.WeblogEntry:areEqual(...)@299: {1}, {0}
*/
275 if ( o == null || o.getClass() != this.getClass()) {
276 return false;
277 }
278
279 WeblogEntry other = (WeblogEntry)o;
280
281 if (!areEqual(getEmailAddress(), other.getEmailAddress())) {
282 return false;
283 }
284 if (!areEqual(getHandle(), other.getHandle())) {
285 return false;
286 }
287 if (!areEqual(getLocale(), other.getLocale())) {
288 return false;
289 }
290 if (!areEqual(getName(), other.getName())) {
291 return false;
292 }
293 if (!areEqual(getDescription(), other.getDescription())) {
294 return false;
295 }
296 if (!areEqual(getTimezone(), other.getTimezone())) {
297 return false;
298 }
299 if (!areEqual(getEnabled(), other.getEnabled())) {
300 return false;
301 }
302
303 return super.equals(o);
304 }
305
306 public String getHandle() {
/*
P/P * Method: String getHandle()
*
* Preconditions:
* init'ed(this.handle)
*
* Postconditions:
* return_value == this.handle
* init'ed(return_value)
*/
307 return handle;
308 }
309
310 public void setHandle(String handle) {
/*
P/P * Method: void setHandle(String)
*
* Postconditions:
* this.handle == handle
* init'ed(this.handle)
*/
311 this.handle = handle;
312 }
313
314 public String getDescription() {
/*
P/P * Method: String getDescription()
*
* Preconditions:
* init'ed(this.description)
*
* Postconditions:
* return_value == this.description
* init'ed(return_value)
*/
315 return description;
316 }
317
318 public void setDescription(String description) {
/*
P/P * Method: void setDescription(String)
*
* Postconditions:
* this.description == description
* init'ed(this.description)
*/
319 this.description = description;
320 }
321
322 public Locale getLocale() {
/*
P/P * Method: Locale getLocale()
*
* Preconditions:
* init'ed(this.locale)
*
* Postconditions:
* return_value == this.locale
* init'ed(return_value)
*/
323 return locale;
324 }
325
326 public void setLocale(Locale locale) {
/*
P/P * Method: void setLocale(Locale)
*
* Postconditions:
* this.locale == locale
* init'ed(this.locale)
*/
327 this.locale = locale;
328 }
329
330 public void setLocale(String localeString) {
/*
P/P * Method: void setLocale(String)
*
* Preconditions:
* localeString == null
*
* Postconditions:
* this.locale == null
* new Locale(LocaleString#1) num objects == 0
* new Locale(LocaleString#2) num objects == 0
* new Locale(LocaleString#3) num objects == 0
*/
331 this.locale = new LocaleString(localeString).getLocale();
332 }
333
334
335 public TimeZone getTimezone() {
/*
P/P * Method: TimeZone getTimezone()
*
* Preconditions:
* init'ed(this.timezone)
*
* Postconditions:
* return_value == this.timezone
* init'ed(return_value)
*/
336 return timezone;
337 }
338
339 public void setTimezone(TimeZone timezone) {
/*
P/P * Method: void setTimezone(TimeZone)
*
* Postconditions:
* this.timezone == timezone
* init'ed(this.timezone)
*/
340 this.timezone = timezone;
341 }
342
343 public void setTimezone(String timezoneString) {
/*
P/P * Method: void setTimezone(String)
*
* Postconditions:
* init'ed(this.timezone)
*/
344 this.timezone = TimeZone.getTimeZone(timezoneString);
345 }
346
347 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* init'ed(this.name)
*
* Postconditions:
* return_value == this.name
* init'ed(return_value)
*/
348 return name;
349 }
350
351 public void setName(String name) {
/*
P/P * Method: void setName(String)
*
* Postconditions:
* this.name == name
* init'ed(this.name)
*/
352 this.name = name;
353 }
354
355 public Date getDateCreated() {
/*
P/P * Method: Date getDateCreated()
*
* Preconditions:
* init'ed(this.dateCreated)
*
* Postconditions:
* return_value == this.dateCreated
* init'ed(return_value)
*/
356 return dateCreated;
357 }
358
359 public void setDateCreated(Date dateCreated) {
/*
P/P * Method: void setDateCreated(Date)
*
* Postconditions:
* this.dateCreated == dateCreated
* init'ed(this.dateCreated)
*/
360 this.dateCreated = dateCreated;
361 }
362
363 public String getCreatingUser() {
/*
P/P * Method: String getCreatingUser()
*
* Preconditions:
* init'ed(this.creatingUser)
*
* Postconditions:
* return_value == this.creatingUser
* init'ed(return_value)
*/
364 return creatingUser;
365 }
366
367 public void setCreatingUser(String creatingUser) {
/*
P/P * Method: void setCreatingUser(String)
*
* Postconditions:
* this.creatingUser == creatingUser
* init'ed(this.creatingUser)
*/
368 this.creatingUser = creatingUser;
369 }
370
371 public String getEmailAddress() {
/*
P/P * Method: String getEmailAddress()
*
* Preconditions:
* init'ed(this.emailAddress)
*
* Postconditions:
* return_value == this.emailAddress
* init'ed(return_value)
*/
372 return emailAddress;
373 }
374
375 public void setEmailAddress(String emailAddress) {
/*
P/P * Method: void setEmailAddress(String)
*
* Postconditions:
* this.emailAddress == emailAddress
* init'ed(this.emailAddress)
*/
376 this.emailAddress = emailAddress;
377 }
378
379 public String getAppEntriesUrl() {
/*
P/P * Method: String getAppEntriesUrl()
*
* Preconditions:
* init'ed(this.appEntriesUrl)
*
* Postconditions:
* return_value == this.appEntriesUrl
* init'ed(return_value)
*/
380 return appEntriesUrl;
381 }
382
383 public void setAppEntriesUrl(String appEntriesUrl) {
/*
P/P * Method: void setAppEntriesUrl(String)
*
* Postconditions:
* this.appEntriesUrl == appEntriesUrl
* init'ed(this.appEntriesUrl)
*/
384 this.appEntriesUrl = appEntriesUrl;
385 }
386
387 public String getAppResourcesUrl() {
/*
P/P * Method: String getAppResourcesUrl()
*
* Preconditions:
* init'ed(this.appResourcesUrl)
*
* Postconditions:
* return_value == this.appResourcesUrl
* init'ed(return_value)
*/
388 return appResourcesUrl;
389 }
390
391 public void setAppResourcesUrl(String appResourcesUrl) {
/*
P/P * Method: void setAppResourcesUrl(String)
*
* Postconditions:
* this.appResourcesUrl == appResourcesUrl
* init'ed(this.appResourcesUrl)
*/
392 this.appResourcesUrl = appResourcesUrl;
393 }
394
395 public Boolean getEnabled() {
/*
P/P * Method: Boolean getEnabled()
*
* Preconditions:
* init'ed(this.enabled)
*
* Postconditions:
* return_value == this.enabled
* init'ed(return_value)
*/
396 return enabled;
397 }
398
399 public void setEnabled(Boolean enabled) {
/*
P/P * Method: void setEnabled(Boolean)
*
* Postconditions:
* this.enabled == enabled
* init'ed(this.enabled)
*/
400 this.enabled = enabled;
401 }
402 }
SofCheck Inspector Build Version : 2.18479
| WeblogEntry.java |
2009-Jan-02 14:25:34 |
| WeblogEntry.class |
2009-Sep-04 03:12:46 |
| WeblogEntry$Tags.class |
2009-Sep-04 03:12:46 |