use of org.apache.wiki.ReferenceManager in project jspwiki by apache.
the class ReferringUndefinedPagesPlugin method execute.
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
ReferenceManager referenceManager = context.getEngine().getReferenceManager();
int items = TextUtil.parseIntParameter(params.get(PARAM_MAX), ALL_ITEMS);
String extras = params.get(PARAM_EXTRAS);
if (extras == null) {
extras = rb.getString("referringundefinedpagesplugin.more");
}
StringBuilder resultHTML = new StringBuilder();
Collection<String> uncreatedPages = referenceManager.findUncreated();
super.initialize(context, params);
Collection<String> result = null;
TreeMap sortedMap = new TreeMap();
if (uncreatedPages != null) {
for (String uncreatedPageName : uncreatedPages) {
Collection<String> referrers = referenceManager.findReferrers(uncreatedPageName);
if (referrers != null) {
for (String referringPage : referrers) {
sortedMap.put(referringPage, "");
}
}
}
result = sortedMap.keySet();
}
result = super.filterAndSortCollection(result);
String wikitext = wikitizeCollection(result, m_separator, items);
resultHTML.append(makeHTML(context, wikitext));
// add the more.... text
if (items < result.size() && items > 0) {
Object[] args = { "" + (result.size() - items) };
extras = MessageFormat.format(extras, args);
resultHTML.append("<br/>" + extras + "<br/>");
}
return resultHTML.toString();
}
use of org.apache.wiki.ReferenceManager in project jspwiki by apache.
the class UnusedPagesPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
ReferenceManager refmgr = context.getEngine().getReferenceManager();
Collection<String> links = refmgr.findUnreferenced();
//
// filter out attachments if "excludeattachments" was requested:
//
String prop = params.get(PARAM_EXCLUDEATTS);
if (TextUtil.isPositive(prop)) {
// remove links to attachments (recognizable by a slash in it)
Iterator<String> iterator = links.iterator();
while (iterator.hasNext()) {
String link = iterator.next();
if (link.indexOf("/") != -1) {
iterator.remove();
}
}
}
super.initialize(context, params);
links = filterAndSortCollection(links);
String wikitext = null;
if (m_show.equals(PARAM_SHOW_VALUE_COUNT)) {
wikitext = "" + links.size();
if (m_lastModified && links.size() != 0) {
wikitext = links.size() + " (" + m_dateFormat.format(m_dateLastModified) + ")";
}
} else {
wikitext = wikitizeCollection(links, m_separator, ALL_ITEMS);
}
return makeHTML(context, wikitext);
}
use of org.apache.wiki.ReferenceManager in project jspwiki by apache.
the class ReferredPagesPlugin method getReferredPages.
/**
* Retrieves a list of all referred pages. Is called recursively
* depending on the depth parameter
*/
@SuppressWarnings("unchecked")
private void getReferredPages(WikiContext context, String pagename, int depth) {
// end of recursion
if (depth >= m_depth)
return;
if (pagename == null)
return;
if (!m_engine.pageExists(pagename))
return;
ReferenceManager mgr = m_engine.getReferenceManager();
Collection<String> allPages = mgr.findRefersTo(pagename);
handleLinks(context, allPages, ++depth, pagename);
}
use of org.apache.wiki.ReferenceManager in project jspwiki by apache.
the class ReferringPagesPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
ReferenceManager refmgr = context.getEngine().getReferenceManager();
String pageName = params.get(PARAM_PAGE);
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
StringBuilder result = new StringBuilder(256);
if (pageName == null) {
pageName = context.getPage().getName();
}
WikiPage page = context.getEngine().getPage(pageName);
if (page != null) {
Collection links = refmgr.findReferrers(page.getName());
String wikitext = "";
super.initialize(context, params);
int items = TextUtil.parseIntParameter(params.get(PARAM_MAX), ALL_ITEMS);
String extras = params.get(PARAM_EXTRAS);
if (extras == null) {
extras = rb.getString("referringpagesplugin.more");
}
if (log.isDebugEnabled())
log.debug("Fetching referring pages for " + page.getName() + " with a max of " + items);
if (links != null && links.size() > 0) {
links = filterAndSortCollection(links);
wikitext = wikitizeCollection(links, m_separator, items);
result.append(makeHTML(context, wikitext));
if (items < links.size() && items > 0) {
Object[] args = { "" + (links.size() - items) };
extras = MessageFormat.format(extras, args);
result.append("<br />");
result.append("<a class='morelink' href='" + context.getURL(WikiContext.INFO, page.getName()) + "' ");
result.append(">" + extras + "</a><br />");
}
}
//
if (links == null || links.size() == 0) {
wikitext = rb.getString("referringpagesplugin.nobody");
result.append(makeHTML(context, wikitext));
} else {
if (m_show.equals(PARAM_SHOW_VALUE_COUNT)) {
result = new StringBuilder();
result.append(links.size());
if (m_lastModified) {
result.append(" (" + m_dateFormat.format(m_dateLastModified) + ")");
}
}
}
return result.toString();
}
return "";
}
use of org.apache.wiki.ReferenceManager in project jspwiki by apache.
the class UndefinedPagesPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
ReferenceManager refmgr = context.getEngine().getReferenceManager();
Collection links = refmgr.findUncreated();
super.initialize(context, params);
links = filterAndSortCollection(links);
String wikitext = null;
if (m_lastModified) {
throw new PluginException("parameter " + PARAM_LASTMODIFIED + " is not valid for the UndefinedPagesPlugin");
}
if (m_show.equals(PARAM_SHOW_VALUE_COUNT)) {
wikitext = "" + links.size();
} else {
wikitext = wikitizeCollection(links, m_separator, ALL_ITEMS);
}
return makeHTML(context, wikitext);
}
Aggregations