1 18 package org.apache.roller.webservices.adminapi.sdk; 19 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.webservices.adminapi.sdk.Entry.Attributes; 36 import org.apache.roller.webservices.adminapi.sdk.Entry.Types; 37 38 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 } 55 56 private String handle; 57 private String name; 58 private String description; 59 private Locale locale; 60 private TimeZone timezone; 61 private Date dateCreated; 62 private String creatingUser; 63 private String emailAddress; 64 private String appEntriesUrl; 65 private String appResourcesUrl; 66 67 public WeblogEntry(Element e, String urlPrefix) throws MissingElementException { 68 populate(e, urlPrefix); 69 } 70 71 public WeblogEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException , 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 urlPrefix) throws MissingElementException { 80 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 String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + getHandle(); 89 setHref(href); 90 91 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 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 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 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 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 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 Element createdElement = e.getChild(Tags.DATE_CREATED, Service.NAMESPACE); 135 if (createdElement != null) { 136 setDateCreated(new Date (Long.valueOf(createdElement.getText()).longValue())); 137 } 138 139 Element appEntriesUrlElement = e.getChild(Tags.APP_ENTRIES_URL, Service.NAMESPACE); 141 if (appEntriesUrlElement != null) { 142 setAppEntriesUrl(appEntriesUrlElement.getText()); 143 } 144 145 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 handle, String urlPrefix) { 154 String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + handle; 155 setHref(href); 156 setHandle(handle); 157 } 158 159 public String 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 weblog.setAttribute(Attributes.HREF, getHref()); 169 170 Element handle = new Element(Tags.HANDLE, Service.NAMESPACE); 172 Text handleText = new Text(getHandle()); 173 handle.addContent(handleText); 174 weblog.addContent(handle); 175 176 Element name = new Element(Tags.NAME, Service.NAMESPACE); 178 Text nameText = new Text(getName()); 179 name.addContent(nameText); 180 weblog.addContent(name); 181 182 Element desc = new Element(Tags.DESCRIPTION, Service.NAMESPACE); 184 Text descText = new Text(getDescription()); 185 desc.addContent(descText); 186 weblog.addContent(desc); 187 188 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 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 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 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 Element created = new Element(Tags.DATE_CREATED, Service.NAMESPACE); 214 Date 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 Element appEntriesUrlElement = new Element(Tags.APP_ENTRIES_URL, Service.NAMESPACE); 223 String appEntriesUrl = getAppEntriesUrl(); 224 if (appEntriesUrl != null) { 225 Text appEntriesUrlText = new Text(appEntriesUrl); 226 appEntriesUrlElement.addContent(appEntriesUrlText); 227 weblog.addContent(appEntriesUrlElement); 228 } 229 230 Element appResourcesUrlElement = new Element(Tags.APP_RESOURCES_URL, Service.NAMESPACE); 232 String 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 243 public boolean equals(Object 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 getHandle() { 273 return handle; 274 } 275 276 public void setHandle(String handle) { 277 this.handle = handle; 278 } 279 280 public String getDescription() { 281 return description; 282 } 283 284 public void setDescription(String description) { 285 this.description = description; 286 } 287 288 public Locale getLocale() { 289 return locale; 290 } 291 292 public void setLocale(Locale locale) { 293 this.locale = locale; 294 } 295 296 public void setLocale(String localeString) { 297 this.locale = new LocaleString(localeString).getLocale(); 298 } 299 300 301 public TimeZone getTimezone() { 302 return timezone; 303 } 304 305 public void setTimezone(TimeZone timezone) { 306 this.timezone = timezone; 307 } 308 309 public void setTimezone(String timezoneString) { 310 this.timezone = TimeZone.getTimeZone(timezoneString); 311 } 312 313 public String getName() { 314 return name; 315 } 316 317 public void setName(String name) { 318 this.name = name; 319 } 320 321 public Date getDateCreated() { 322 return dateCreated; 323 } 324 325 public void setDateCreated(Date dateCreated) { 326 this.dateCreated = dateCreated; 327 } 328 329 public String getCreatingUser() { 330 return creatingUser; 331 } 332 333 public void setCreatingUser(String creatingUser) { 334 this.creatingUser = creatingUser; 335 } 336 337 public String getEmailAddress() { 338 return emailAddress; 339 } 340 341 public void setEmailAddress(String emailAddress) { 342 this.emailAddress = emailAddress; 343 } 344 345 public String getAppEntriesUrl() { 346 return appEntriesUrl; 347 } 348 349 public void setAppEntriesUrl(String appEntriesUrl) { 350 this.appEntriesUrl = appEntriesUrl; 351 } 352 353 public String getAppResourcesUrl() { 354 return appResourcesUrl; 355 } 356 357 public void setAppResourcesUrl(String appResourcesUrl) { 358 this.appResourcesUrl = appResourcesUrl; 359 } 360 } 361 | Popular Tags |