File Source: UserEntry.java
/*
P/P * Method: org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry__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 import java.io.IOException;
21 import java.io.InputStream;
22 import java.util.Date;
23 import java.util.Locale;
24 import java.util.TimeZone;
25 import org.jdom.Document;
26 import org.jdom.Element;
27 import org.jdom.JDOMException;
28 import org.jdom.Text;
29 import org.jdom.input.SAXBuilder;
30 import org.apache.roller.weblogger.webservices.adminprotocol.sdk.Entry.Attributes;
31 import org.apache.roller.weblogger.webservices.adminprotocol.sdk.Entry.Types;
32
33 /**
34 * This class describes a user entry; a user weblog resource.
35 * @author jtb
36 */
37 public class UserEntry extends Entry {
38 /** XML tags that define a user entry. */
39 static interface Tags {
40 public static final String USER = "user";
41 public static final String NAME = "name";
42 public static final String SCREEN_NAME = "screen-name";
43 public static final String FULL_NAME = "full-name";
44 public static final String PASSWORD = "password";
45 public static final String EMAIL_ADDRESS = "email-address";
46 public static final String LOCALE = "locale";
47 public static final String TIMEZONE = "timezone";
48 public static final String DATE_CREATED = "date-created";
49 public static final String ENABLED = "enabled";
50 }
51
52 private String name;
53 private String screenName;
54 private String fullName;
55 private String password;
56 private Locale locale;
57 private TimeZone timezone;
58 private Date dateCreated;
59 private String emailAddress;
60 private Boolean enabled;
61
62 /** Construct an empty user entry */
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry(String, String)
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == urlPrefix._tainted | name._tainted
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.href == &java.lang.StringBuilder:toString(...)
* this.name == name
* init'ed(this.name)
*/
63 public UserEntry(String name, String urlPrefix) {
64 setName(name);
65 String href = urlPrefix + "/" + EntrySet.Types.USERS + "/" + name;
66 setHref(href);
67 }
68
69 /** Construct a user entry from a JDOM element. */
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry(Element, String)
*
* Preconditions:
* e != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.dateCreated == One-of{undefined, &new Date(populate#2)}
* this.dateCreated in Addr_Set{null,&new Date(populate#2)}
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* possibly_updated(this.fullName)
* this.href == &java.lang.StringBuilder:toString(...)
* this.locale == One-of{undefined, null, &new Locale(LocaleString#1), &new Locale(LocaleString#2), &new Locale(LocaleString#3)}
* this.locale == null
* init'ed(this.name)
* ...
*/
70 public UserEntry(Element e, String urlPrefix) {
71 populate(e, urlPrefix);
72 }
73
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry(InputStream, String)
*
* Presumptions:
* org.jdom.Document:detachRootElement(...)@77 != null
* org.jdom.input.SAXBuilder:build(...)@76 != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.dateCreated == One-of{undefined, &new Date(populate#2)}
* this.dateCreated in Addr_Set{null,&new Date(populate#2)}
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* possibly_updated(this.fullName)
* this.href == &java.lang.StringBuilder:toString(...)
* this.locale == One-of{undefined, null, &new Locale(LocaleString#1), &new Locale(LocaleString#2), &new Locale(LocaleString#3)}
* this.locale == null
* init'ed(this.name)
* ...
*/
74 public UserEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException {
75 SAXBuilder sb = new SAXBuilder();
76 Document d = sb.build(stream);
77 Element e = d.detachRootElement();
78
79 populate(e, urlPrefix);
80 }
81
82 private void populate(Element e, String urlPrefix) {
83 // name (required)
/*
P/P * Method: void populate(Element, String)
*
* Preconditions:
* e != null
* (soft) init'ed(this.name)
*
* Presumptions:
* java.lang.Long:valueOf(...)@132 != null
* org.jdom.Element:getText(...)@114 == null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* this.dateCreated == One-of{old this.dateCreated, &new Date(populate#2)}
* possibly_updated(this.emailAddress)
* possibly_updated(this.enabled)
* possibly_updated(this.fullName)
* this.href == &java.lang.StringBuilder:toString(...)
* this.locale == One-of{old this.locale, null, &new Locale(LocaleString#1), &new Locale(LocaleString#2), &new Locale(LocaleString#3)}
* init'ed(this.name)
* possibly_updated(this.password)
* possibly_updated(this.screenName)
* ...
*
* Test Vectors:
* org.jdom.Element:getChild(...)@100: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@106: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@112: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@118: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@124: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@130: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@136: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@84: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@94: Addr_Set{null}, Inverse{null}
*/
84 Element nameElement = e.getChild(Tags.NAME, NAMESPACE);
85 if (nameElement != null) {
86 setName(nameElement.getText());
87 }
88
89 // href
90 String href = urlPrefix + "/" + EntrySet.Types.USERS + "/" + getName();
91 setHref(href);
92
93 // full name
94 Element fullNameElement = e.getChild(Tags.FULL_NAME, NAMESPACE);
95 if (fullNameElement != null) {
96 setFullName(fullNameElement.getText());
97 }
98
99 // screenname
100 Element screenNameElement = e.getChild(Tags.SCREEN_NAME, NAMESPACE);
101 if (screenNameElement != null) {
102 setScreenName(screenNameElement.getText());
103 }
104
105 // password
106 Element passwordElement = e.getChild(Tags.PASSWORD, NAMESPACE);
107 if (passwordElement != null) {
108 setPassword(passwordElement.getText());
109 }
110
111 // locale
112 Element localeElement = e.getChild(Tags.LOCALE, Service.NAMESPACE);
113 if (localeElement != null) {
114 setLocale(localeElement.getText());
115 }
116
117 // timezone
118 Element tzElement = e.getChild(Tags.TIMEZONE, Service.NAMESPACE);
119 if (tzElement != null) {
120 setTimezone(tzElement.getText());
121 }
122
123 // email address
124 Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
125 if (emailElement != null) {
126 setEmailAddress(emailElement.getText());
127 }
128
129 // created (optional)
130 Element createdElement = e.getChild(Tags.DATE_CREATED, Service.NAMESPACE);
131 if (createdElement != null) {
132 setDateCreated(new Date(Long.valueOf(createdElement.getText()).longValue()));
133 }
134
135 // enabled
136 Element enabledElement = e.getChild(Tags.ENABLED, Service.NAMESPACE);
137 if (enabledElement != null) {
138 setEnabled(Boolean.valueOf(enabledElement.getText()));
139 }
140 }
141
142
143 public String getType() {
/*
P/P * Method: String getType()
*
* Postconditions:
* return_value == &"user"
*/
144 return Types.USER;
145 }
146
147 public Document toDocument() {
/*
P/P * Method: Document toDocument()
*
* Preconditions:
* init'ed(this.dateCreated)
* init'ed(this.emailAddress)
* init'ed(this.enabled)
* init'ed(this.fullName)
* init'ed(this.href)
* init'ed(this.locale)
* init'ed(this.name)
* init'ed(this.password)
* init'ed(this.screenName)
* init'ed(this.timezone)
*
* Postconditions:
* return_value == &new Document(toDocument#2)
* new Document(toDocument#2) num objects == 1
*
* Test Vectors:
* this.dateCreated: Addr_Set{null}, Inverse{null}
* this.emailAddress: Addr_Set{null}, Inverse{null}
* this.enabled: Addr_Set{null}, Inverse{null}
* this.fullName: Addr_Set{null}, Inverse{null}
* this.href: Addr_Set{null}, Inverse{null}
* this.locale: Addr_Set{null}, Inverse{null}
* this.name: Addr_Set{null}, Inverse{null}
* this.password: Addr_Set{null}, Inverse{null}
* this.screenName: Addr_Set{null}, Inverse{null}
* this.timezone: Addr_Set{null}, Inverse{null}
*/
148 Element userElement = new Element(Tags.USER, NAMESPACE);
149 Document doc = new Document(userElement);
150
151 // href
152 String href = getHref();
153 if (href != null) {
154 userElement.setAttribute(Attributes.HREF, href);
155 }
156
157 // name
158 String name = getName();
159 if (name != null) {
160 Element nameElement = new Element(Tags.NAME, Service.NAMESPACE);
161 Text nameText = new Text(name);
162 nameElement.addContent(nameText);
163 userElement.addContent(nameElement);
164 }
165
166 // screen name
167 String screenName = getScreenName();
168 if (screenName != null) {
169 Element screenNameElement = new Element(Tags.SCREEN_NAME, NAMESPACE);
170 Text screenNameText = new Text(screenName);
171 screenNameElement.addContent(screenNameText);
172 userElement.addContent(screenNameElement);
173 }
174
175 // full name
176 String fullName = getFullName();
177 if (fullName != null) {
178 Element fullNameElement = new Element(Tags.FULL_NAME, NAMESPACE);
179 Text fullNameText = new Text(fullName);
180 fullNameElement.addContent(fullNameText);
181 userElement.addContent(fullNameElement);
182 }
183
184 // password
185 String password = getPassword();
186 if (password != null) {
187 Element passwordElement = new Element(Tags.PASSWORD, NAMESPACE);
188 Text passwordText = new Text(password);
189 passwordElement.addContent(passwordText);
190 userElement.addContent(passwordElement);
191 }
192
193 // locale
194 Locale locale = getLocale();
195 if (locale != null) {
196 Element localeElement = new Element(Tags.LOCALE, Service.NAMESPACE);
197 Text localeText = new Text(getLocale().toString());
198 localeElement.addContent(localeText);
199 userElement.addContent(localeElement);
200 }
201
202 // timezone
203 TimeZone timezone = getTimezone();
204 if (timezone != null) {
205 Element timezoneElement = new Element(Tags.TIMEZONE, Service.NAMESPACE);
206 Text timezoneText = new Text(timezone.getID());
207 timezoneElement.addContent(timezoneText);
208 userElement.addContent(timezoneElement);
209 }
210
211 // email address
212 String emailAddress = getEmailAddress();
213 if (emailAddress != null) {
214 Element emailAddressElement = new Element(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
215 Text emailAddressText = new Text(emailAddress);
216 emailAddressElement.addContent(emailAddressText);
217 userElement.addContent(emailAddressElement);
218 }
219
220 // creation date
+ 221 Date datedCreated = getDateCreated();
222 if (dateCreated != null) {
223 Element dateCreatedElement = new Element(Tags.DATE_CREATED, Service.NAMESPACE);
224 Text dateCreatedText = new Text(String.valueOf(dateCreated.getTime()));
225 dateCreatedElement.addContent(dateCreatedText);
226 userElement.addContent(dateCreatedElement);
227 }
228
229 // enabled
230 Boolean enabled = getEnabled();
231 if (enabled != null) {
232 Element enabledElement = new Element(Tags.ENABLED, NAMESPACE);
233 Text enabledText = new Text(enabled.toString());
234 enabledElement.addContent(enabledText);
235 userElement.addContent(enabledElement);
236 }
237
238 return doc;
239 }
240
241 /** Get the user name of this user entry. */
242 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* init'ed(this.name)
*
* Postconditions:
* return_value == this.name
* init'ed(return_value)
*/
243 return name;
244 }
245
246 /** Set of the user name of this user entry. */
247 public void setName(String name) {
/*
P/P * Method: void setName(String)
*
* Postconditions:
* this.name == name
* init'ed(this.name)
*/
248 this.name = name;
249 }
250
251 /** Get the screen name of this user entry. */
252 public String getScreenName() {
/*
P/P * Method: String getScreenName()
*
* Preconditions:
* init'ed(this.screenName)
*
* Postconditions:
* return_value == this.screenName
* init'ed(return_value)
*/
253 return screenName;
254 }
255
256 /** Set the screen name of this user entry. */
257 public void setScreenName(String screenName) {
/*
P/P * Method: void setScreenName(String)
*
* Postconditions:
* this.screenName == screenName
* init'ed(this.screenName)
*/
258 this.screenName = screenName;
259 }
260
261 /** Get the full name of this user entry. */
262 public String getFullName() {
/*
P/P * Method: String getFullName()
*
* Preconditions:
* init'ed(this.fullName)
*
* Postconditions:
* return_value == this.fullName
* init'ed(return_value)
*/
263 return fullName;
264 }
265
266 /** Set the full name of this user entry. */
267 public void setFullName(String fullName) {
/*
P/P * Method: void setFullName(String)
*
* Postconditions:
* this.fullName == fullName
* init'ed(this.fullName)
*/
268 this.fullName = fullName;
269 }
270
271 /** Get the password of this user entry. */
272 public String getPassword() {
/*
P/P * Method: String getPassword()
*
* Preconditions:
* init'ed(this.password)
*
* Postconditions:
* return_value == this.password
* init'ed(return_value)
*/
273 return password;
274 }
275
276 /** Set the password of this user entry. */
277 public void setPassword(String password) {
/*
P/P * Method: void setPassword(String)
*
* Postconditions:
* this.password == password
* init'ed(this.password)
*/
278 this.password = password;
279 }
280
281 /** Get the locale string of this user entry. */
282 public Locale getLocale() {
/*
P/P * Method: Locale getLocale()
*
* Preconditions:
* init'ed(this.locale)
*
* Postconditions:
* return_value == this.locale
* init'ed(return_value)
*/
283 return locale;
284 }
285
286 /** Set the locale of this user entry. */
287 public void setLocale(Locale locale) {
/*
P/P * Method: void setLocale(Locale)
*
* Postconditions:
* this.locale == locale
* init'ed(this.locale)
*/
288 this.locale = locale;
289 }
290
291 /** Set the locale string of this user entry. */
292 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
*/
293 this.locale = new LocaleString(localeString).getLocale();
294 }
295
296 /** Get the timezone string of this user entry. */
297 public TimeZone getTimezone() {
/*
P/P * Method: TimeZone getTimezone()
*
* Preconditions:
* init'ed(this.timezone)
*
* Postconditions:
* return_value == this.timezone
* init'ed(return_value)
*/
298 return timezone;
299 }
300
301 /** Set the timezone of this user entry. */
302 public void setTimezone(TimeZone timezone) {
/*
P/P * Method: void setTimezone(TimeZone)
*
* Postconditions:
* this.timezone == timezone
* init'ed(this.timezone)
*/
303 this.timezone = timezone;
304 }
305
306 /** Set the timezone string of this user entry. */
307 public void setTimezone(String timezoneString) {
/*
P/P * Method: void setTimezone(String)
*
* Postconditions:
* init'ed(this.timezone)
*/
308 this.timezone = TimeZone.getTimeZone(timezoneString);
309 }
310
311 /** Get the date created of this user entry. */
312 public Date getDateCreated() {
/*
P/P * Method: Date getDateCreated()
*
* Preconditions:
* init'ed(this.dateCreated)
*
* Postconditions:
* return_value == this.dateCreated
* init'ed(return_value)
*/
313 return dateCreated;
314 }
315
316 /** Set the date created of this user entry. */
317 public void setDateCreated(Date dateCreated) {
/*
P/P * Method: void setDateCreated(Date)
*
* Postconditions:
* this.dateCreated == dateCreated
* init'ed(this.dateCreated)
*/
318 this.dateCreated = dateCreated;
319 }
320
321 /** Get the email address of this user entry. */
322 public String getEmailAddress() {
/*
P/P * Method: String getEmailAddress()
*
* Preconditions:
* init'ed(this.emailAddress)
*
* Postconditions:
* return_value == this.emailAddress
* init'ed(return_value)
*/
323 return emailAddress;
324 }
325
326 /** Set the email address of this user entry. */
327 public void setEmailAddress(String emailAddress) {
/*
P/P * Method: void setEmailAddress(String)
*
* Postconditions:
* this.emailAddress == emailAddress
* init'ed(this.emailAddress)
*/
328 this.emailAddress = emailAddress;
329 }
330
331 /** Test if a user entry is equal to this user entry. */
332 public boolean equals(Object o) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) init'ed(o.emailAddress)
* (soft) init'ed(o.enabled)
* (soft) init'ed(o.fullName)
* (soft) init'ed(o.href)
* (soft) init'ed(o.locale)
* (soft) init'ed(o.name)
* (soft) init'ed(o.timezone)
* (soft) init'ed(this.emailAddress)
* (soft) init'ed(this.enabled)
* (soft) init'ed(this.fullName)
* ...
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* o: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@339: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@342: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@345: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@348: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@351: {1}, {0}
* org.apache.roller.weblogger.webservices.adminprotocol.sdk.UserEntry:areEqual(...)@354: {1}, {0}
*/
333 if ( o == null || o.getClass() != this.getClass()) {
334 return false;
335 }
336
337 UserEntry other = (UserEntry)o;
338
339 if (!areEqual(getEmailAddress(), other.getEmailAddress())) {
340 return false;
341 }
342 if (!areEqual(getFullName(), other.getFullName())) {
343 return false;
344 }
345 if (!areEqual(getLocale(), other.getLocale())) {
346 return false;
347 }
348 if (!areEqual(getName(), other.getName())) {
349 return false;
350 }
351 if (!areEqual(getTimezone(), other.getTimezone())) {
352 return false;
353 }
354 if (!areEqual(getEnabled(), other.getEnabled())) {
355 return false;
356 }
357
358 return super.equals(o);
359 }
360
361 public Boolean getEnabled() {
/*
P/P * Method: Boolean getEnabled()
*
* Preconditions:
* init'ed(this.enabled)
*
* Postconditions:
* return_value == this.enabled
* init'ed(return_value)
*/
362 return enabled;
363 }
364
365 public void setEnabled(Boolean enabled) {
/*
P/P * Method: void setEnabled(Boolean)
*
* Postconditions:
* this.enabled == enabled
* init'ed(this.enabled)
*/
366 this.enabled = enabled;
367 }
368
369 }
SofCheck Inspector Build Version : 2.18479
| UserEntry.java |
2009-Jan-02 14:25:04 |
| UserEntry.class |
2009-Sep-04 03:12:46 |
| UserEntry$Tags.class |
2009-Sep-04 03:12:46 |