use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class WeblogEntryPlugin method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
final Engine engine = context.getEngine();
String weblogName = params.get(PARAM_BLOGNAME);
if (weblogName == null) {
weblogName = context.getPage().getName();
}
String entryText = TextUtil.replaceEntities(params.get(PARAM_ENTRYTEXT));
if (entryText == null) {
entryText = rb.getString("weblogentryplugin.newentry");
}
final String url = context.getURL(ContextEnum.PAGE_NONE.getRequestContext(), "NewBlogEntry.jsp", "page=" + engine.encodeName(weblogName));
return "<a href=\"" + url + "\">" + entryText + "</a>";
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class WeblogPlugin method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
final Calendar startTime;
final Calendar stopTime;
int numDays = DEFAULT_DAYS;
final Engine engine = context.getEngine();
final AuthorizationManager mgr = engine.getManager(AuthorizationManager.class);
//
// Parse parameters.
//
String days;
final DateFormat entryFormat;
String startDay;
boolean hasComments = false;
int maxEntries;
String weblogName;
if ((weblogName = params.get(PARAM_PAGE)) == null) {
weblogName = context.getPage().getName();
}
if ((days = context.getHttpParameter("weblog." + PARAM_DAYS)) == null) {
days = params.get(PARAM_DAYS);
}
if ((params.get(PARAM_ENTRYFORMAT)) == null) {
entryFormat = Preferences.getDateFormat(context, TimeFormat.DATETIME);
} else {
entryFormat = new SimpleDateFormat(params.get(PARAM_ENTRYFORMAT));
}
if (days != null) {
if (days.equalsIgnoreCase("all")) {
numDays = Integer.MAX_VALUE;
} else {
numDays = TextUtil.parseIntParameter(days, DEFAULT_DAYS);
}
}
if ((startDay = params.get(PARAM_STARTDATE)) == null) {
startDay = context.getHttpParameter("weblog." + PARAM_STARTDATE);
}
if (TextUtil.isPositive(params.get(PARAM_ALLOWCOMMENTS))) {
hasComments = true;
}
maxEntries = TextUtil.parseIntParameter(params.get(PARAM_MAXENTRIES), Integer.MAX_VALUE);
//
// Determine the date range which to include.
//
startTime = Calendar.getInstance();
stopTime = Calendar.getInstance();
if (startDay != null) {
final SimpleDateFormat fmt = new SimpleDateFormat(DEFAULT_DATEFORMAT);
try {
final Date d = fmt.parse(startDay);
startTime.setTime(d);
stopTime.setTime(d);
} catch (final ParseException e) {
return "Illegal time format: " + startDay;
}
}
//
// Mark this to be a weblog
//
context.getPage().setAttribute(ATTR_ISWEBLOG, "true");
//
// We make a wild guess here that nobody can do millisecond accuracy here.
//
startTime.add(Calendar.DAY_OF_MONTH, -numDays);
startTime.set(Calendar.HOUR, 0);
startTime.set(Calendar.MINUTE, 0);
startTime.set(Calendar.SECOND, 0);
stopTime.set(Calendar.HOUR, 23);
stopTime.set(Calendar.MINUTE, 59);
stopTime.set(Calendar.SECOND, 59);
final StringBuilder sb = new StringBuilder();
final List<Page> blogEntries = findBlogEntries(engine, weblogName, startTime.getTime(), stopTime.getTime());
blogEntries.sort(new PageDateComparator());
sb.append("<div class=\"weblog\">\n");
for (final Iterator<Page> i = blogEntries.iterator(); i.hasNext() && maxEntries-- > 0; ) {
final Page p = i.next();
if (mgr.checkPermission(context.getWikiSession(), new PagePermission(p, PagePermission.VIEW_ACTION))) {
addEntryHTML(context, entryFormat, hasComments, sb, p, params);
}
}
sb.append("</div>\n");
return sb.toString();
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class RecentChangesPlugin method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
final int since = TextUtil.parseIntParameter(params.get("since"), DEFAULT_DAYS);
String spacing = "4";
boolean showAuthor = true;
boolean showChangenote = true;
String tablewidth = "4";
final Engine engine = context.getEngine();
//
if ("compact".equals(params.get(PARAM_FORMAT))) {
spacing = "0";
showAuthor = false;
showChangenote = false;
tablewidth = "2";
}
final Calendar sincedate = new GregorianCalendar();
sincedate.add(Calendar.DAY_OF_MONTH, -since);
log.debug("Calculating recent changes from " + sincedate.getTime());
// FIXME: Should really have a since date on the getRecentChanges method.
Collection<Page> changes = engine.getManager(PageManager.class).getRecentChanges();
super.initialize(context, params);
changes = filterWikiPageCollection(changes);
if (changes != null) {
Date olddate = new Date(0);
final DateFormat fmt = getDateFormat(context, params);
final DateFormat tfmt = getTimeFormat(context, params);
final Element rt = XhtmlUtil.element(XHTML.table);
rt.setAttribute(XHTML.ATTR_class, "recentchanges");
rt.setAttribute(XHTML.ATTR_cellpadding, spacing);
for (final Page pageref : changes) {
final Date lastmod = pageref.getLastModified();
if (lastmod.before(sincedate.getTime())) {
break;
}
if (!isSameDay(lastmod, olddate)) {
final Element row = XhtmlUtil.element(XHTML.tr);
final Element col = XhtmlUtil.element(XHTML.td);
col.setAttribute(XHTML.ATTR_colspan, tablewidth);
col.setAttribute(XHTML.ATTR_class, "date");
col.addContent(XhtmlUtil.element(XHTML.b, fmt.format(lastmod)));
rt.addContent(row);
row.addContent(col);
olddate = lastmod;
}
final String href = context.getURL(pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName());
Element link = XhtmlUtil.link(href, engine.getManager(RenderingManager.class).beautifyTitle(pageref.getName()));
final Element row = XhtmlUtil.element(XHTML.tr);
final Element col = XhtmlUtil.element(XHTML.td);
col.setAttribute(XHTML.ATTR_width, "30%");
col.addContent(link);
//
if (pageref instanceof Attachment) {
link = XhtmlUtil.link(context.getURL(WikiContext.INFO, pageref.getName()), null);
link.setAttribute(XHTML.ATTR_class, "infolink");
final Element img = XhtmlUtil.img(context.getURL(WikiContext.NONE, "images/attachment_small.png"), null);
link.addContent(img);
col.addContent(link);
}
row.addContent(col);
rt.addContent(row);
if (pageref instanceof Attachment) {
final Element td = XhtmlUtil.element(XHTML.td, tfmt.format(lastmod));
td.setAttribute(XHTML.ATTR_class, "lastchange");
row.addContent(td);
} else {
final Element infocol = XhtmlUtil.element(XHTML.td);
infocol.setAttribute(XHTML.ATTR_class, "lastchange");
infocol.addContent(XhtmlUtil.link(context.getURL(WikiContext.DIFF, pageref.getName(), "r1=-1"), tfmt.format(lastmod)));
row.addContent(infocol);
}
//
if (showAuthor) {
final String author = pageref.getAuthor();
final Element authorinfo = XhtmlUtil.element(XHTML.td);
authorinfo.setAttribute(XHTML.ATTR_class, "author");
if (author != null) {
if (engine.getManager(PageManager.class).wikiPageExists(author)) {
authorinfo.addContent(XhtmlUtil.link(context.getURL(WikiContext.VIEW, author), author));
} else {
authorinfo.addContent(author);
}
} else {
authorinfo.addContent(Preferences.getBundle(context, InternationalizationManager.CORE_BUNDLE).getString("common.unknownauthor"));
}
row.addContent(authorinfo);
}
// Change note
if (showChangenote) {
final String changenote = pageref.getAttribute(Page.CHANGENOTE);
final Element td_changenote = XhtmlUtil.element(XHTML.td, changenote);
td_changenote.setAttribute(XHTML.ATTR_class, "changenote");
row.addContent(td_changenote);
}
// Revert note
/*
if( context.hasAdminPermissions() )
{
row.addElement( new td("Revert") );
}
*/
}
return XhtmlUtil.serialize(rt, XhtmlUtil.EXPAND_EMPTY_NODES);
}
return "";
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class AtomFeed method getItems.
private Collection<Element> getItems() {
final ArrayList<Element> list = new ArrayList<>();
final Engine engine = m_wikiContext.getEngine();
ServletContext servletContext = null;
if (m_wikiContext.getHttpRequest() != null) {
servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
}
for (final Entry e : m_entries) {
final Page p = e.getPage();
final Element entryEl = getElement("entry");
// Mandatory elements
entryEl.addContent(getElement("id").setText(getEntryID(e)));
entryEl.addContent(getElement("title").setAttribute("type", "html").setText(e.getTitle()));
entryEl.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(p.getLastModified(), RFC3339FORMAT)));
// Optional elements
entryEl.addContent(getElement("author").addContent(getElement("name").setText(e.getAuthor())));
entryEl.addContent(getElement("link").setAttribute("rel", "alternate").setAttribute("href", e.getURL()));
entryEl.addContent(getElement("content").setAttribute("type", "html").setText(e.getContent()));
// Check for enclosures
if (engine.getManager(AttachmentManager.class).hasAttachments(p) && servletContext != null) {
try {
final List<Attachment> c = engine.getManager(AttachmentManager.class).listAttachments(p);
for (final Attachment att : c) {
final Element attEl = getElement("link");
attEl.setAttribute("rel", "enclosure");
attEl.setAttribute("href", engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName(), null));
attEl.setAttribute("length", Long.toString(att.getSize()));
attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
entryEl.addContent(attEl);
}
} catch (final ProviderException ex) {
// FIXME: log.info("Can't get attachment data",ex);
}
}
list.add(entryEl);
}
return list;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class Feed method getSiteName.
/**
* Figure out a site name for a feed.
*
* @param context the wiki context
* @return the site name
*/
public static String getSiteName(final Context context) {
final Engine engine = context.getEngine();
String blogname = null;
try {
blogname = engine.getManager(VariableManager.class).getValue(context, VAR_BLOGNAME);
} catch (final NoSuchVariableException e) {
}
if (blogname == null) {
blogname = engine.getApplicationName() + ": " + context.getPage().getName();
}
return blogname;
}
Aggregations