001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /* Created on April 14, 2006 */
019: package org.apache.roller.ui.authoring.tags;
020:
021: import java.util.HashMap;
022: import javax.servlet.jsp.JspException;
023: import javax.servlet.jsp.tagext.TagSupport;
024: import java.util.Map;
025: import org.apache.commons.lang.StringUtils;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.apache.struts.util.RequestUtils;
029:
030: import org.apache.roller.business.Roller;
031: import org.apache.roller.business.PluginManager;
032: import org.apache.roller.business.RollerFactory;
033: import org.apache.roller.pojos.WeblogEntryData;
034: import org.apache.roller.ui.core.RollerContext;
035: import org.apache.roller.util.Utilities;
036:
037: /**
038: * Shows either entry summary or text, as appropriate and with plugins applied.
039: * @jsp.tag name="ShowEntryText"
040: */
041: public class ShowEntryTextTag extends TagSupport {
042: static final long serialVersionUID = 3166731504235428544L;
043: private static Log mLogger = LogFactory.getFactory().getInstance(
044: ShowEntrySummaryTag.class);
045:
046: private String name = null;
047: private String property = null;
048: private String scope = "request";
049: private boolean noPlugins = false;
050: private boolean stripHtml = false;
051: private boolean singleEntry = false;
052: private int maxLength = -1;
053:
054: /**
055: * @see javax.servlet.jsp.tagext.Tag#doStartTag()
056: */
057: public int doStartTag() throws JspException {
058: Roller roller = RollerFactory.getRoller();
059: WeblogEntryData entry = (WeblogEntryData) RequestUtils.lookup(
060: pageContext, name, property, scope);
061:
062: String sourceText = null;
063: boolean hasSummary = StringUtils.isNotEmpty(entry.getSummary());
064: boolean hasText = StringUtils.isNotEmpty(entry.getText());
065: if (singleEntry) {
066: if (hasText)
067: sourceText = entry.getText();
068: else if (hasSummary)
069: sourceText = entry.getSummary();
070: } else {
071: if (hasSummary)
072: sourceText = entry.getSummary();
073: else if (hasText)
074: sourceText = entry.getText();
075: }
076: if (StringUtils.isNotEmpty(sourceText)) {
077: try {
078: String xformed = sourceText;
079: if (entry.getPlugins() != null) {
080: RollerContext rctx = RollerContext
081: .getRollerContext();
082: try {
083: PluginManager ppmgr = roller
084: .getPagePluginManager();
085: Map plugins = ppmgr.getWeblogEntryPlugins(entry
086: .getWebsite());
087:
088: xformed = ppmgr.applyWeblogEntryPlugins(
089: plugins, entry, sourceText);
090:
091: } catch (Exception e) {
092: mLogger.error(e);
093: }
094: }
095:
096: if (stripHtml) {
097: // don't escape ampersands
098: xformed = Utilities.escapeHTML(Utilities
099: .removeHTML(xformed), false);
100: }
101:
102: if (maxLength != -1) {
103: xformed = Utilities.truncateNicely(xformed,
104: maxLength, maxLength, "...");
105: }
106:
107: // somehow things (“) are getting double-escaped
108: // but I cannot seem to track it down
109: xformed = StringUtils.replace(xformed, "&#", "&#");
110:
111: pageContext.getOut().println(xformed);
112:
113: } catch (Throwable e) {
114: throw new JspException(
115: "ERROR applying plugin to entry", e);
116: }
117: }
118: return TagSupport.SKIP_BODY;
119: }
120:
121: /**
122: * Maximum length of text displayed, only applies if stripHtml is true.
123: * @jsp.attribute required="false"
124: * @return Returns the maxLength.
125: */
126: public int getMaxLength() {
127: return maxLength;
128: }
129:
130: /**
131: * Maximum length of text displayed, only applies if stripHtml is true.
132: * @param maxLength The maxLength to set.
133: */
134: public void setMaxLength(int maxLength) {
135: this .maxLength = maxLength;
136: }
137:
138: /**
139: * Set to true to prevent application of plugins.
140: * @jsp.attribute required="false"
141: * @return Returns the noPlugins.
142: */
143: public boolean getNoPlugins() {
144: return noPlugins;
145: }
146:
147: /**
148: * Set to true to prevent application of plugins.
149: * @param stripHtml The stripHtml to set.
150: */
151: public void setNoPlugins(boolean noPlugins) {
152: this .noPlugins = noPlugins;
153: }
154:
155: /**
156: * Set to true to strip all HTML markup from output.
157: * @jsp.attribute required="false"
158: * @return Returns the noPlugins.
159: */
160: public boolean getStripHtml() {
161: return stripHtml;
162: }
163:
164: /**
165: * Set to true to strip all HTML markup from output.
166: * @param stripHtml The stripHtml to set.
167: */
168: public void setStripHtml(boolean stripHtml) {
169: this .stripHtml = stripHtml;
170: }
171:
172: /**
173: * Set to true to inform PagePlugins of single entry page.
174: * @jsp.attribute required="false"
175: */
176: public boolean getSingleEntry() {
177: return singleEntry;
178: }
179:
180: /**
181: * Set to true to inform PagePlugins of single entry page.
182: * should "skip" themselves.
183: */
184: public void setSingleEntry(boolean singleEntry) {
185: this .singleEntry = singleEntry;
186: }
187:
188: /**
189: * @return Returns the name.
190: */
191: public String getName() {
192: return name;
193: }
194:
195: /**
196: * @jsp.attribute required="true"
197: */
198: public void setName(String name) {
199: this .name = name;
200: }
201:
202: /**
203: * @return Returns the property.
204: */
205: public String getProperty() {
206: return property;
207: }
208:
209: /**
210: * @jsp.attribute required="false"
211: */
212: public void setProperty(String property) {
213: this .property = property;
214: }
215:
216: /**
217: * @jsp.attribute required="false"
218: */
219: public String getScope() {
220: return scope;
221: }
222:
223: /**
224: * @param scope The scope to set.
225: */
226: public void setScope(String scope) {
227: this.scope = scope;
228: }
229: }
|