1 18 package org.apache.roller.ui.authoring.struts.formbeans; 19 20 import java.sql.Timestamp ; 21 import java.text.DateFormat ; 22 import java.text.ParseException ; 23 import java.util.ArrayList ; 24 import java.util.Calendar ; 25 import java.util.TimeZone ; 26 import java.util.Date ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Locale ; 30 import java.util.Map ; 31 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 35 import org.apache.commons.lang.StringUtils; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.roller.RollerException; 39 import org.apache.roller.pojos.CommentData; 40 import org.apache.roller.pojos.EntryAttributeData; 41 import org.apache.roller.pojos.WeblogEntryData; 42 import org.apache.roller.pojos.WebsiteData; 43 import org.apache.roller.ui.core.RollerRequest; 44 import org.apache.roller.ui.core.RollerSession; 45 import org.apache.roller.ui.authoring.struts.forms.WeblogEntryForm; 46 import org.apache.roller.util.DateUtil; 47 48 49 54 public class WeblogEntryFormEx extends WeblogEntryForm 55 { 56 private static Log mLogger = 57 LogFactory.getFactory().getInstance(WeblogEntryFormEx.class); 58 59 private String mCategoryId = null; 60 private String mCreatorId = null; 61 private String mWebsiteId = null; 62 private Date mDate = new Date (); 63 private String mDateString = null; 64 private Integer mHours = new Integer (0); 65 private Integer mMinutes = new Integer (0); 66 private Integer mSeconds = new Integer (0); 67 private String [] mReplacementWords = null; 68 private String [] pluginsArray = new String [0]; 69 private String [] deleteComments = new String [0]; 70 private String [] spamComments = new String [0]; 71 private String trackbackUrl = null; 72 private Map attributes = new HashMap (); 73 74 public WeblogEntryFormEx() 75 { 76 super(); 77 mLogger.debug("default construction"); 78 } 79 80 public WeblogEntryFormEx(WeblogEntryData entryData, java.util.Locale locale) 81 throws RollerException 82 { 83 mLogger.debug("construction from existing entry"); 84 copyFrom(entryData, locale); 85 } 86 87 91 public void initNew(HttpServletRequest request, HttpServletResponse response) 92 { 93 mLogger.debug("init new called"); 94 95 RollerRequest rreq = RollerRequest.getRollerRequest(request); 96 RollerSession rses = RollerSession.getRollerSession(request); 97 if (rreq.getWebsite().getDefaultPlugins() != null) 98 { 99 setPluginsArray(StringUtils.split( 100 rreq.getWebsite().getDefaultPlugins(), ",") ); 101 } 102 status = WeblogEntryData.DRAFT; 103 allowComments = Boolean.TRUE; 104 locale = rreq.getWebsite().getLocale(); 105 106 } 111 112 115 public void copyTo(WeblogEntryData entry, Locale locale, Map paramMap) 116 throws RollerException 117 { 118 mLogger.debug("copy to called"); 119 120 super.copyTo(entry, locale); 121 122 if(getDateString() != null && !"0/0/0".equals(getDateString())) { 124 Date pubtime = null; 125 126 TimeZone timezone = entry.getWebsite().getTimeZoneInstance(); 127 try { 128 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); 129 Date newDate = df.parse(getDateString()); 130 131 if(newDate != null) { 133 Calendar cal = Calendar.getInstance(locale); 134 cal.setTime(newDate); 135 cal.setTimeZone(timezone); 136 cal.set(Calendar.HOUR_OF_DAY, getHours().intValue()); 137 cal.set(Calendar.MINUTE, getMinutes().intValue()); 138 cal.set(Calendar.SECOND, getSeconds().intValue()); 139 entry.setPubTime(new Timestamp (cal.getTimeInMillis())); 140 } 141 142 } catch(Exception e) { 143 mLogger.error(e); 144 } 145 146 mLogger.debug("set pubtime to "+entry.getPubTime()); 147 } 148 149 entry.setPlugins( StringUtils.join(this.pluginsArray,",") ); 150 151 if (getCategoryId() != null) 152 { 153 entry.setCategoryId(getCategoryId()); 154 } 155 if (getAllowComments() == null) 156 { 157 entry.setAllowComments(Boolean.FALSE); 158 } 159 if (getRightToLeft() == null) 160 { 161 entry.setRightToLeft(Boolean.FALSE); 162 } 163 if (getPinnedToMain() == null) 164 { 165 entry.setPinnedToMain(Boolean.FALSE); 166 } 167 168 Iterator params = paramMap.keySet().iterator(); 169 while (params.hasNext()) 170 { 171 String name = (String )params.next(); 172 String [] value = (String [])paramMap.get(name); 173 if (name.startsWith("att_") && value.length > 0) 174 { 175 try 176 { 177 entry.putEntryAttribute(name, value[0]); 178 } 179 catch (Exception e) 180 { 181 throw new RollerException("ERROR setting attributes",e); 182 } 183 } 184 } 185 } 186 187 190 public void copyFrom(WeblogEntryData entry, Locale locale) 191 throws RollerException 192 { 193 mLogger.debug("copy from called"); 194 195 super.copyFrom(entry, locale); 196 mCategoryId = entry.getCategory().getId(); 197 mCreatorId = entry.getCreator().getId(); 198 mWebsiteId = entry.getWebsite().getId(); 199 200 initPubTimeDateStrings(entry.getWebsite(), locale); 201 202 if (entry.getPlugins() != null) 203 { 204 pluginsArray = StringUtils.split(entry.getPlugins(), ","); 205 } 206 207 attributes = new HashMap (); 208 Iterator atts = entry.getEntryAttributes().iterator(); 209 while (atts.hasNext()) 210 { 211 EntryAttributeData att = (EntryAttributeData)atts.next(); 212 attributes.put(att.getName(), att.getValue()); 213 } 214 } 215 216 public Map getAttributes() 217 { 218 return attributes; 219 } 220 221 225 private void initPubTimeDateStrings(WebsiteData website, Locale locale) 226 { 227 mLogger.debug("init pub time date sting called"); 228 229 if(getPubTime() != null) { 230 mLogger.debug("figuring pubtime values"); 231 232 Calendar cal = Calendar.getInstance(); 233 cal.setTime(getPubTime()); 234 cal.setTimeZone(website.getTimeZoneInstance()); 235 mHours = new Integer (cal.get(Calendar.HOUR_OF_DAY)); 236 mMinutes = new Integer (cal.get(Calendar.MINUTE)); 237 mSeconds = new Integer (cal.get(Calendar.SECOND)); 238 239 DateFormat df = DateFormat.getDateInstance( 240 DateFormat.SHORT, locale); 241 df.setTimeZone(website.getTimeZoneInstance()); 242 mDateString = df.format(getPubTime()); 243 244 } else { 245 mLogger.debug("pubtime is null, must be a draft"); 246 247 mDateString = "0/0/0"; 248 } 249 } 250 251 255 public String getCategoryId() 256 { 257 return mCategoryId; 258 } 259 260 public Date getDate() 261 { 262 return mDate; 263 } 264 265 269 public String getDateString() 270 { 271 return mDateString; 272 } 273 274 277 public Integer getHours() 278 { 279 return mHours; 280 } 281 282 285 public Integer getMinutes() 286 { 287 return mMinutes; 288 } 289 290 294 public String [] getReplacementWords() 295 { 296 return mReplacementWords; 297 } 298 299 302 public Integer getSeconds() 303 { 304 return mSeconds; 305 } 306 307 311 public void setCategoryId(String categoryId) 312 { 313 this.mCategoryId = categoryId; 314 } 315 316 320 public void setDateString(String dateString) throws ParseException 321 { 322 mLogger.debug("somebody setting date string"); 323 mDateString = dateString; 324 } 325 326 329 public void setHours(Integer hours) 330 { 331 mHours = hours; 332 } 333 334 337 public void setMinutes(Integer minutes) 338 { 339 mMinutes = minutes; 340 } 341 342 public void setReplacementWords(String [] words) 343 { 344 this.mReplacementWords = words; 345 } 346 347 350 public void setSeconds(Integer seconds) 351 { 352 mSeconds = seconds; 353 } 354 355 public String getDay() 356 { 357 java.util.Date theDay = getPubTime(); 358 theDay = theDay!=null ? theDay : new java.util.Date (); 359 return DateUtil.format8chars(theDay); 360 } 361 362 365 public String [] getPluginsArray() 366 { 367 return pluginsArray; 368 } 369 370 373 public void setPluginsArray(String [] strings) 374 { 375 pluginsArray = strings; 376 } 377 378 public void doReset( 379 org.apache.struts.action.ActionMapping mapping, 380 javax.servlet.ServletRequest request) 381 { 382 super.doReset(mapping, request); 383 mLogger.debug("reset called"); 384 385 pluginsArray = new String [0]; 386 387 398 mDateString = "0/0/0"; 399 } 400 401 404 public String [] getDeleteComments() { 405 return deleteComments; 406 } 407 408 411 public void setDeleteComments(String [] selectedComments) { 412 this.deleteComments = selectedComments; 413 } 414 415 418 public String [] getSpamComments() { 419 return spamComments; 420 } 421 422 425 public void setSpamComments(String [] commentsToMarkAsSpam) { 426 this.spamComments = commentsToMarkAsSpam; 427 } 428 429 432 public String getTrackbackUrl() 433 { 434 return trackbackUrl; 435 } 436 439 public void setTrackbackUrl(String trackbackUrl) 440 { 441 this.trackbackUrl = trackbackUrl; 442 } 443 444 public String getCreatorId() 445 { 446 return mCreatorId; 447 } 448 public void setCreatorId(String creatorId) 449 { 450 mCreatorId = creatorId; 451 } 452 453 public String getWebsiteId() 454 { 455 return mWebsiteId; 456 } 457 public void setWebsiteId(String websiteId) 458 { 459 mWebsiteId = websiteId; 460 } 461 462 463 public boolean isDraft() 464 { 465 return status.equals(WeblogEntryData.DRAFT); 466 } 467 468 469 public boolean isPending() 470 { 471 return status.equals(WeblogEntryData.PENDING); 472 } 473 474 475 public boolean isPublished() 476 { 477 return status.equals(WeblogEntryData.PUBLISHED); 478 } 479 } 480 481 | Popular Tags |