1 18 19 package org.apache.roller.ui.authoring.tags; 20 21 import java.util.HashMap ; 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 import java.util.Map ; 25 import org.apache.commons.lang.StringUtils; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.struts.util.RequestUtils; 29 30 import org.apache.roller.model.Roller; 31 import org.apache.roller.model.PluginManager; 32 import org.apache.roller.model.RollerFactory; 33 import org.apache.roller.pojos.WeblogEntryData; 34 import org.apache.roller.ui.core.RollerContext; 35 import org.apache.roller.util.Utilities; 36 37 41 public class ShowEntryTextTag extends TagSupport { 42 static final long serialVersionUID = 3166731504235428544L; 43 private static Log mLogger = 44 LogFactory.getFactory().getInstance(ShowEntrySummaryTag.class); 45 46 private String name = null; 47 private String property = null; 48 private String scope = "request"; 49 private boolean noPlugins = false; 50 private boolean stripHtml = false; 51 private boolean singleEntry = false; 52 private int maxLength = -1; 53 54 57 public int doStartTag() throws JspException { 58 Roller roller = RollerFactory.getRoller(); 59 WeblogEntryData entry = (WeblogEntryData) 60 RequestUtils.lookup(pageContext, name, property, scope); 61 62 String sourceText = null; 63 boolean hasSummary = StringUtils.isNotEmpty(entry.getSummary()); 64 boolean hasText= StringUtils.isNotEmpty(entry.getText()); 65 if (singleEntry) { 66 if (hasText) sourceText = entry.getText(); 67 else if (hasSummary) sourceText = entry.getSummary(); 68 } else { 69 if (hasSummary) sourceText = entry.getSummary(); 70 else if (hasText) sourceText = entry.getText(); 71 } 72 if (StringUtils.isNotEmpty(sourceText)) { 73 try { 74 String xformed = sourceText; 75 if (entry.getPlugins() != null) { 76 RollerContext rctx = 77 RollerContext.getRollerContext(); 78 try { 79 PluginManager ppmgr = roller.getPagePluginManager(); 80 Map plugins = ppmgr.getWeblogEntryPlugins( 81 entry.getWebsite()); 82 83 xformed = ppmgr.applyWeblogEntryPlugins(plugins, entry, sourceText); 84 85 } catch (Exception e) { 86 mLogger.error(e); 87 } 88 } 89 90 if (stripHtml) { 91 xformed = Utilities.escapeHTML( Utilities.removeHTML(xformed), false ); 93 } 94 95 if (maxLength != -1) { 96 xformed = Utilities.truncateNicely(xformed, maxLength, maxLength, "..."); 97 } 98 99 xformed = StringUtils.replace(xformed, "&#", "&#"); 102 103 pageContext.getOut().println(xformed); 104 105 } catch (Throwable e) { 106 throw new JspException ("ERROR applying plugin to entry", e); 107 } 108 } 109 return TagSupport.SKIP_BODY; 110 } 111 112 117 public int getMaxLength() { 118 return maxLength; 119 } 120 121 125 public void setMaxLength(int maxLength) { 126 this.maxLength = maxLength; 127 } 128 129 134 public boolean getNoPlugins() { 135 return noPlugins; 136 } 137 138 142 public void setNoPlugins(boolean noPlugins) { 143 this.noPlugins = noPlugins; 144 } 145 146 151 public boolean getStripHtml() { 152 return stripHtml; 153 } 154 155 159 public void setStripHtml(boolean stripHtml) { 160 this.stripHtml = stripHtml; 161 } 162 163 167 public boolean getSingleEntry() { 168 return singleEntry; 169 } 170 171 175 public void setSingleEntry(boolean singleEntry) { 176 this.singleEntry = singleEntry; 177 } 178 179 182 public String getName() { 183 return name; 184 } 185 186 189 public void setName(String name) { 190 this.name = name; 191 } 192 193 196 public String getProperty() { 197 return property; 198 } 199 202 public void setProperty(String property) { 203 this.property = property; 204 } 205 206 209 public String getScope() { 210 return scope; 211 } 212 215 public void setScope(String scope) { 216 this.scope = scope; 217 } 218 } 219 | Popular Tags |