📄 weblogentrydata.java
字号:
} else { Calendar expireCal = Calendar.getInstance(getWebsite().getLocaleInstance()); expireCal.setTime(getPubTime()); expireCal.add(Calendar.DATE, getCommentDays().intValue()); Date expireDay = expireCal.getTime(); Date today = new Date(); if (today.before(expireDay)) { ret = true; } } } return ret; } public void setCommentsStillAllowed(boolean ignored) { // no-op } //------------------------------------------------------------------------ /** * Format the publish time of this weblog entry using the specified pattern. * See java.text.SimpleDateFormat for more information on this format. * @see java.text.SimpleDateFormat * @return Publish time formatted according to pattern. */ public String formatPubTime(String pattern) { try { SimpleDateFormat format = new SimpleDateFormat(pattern, this.getWebsite().getLocaleInstance()); return format.format(getPubTime()); } catch (RuntimeException e) { mLogger.error("Unexpected exception", e); } return "ERROR: formatting date"; } //------------------------------------------------------------------------ /** * Format the update time of this weblog entry using the specified pattern. * See java.text.SimpleDateFormat for more information on this format. * @see java.text.SimpleDateFormat * @return Update time formatted according to pattern. */ public String formatUpdateTime(String pattern) { try { SimpleDateFormat format = new SimpleDateFormat(pattern); return format.format(getUpdateTime()); } catch (RuntimeException e) { mLogger.error("Unexpected exception", e); } return "ERROR: formatting date"; } //------------------------------------------------------------------------ public List getComments() { return getComments(true); } public List getComments(boolean ignoreSpam) { List list = new ArrayList(); try { return RollerFactory.getRoller().getWeblogManager().getComments(getId(), ignoreSpam); } catch (RollerException alreadyLogged) {} return list; } //------------------------------------------------------------------------ public List getReferers() { List referers = null; try { referers = RollerFactory.getRoller().getRefererManager().getReferersToEntry(getId()); } catch (RollerException e) { mLogger.error("Unexpected exception", e); } return referers; } //------------------------------------------------------------------------ /** * @param entry * @param url * @param title * @param excerpt * @param blogName */ public void addTrackback( String url, String title, String excerpt, String blogName) throws RollerException { String modTitle = blogName + ": " + title; if (modTitle.length() >= 250) { modTitle = modTitle.substring(0, 257); modTitle += "..."; } // Track trackbacks as comments CommentData comment = new CommentData(); comment.setContent("[Trackback] "+excerpt); comment.setName(blogName); comment.setUrl(url); comment.setWeblogEntry(this); comment.setNotify(Boolean.FALSE); comment.setPostTime(new Timestamp(new Date().getTime())); comment.save(); // Alternative: treat trackbacks as referers //RefererData ref = new RefererData(); //ref.setWebsite(getWebsite()); //ref.setWeblogEntry(this); //ref.setRequestUrl("(trackback)"); //ref.setRefererUrl(url); //ref.setTitle(modTitle); //ref.setExcerpt(excerpt); //ref.setVisible(Boolean.TRUE); //ref.setDayHits(new Integer(0)); //ref.setTotalHits(new Integer(0)); //ref.setDuplicate(Boolean.FALSE); //ref.setDateString(formatPubTime("yyyyMMdd")); //mRoller.getRefererManager().storeReferer(ref); } /** * Convenience method for getPermalink(category) * where no category is necessary. * @return */ public String getPermaLink() { String lAnchor = this.getAnchor(); try { lAnchor = URLEncoder.encode(anchor, "UTF-8"); } catch (UnsupportedEncodingException e) { // go with the "no encoding" version } WebsiteData website = this.getWebsite(); String plink = "/page/" + website.getUser().getUserName() + "?entry=" + lAnchor; return plink; } /** * Get the "relative" URL to this entry. Proper use of this will * require prepending the baseURL (either the full root * [http://server.com/context] or at least the context * [/context]) in order to generate a functional link. * @param category The category name to insert into the permalink. * @return String */ public String getPermaLink(String categoryPath) { // i don't really understand the purpose of this method since // WeblogEntryData.getPermaLink() is only meant to point to this entry return this.getPermaLink(); } public String getCommentsLink() { String dayString = DateUtil.format8chars(this.getPubTime()); String lAnchor = this.getAnchor(); try { lAnchor = URLEncoder.encode(anchor, "UTF-8"); } catch (UnsupportedEncodingException e) { // go with the "no encoding" version } String clink = "/page/" + this.getWebsite().getUser().getUserName() + "?anchor=" + lAnchor; return clink; } /** to please XDoclet */ public void setCommentsLink(String ignored) {} /** * Return the Title of this post, or the first 255 characters of the * entry's text. * * @return String */ public String getDisplayTitle() { if ( getTitle()==null || getTitle().trim().equals("") ) { return StringUtils.left(Utilities.removeHTML(text),255); } return Utilities.removeHTML(getTitle()); } //------------------------------------------------------------------------ public String toString() { StringBuffer str = new StringBuffer("{"); str.append("id=" + id + " " + "category=" + category + " " + "title=" + title + " " + "text=" + text + " " + "anchor=" + anchor + " " + "pubTime=" + pubTime + " " + "updateTime=" + updateTime + " " + "publishEntry=" + publishEntry + " " + "plugins=" + mPlugins); str.append('}'); return (str.toString()); } //------------------------------------------------------------------------ public boolean equals(Object pOther) { if (pOther instanceof WeblogEntryData) { WeblogEntryData lTest = (WeblogEntryData) pOther; boolean lEquals = true; if (this.id == null) { lEquals = lEquals && (lTest.id == null); } else { lEquals = lEquals && this.id.equals(lTest.id); } if (this.category == null) { lEquals = lEquals && (lTest.category == null); } else { lEquals = lEquals && this.category.equals(lTest.category); } if (this.mWebsite == null) { lEquals = lEquals && (lTest.mWebsite == null); } else { lEquals = lEquals && this.mWebsite.equals(lTest.mWebsite); } if (this.title == null) { lEquals = lEquals && (lTest.title == null); } else { lEquals = lEquals && this.title.equals(lTest.title); } if (this.text == null) { lEquals = lEquals && (lTest.text == null); } else { lEquals = lEquals && this.text.equals(lTest.text); } if (this.anchor == null) { lEquals = lEquals && (lTest.anchor == null); } else { lEquals = lEquals && this.anchor.equals(lTest.anchor); } if (this.pubTime == null) { lEquals = lEquals && (lTest.pubTime == null); } else { lEquals = lEquals && this.pubTime.equals(lTest.pubTime); } if (this.updateTime == null) { lEquals = lEquals && (lTest.updateTime == null); } else { lEquals = lEquals && this.updateTime.equals(lTest.updateTime); } if (this.publishEntry == null) { lEquals = lEquals && (lTest.publishEntry == null); } else { lEquals = lEquals && this.publishEntry.equals(lTest.publishEntry); } if (this.mPlugins == null) { lEquals = lEquals && (lTest.mPlugins == null); } else { lEquals = lEquals && this.mPlugins.equals(lTest.mPlugins); } return lEquals; } else { return false; } } //------------------------------------------------------------------------ public int hashCode() { int result = 17; result = (37 * result) + ((this.id != null) ? this.id.hashCode() : 0); result = (37 * result) + ((this.category != null) ? this.category.hashCode() : 0); result = (37 * result) + ((this.mWebsite != null) ? this.mWebsite.hashCode() : 0); result = (37 * result) + ((this.title != null) ? this.title.hashCode() : 0); result = (37 * result) + ((this.text != null) ? this.text.hashCode() : 0); result = (37 * result) + ((this.anchor != null) ? this.anchor.hashCode() : 0); result = (37 * result) + ((this.pubTime != null) ? this.pubTime.hashCode() : 0); result = (37 * result) + ((this.updateTime != null) ? this.updateTime.hashCode() : 0); result = (37 * result) + ((this.publishEntry != null) ? this.publishEntry.hashCode() : 0); result = (37 * result) + ((this.mPlugins != null) ? this.mPlugins.hashCode() : 0); return result; } /** Return RSS 09x style description (escaped HTML version of entry text) */ public String getRss09xDescription() { return getRss09xDescription(-1); } /** Return RSS 09x style description (escaped HTML version of entry text) */ public String getRss09xDescription(int maxLength) { String ret = Utilities.escapeHTML(text); if (maxLength != -1 && ret.length() > maxLength) { ret = ret.substring(0,maxLength-3)+"..."; } return ret; } /** Create anchor for weblog entry, based on title or text */ protected String createAnchor() throws RollerException { return RollerFactory.getRoller().getWeblogManager().createAnchor(this); } /** Create anchor for weblog entry, based on title or text */ public String createAnchorBase() { // Use title or text for base anchor String base = getTitle(); if (base == null || base.trim().equals("")) { base = getText(); } if (base != null && !base.trim().equals("")) { base = Utilities.replaceNonAlphanumeric(base, ' '); // Use only the first 4 words StringTokenizer toker = new StringTokenizer(base); String tmp = null; int count = 0; while (toker.hasMoreTokens() && count < 5) { String s = toker.nextToken(); s = s.toLowerCase(); tmp = (tmp == null) ? s : tmp + "_" + s; count++; } base = tmp; } // No title or text, so instead we will use the items date // in YYYYMMDD format as the base anchor else { base = DateUtil.format8chars(getPubTime()); } return base; } /** * A no-op. * TODO: fix formbean generation so this is not needed. * @param string */ public void setPermaLink(String string) { } /** * A no-op. * TODO: fix formbean generation so this is not needed. * @param string */ public void setDisplayTitle(String string) { } /** * A no-op. * TODO: fix formbean generation so this is not needed. * @param string */ public void setRss09xDescription(String string) { } /** * @see org.roller.pojos.PersistentObject#remove() */ public void remove() throws RollerException { RollerFactory.getRoller().getWeblogManager().removeWeblogEntryContents(this); super.remove(); } /** * Convenience method to transform mPlugins to a List * @return */ public List getPluginsList() { if (mPlugins != null) { return Arrays.asList( StringUtils.split(mPlugins, ",") ); } return new ArrayList(); } public boolean canSave() throws RollerException { Roller roller = RollerFactory.getRoller(); if (roller.getUser().equals(UserData.SYSTEM_USER)) { return true; } if (roller.getUser().equals(getWebsite().getUser())) { return true; } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -