KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Map JavaDoc;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
26 import org.apache.commons.lang.StringUtils;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.roller.model.PluginManager;
31
32 import org.apache.roller.model.Roller;
33 import org.apache.roller.model.RollerFactory;
34 import org.apache.roller.pojos.WeblogEntryData;
35 import org.apache.roller.ui.core.RollerContext;
36 import org.apache.roller.util.Utilities;
37 import org.apache.struts.util.RequestUtils;
38
39 /**
40  * Shows entry text with plugins applied.
41  * @jsp.tag name="ShowEntryContent"
42  */

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

59     public int doStartTag() throws JspException JavaDoc {
60         Roller roller = RollerFactory.getRoller();
61         WeblogEntryData entry = (WeblogEntryData)
62             RequestUtils.lookup(pageContext, name, property, scope);
63         if (StringUtils.isNotEmpty(entry.getText())) {
64             String JavaDoc xformed = entry.getText();;
65             try {
66                 if (entry.getPlugins() != null) {
67                     RollerContext rctx =
68                         RollerContext.getRollerContext();
69                     try {
70                         PluginManager ppmgr = roller.getPagePluginManager();
71                         Map JavaDoc plugins = ppmgr.getWeblogEntryPlugins(
72                             entry.getWebsite());
73                         xformed = ppmgr.applyWeblogEntryPlugins(
74                             plugins, entry, entry.getText());
75                     } catch (Exception JavaDoc e) {
76                         mLogger.error(e);
77                     }
78                 }
79
80                 if (stripHtml) {
81                     // don't escape ampersands
82
xformed = Utilities.escapeHTML( Utilities.removeHTML(xformed), false );
83                 }
84
85                 if (maxLength != -1) {
86                     xformed = Utilities.truncateNicely(xformed, maxLength, maxLength, "...");
87                 }
88
89                 // somehow things (&#8220) are getting double-escaped
90
// but I cannot seem to track it down
91
xformed = StringUtils.replace(xformed, "&amp#", "&#");
92
93                 pageContext.getOut().println(xformed);
94
95             } catch (Throwable JavaDoc e) {
96                 throw new JspException JavaDoc("ERROR applying plugin to entry", e);
97             }
98         }
99         return TagSupport.SKIP_BODY;
100     }
101     
102     /**
103      * @return Returns the name.
104      */

105     public String JavaDoc getName() {
106         return name;
107     }
108     
109     /**
110      * @jsp.attribute required="true"
111      */

112     public void setName(String JavaDoc name) {
113         this.name = name;
114     }
115     
116     /**
117      * @return Returns the property.
118      */

119     public String JavaDoc getProperty() {
120         return property;
121     }
122     /**
123      * @jsp.attribute required="false"
124      */

125     public void setProperty(String JavaDoc property) {
126         this.property = property;
127     }
128     
129     /**
130      * @jsp.attribute required="false"
131      */

132     public String JavaDoc getScope() {
133         return scope;
134     }
135     /**
136      * @param scope The scope to set.
137      */

138     public void setScope(String JavaDoc scope) {
139         this.scope = scope;
140     }
141 }
142
Popular Tags