Search in sources :

Example 6 with Attachment

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

the class DefaultRSSGenerator method generateBlogRSS.

/**
 * {@inheritDoc}
 */
@Override
public String generateBlogRSS(final Context wikiContext, final List<Page> changed, final Feed feed) {
    log.debug("Generating RSS for blog, size={}", changed.size());
    final String ctitle = m_engine.getManager(VariableManager.class).getVariable(wikiContext, PROP_CHANNEL_TITLE);
    if (ctitle != null) {
        feed.setChannelTitle(ctitle);
    } else {
        feed.setChannelTitle(m_engine.getApplicationName() + ":" + wikiContext.getPage().getName());
    }
    feed.setFeedURL(wikiContext.getViewURL(wikiContext.getPage().getName()));
    final String language = m_engine.getManager(VariableManager.class).getVariable(wikiContext, PROP_CHANNEL_LANGUAGE);
    if (language != null) {
        feed.setChannelLanguage(language);
    } else {
        feed.setChannelLanguage(m_channelLanguage);
    }
    final String channelDescription = m_engine.getManager(VariableManager.class).getVariable(wikiContext, PROP_CHANNEL_DESCRIPTION);
    if (channelDescription != null) {
        feed.setChannelDescription(channelDescription);
    }
    changed.sort(new PageTimeComparator());
    int items = 0;
    for (final Iterator<Page> i = changed.iterator(); i.hasNext() && items < 15; items++) {
        final Page page = i.next();
        final Entry e = new Entry();
        e.setPage(page);
        final String url;
        if (page instanceof Attachment) {
            url = m_engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), page.getName(), null);
        } else {
            url = m_engine.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), page.getName(), null);
        }
        e.setURL(url);
        // Title
        String pageText = m_engine.getManager(PageManager.class).getPureText(page.getName(), WikiProvider.LATEST_VERSION);
        String title = "";
        final int firstLine = pageText.indexOf('\n');
        if (firstLine > 0) {
            title = pageText.substring(0, firstLine).trim();
        }
        if (title.isEmpty()) {
            title = page.getName();
        }
        // Remove wiki formatting
        while (title.startsWith("!")) {
            title = title.substring(1);
        }
        e.setTitle(title);
        // Description
        if (firstLine > 0) {
            int maxlen = pageText.length();
            if (maxlen > MAX_CHARACTERS) {
                maxlen = MAX_CHARACTERS;
            }
            pageText = m_engine.getManager(RenderingManager.class).textToHTML(wikiContext, pageText.substring(firstLine + 1, maxlen).trim());
            if (maxlen == MAX_CHARACTERS) {
                pageText += "...";
            }
            e.setContent(pageText);
        } else {
            e.setContent(title);
        }
        e.setAuthor(getAuthor(page));
        feed.addEntry(e);
    }
    return feed.getString();
}
Also used : VariableManager(org.apache.wiki.variables.VariableManager) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator)

Example 7 with Attachment

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

the class Image method execute.

