Search in sources :

Example 31 with WikiPage

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

the class EditLinkTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = null;
    String versionString = "";
    String pageName = null;
    // 
    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.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.
    // 
    JspWriter out = pageContext.getOut();
    switch(m_format) {
        case ANCHOR:
            out.print("<a href=\"" + m_wikiContext.getURL(WikiContext.EDIT, pageName, versionString) + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
            break;
        case URL:
            out.print(m_wikiContext.getURL(WikiContext.EDIT, pageName, versionString));
            break;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : WikiPage(org.apache.wiki.WikiPage) JspWriter(javax.servlet.jsp.JspWriter) WikiEngine(org.apache.wiki.WikiEngine)

Example 32 with WikiPage

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

the class FeedDiscoveryTag method doWikiStartTag.

public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page = m_wikiContext.getPage();
    String encodedName = engine.encodeName(page.getName());
    String rssURL = engine.getGlobalRSSURL();
    String rssFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp", "page=" + encodedName + "&amp;mode=wiki", true);
    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))) {
            String blogFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp", "page=" + encodedName, true);
            String atomFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp", "page=" + encodedName + "&amp;type=atom", true);
            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 : WikiPage(org.apache.wiki.WikiPage) WikiEngine(org.apache.wiki.WikiEngine)

Example 33 with WikiPage

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

the class HistoryIteratorTag method doStartTag.

public final int doStartTag() {
    m_wikiContext = (WikiContext) pageContext.getAttribute(WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
    WikiEngine engine = m_wikiContext.getEngine();
    WikiPage page;
    page = m_wikiContext.getPage();
    try {
        if (page != null && engine.pageExists(page)) {
            Collection versions = engine.getVersionHistory(page.getName());
            if (versions == null) {
                // There is no history
                return SKIP_BODY;
            }
            m_iterator = versions.iterator();
            if (m_iterator.hasNext()) {
                WikiContext context = (WikiContext) m_wikiContext.clone();
                context.setPage((WikiPage) m_iterator.next());
                pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
                pageContext.setAttribute(getId(), context.getPage());
            } else {
                return SKIP_BODY;
            }
        }
        return EVAL_BODY_BUFFERED;
    } catch (ProviderException e) {
        log.fatal("Provider failed while trying to iterator through history", e);
    // FIXME: THrow something.
    }
    return SKIP_BODY;
}
Also used : WikiContext(org.apache.wiki.WikiContext) ProviderException(org.apache.wiki.api.exceptions.ProviderException) WikiPage(org.apache.wiki.WikiPage) Collection(java.util.Collection) WikiEngine(org.apache.wiki.WikiEngine)

Example 34 with WikiPage

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

the class InsertPageTag method doWikiStartTag.

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

Example 35 with WikiPage

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

the class IteratorTag method buildContext.

/**
 *  Arg, I hate globals.
 */
private void buildContext() {
    // 
    // Build a clone of the current context
    // 
    WikiContext context = (WikiContext) m_wikiContext.clone();
    Object o = m_iterator.next();
    if (o instanceof WikiPage)
        context.setPage((WikiPage) o);
    // 
    // Push it to the iterator stack, and set the id.
    // 
    pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
    pageContext.setAttribute(getId(), o);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage)

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