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;
}
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();
}
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;
}
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;
}
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, "&", "&");
e.setURL(url);
e.setTitle(getEntryTitle(page));
e.setContent(getEntryDescription(page));
e.setAuthor(getAuthor(page));
feed.addEntry(e);
}
return feed.getString();
}
Aggregations