Search in sources :

Example 11 with WikiEngine

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

the class AtomFeed method getItems.

private Collection getItems() {
    ArrayList<Element> list = new ArrayList<Element>();
    WikiEngine engine = m_wikiContext.getEngine();
    ServletContext servletContext = null;
    if (m_wikiContext.getHttpRequest() != null)
        servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
    for (Iterator i = m_entries.iterator(); i.hasNext(); ) {
        Entry e = (Entry) i.next();
        WikiPage p = e.getPage();
        Element entryEl = getElement("entry");
        // 
        // Mandatory elements
        // 
        entryEl.addContent(getElement("id").setText(getEntryID(e)));
        entryEl.addContent(getElement("title").setAttribute("type", "html").setText(e.getTitle()));
        entryEl.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(p.getLastModified(), RFC3339FORMAT)));
        // 
        // Optional elements
        // 
        entryEl.addContent(getElement("author").addContent(getElement("name").setText(e.getAuthor())));
        entryEl.addContent(getElement("link").setAttribute("rel", "alternate").setAttribute("href", e.getURL()));
        entryEl.addContent(getElement("content").setAttribute("type", "html").setText(e.getContent()));
        if (engine.getAttachmentManager().hasAttachments(p) && servletContext != null) {
            try {
                Collection c = engine.getAttachmentManager().listAttachments(p);
                for (Iterator a = c.iterator(); a.hasNext(); ) {
                    Attachment att = (Attachment) a.next();
                    Element attEl = getElement("link");
                    attEl.setAttribute("rel", "enclosure");
                    attEl.setAttribute("href", engine.getURL(WikiContext.ATTACH, att.getName(), null, true));
                    attEl.setAttribute("length", Long.toString(att.getSize()));
                    attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
                    entryEl.addContent(attEl);
                }
            } catch (ProviderException ex) {
            // FIXME: log.info("Can't get attachment data",ex);
            }
        }
        list.add(entryEl);
    }
    return list;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) Element(org.jdom2.Element) WikiPage(org.apache.wiki.WikiPage) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ServletContext(javax.servlet.ServletContext) Collection(java.util.Collection) Attachment(org.apache.wiki.attachment.Attachment) WikiEngine(org.apache.wiki.WikiEngine)

Example 12 with WikiEngine

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

the class ContentEncodingTag method doWikiStartTag.

/**
 *  {@inheritDoc}
 */
public final int doWikiStartTag() throws IOException {
    WikiEngine engine = m_wikiContext.getEngine();
    pageContext.getOut().print(engine.getContentEncoding());
    return SKIP_BODY;
}
Also used : WikiEngine(org.apache.wiki.WikiEngine)

Example 13 with WikiEngine

use of org.apache.wiki.WikiEngine 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 14 with WikiEngine

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

the class EditorTag method doEndTag.

public int doEndTag() throws JspException {
    WikiEngine engine = m_wikiContext.getEngine();
    EditorManager mgr = engine.getEditorManager();
    String editorPath = mgr.getEditorPath(m_wikiContext);
    try {
        String page = engine.getTemplateManager().findJSP(pageContext, m_wikiContext.getTemplate(), editorPath);
        if (page == null) {
            // FIXME: should be I18N ...
            pageContext.getOut().println("Unable to find editor '" + editorPath + "'");
        } else {
            pageContext.include(page);
        }
    } catch (ServletException e) {
        log.error("Failed to include editor", e);
        throw new JspException("Failed to include editor: " + e.getMessage());
    } catch (IOException e) {
        throw new JspException("Could not print Editor tag: " + e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) WikiEngine(org.apache.wiki.WikiEngine) EditorManager(org.apache.wiki.ui.EditorManager)

Example 15 with WikiEngine

use of org.apache.wiki.WikiEngine 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)

Aggregations

WikiEngine (org.apache.wiki.WikiEngine)67 WikiPage (org.apache.wiki.WikiPage)29 ProviderException (org.apache.wiki.api.exceptions.ProviderException)15 Attachment (org.apache.wiki.attachment.Attachment)10 WikiContext (org.apache.wiki.WikiContext)9 Properties (java.util.Properties)8 JspWriter (javax.servlet.jsp.JspWriter)8 TestEngine (org.apache.wiki.TestEngine)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Calendar (java.util.Calendar)5 Date (java.util.Date)5 ResourceBundle (java.util.ResourceBundle)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 Before (org.junit.Before)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 InternalWikiException (org.apache.wiki.InternalWikiException)4 ArrayList (java.util.ArrayList)3