KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > authoring > tags > ShowEntryTextTag


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /* Created on April 14, 2006 */
19 package org.apache.roller.ui.authoring.tags;
20
21 import java.util.HashMap JavaDoc;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
24 import java.util.Map JavaDoc;
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 /**
38  * Shows either entry summary or text, as appropriate and with plugins applied.
39  * @jsp.tag name="ShowEntryText"
40  */

41 public class ShowEntryTextTag extends TagSupport JavaDoc {
42     static final long serialVersionUID = 3166731504235428544L;
43     private static Log mLogger =
44             LogFactory.getFactory().getInstance(ShowEntrySummaryTag.class);
45     
46     private String JavaDoc name = null;
47     private String JavaDoc property = null;
48     private String JavaDoc scope = "request";
49     private boolean noPlugins = false;
50     private boolean stripHtml = false;
51     private boolean singleEntry = false;
52     private int maxLength = -1;
53     
54     /**
55      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
56      */

57     public int doStartTag() throws JspException JavaDoc {
58         Roller roller = RollerFactory.getRoller();
59         WeblogEntryData entry = (WeblogEntryData)
60             RequestUtils.lookup(pageContext, name, property, scope);
61         
62         String JavaDoc 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 JavaDoc xformed = sourceText;
75                 if (entry.getPlugins() != null) {
76                     RollerContext rctx =
77                         RollerContext.getRollerContext();
78                     try {
79                         PluginManager ppmgr = roller.getPagePluginManager();
80                         Map JavaDoc plugins = ppmgr.getWeblogEntryPlugins(
81                                 entry.getWebsite());
82
83                         xformed = ppmgr.applyWeblogEntryPlugins(plugins, entry, sourceText);
84
85                     } catch (Exception JavaDoc e) {
86                         mLogger.error(e);
87                     }
88                 }
89
90                 if (stripHtml) {
91                     // don't escape ampersands
92
xformed = Utilities.escapeHTML( Utilities.removeHTML(xformed), false );
93                 }
94
95                 if (maxLength != -1) {
96                     xformed = Utilities.truncateNicely(xformed, maxLength, maxLength, "...");
97                 }
98
99                 // somehow things (&#8220) are getting double-escaped
100
// but I cannot seem to track it down
101
xformed = StringUtils.replace(xformed, "&amp#", "&#");
102
103                 pageContext.getOut().println(xformed);
104                 
105             } catch (Throwable JavaDoc e) {
106                 throw new JspException JavaDoc("ERROR applying plugin to entry", e);
107             }
108         }
109         return TagSupport.SKIP_BODY;
110     }
111     
112     /**
113      * Maximum length of text displayed, only applies if stripHtml is true.
114      * @jsp.attribute required="false"
115      * @return Returns the maxLength.
116      */

117     public int getMaxLength() {
118         return maxLength;
119     }
120     
121     /**
122      * Maximum length of text displayed, only applies if stripHtml is true.
123      * @param maxLength The maxLength to set.
124      */

125     public void setMaxLength(int maxLength) {
126         this.maxLength = maxLength;
127     }
128     
129     /**
130      * Set to true to prevent application of plugins.
131      * @jsp.attribute required="false"
132      * @return Returns the noPlugins.
133      */

134     public boolean getNoPlugins() {
135         return noPlugins;
136     }
137     
138     /**
139      * Set to true to prevent application of plugins.
140      * @param stripHtml The stripHtml to set.
141      */

142     public void setNoPlugins(boolean noPlugins) {
143         this.noPlugins = noPlugins;
144     }
145     
146     /**
147      * Set to true to strip all HTML markup from output.
148      * @jsp.attribute required="false"
149      * @return Returns the noPlugins.
150      */

151     public boolean getStripHtml() {
152         return stripHtml;
153     }
154     
155     /**
156      * Set to true to strip all HTML markup from output.
157      * @param stripHtml The stripHtml to set.
158      */

159     public void setStripHtml(boolean stripHtml) {
160         this.stripHtml = stripHtml;
161     }
162     
163     /**
164      * Set to true to inform PagePlugins of single entry page.
165      * @jsp.attribute required="false"
166      */

167     public boolean getSingleEntry() {
168         return singleEntry;
169     }
170     
171     /**
172      * Set to true to inform PagePlugins of single entry page.
173      * should "skip" themselves.
174      */

175     public void setSingleEntry(boolean singleEntry) {
176         this.singleEntry = singleEntry;
177     }
178     
179     /**
180      * @return Returns the name.
181      */

182     public String JavaDoc getName() {
183         return name;
184     }
185     
186     /**
187      * @jsp.attribute required="true"
188      */

189     public void setName(String JavaDoc name) {
190         this.name = name;
191     }
192     
193     /**
194      * @return Returns the property.
195      */

196     public String JavaDoc getProperty() {
197         return property;
198     }
199     /**
200      * @jsp.attribute required="false"
201      */

202     public void setProperty(String JavaDoc property) {
203         this.property = property;
204     }
205     
206     /**
207      * @jsp.attribute required="false"
208      */

209     public String JavaDoc getScope() {
210         return scope;
211     }
212     /**
213      * @param scope The scope to set.
214      */

215     public void setScope(String JavaDoc scope) {
216         this.scope = scope;
217     }
218 }
219
Popular Tags