Search in sources :

Example 1 with PageTimeComparator

use of org.apache.wiki.pages.PageTimeComparator in project jspwiki by apache.

the class BasicAttachmentProvider method listAllChanged.

/**
 *  {@inheritDoc}
 */
// FIXME: Very unoptimized.
@Override
public List<Attachment> listAllChanged(final Date timestamp) throws ProviderException {
    final File attDir = new File(m_storageDir);
    if (!attDir.exists()) {
        throw new ProviderException("Specified attachment directory " + m_storageDir + " does not exist!");
    }
    final ArrayList<Attachment> list = new ArrayList<>();
    final String[] pagesWithAttachments = attDir.list(new AttachmentFilter());
    if (pagesWithAttachments != null) {
        for (final String pagesWithAttachment : pagesWithAttachments) {
            String pageId = unmangleName(pagesWithAttachment);
            pageId = pageId.substring(0, pageId.length() - DIR_EXTENSION.length());
            final Collection<Attachment> c = listAttachments(Wiki.contents().page(m_engine, pageId));
            for (final Attachment att : c) {
                if (att.getLastModified().after(timestamp)) {
                    list.add(att);
                }
            }
        }
    }
    list.sort(new PageTimeComparator());
    return list;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) ArrayList(java.util.ArrayList) Attachment(org.apache.wiki.api.core.Attachment) File(java.io.File) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator)

Example 2 with PageTimeComparator

use of org.apache.wiki.pages.PageTimeComparator 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 3 with PageTimeComparator

use of org.apache.wiki.pages.PageTimeComparator in project jspwiki by apache.

the class MetaWeblogHandler method getRecentPosts.

/**
 *  Returns a list of the recent posts to this weblog.
 *
 *  @param blogid The id of the blog.
 *  @param username The username to use
 *  @param password The password
 *  @param numberOfPosts How many posts to find
 *  @throws XmlRpcException If something goes wrong
 *  @return As per MetaweblogAPI specification
 */
// FIXME: The implementation is suboptimal, as it goes through all of the blog entries.
public Hashtable getRecentPosts(final String blogid, final String username, final String password, final int numberOfPosts) throws XmlRpcException {
    final Hashtable<String, Hashtable<String, Object>> result = new Hashtable<>();
    log.info("metaWeblog.getRecentPosts() called");
    final Page page = m_context.getEngine().getManager(PageManager.class).getPage(blogid);
    checkPermissions(page, username, password, "view");
    final WeblogPlugin plugin = new WeblogPlugin();
    final List<Page> changed = plugin.findBlogEntries(m_context.getEngine(), blogid, new Date(0L), new Date());
    changed.sort(new PageTimeComparator());
    int items = 0;
    for (final Iterator<Page> i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++) {
        final Page p = i.next();
        result.put("entry", makeEntry(p));
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) WeblogPlugin(org.apache.wiki.plugin.WeblogPlugin) Hashtable(java.util.Hashtable) Page(org.apache.wiki.api.core.Page) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator) Date(java.util.Date)

Example 4 with PageTimeComparator

use of org.apache.wiki.pages.PageTimeComparator in project jspwiki by apache.

the class TwoXWikiAttachmentProvider method listAllChanged.

/**
 * {@inheritDoc}
 */
@Override
public List<Attachment> listAllChanged(final Date timestamp) throws ProviderException {
    final List<Attachment> attachs = attachments.values().stream().map(attrs -> attrs.get(attrs.size() - 1)).filter(att -> att.getLastModified() != null && att.getLastModified().after(timestamp)).collect(Collectors.toList());
    attachs.sort(new PageTimeComparator());
    return attachs;
}
Also used : Arrays(java.util.Arrays) Properties(java.util.Properties) Date(java.util.Date) Collection(java.util.Collection) WikiAttachmentProvider(org.apache.wiki.providers.WikiAttachmentProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WikiPage(org.apache.wiki.WikiPage) IOException(java.io.IOException) WikiEngine(org.apache.wiki.WikiEngine) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) List(java.util.List) Attachment(org.apache.wiki.attachment.Attachment) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) QueryItem(org.apache.wiki.search.QueryItem) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator) Collections(java.util.Collections) WikiProvider(org.apache.wiki.WikiProvider) InputStream(java.io.InputStream) Attachment(org.apache.wiki.attachment.Attachment) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator)

Example 5 with PageTimeComparator

use of org.apache.wiki.pages.PageTimeComparator in project jspwiki by apache.

the class DefaultRSSGenerator method generateWikiPageRSS.

/**
 * {@inheritDoc}
 */
@Override
public String generateWikiPageRSS(final Context wikiContext, final List<Page> changed, final Feed feed) {
    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);
        String url;
        if (page instanceof Attachment) {
            url = m_engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), page.getName(), "version=" + page.getVersion());
        } else {
            url = m_engine.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), page.getName(), "version=" + page.getVersion());
        }
        // Unfortunately, this is needed because the code will again go through replacement conversion
        url = TextUtil.replaceString(url, "&amp;", "&");
        e.setURL(url);
        e.setTitle(getEntryTitle(page));
        e.setContent(getEntryDescription(page));
        e.setAuthor(getAuthor(page));
        feed.addEntry(e);
    }
    return feed.getString();
}
Also used : VariableManager(org.apache.wiki.variables.VariableManager) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) PageTimeComparator(org.apache.wiki.pages.PageTimeComparator)

Aggregations

PageTimeComparator (org.apache.wiki.pages.PageTimeComparator)5 Attachment (org.apache.wiki.api.core.Attachment)3 Page (org.apache.wiki.api.core.Page)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ProviderException (org.apache.wiki.api.exceptions.ProviderException)2 PageManager (org.apache.wiki.pages.PageManager)2 VariableManager (org.apache.wiki.variables.VariableManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1