01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
19: package org.apache.roller.ui.rendering.plugins;
20:
21: import org.apache.commons.lang.StringEscapeUtils;
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.apache.roller.RollerException;
25: import org.apache.roller.pojos.WeblogEntryData;
26: import org.apache.roller.pojos.WebsiteData;
27: import org.apache.roller.business.WeblogEntryPlugin;
28: import org.apache.roller.util.Utilities;
29:
30: /**
31: * Truncates the string passed in and applies a "Read More" link if the
32: * text is longer than the truncation limit.
33: */
34: public class ReadMorePlugin implements WeblogEntryPlugin {
35:
36: private static Log log = LogFactory.getLog(ReadMorePlugin.class);
37:
38: private String name = "Read More Summary";
39: private String description = "Stops entry after 250 characters and creates "
40: + "a link to the full entry.";
41:
42: public ReadMorePlugin() {
43: log.debug("ReadMorePlugin instantiated.");
44: }
45:
46: public String getName() {
47: return name;
48: }
49:
50: public String getDescription() {
51: return StringEscapeUtils.escapeJavaScript(description);
52: }
53:
54: public void init(WebsiteData website) throws RollerException {
55: // no-op
56: }
57:
58: public String render(WeblogEntryData entry, String str) {
59:
60: String result = Utilities.removeHTML(str, true);
61: result = Utilities.truncateText(result, 240, 260, "...");
62:
63: // if the result is shorter, we need to add "Read More" link
64: if (result.length() < str.length()) {
65: String link = "<div class=\"readMore\"><a href=\""
66: + entry.getPermalink() + "\">Read More</a></div>";
67:
68: result += link;
69: }
70:
71: return result;
72: }
73:
74: }
|