001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.plugin;
021:
022: import org.apache.log4j.Logger;
023: import com.ecyrd.jspwiki.*;
024:
025: import java.text.MessageFormat;
026: import java.util.*;
027:
028: /**
029: * Displays the pages referring to the current page.
030: *
031: * Parameters: <BR>
032: * max: How many items to show.<BR>
033: * extras: How to announce extras.<BR>
034: * From AbstractReferralPlugin:<BR>
035: * separator: How to separate generated links; default is a wikitext line break,
036: * producing a vertical list.<BR>
037: * maxwidth: maximum width, in chars, of generated links.
038: *
039: * @author Janne Jalkanen
040: */
041: public class ReferringPagesPlugin extends AbstractReferralPlugin {
042: private static Logger log = Logger
043: .getLogger(ReferringPagesPlugin.class);
044:
045: public static final String PARAM_MAX = "max";
046: public static final String PARAM_EXTRAS = "extras";
047: public static final String PARAM_PAGE = "page";
048:
049: public String execute(WikiContext context, Map params)
050: throws PluginException {
051: ReferenceManager refmgr = context.getEngine()
052: .getReferenceManager();
053: String pageName = (String) params.get(PARAM_PAGE);
054: ResourceBundle rb = context
055: .getBundle(WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
056:
057: if (pageName == null) {
058: pageName = context.getPage().getName();
059: }
060:
061: WikiPage page = context.getEngine().getPage(pageName);
062:
063: if (page != null) {
064: Collection links = refmgr.findReferrers(page.getName());
065: String wikitext = "";
066:
067: super .initialize(context, params);
068:
069: int items = TextUtil.parseIntParameter((String) params
070: .get(PARAM_MAX), ALL_ITEMS);
071: String extras = (String) params.get(PARAM_EXTRAS);
072: if (extras == null) {
073: extras = rb.getString("referringpagesplugin.more");
074: }
075:
076: log.debug("Fetching referring pages for " + page.getName()
077: + " with a max of " + items);
078:
079: if (links != null && links.size() > 0) {
080: links = filterCollection(links);
081: wikitext = wikitizeCollection(links, m_separator, items);
082:
083: if (items < links.size() && items > 0) {
084: Object[] args = {
085: "" + (links.size() - items),
086: context.getURL(WikiContext.INFO, page
087: .getName()) };
088: extras = MessageFormat.format(extras, args);
089: wikitext += extras;
090: }
091: }
092:
093: //
094: // If nothing was left after filtering or during search
095: //
096: if (links == null || links.size() == 0) {
097: wikitext = rb.getString("referringpagesplugin.nobody");
098: }
099:
100: return makeHTML(context, wikitext);
101: }
102:
103: return "";
104: }
105:
106: }
|