Search in sources :

Example 36 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class EditLinkTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    Page page = null;
    String versionString = "";
    final String pageName;
    // Determine the page and the link.
    if (m_pageName == null) {
        page = m_wikiContext.getPage();
        if (page == null) {
            // You can't call this on the page itself anyways.
            return SKIP_BODY;
        }
        pageName = page.getName();
    } else {
        pageName = m_pageName;
    }
    // 
    if (m_version != null) {
        if ("this".equalsIgnoreCase(m_version)) {
            if (page == null) {
                // No page, so go fetch according to page name.
                page = engine.getManager(PageManager.class).getPage(m_pageName);
            }
            if (page != null) {
                versionString = "version=" + page.getVersion();
            }
        } else {
            versionString = "version=" + m_version;
        }
    }
    // 
    // Finally, print out the correct link, according to what user commanded.
    // 
    final JspWriter out = pageContext.getOut();
    switch(m_format) {
        case ANCHOR:
            out.print("<a href=\"" + m_wikiContext.getURL(ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString) + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
            break;
        case URL:
            out.print(m_wikiContext.getURL(ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString));
            break;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : Page(org.apache.wiki.api.core.Page) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine)

Example 37 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class FeedDiscoveryTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    final Page page = m_wikiContext.getPage();
    final String encodedName = engine.encodeName(page.getName());
    final String rssURL = engine.getGlobalRSSURL();
    final String rssFeedURL = engine.getURL(ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp", "page=" + encodedName + "&amp;mode=wiki");
    if (rssURL != null) {
        String siteName = Feed.getSiteName(m_wikiContext);
        siteName = TextUtil.replaceEntities(siteName);
        pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for the entire site.\" href=\"" + rssURL + "\" />\n");
        pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for page " + siteName + ".\" href=\"" + rssFeedURL + "\" />\n");
        // FIXME: This does not work always, as plugins are not initialized until the first fetch
        if ("true".equals(page.getAttribute(WeblogPlugin.ATTR_ISWEBLOG))) {
            final String blogFeedURL = engine.getURL(ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp", "page=" + encodedName);
            final String atomFeedURL = engine.getURL(ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp", "page=" + encodedName + "&amp;type=atom");
            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS feed for weblog " + siteName + ".\" href=\"" + blogFeedURL + "\" />\n");
            pageContext.getOut().print("<link rel=\"service.feed\" type=\"application/atom+xml\" title=\"Atom 1.0 weblog feed for " + siteName + "\" href=\"" + atomFeedURL + "\" />\n");
        }
    }
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page) Engine(org.apache.wiki.api.core.Engine)

Example 38 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class InsertPageTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException, ProviderException {
    final Engine engine = m_wikiContext.getEngine();
    final Page insertedPage;
    if (m_pageName == null) {
        insertedPage = m_wikiContext.getPage();
        if (!engine.getManager(PageManager.class).wikiPageExists(insertedPage))
            return SKIP_BODY;
    } else {
        insertedPage = engine.getManager(PageManager.class).getPage(m_pageName);
    }
    if (insertedPage != null) {
        // FIXME: Do version setting later.
        // page.setVersion( WikiProvider.LATEST_VERSION );
        log.debug("Inserting page " + insertedPage);
        final JspWriter out = pageContext.getOut();
        final Page oldPage = m_wikiContext.setRealPage(insertedPage);
        switch(m_mode) {
            case HTML:
                out.print(engine.getManager(RenderingManager.class).getHTML(m_wikiContext, insertedPage));
                break;
            case PLAIN:
                out.print(engine.getManager(PageManager.class).getText(insertedPage));
                break;
        }
        m_wikiContext.setRealPage(oldPage);
    }
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine)

Example 39 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class LinkToTag method doWikiStartTag.

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

Example 40 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class CalendarTag method getMonthNaviLink.

private String getMonthNaviLink(final Calendar day, final String txt, String queryString) {
    final String result;
    queryString = TextUtil.replaceEntities(queryString);
    final 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)) {
        final Page thePage = m_wikiContext.getPage();
        final String pageName = thePage.getName();
        final String calendarDate = m_dateFormat.format(day.getTime());
        String url = m_wikiContext.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), pageName, "calendar.date=" + calendarDate);
        final int queryStringLlength = queryString.length();
        if (queryStringLlength > 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.
            final 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
                final int pos2 = queryString.indexOf("&", pos1) + 1;
                if ((pos2 > 0) && (pos2 < queryStringLlength)) {
                    tmp = tmp + queryString.substring(pos2);
                }
                queryString = tmp;
            }
            if (queryStringLlength > 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) Page(org.apache.wiki.api.core.Page)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8