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 java.util.Map;
023:
024: import javax.servlet.jsp.JspException;
025: import javax.servlet.jsp.tagext.TagSupport;
026: import org.apache.commons.lang.StringUtils;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.roller.business.PluginManager;
031:
032: import org.apache.roller.business.Roller;
033: import org.apache.roller.business.RollerFactory;
034: import org.apache.roller.pojos.WeblogEntryData;
035: import org.apache.roller.ui.core.RollerContext;
036: import org.apache.roller.util.Utilities;
037: import org.apache.struts.util.RequestUtils;
038:
039: /**
040: * Shows entry text with plugins applied.
041: * @jsp.tag name="ShowEntryContent"
042: */
043: public class ShowEntryContentTag extends TagSupport {
044: static final long serialVersionUID = 3166731504235428544L;
045: private static Log mLogger = LogFactory.getFactory().getInstance(
046: ShowEntrySummaryTag.class);
047:
048: private String name = null;
049: private String property = null;
050: private String scope = "request";
051:
052: private boolean stripHtml = false;
053: private int maxLength = -1;
054: private boolean singleEntry = false;
055:
056: /**
057: * @see javax.servlet.jsp.tagext.Tag#doStartTag()
058: */
059: public int doStartTag() throws JspException {
060: Roller roller = RollerFactory.getRoller();
061: WeblogEntryData entry = (WeblogEntryData) RequestUtils.lookup(
062: pageContext, name, property, scope);
063: if (StringUtils.isNotEmpty(entry.getText())) {
064: String xformed = entry.getText();
065: ;
066: try {
067: if (entry.getPlugins() != null) {
068: RollerContext rctx = RollerContext
069: .getRollerContext();
070: try {
071: PluginManager ppmgr = roller
072: .getPagePluginManager();
073: Map plugins = ppmgr.getWeblogEntryPlugins(entry
074: .getWebsite());
075: xformed = ppmgr.applyWeblogEntryPlugins(
076: plugins, entry, entry.getText());
077: } catch (Exception e) {
078: mLogger.error(e);
079: }
080: }
081:
082: if (stripHtml) {
083: // don't escape ampersands
084: xformed = Utilities.escapeHTML(Utilities
085: .removeHTML(xformed), false);
086: }
087:
088: if (maxLength != -1) {
089: xformed = Utilities.truncateNicely(xformed,
090: maxLength, maxLength, "...");
091: }
092:
093: // somehow things (“) are getting double-escaped
094: // but I cannot seem to track it down
095: xformed = StringUtils.replace(xformed, "&#", "&#");
096:
097: pageContext.getOut().println(xformed);
098:
099: } catch (Throwable e) {
100: throw new JspException(
101: "ERROR applying plugin to entry", e);
102: }
103: }
104: return TagSupport.SKIP_BODY;
105: }
106:
107: /**
108: * @return Returns the name.
109: */
110: public String getName() {
111: return name;
112: }
113:
114: /**
115: * @jsp.attribute required="true"
116: */
117: public void setName(String name) {
118: this .name = name;
119: }
120:
121: /**
122: * @return Returns the property.
123: */
124: public String getProperty() {
125: return property;
126: }
127:
128: /**
129: * @jsp.attribute required="false"
130: */
131: public void setProperty(String property) {
132: this .property = property;
133: }
134:
135: /**
136: * @jsp.attribute required="false"
137: */
138: public String getScope() {
139: return scope;
140: }
141:
142: /**
143: * @param scope The scope to set.
144: */
145: public void setScope(String scope) {
146: this.scope = scope;
147: }
148: }
|