1 4 package org.roller.presentation.weblog.tags; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.apache.struts.util.RequestUtils; 9 import org.roller.pojos.WeblogEntryData; 10 import org.roller.presentation.velocity.PageHelper; 11 import org.roller.util.Utilities; 12 13 import java.io.IOException ; 14 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 import javax.servlet.jsp.JspException ; 18 import javax.servlet.jsp.tagext.TagSupport ; 19 20 25 public class ApplyPluginsTag extends TagSupport 26 { 27 static final long serialVersionUID = 3166731504235428544L; 28 29 private static final String HELPER_KEY = "roller.pageHelper"; 30 private static Log mLogger = 31 LogFactory.getFactory().getInstance(ApplyPluginsTag.class); 32 33 private String name = null; 34 private String property = null; 35 private String scope = "request"; 36 37 private boolean stripHtml = false; 38 private int maxLength = -1; 39 private boolean skipFlag = false; 40 41 44 public int doStartTag() throws JspException 45 { 46 WeblogEntryData entry = 47 (WeblogEntryData)RequestUtils.lookup(pageContext, name, property, scope); 48 49 String xformed = null; 50 51 if (entry.getPlugins() != null) 52 { 53 PageHelper helper = (PageHelper)pageContext.getRequest().getAttribute(HELPER_KEY); 55 if (helper == null) 56 { 57 helper = loadNewPageHelper(); 58 } 59 helper.setSkipFlag(skipFlag); 60 61 xformed = helper.renderPlugins(entry); 62 } 63 else 64 { 65 xformed = entry.getText(); 66 } 67 68 if (stripHtml) 69 { 70 xformed = Utilities.escapeHTML( Utilities.removeHTML(xformed), false ); 72 } 73 74 if (maxLength != -1) 75 { 76 xformed = Utilities.truncateNicely(xformed, maxLength, maxLength, "..."); 77 } 78 79 xformed = Utilities.stringReplace(xformed, "&#", "&#"); 82 83 try 84 { 85 pageContext.getOut().println(xformed); 86 } 87 catch (IOException e) 88 { 89 throw new JspException ("ERROR applying plugin to entry", e); 90 } 91 return TagSupport.SKIP_BODY; 92 } 93 94 99 private PageHelper loadNewPageHelper() 100 { 101 PageHelper pageHelper = PageHelper.createPageHelper( 102 (HttpServletRequest )pageContext.getRequest(), 103 (HttpServletResponse )pageContext.getResponse()); 104 105 pageContext.getRequest().setAttribute(HELPER_KEY, pageHelper); 106 return pageHelper; 107 } 108 109 114 public int getMaxLength() 115 { 116 return maxLength; 117 } 118 119 123 public void setMaxLength(int maxLength) 124 { 125 this.maxLength = maxLength; 126 } 127 128 133 public boolean getStripHtml() 134 { 135 return stripHtml; 136 } 137 138 142 public void setStripHtml(boolean stripHtml) 143 { 144 this.stripHtml = stripHtml; 145 } 146 147 154 public boolean getSkipFlag() 155 { 156 return skipFlag; 157 } 158 159 164 public void setSkipFlag(boolean skipFlag) 165 { 166 this.skipFlag = skipFlag; 167 } 168 169 172 public String getName() { 173 return name; 174 } 175 176 179 public void setName(String name) { 180 this.name = name; 181 } 182 183 186 public String getProperty() { 187 return property; 188 } 189 192 public void setProperty(String property) { 193 this.property = property; 194 } 195 196 199 public String getScope() { 200 return scope; 201 } 202 205 public void setScope(String scope) { 206 this.scope = scope; 207 } 208 } 209 | Popular Tags |