1 package org.roller.presentation.weblog.formbeans; 2 3 import org.apache.commons.lang.StringUtils; 4 import org.roller.RollerException; 5 import org.roller.pojos.CommentData; 6 import org.roller.pojos.WeblogEntryData; 7 import org.roller.presentation.RollerRequest; 8 import org.roller.presentation.forms.WeblogEntryForm; 9 import org.roller.util.DateUtil; 10 11 import java.sql.Timestamp ; 12 import java.text.DateFormat ; 13 import java.text.ParseException ; 14 import java.util.ArrayList ; 15 import java.util.Calendar ; 16 import java.util.Date ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.Locale ; 20 import java.util.Map ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 import org.roller.pojos.EntryAttributeData; 25 import org.roller.pojos.WebsiteData; 26 27 32 public class WeblogEntryFormEx extends WeblogEntryForm 33 { 34 private String mCategoryId = null; 35 private Date mDate = new Date (); 36 private String mDateString = null; 37 private Integer mHours = new Integer (0); 38 private Integer mMinutes = new Integer (0); 39 private Integer mSeconds = new Integer (0); 40 private String [] mReplacementWords = null; 41 private String [] pluginsArray = new String [0]; 42 private String [] deleteComments = new String [0]; 43 private String [] spamComments = new String [0]; 44 private String trackbackUrl = null; 45 private Map attributes = new HashMap (); 46 47 public WeblogEntryFormEx() 48 { 49 super(); 50 } 51 52 public WeblogEntryFormEx(WeblogEntryData entryData, java.util.Locale locale) 53 throws RollerException 54 { 55 copyFrom(entryData, locale); 56 } 57 58 62 public void initNew(HttpServletRequest request, HttpServletResponse response) 63 { 64 RollerRequest rreq = RollerRequest.getRollerRequest(request); 65 if (rreq.getWebsite().getDefaultPlugins() != null) 66 { 67 setPluginsArray(StringUtils.split( 68 rreq.getWebsite().getDefaultPlugins(), ",") ); 69 } 70 allowComments = Boolean.TRUE; 71 updateTime = new Timestamp (new Date ().getTime()); 72 pubTime = updateTime; 73 initPubTimeDateStrings(rreq.getWebsite(), request.getLocale()); 74 } 75 76 79 public void copyTo(WeblogEntryData entry, Locale locale, Map paramMap) 80 throws RollerException 81 { 82 super.copyTo(entry, locale); 83 84 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); 86 final Date newDate; 87 try 88 { 89 newDate = df.parse(getDateString()); 90 } 91 catch (ParseException e) 92 { 93 throw new RollerException("ERROR parsing date."); 94 } 95 96 final Calendar cal = Calendar.getInstance(locale); 98 cal.setTime(newDate); 99 cal.setTimeZone(entry.getWebsite().getTimeZoneInstance()); 100 cal.set(Calendar.HOUR_OF_DAY, getHours().intValue()); 101 cal.set(Calendar.MINUTE, getMinutes().intValue()); 102 cal.set(Calendar.SECOND, getSeconds().intValue()); 103 entry.setPubTime(new Timestamp (cal.getTimeInMillis())); 104 105 entry.setPlugins( StringUtils.join(this.pluginsArray,",") ); 106 107 if (entry.getPublishEntry() == null) 109 { 110 entry.setPublishEntry(Boolean.FALSE); 111 } 112 if (getCategoryId() != null) 113 { 114 entry.setCategoryId(getCategoryId()); 115 } 116 117 Iterator params = paramMap.keySet().iterator(); 118 while (params.hasNext()) 119 { 120 String name = (String )params.next(); 121 String [] value = (String [])paramMap.get(name); 122 if (name.startsWith("att_") && value.length > 0) 123 { 124 try 125 { 126 entry.putEntryAttribute(name, value[0]); 127 } 128 catch (Exception e) 129 { 130 throw new RollerException("ERROR setting attributes",e); 131 } 132 } 133 } 134 } 135 136 139 public void copyFrom(WeblogEntryData entry, Locale locale) 140 throws RollerException 141 { 142 super.copyFrom(entry, locale); 143 mCategoryId = entry.getCategory().getId(); 144 145 initPubTimeDateStrings(entry.getWebsite(), locale); 146 147 if (entry.getPlugins() != null) 148 { 149 pluginsArray = StringUtils.split(entry.getPlugins(), ","); 150 } 151 152 attributes = new HashMap (); 153 Iterator atts = entry.getEntryAttributes().iterator(); 154 while (atts.hasNext()) 155 { 156 EntryAttributeData att = (EntryAttributeData)atts.next(); 157 attributes.put(att.getName(), att.getValue()); 158 } 159 160 populateSpamComments(entry); 161 } 162 163 public Map getAttributes() 164 { 165 return attributes; 166 } 167 168 172 private void populateSpamComments(WeblogEntryData entry) 173 { 174 ArrayList spamList = new ArrayList (); 175 Iterator it = entry.getComments(false).iterator(); 176 while (it.hasNext()) { 177 CommentData comment = (CommentData)it.next(); 178 if (comment.getSpam().booleanValue()) 179 { 180 spamList.add(comment.getId()); 181 } 182 } 183 spamComments = (String [])spamList.toArray(new String [spamList.size()]); 184 } 185 186 190 private void initPubTimeDateStrings(WebsiteData website, Locale locale) 191 { 192 Calendar cal = Calendar.getInstance(); 193 cal.setTime(getPubTime()); 194 cal.setTimeZone(website.getTimeZoneInstance()); 195 mHours = new Integer (cal.get(Calendar.HOUR_OF_DAY)); 196 mMinutes = new Integer (cal.get(Calendar.MINUTE)); 197 mSeconds = new Integer (cal.get(Calendar.SECOND)); 198 199 DateFormat df = DateFormat.getDateInstance( 200 DateFormat.SHORT, locale); 201 mDateString = df.format(getPubTime()); 202 } 203 204 208 public String getCategoryId() 209 { 210 return mCategoryId; 211 } 212 213 public Date getDate() 214 { 215 return mDate; 216 } 217 218 222 public String getDateString() 223 { 224 return mDateString; 225 } 226 227 230 public Integer getHours() 231 { 232 return mHours; 233 } 234 235 238 public Integer getMinutes() 239 { 240 return mMinutes; 241 } 242 243 247 public String [] getReplacementWords() 248 { 249 return mReplacementWords; 250 } 251 252 255 public Integer getSeconds() 256 { 257 return mSeconds; 258 } 259 260 264 public void setCategoryId(String categoryId) 265 { 266 this.mCategoryId = categoryId; 267 } 268 269 273 public void setDateString(String dateString) throws ParseException 274 { 275 mDateString = dateString; 276 } 277 278 281 public void setHours(Integer hours) 282 { 283 mHours = hours; 284 } 285 286 289 public void setMinutes(Integer minutes) 290 { 291 mMinutes = minutes; 292 } 293 294 public void setReplacementWords(String [] words) 295 { 296 this.mReplacementWords = words; 297 } 298 299 302 public void setSeconds(Integer seconds) 303 { 304 mSeconds = seconds; 305 } 306 307 public String getDay() 308 { 309 java.util.Date theDay = getPubTime(); 310 theDay = theDay!=null ? theDay : new java.util.Date (); 311 return DateUtil.format8chars(theDay); 312 } 313 314 317 public String [] getPluginsArray() 318 { 319 return pluginsArray; 320 } 321 322 325 public void setPluginsArray(String [] strings) 326 { 327 pluginsArray = strings; 328 } 329 330 public void doReset( 331 org.apache.struts.action.ActionMapping mapping, 332 javax.servlet.ServletRequest request) 333 { 334 super.doReset(mapping, request); 335 336 pluginsArray = new String [0]; 337 338 Calendar cal = Calendar.getInstance(request.getLocale()); 340 Date now = new Date (); 341 cal.setTime(now); 342 mHours = new Integer (cal.get(Calendar.HOUR_OF_DAY)); 343 mMinutes = new Integer (cal.get(Calendar.MINUTE)); 344 mSeconds = new Integer (cal.get(Calendar.SECOND)); 345 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, request.getLocale()); 346 mDateString = df.format(now); 347 } 348 349 352 public String [] getDeleteComments() { 353 return deleteComments; 354 } 355 356 359 public void setDeleteComments(String [] selectedComments) { 360 this.deleteComments = selectedComments; 361 } 362 363 366 public String [] getSpamComments() { 367 return spamComments; 368 } 369 370 373 public void setSpamComments(String [] commentsToMarkAsSpam) { 374 this.spamComments = commentsToMarkAsSpam; 375 } 376 377 380 public String getTrackbackUrl() 381 { 382 return trackbackUrl; 383 } 384 387 public void setTrackbackUrl(String trackbackUrl) 388 { 389 this.trackbackUrl = trackbackUrl; 390 } 391 } 392 393 | Popular Tags |