/**
 *  {@inheritDoc}
 */
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
    final Engine engine = context.getEngine();
    String src = getCleanParameter(params, PARAM_SRC);
    final String align = getCleanParameter(params, PARAM_ALIGN);
    final String ht = getCleanParameter(params, PARAM_HEIGHT);
    final String wt = getCleanParameter(params, PARAM_WIDTH);
    final String alt = getCleanParameter(params, PARAM_ALT);
    final String caption = getCleanParameter(params, PARAM_CAPTION);
    final String link = getCleanParameter(params, PARAM_LINK);
    String target = getCleanParameter(params, PARAM_TARGET);
    final String style = getCleanParameter(params, PARAM_STYLE);
    final String cssclass = getCleanParameter(params, PARAM_CLASS);
    // String map        = getCleanParameter( params, PARAM_MAP );
    final String border = getCleanParameter(params, PARAM_BORDER);
    final String title = getCleanParameter(params, PARAM_TITLE);
    if (src == null) {
        throw new PluginException("Parameter 'src' is required for Image plugin");
    }
    if (target != null && !validTargetValue(target)) {
        // not a valid value so ignore
        target = null;
    }
    try {
        final AttachmentManager mgr = engine.getManager(AttachmentManager.class);
        final Attachment att = mgr.getAttachmentInfo(context, src);
        if (att != null) {
            src = context.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName());
        }
    } catch (final ProviderException e) {
        throw new PluginException("Attachment info failed: " + e.getMessage());
    }
    final StringBuilder result = new StringBuilder();
    result.append("<table border=\"0\" class=\"imageplugin\"");
    if (title != null) {
        result.append(" title=\"").append(title).append("\"");
    }
    if (align != null) {
        if (align.equals("center")) {
            result.append(" style=\"margin-left: auto; margin-right: auto; text-align:center; vertical-align:middle;\"");
        } else {
            result.append(" style=\"float:").append(align).append(";\"");
        }
    }
    result.append(">\n");
    if (caption != null) {
        result.append("<caption>").append(caption).append("</caption>\n");
    }
    // move css class and style to the container of the image, so it doesn't affect the caption
    result.append("<tr><td");
    if (cssclass != null) {
        result.append(" class=\"").append(cssclass).append("\"");
    }
    if (style != null) {
        result.append(" style=\"").append(style);
        // Make sure that we add a ";" to the end of the style string
        if (result.charAt(result.length() - 1) != ';')
            result.append(";");
        result.append("\"");
    }
    result.append(">");
    if (link != null) {
        result.append("<a href=\"").append(link).append("\"");
        if (target != null) {
            result.append(" target=\"").append(target).append("\"");
        }
        result.append(">");
    }
    result.append("<img src=\"").append(src).append("\"");
    if (ht != null) {
        result.append(" height=\"").append(ht).append("\"");
    }
    if (wt != null) {
        result.append(" width=\"").append(wt).append("\"");
    }
    if (alt != null) {
        result.append(" alt=\"").append(alt).append("\"");
    }
    if (border != null) {
        result.append(" border=\"").append(border).append("\"");
    }
    // if( map != null )    result.append(" map=\""+map+"\"");
    result.append(" />");
    if (link != null) {
        result.append("</a>");
    }
    result.append("</td></tr>\n");
    result.append("</table>\n");
    return result.toString();
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) PluginException(org.apache.wiki.api.exceptions.PluginException) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Engine(org.apache.wiki.api.core.Engine)

Example 8 with Attachment

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

the class RPCHandler method getAllPages.

public Vector<String> getAllPages() {
    checkPermission(PagePermission.VIEW);
    final Collection<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
    final Vector<String> result = new Vector<>();
    for (final Page p : pages) {
        if (!(p instanceof Attachment)) {
            result.add(toRPCString(p.getName()));
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Vector(java.util.Vector)

Example 9 with Attachment

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

the class AttachmentManagerTest method testExistsUTF1.

@Test
public void testExistsUTF1() throws Exception {
    final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test\u00e4.bin");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(att.getName()), "attachment disappeared");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Example 10 with Attachment

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

the class AttachmentManagerTest method testExistsSpace.

@Test
public void testExistsSpace() throws Exception {
    final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test file.bin");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(NAME1 + "/test file.bin"), "attachment disappeared");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (org.apache.wiki.api.core.Attachment)76 Test (org.junit.jupiter.api.Test)37 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)35 Page (org.apache.wiki.api.core.Page)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)20 PageManager (org.apache.wiki.pages.PageManager)19 File (java.io.File)15 Date (java.util.Date)10 Engine (org.apache.wiki.api.core.Engine)10 ReferenceManager (org.apache.wiki.references.ReferenceManager)9 InputStream (java.io.InputStream)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 StringWriter (java.io.StringWriter)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)6 Permission (java.security.Permission)4 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4