use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class AttachmentsIteratorTag method doStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doStartTag() {
m_wikiContext = (Context) pageContext.getAttribute(Context.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
final Engine engine = m_wikiContext.getEngine();
final AttachmentManager mgr = engine.getManager(AttachmentManager.class);
final Page page;
page = m_wikiContext.getPage();
if (!mgr.attachmentsEnabled()) {
return SKIP_BODY;
}
try {
if (page != null && engine.getManager(PageManager.class).wikiPageExists(page)) {
final List<Attachment> atts = mgr.listAttachments(page);
if (atts == null) {
log.debug("No attachments to display.");
// There are no attachments included
return SKIP_BODY;
}
m_iterator = atts.iterator();
if (m_iterator.hasNext()) {
final Attachment att = (Attachment) m_iterator.next();
final Context context = m_wikiContext.clone();
context.setPage(att);
pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), att);
} else {
return SKIP_BODY;
}
} else {
return SKIP_BODY;
}
return EVAL_BODY_BUFFERED;
} catch (final ProviderException e) {
log.fatal("Provider failed while trying to iterator through history", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class CalendarTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final JspWriter out = pageContext.getOut();
final Calendar cal = Calendar.getInstance();
final Calendar prevCal = Calendar.getInstance();
final Calendar nextCal = Calendar.getInstance();
//
// Check if there is a parameter in the request to set the date.
//
String calendarDate = pageContext.getRequest().getParameter("calendar.date");
if (calendarDate == null) {
calendarDate = pageContext.getRequest().getParameter("weblog.startDate");
}
if (calendarDate != null) {
try {
final Date d = m_dateFormat.parse(calendarDate);
cal.setTime(d);
prevCal.setTime(d);
nextCal.setTime(d);
} catch (final ParseException e) {
log.warn("date format wrong: " + calendarDate);
}
}
// First, set to first day of month
cal.set(Calendar.DATE, 1);
prevCal.set(Calendar.DATE, 1);
nextCal.set(Calendar.DATE, 1);
// Now move to first day of previous month
prevCal.add(Calendar.MONTH, -1);
// Now move to first day of next month
nextCal.add(Calendar.MONTH, 1);
out.write("<table class=\"calendar\">\n");
final HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
final String queryString = HttpUtil.safeGetQueryString(httpServletRequest, engine.getContentEncoding());
out.write("<tr>" + getMonthNaviLink(prevCal, "<<", queryString) + "<td colspan=5 class=\"month\">" + getMonthLink(cal) + "</td>" + getMonthNaviLink(nextCal, ">>", queryString) + "</tr>\n");
final int month = cal.get(Calendar.MONTH);
// Then, find the first day of the week.
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
out.write("<tr><td class=\"weekdays\">Mon</td>" + "<td class=\"weekdays\">Tue</td>" + "<td class=\"weekdays\">Wed</td>" + "<td class=\"weekdays\">Thu</td>" + "<td class=\"weekdays\">Fri</td>" + "<td class=\"weekdays\">Sat</td>" + "<td class=\"weekdays\">Sun</td></tr>\n");
boolean noMoreDates = false;
while (!noMoreDates) {
out.write("<tr>");
for (int i = 0; i < 7; i++) {
final int mth = cal.get(Calendar.MONTH);
if (mth != month) {
out.write("<td class=\"othermonth\">" + cal.get(Calendar.DATE) + "</td>");
} else {
out.write(getDayLink(cal));
}
cal.add(Calendar.DATE, 1);
}
if (cal.get(Calendar.MONTH) != month) {
noMoreDates = true;
}
out.write("</tr>\n");
}
out.write("</table>\n");
return EVAL_BODY_INCLUDE;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class CalendarTag method getDayLink.
/**
* Returns a link to the given day.
*/
private String getDayLink(final Calendar day) {
final Engine engine = m_wikiContext.getEngine();
final String result;
if (m_pageFormat != null) {
final String pagename = m_pageFormat.format(day.getTime());
if (engine.getManager(PageManager.class).wikiPageExists(pagename)) {
if (m_urlFormat != null) {
final String url = m_urlFormat.format(day.getTime());
result = "<td class=\"link\"><a href=\"" + url + "\">" + day.get(Calendar.DATE) + "</a></td>";
} else {
result = "<td class=\"link\"><a href=\"" + m_wikiContext.getViewURL(pagename) + "\">" + day.get(Calendar.DATE) + "</a></td>";
}
} else {
result = "<td class=\"days\">" + day.get(Calendar.DATE) + "</td>";
}
} else if (m_urlFormat != null) {
final String url = m_urlFormat.format(day.getTime());
result = "<td><a href=\"" + url + "\">" + day.get(Calendar.DATE) + "</a></td>";
} else {
result = "<td class=\"days\">" + day.get(Calendar.DATE) + "</td>";
}
return format(result);
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class CheckVersionTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null && engine.getManager(PageManager.class).wikiPageExists(page.getName())) {
final int version = page.getVersion();
final boolean include;
final Page latest = engine.getManager(PageManager.class).getPage(page.getName());
switch(m_mode) {
case LATEST:
include = (version < 0) || (latest.getVersion() == version);
break;
case NOTLATEST:
include = (version > 0) && (latest.getVersion() != version);
break;
case FIRST:
include = (version == 1) || (version < 0 && latest.getVersion() == 1);
break;
case NOTFIRST:
include = version > 1;
break;
default:
throw new InternalWikiException("Mode which is not available!");
}
if (include) {
return EVAL_BODY_INCLUDE;
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class EditorIteratorTag method doStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doStartTag() {
m_wikiContext = Context.findContext(pageContext);
final Engine engine = m_wikiContext.getEngine();
final EditorManager mgr = engine.getManager(EditorManager.class);
final String[] editorList = mgr.getEditorList();
final Collection<Editor> editors = new ArrayList<>();
for (final String editor : editorList) {
editors.add(new Editor(m_wikiContext, editor));
}
setList(editors);
return super.doStartTag();
}
Aggregations