use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class PingWeblogsComFilter method postSave.
/**
* {@inheritDoc}
*/
public void postSave(WikiContext context, String pagecontent) {
String blogName = context.getPage().getName();
WikiEngine engine = context.getEngine();
int blogentryTxt = blogName.indexOf("_blogentry_");
if (blogentryTxt == -1) {
// This is not a weblog entry.
return;
}
blogName = blogName.substring(0, blogentryTxt);
if (blogName.equals(engine.getFrontPage())) {
blogName = null;
}
try {
XmlRpcClient xmlrpc = new XmlRpcClient(m_pingURL);
Vector<String> params = new Vector<String>();
// FIXME: Must be settable
params.addElement("The Butt Ugly Weblog");
params.addElement(engine.getURL(WikiContext.VIEW, blogName, null, true));
if (log.isDebugEnabled())
log.debug("Pinging weblogs.com with URL: " + engine.getURL(WikiContext.VIEW, blogName, null, true));
xmlrpc.executeAsync("weblogUpdates.ping", params, new AsyncCallback() {
public void handleError(Exception ex, URL url, String method) {
log.error("Unable to execute weblogs.com ping to URL: " + url.toString(), ex);
}
public void handleResult(Object result, URL url, String method) {
Hashtable res = (Hashtable) result;
Boolean flerror = (Boolean) res.get("flerror");
String msg = (String) res.get("message");
if (flerror.booleanValue()) {
log.error("Failed to ping: " + msg);
}
log.info("Weblogs.com has been pinged.");
}
});
} catch (MalformedURLException e) {
log.error("Malformed URL", e);
}
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class Search method renderResults.
private String renderResults(Collection<SearchResult> results, WikiContext context, int maxItems) {
WikiEngine engine = context.getEngine();
Element table = XhtmlUtil.element(XHTML.table);
// table.setAttribute(XHTML.ATTR_border,"0");
// table.setAttribute(XHTML.ATTR_cellpadding,"4");
table.setAttribute(XHTML.ATTR_class, "wikitable search-result");
Element row = XhtmlUtil.element(XHTML.tr);
table.addContent(row);
Element th1 = XhtmlUtil.element(XHTML.th, "Page");
th1.setAttribute(XHTML.ATTR_width, "30%");
th1.setAttribute(XHTML.ATTR_align, "left");
row.addContent(th1);
Element th2 = XhtmlUtil.element(XHTML.th, "Score");
th2.setAttribute(XHTML.ATTR_align, "left");
row.addContent(th2);
int idx = 0;
for (Iterator<SearchResult> i = results.iterator(); i.hasNext() && idx++ <= maxItems; ) {
SearchResult sr = i.next();
row = XhtmlUtil.element(XHTML.tr);
Element name = XhtmlUtil.element(XHTML.td);
name.setAttribute(XHTML.ATTR_width, "30%");
name.addContent(XhtmlUtil.link(context.getURL(WikiContext.VIEW, sr.getPage().getName()), engine.beautifyTitle(sr.getPage().getName())));
row.addContent(name);
row.addContent(XhtmlUtil.element(XHTML.td, "" + sr.getScore()));
table.addContent(row);
}
if (results.isEmpty()) {
row = XhtmlUtil.element(XHTML.tr);
Element td = XhtmlUtil.element(XHTML.td);
td.setAttribute(XHTML.ATTR_colspan, "2");
Element b = XhtmlUtil.element(XHTML.b, "No results");
td.addContent(b);
row.addContent(td);
table.addContent(row);
}
return XhtmlUtil.serialize(table);
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class TableOfContents method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
WikiEngine engine = context.getEngine();
WikiPage page = context.getPage();
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
if (context.getVariable(VAR_ALREADY_PROCESSING) != null) {
// return rb.getString("tableofcontents.title");
return "<a href=\"#section-TOC\" class=\"toc\">" + rb.getString("tableofcontents.title") + "</a>";
}
StringBuilder sb = new StringBuilder();
sb.append("<div class=\"toc\">\n");
sb.append("<div class=\"collapsebox\">\n");
String title = params.get(PARAM_TITLE);
sb.append("<h4 id=\"section-TOC\">");
if (title != null) {
// sb.append("<h4>"+TextUtil.replaceEntities(title)+"</h4>\n");
sb.append(TextUtil.replaceEntities(title));
} else {
// sb.append("<h4>"+rb.getString("tableofcontents.title")+"</h4>\n");
sb.append(rb.getString("tableofcontents.title"));
}
sb.append("</h4>\n");
// should we use an ordered list?
m_usingNumberedList = false;
if (params.containsKey(PARAM_NUMBERED)) {
String numbered = params.get(PARAM_NUMBERED);
if (numbered.equalsIgnoreCase("true")) {
m_usingNumberedList = true;
} else if (numbered.equalsIgnoreCase("yes")) {
m_usingNumberedList = true;
}
}
// if we are using a numbered list, get the rest of the parameters (if any) ...
if (m_usingNumberedList) {
int start = 0;
String startStr = params.get(PARAM_START);
if ((startStr != null) && (startStr.matches("^\\d+$"))) {
start = Integer.parseInt(startStr);
}
if (start < 0)
start = 0;
m_starting = start;
m_level1Index = start - 1;
if (m_level1Index < 0)
m_level1Index = 0;
m_level2Index = 0;
m_level3Index = 0;
m_prefix = params.get(PARAM_PREFIX);
if (m_prefix == null)
m_prefix = "";
m_lastLevel = Heading.HEADING_LARGE;
}
try {
String wikiText = engine.getPureText(page);
boolean runFilters = "true".equals(engine.getVariableManager().getValue(context, WikiEngine.PROP_RUNFILTERS, "true"));
if (runFilters) {
try {
FilterManager fm = engine.getFilterManager();
wikiText = fm.doPreTranslateFiltering(context, wikiText);
} catch (Exception e) {
log.error("Could not construct table of contents: Filter Error", e);
throw new PluginException("Unable to construct table of contents (see logs)");
}
}
context.setVariable(VAR_ALREADY_PROCESSING, "x");
MarkupParser parser = engine.getRenderingManager().getParser(context, wikiText);
parser.addHeadingListener(this);
parser.parse();
sb.append("<ul>\n" + m_buf.toString() + "</ul>\n");
} catch (IOException e) {
log.error("Could not construct table of contents", e);
throw new PluginException("Unable to construct table of contents (see logs)");
}
sb.append("</div>\n</div>\n");
return sb.toString();
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class WeblogArchivePlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
WikiEngine engine = context.getEngine();
//
// Parameters
//
String weblogName = params.get(PARAM_PAGE);
if (weblogName == null)
weblogName = context.getPage().getName();
m_monthUrlFormat = new SimpleDateFormat("'" + context.getURL(WikiContext.VIEW, weblogName, "weblog.startDate='ddMMyy'&weblog.days=%d") + "'");
StringBuilder sb = new StringBuilder();
sb.append("<div class=\"weblogarchive\">\n");
try {
Collection<Calendar> months = collectMonths(engine, weblogName);
int year = 0;
//
// Output proper HTML.
//
sb.append("<ul>\n");
if (months.size() > 0) {
year = (months.iterator().next()).get(Calendar.YEAR);
sb.append("<li class=\"archiveyear\">" + year + "</li>\n");
}
for (Iterator<Calendar> i = months.iterator(); i.hasNext(); ) {
Calendar cal = i.next();
if (cal.get(Calendar.YEAR) != year) {
year = cal.get(Calendar.YEAR);
sb.append("<li class=\"archiveyear\">" + year + "</li>\n");
}
sb.append(" <li>");
sb.append(getMonthLink(cal));
sb.append("</li>\n");
}
sb.append("</ul>\n");
} catch (ProviderException ex) {
log.info("Cannot get archive", ex);
sb.append("Cannot get archive: " + ex.getMessage());
}
sb.append("</div>\n");
return sb.toString();
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class Note method imageUrl.
private String imageUrl(WikiContext ctx) {
WikiEngine engine = ctx.getEngine();
String commentImage = engine.getWikiProperties().getProperty(PROP_NOTE_IMAGE, DEFAULT_NOTE_IMAGE);
commentImage = "images/" + commentImage;
String resource = engine.getTemplateManager().findResource(ctx, engine.getTemplateDir(), commentImage);
// JSPWIKI-876 Fixed error with Note Plugin. Only one preceding "/" is needed.
if (resource != null && resource.startsWith("/")) {
resource = resource.substring(1);
}
return ctx.getURL(WikiContext.NONE, resource);
}
Aggregations