1 5 package org.roller.presentation.velocity.plugins.readmore; 6 7 import org.apache.commons.lang.StringEscapeUtils; 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.apache.velocity.context.Context; 11 import org.roller.RollerException; 12 import org.roller.model.RollerFactory; 13 import org.roller.model.UserManager; 14 import org.roller.pojos.WeblogEntryData; 15 import org.roller.pojos.WebsiteData; 16 import org.roller.presentation.RollerRequest; 17 import org.roller.presentation.velocity.PagePlugin; 18 import org.roller.util.Utilities; 19 20 23 public class ReadMorePlugin implements PagePlugin 24 { 25 protected String name = "Read More Summary"; 26 protected String description = "Stops entry after 250 characters and creates " + 27 "a link to the full entry."; 28 29 private static Log mLogger = 30 LogFactory.getFactory().getInstance(ReadMorePlugin.class); 31 32 String ctxPath = ""; 33 34 public ReadMorePlugin() 35 { 36 mLogger.debug("ReadMorePlugin instantiated."); 37 } 38 39 public String toString() { return name; } 40 41 44 public void init(RollerRequest rreq, Context ctx) throws RollerException 45 { 46 if (rreq == null) throw new RollerException("RollerRequest is null."); 47 48 ctxPath = rreq.getRequest().getContextPath(); 49 } 50 51 56 private String getPageLink(UserManager mgr, WebsiteData website) throws RollerException 57 { 58 return mgr.retrievePage(website.getDefaultPageId()).getLink(); 59 } 60 61 68 public String render(String str) 69 { 70 return str; 71 } 72 73 public String render(WeblogEntryData entry, boolean skipFlag) 74 { 75 if (skipFlag) 76 return entry.getText(); 77 78 String pageLink = "Weblog"; 80 try 81 { 82 pageLink = getPageLink( 83 RollerFactory.getRoller().getUserManager(), entry.getWebsite()); 84 } 85 catch (RollerException e) 86 { 87 mLogger.warn("Unable to get pageLink", e); 88 } 89 90 String result = Utilities.removeHTML(entry.getText(), true); 91 result = Utilities.truncateText(result, 240, 260, "..."); 92 94 if (result.length() < entry.getText().length()) 96 { 97 String link = "<div class=\"readMore\"><a HREF=\"" + 98 ctxPath + "/comments/" + 99 entry.getWebsite().getUser().getUserName() + 100 "/" + pageLink + "/" + Utilities.encode(entry.getAnchor()) + 101 "\">Read More</a></div>"; 102 103 result += link; 104 } 105 return result; 106 } 107 108 109 public String getName() { return name; } 110 public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); } 111 } | Popular Tags |