Search in sources :

Example 51 with Engine

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;
}
Also used : Context(org.apache.wiki.api.core.Context) PageContext(javax.servlet.jsp.PageContext) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Engine(org.apache.wiki.api.core.Engine)

Example 52 with Engine

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, "&lt;&lt;", queryString) + "<td colspan=5 class=\"month\">" + getMonthLink(cal) + "</td>" + getMonthNaviLink(nextCal, "&gt;&gt;", 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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Calendar(java.util.Calendar) ParseException(java.text.ParseException) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine) Date(java.util.Date)

Example 53 with Engine

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);
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Engine(org.apache.wiki.api.core.Engine)

Example 54 with Engine

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;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Engine(org.apache.wiki.api.core.Engine) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 55 with Engine

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();
}
Also used : ArrayList(java.util.ArrayList) Editor(org.apache.wiki.ui.Editor) EditorManager(org.apache.wiki.ui.EditorManager) Engine(org.apache.wiki.api.core.Engine)

Aggregations

Engine (org.apache.wiki.api.core.Engine)60 Page (org.apache.wiki.api.core.Page)30 PageManager (org.apache.wiki.pages.PageManager)20 ProviderException (org.apache.wiki.api.exceptions.ProviderException)11 Attachment (org.apache.wiki.api.core.Attachment)10 JspWriter (javax.servlet.jsp.JspWriter)9 Context (org.apache.wiki.api.core.Context)9 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 ResourceBundle (java.util.ResourceBundle)6 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 PageContext (javax.servlet.jsp.PageContext)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 PluginException (org.apache.wiki.api.exceptions.PluginException)4 RenderingManager (org.apache.wiki.render.RenderingManager)4 ArrayList (java.util.ArrayList)3