use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicSearchProvider method attachmentNames.
private String attachmentNames(final Page page) {
if (m_engine.getManager(AttachmentManager.class).hasAttachments(page)) {
final List<Attachment> attachments;
try {
attachments = m_engine.getManager(AttachmentManager.class).listAttachments(page);
} catch (final ProviderException e) {
log.error("Unable to get attachments for page", e);
return "";
}
final StringBuilder attachmentNames = new StringBuilder();
for (final Iterator<Attachment> it = attachments.iterator(); it.hasNext(); ) {
final Attachment att = it.next();
attachmentNames.append(att.getName());
if (it.hasNext()) {
attachmentNames.append(" ");
}
}
return attachmentNames.toString();
}
return "";
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class LuceneSearchProvider method doFullLuceneReindex.
/**
* Performs a full Lucene reindex, if necessary.
*
* @throws IOException If there's a problem during indexing
*/
protected void doFullLuceneReindex() throws IOException {
final File dir = new File(m_luceneDirectory);
final String[] filelist = dir.list();
if (filelist == null) {
throw new IOException("Invalid Lucene directory: cannot produce listing: " + dir.getAbsolutePath());
}
try {
if (filelist.length == 0) {
//
// No files? Reindex!
//
final Date start = new Date();
log.info("Starting Lucene reindexing, this can take a couple of minutes...");
final Directory luceneDir = new NIOFSDirectory(dir.toPath());
try (final IndexWriter writer = getIndexWriter(luceneDir)) {
final Collection<Page> allPages = m_engine.getManager(PageManager.class).getAllPages();
for (final Page page : allPages) {
try {
final String text = m_engine.getManager(PageManager.class).getPageText(page.getName(), WikiProvider.LATEST_VERSION);
luceneIndexPage(page, text, writer);
} catch (final IOException e) {
log.warn("Unable to index page " + page.getName() + ", continuing to next ", e);
}
}
final Collection<Attachment> allAttachments = m_engine.getManager(AttachmentManager.class).getAllAttachments();
for (final Attachment att : allAttachments) {
try {
final String text = getAttachmentContent(att.getName(), WikiProvider.LATEST_VERSION);
luceneIndexPage(att, text, writer);
} catch (final IOException e) {
log.warn("Unable to index attachment " + att.getName() + ", continuing to next", e);
}
}
}
final Date end = new Date();
log.info("Full Lucene index finished in " + (end.getTime() - start.getTime()) + " milliseconds.");
} else {
log.info("Files found in Lucene directory, not reindexing.");
}
} catch (final IOException e) {
log.error("Problem while creating Lucene index - not using Lucene.", e);
} catch (final ProviderException e) {
log.error("Problem reading pages while creating Lucene index (JSPWiki won't start.)", e);
throw new IllegalArgumentException("unable to create Lucene index");
} catch (final Exception e) {
log.error("Unable to start lucene", e);
}
}
use of org.apache.wiki.api.core.Attachment 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.api.core.Attachment in project jspwiki by apache.
the class DefaultRenderingManager method beautifyTitle.
/**
* {@inheritDoc}
*/
@Override
public String beautifyTitle(final String title) {
if (m_beautifyTitle) {
try {
final Attachment att = m_engine.getManager(AttachmentManager.class).getAttachmentInfo(title);
if (att == null) {
return TextUtil.beautifyString(title);
}
final String parent = TextUtil.beautifyString(att.getParentName());
return parent + "/" + att.getFileName();
} catch (final ProviderException e) {
return title;
}
}
return title;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AtomFeed method getItems.
private Collection<Element> getItems() {
final ArrayList<Element> list = new ArrayList<>();
final Engine engine = m_wikiContext.getEngine();
ServletContext servletContext = null;
if (m_wikiContext.getHttpRequest() != null) {
servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
}
for (final Entry e : m_entries) {
final Page p = e.getPage();
final 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()));
// Check for enclosures
if (engine.getManager(AttachmentManager.class).hasAttachments(p) && servletContext != null) {
try {
final List<Attachment> c = engine.getManager(AttachmentManager.class).listAttachments(p);
for (final Attachment att : c) {
final Element attEl = getElement("link");
attEl.setAttribute("rel", "enclosure");
attEl.setAttribute("href", engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName(), null));
attEl.setAttribute("length", Long.toString(att.getSize()));
attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
entryEl.addContent(attEl);
}
} catch (final ProviderException ex) {
// FIXME: log.info("Can't get attachment data",ex);
}
}
list.add(entryEl);
}
return list;
}
Aggregations