use of org.apache.wiki.api.core.Attachment 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();
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class DefaultRSSGenerator method generateFullWikiRSS.
/**
* {@inheritDoc}
*/
@Override
public String generateFullWikiRSS(final Context wikiContext, final Feed feed) {
feed.setChannelTitle(m_engine.getApplicationName());
feed.setFeedURL(m_engine.getBaseURL());
feed.setChannelLanguage(m_channelLanguage);
feed.setChannelDescription(m_channelDescription);
final Set<Page> changed = m_engine.getManager(PageManager.class).getRecentChanges();
final Session session = Wiki.session().guest(m_engine);
int items = 0;
for (final Iterator<Page> i = changed.iterator(); i.hasNext() && items < 15; items++) {
final Page page = i.next();
// Check if the anonymous user has view access to this page.
if (!m_engine.getManager(AuthorizationManager.class).checkPermission(session, new PagePermission(page, PagePermission.VIEW_ACTION))) {
// No permission, skip to the next one.
continue;
}
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);
}
final Entry e = new Entry();
e.setPage(page);
e.setURL(url);
e.setTitle(page.getName());
e.setContent(getEntryDescription(page));
e.setAuthor(getAuthor(page));
feed.addEntry(e);
}
return feed.getString();
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class DefaultReferenceManager method initialize.
/**
* Initializes the entire reference manager with the initial set of pages from the collection.
*
* @param pages A collection of all pages you want to be included in the reference count.
* @since 2.2
* @throws ProviderException If reading of pages fails.
*/
@Override
public void initialize(final Collection<Page> pages) throws ProviderException {
LOG.debug("Initializing new ReferenceManager with {} initial pages.", pages.size());
final StopWatch sw = new StopWatch();
sw.start();
LOG.info("Starting cross reference scan of WikiPages");
// First, try to serialize old data from disk. If that fails, we'll go and update the entire reference lists (which'll take time)
try {
// Unserialize things. The loop below cannot be combined with the other loop below, simply because
// engine.getPage() has side effects such as loading initializing the user databases, which in turn want all
// the pages to be read already...
//
// Yes, this is a kludge. We know. Will be fixed.
final long saved = unserializeFromDisk();
for (final Page page : pages) {
unserializeAttrsFromDisk(page);
}
// and update the references for them.
for (final Page page : pages) {
if (!(page instanceof Attachment)) {
// Refresh with the latest copy
final Page wp = m_engine.getManager(PageManager.class).getPage(page.getName());
if (wp.getLastModified() == null) {
LOG.fatal("Provider returns null lastModified. Please submit a bug report.");
} else if (wp.getLastModified().getTime() > saved) {
updatePageReferences(wp);
}
}
}
} catch (final Exception e) {
LOG.info("Unable to unserialize old refmgr information, rebuilding database: {}", e.getMessage());
buildKeyLists(pages);
// Scan the existing pages from disk and update references in the manager.
for (final Page page : pages) {
// We cannot build a reference list from the contents of attachments, so we skip them.
if (!(page instanceof Attachment)) {
updatePageReferences(page);
serializeAttrsToDisk(page);
}
}
serializeToDisk();
}
sw.stop();
LOG.info("Cross reference scan done in {}", sw);
WikiEventManager.addWikiEventListener(m_engine.getManager(PageManager.class), this);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class DefaultReferenceManager method updatePageReferences.
/**
* Does a full reference update. Does not sync; assumes that you do it afterwards.
*/
private void updatePageReferences(final Page page) throws ProviderException {
final String content = m_engine.getManager(PageManager.class).getPageText(page.getName(), PageProvider.LATEST_VERSION);
final Collection<String> links = scanWikiLinks(page, content);
final TreeSet<String> res = new TreeSet<>(links);
final List<Attachment> attachments = m_engine.getManager(AttachmentManager.class).listAttachments(page);
for (final Attachment att : attachments) {
res.add(att.getName());
}
internalUpdateReferences(page.getName(), res);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class CachingAttachmentProvider method listAllChanged.
/**
* {@inheritDoc}
*/
@Override
public List<Attachment> listAllChanged(final Date timestamp) throws ProviderException {
final List<Attachment> all;
if (!m_gotall) {
all = m_provider.listAllChanged(timestamp);
// Make sure that all attachments are in the cache.
synchronized (this) {
for (final Attachment att : all) {
cachingManager.put(CachingManager.CACHE_ATTACHMENTS, att.getName(), att);
}
m_gotall = true;
}
} else {
final List<String> keys = cachingManager.keys(CachingManager.CACHE_ATTACHMENTS);
all = new ArrayList<>();
for (final String key : keys) {
final Attachment cachedAttachment = cachingManager.get(CachingManager.CACHE_ATTACHMENTS, key, () -> null);
if (cachedAttachment != null) {
all.add(cachedAttachment);
}
}
}
if (cachingManager.enabled(CachingManager.CACHE_ATTACHMENTS) && all.size() >= cachingManager.info(CachingManager.CACHE_ATTACHMENTS).getMaxElementsAllowed()) {
LOG.warn("seems {} can't hold all attachments from your page repository, " + "so we're delegating on the underlying provider instead. Please consider increasing " + "your cache sizes on the ehcache configuration file to avoid this behaviour", CachingManager.CACHE_ATTACHMENTS);
return m_provider.listAllChanged(timestamp);
}
return all;
}
Aggregations