| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
package net.sourceforge.pebble.domain; |
| 34 | |
|
| 35 | |
import net.sourceforge.pebble.PebbleContext; |
| 36 | |
import net.sourceforge.pebble.security.PebbleUserDetails; |
| 37 | |
import net.sourceforge.pebble.security.SecurityRealm; |
| 38 | |
import net.sourceforge.pebble.security.SecurityRealmException; |
| 39 | |
import net.sourceforge.pebble.util.StringUtils; |
| 40 | |
|
| 41 | |
import org.apache.commons.logging.Log; |
| 42 | |
import org.apache.commons.logging.LogFactory; |
| 43 | |
|
| 44 | |
import java.util.*; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public abstract class PageBasedContent extends Content { |
| 52 | |
|
| 53 | 4 | private static final Log log = LogFactory.getLog(PageBasedContent.class); |
| 54 | |
|
| 55 | |
public static final String TITLE_PROPERTY = "title"; |
| 56 | |
public static final String SUBTITLE_PROPERTY = "subtitle"; |
| 57 | |
public static final String BODY_PROPERTY = "body"; |
| 58 | |
public static final String AUTHOR_PROPERTY = "author"; |
| 59 | |
public static final String DATE_PROPERTY = "date"; |
| 60 | |
public static final String ORIGINAL_PERMALINK_PROPERTY = "originalPermalink"; |
| 61 | |
public static final String TAGS_PROPERTY = "tags"; |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
private String id; |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 3136 | private String title = ""; |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | 3136 | private String subtitle = ""; |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | 3136 | private String body = ""; |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
private Date date; |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | 3136 | private String author = ""; |
| 92 | |
|
| 93 | |
|
| 94 | |
private PebbleUserDetails user; |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
private String originalPermalink; |
| 100 | |
|
| 101 | |
|
| 102 | 3136 | private String tags = ""; |
| 103 | |
|
| 104 | |
|
| 105 | 3136 | private List<Tag> tagsAsList = new LinkedList<Tag>(); |
| 106 | |
|
| 107 | |
|
| 108 | 3136 | private String tagsAsCommaSeparated = ""; |
| 109 | |
|
| 110 | |
|
| 111 | |
private Blog blog; |
| 112 | |
|
| 113 | 3136 | private boolean persistent = false; |
| 114 | 3136 | private String lockedBy = null; |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | 3136 | public PageBasedContent(Blog blog) { |
| 122 | 3136 | this.blog = blog; |
| 123 | 3136 | setDate(new Date()); |
| 124 | 3136 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
public String getId() { |
| 132 | 10692 | return id; |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public String getTitle() { |
| 141 | 4824 | return title; |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
public void setTitle(String newTitle) { |
| 150 | 2524 | newTitle = newTitle; |
| 151 | 2524 | propertyChangeSupport.firePropertyChange(TITLE_PROPERTY, title, newTitle); |
| 152 | 2524 | this.title = newTitle; |
| 153 | 2524 | } |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
public String getSubtitle() { |
| 161 | 1676 | return subtitle; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
public void setSubtitle(String newSubtitle) { |
| 170 | |
|
| 171 | 1644 | propertyChangeSupport.firePropertyChange(SUBTITLE_PROPERTY, subtitle, newSubtitle); |
| 172 | 1644 | this.subtitle = newSubtitle; |
| 173 | 1644 | } |
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public String getBody() { |
| 181 | 2632 | return body; |
| 182 | |
} |
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
public String getContent() { |
| 190 | 0 | return body; |
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
public void setBody(String newBody) { |
| 199 | 2680 | propertyChangeSupport.firePropertyChange(BODY_PROPERTY, body, newBody); |
| 200 | 2680 | this.body = newBody; |
| 201 | 2680 | } |
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
public Date getDate() { |
| 209 | 3596 | return date; |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
public Date getLastModified() { |
| 218 | 0 | return date; |
| 219 | |
} |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
public void setDate(Date newDate) { |
| 227 | 5472 | propertyChangeSupport.firePropertyChange(DATE_PROPERTY, date, newDate); |
| 228 | 5472 | this.date = newDate; |
| 229 | 5472 | this.id = "" + this.date.getTime(); |
| 230 | 5472 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
public String getAuthor() { |
| 238 | 2484 | return author; |
| 239 | |
} |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
public PebbleUserDetails getUser() { |
| 247 | 36 | if (this.user == null) { |
| 248 | 36 | SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm(); |
| 249 | |
try { |
| 250 | 36 | this.user = realm.getUser(getAuthor()); |
| 251 | 0 | } catch (SecurityRealmException e) { |
| 252 | 0 | log.error("Exception encountered", e); |
| 253 | 36 | } |
| 254 | |
} |
| 255 | |
|
| 256 | 36 | return this.user; |
| 257 | |
} |
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public void setAuthor(String newAuthor) { |
| 265 | 2048 | this.author = StringUtils.transformHTML(newAuthor); |
| 266 | 2048 | } |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public String getTags() { |
| 274 | 1812 | return this.tags; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
public List<Tag> getTagsAsList() { |
| 283 | 2236 | return this.tagsAsList; |
| 284 | |
} |
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
public String getTagsAsCommaSeparated() { |
| 292 | 0 | return this.tagsAsCommaSeparated; |
| 293 | |
} |
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
public abstract List<Tag> getAllTags(); |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
public void setTags(String newTags) { |
| 308 | 1780 | if (newTags != null && newTags.indexOf(",") > -1) { |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | 60 | newTags = newTags.replaceAll(" ", "").replaceAll(",", " "); |
| 314 | |
} |
| 315 | 1780 | propertyChangeSupport.firePropertyChange(TAGS_PROPERTY, tags, newTags); |
| 316 | 1780 | this.tags = newTags; |
| 317 | 1780 | this.tagsAsList = Tag.parse(getBlog(), tags); |
| 318 | 1780 | this.tagsAsCommaSeparated = Tag.format(getAllTags()); |
| 319 | 1780 | } |
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
public boolean isAggregated() { |
| 328 | 368 | return (originalPermalink != null); |
| 329 | |
} |
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
public String getOriginalPermalink() { |
| 337 | 1536 | return this.originalPermalink; |
| 338 | |
} |
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
public void setOriginalPermalink(String newPermalink) { |
| 346 | 1560 | newPermalink = StringUtils.transformHTML(newPermalink); |
| 347 | 1560 | if (newPermalink == null || newPermalink.length() == 0) { |
| 348 | 1508 | propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, null); |
| 349 | 1508 | this.originalPermalink = null; |
| 350 | |
} else { |
| 351 | 52 | propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, newPermalink); |
| 352 | 52 | this.originalPermalink = newPermalink; |
| 353 | |
} |
| 354 | 1560 | } |
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
public String getPermalink() { |
| 362 | 192 | if (isAggregated()) { |
| 363 | 0 | return getOriginalPermalink(); |
| 364 | |
} else { |
| 365 | 192 | return getLocalPermalink(); |
| 366 | |
} |
| 367 | |
} |
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
public abstract String getLocalPermalink(); |
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
public Blog getBlog() { |
| 384 | 18440 | return this.blog; |
| 385 | |
} |
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
public String toString() { |
| 393 | 0 | return getBlog().getId() + "/" + getTitle(); |
| 394 | |
} |
| 395 | |
|
| 396 | |
public boolean isPersistent() { |
| 397 | 3312 | return persistent; |
| 398 | |
} |
| 399 | |
|
| 400 | |
public void setPersistent(boolean persistent) { |
| 401 | 4052 | this.persistent = persistent; |
| 402 | 4052 | } |
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
public boolean isPublished() { |
| 410 | 5952 | return getState().equals(State.PUBLISHED); |
| 411 | |
} |
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
public boolean isUnpublished() { |
| 419 | 52 | return getState().equals(State.UNPUBLISHED); |
| 420 | |
} |
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
public void setPublished(boolean published) { |
| 428 | 5072 | if (published) { |
| 429 | 728 | setState(State.PUBLISHED); |
| 430 | |
} else { |
| 431 | 4344 | setState(State.UNPUBLISHED); |
| 432 | |
} |
| 433 | 5072 | } |
| 434 | |
|
| 435 | |
public String getLockedBy() { |
| 436 | 0 | return lockedBy; |
| 437 | |
} |
| 438 | |
|
| 439 | |
public void setLockedBy(String lockedBy) { |
| 440 | 4 | this.lockedBy = lockedBy; |
| 441 | 4 | } |
| 442 | |
|
| 443 | |
} |