Search in sources :

Example 36 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class CalendarTag method getMonthNaviLink.

private String getMonthNaviLink(Calendar day, String txt, String queryString) {
    String result = "";
    queryString = TextUtil.replaceEntities(queryString);
    Calendar nextMonth = Calendar.getInstance();
    nextMonth.set(Calendar.DATE, 1);
    nextMonth.add(Calendar.DATE, -1);
    // Now move to 1st day of next month
    nextMonth.add(Calendar.MONTH, 1);
    if (day.before(nextMonth)) {
        WikiPage thePage = m_wikiContext.getPage();
        String pageName = thePage.getName();
        String calendarDate = m_dateFormat.format(day.getTime());
        String url = m_wikiContext.getURL(WikiContext.VIEW, pageName, "calendar.date=" + calendarDate);
        if ((queryString != null) && (queryString.length() > 0)) {
            // 
            // Ensure that the 'calendar.date=ddMMyy' has been removed
            // from the queryString
            // 
            // FIXME: Might be useful to have an entire library of
            // routines for this.  Will fail if it's not calendar.date
            // but something else.
            int pos1 = queryString.indexOf("calendar.date=");
            if (pos1 >= 0) {
                String tmp = queryString.substring(0, pos1);
                // FIXME: Will this fail when we use & instead of &amp?
                // FIXME: should use some parsing routine
                int pos2 = queryString.indexOf("&", pos1) + 1;
                if ((pos2 > 0) && (pos2 < queryString.length())) {
                    tmp = tmp + queryString.substring(pos2);
                }
                queryString = tmp;
            }
            if (queryString != null && queryString.length() > 0) {
                url = url + "&amp;" + queryString;
            }
        }
        result = "<td><a href=\"" + url + "\">" + txt + "</a></td>";
    } else {
        result = "<td> </td>";
    }
    return format(result);
}
Also used : Calendar(java.util.Calendar) WikiPage(org.apache.wiki.WikiPage)

Example 37 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class CheckLockTag method doWikiStartTag.

/**
 *  {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();
    if (page != null) {
        PageManager mgr = engine.getPageManager();
        PageLock lock = mgr.getCurrentLock(page);
        HttpSession session = pageContext.getSession();
        PageLock userLock = (PageLock) session.getAttribute("lock-" + page.getName());
        if ((lock != null && m_mode == LockState.LOCKED && lock != userLock) || (lock != null && m_mode == LockState.OWNED && lock == userLock) || (lock == null && m_mode == LockState.NOTLOCKED)) {
            String tid = getId();
            if (tid != null && lock != null) {
                pageContext.setAttribute(tid, lock);
            }
            return EVAL_BODY_INCLUDE;
        }
    }
    return SKIP_BODY;
}
Also used : PageManager(org.apache.wiki.PageManager) HttpSession(javax.servlet.http.HttpSession) WikiPage(org.apache.wiki.WikiPage) PageLock(org.apache.wiki.PageLock) WikiEngine(org.apache.wiki.WikiEngine)

Example 38 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class LinkToTag method doWikiStartTag.

public int doWikiStartTag() throws IOException {
    String pageName = m_pageName;
    boolean isattachment = false;
    if (m_pageName == null) {
        WikiPage p = m_wikiContext.getPage();
        if (p != null) {
            pageName = p.getName();
            isattachment = p instanceof Attachment;
        } else {
            return SKIP_BODY;
        }
    }
    JspWriter out = pageContext.getOut();
    String url;
    String linkclass;
    if (isattachment) {
        url = m_wikiContext.getURL(WikiContext.ATTACH, pageName, (getVersion() != null) ? "version=" + getVersion() : null);
        linkclass = "attachment";
    } else {
        StringBuilder params = new StringBuilder();
        if (getVersion() != null)
            params.append("version=" + getVersion());
        if (getTemplate() != null)
            params.append((params.length() > 0 ? "&amp;" : "") + "skin=" + getTemplate());
        url = m_wikiContext.getURL(WikiContext.VIEW, pageName, params.toString());
        linkclass = "wikipage";
    }
    switch(m_format) {
        case ANCHOR:
            out.print("<a class=\"" + linkclass + "\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
            break;
        case URL:
            out.print(url);
            break;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) JspWriter(javax.servlet.jsp.JspWriter)

Example 39 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class NextVersionTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiPage page = m_wikiContext.getPage();
    int version = page.getVersion();
    if (version == -1)
        version = -1;
    else
        version++;
    pageContext.getOut().print(version);
    return SKIP_BODY;
}
Also used : WikiPage(org.apache.wiki.WikiPage)

Example 40 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class NoSuchPageTag method doWikiStartTag.

public int doWikiStartTag() throws IOException, ProviderException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page;
    if (m_pageName == null) {
        page = m_wikiContext.getPage();
    } else {
        page = engine.getPage(m_pageName);
    }
    if (page != null && engine.pageExists(page.getName(), page.getVersion())) {
        return SKIP_BODY;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : WikiPage(org.apache.wiki.WikiPage) WikiEngine(org.apache.wiki.WikiEngine)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7