use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testListAllExtrafile.
/**
* Check that the system does not Assertions.fail if there are extra files in the directory.
*/
@Test
public void testListAllExtrafile() throws Exception {
final File in = makeAttachmentFile();
final File sDir = new File(m_engine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR));
makeExtraFile(sDir, "foobar.blob");
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
m_provider.putAttachmentData(att, new FileInputStream(in));
awaitility().await("testListAllExtrafile").until(attachmentIsSaved(att));
final Attachment att2 = Wiki.contents().attachment(m_engine, NAME2, "test2.txt");
m_provider.putAttachmentData(att2, new FileInputStream(in));
final List<Attachment> res = m_provider.listAllChanged(new Date(0L));
Assertions.assertEquals(2, res.size(), "list size");
// Most recently changed
final Attachment a2 = res.get(0);
// Least recently changed
final Attachment a1 = res.get(1);
Assertions.assertEquals(att.getName(), a1.getName(), "a1 name :: " + res);
Assertions.assertEquals(att2.getName(), a2.getName(), "a2 name :: " + res);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testListAllExtradirInAttachmentDir.
/**
* Check that the system does not Assertions.fail if there are extra dirs in the attachment directory.
*/
@Test
public void testListAllExtradirInAttachmentDir() throws Exception {
final File in = makeAttachmentFile();
final File sDir = new File(m_engine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR));
final File attDir = new File(sDir, NAME1 + "-att");
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
m_provider.putAttachmentData(att, new FileInputStream(in));
// This is our extraneous directory.
final File extrafile = new File(attDir, "ping.pong");
extrafile.mkdir();
awaitility().await("testListAllExtradirInAttachmentDir").until(attachmentIsSaved(att));
final Attachment att2 = Wiki.contents().attachment(m_engine, NAME2, "test2.txt");
m_provider.putAttachmentData(att2, new FileInputStream(in));
final List<Attachment> res = m_provider.listAllChanged(new Date(0L));
Assertions.assertEquals(2, res.size(), "list size");
// Most recently changed
final Attachment a2 = res.get(0);
// Least recently changed
final Attachment a1 = res.get(1);
Assertions.assertEquals(att.getName(), a1.getName(), "a1 name :: " + res);
Assertions.assertEquals(att2.getName(), a2.getName(), "a2 name :: " + res);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testListAllNoExtension.
@Test
public void testListAllNoExtension() throws Exception {
final File in = makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.");
m_provider.putAttachmentData(att, new FileInputStream(in));
awaitility().await("testListAllNoExtension").until(attachmentIsSaved(att));
final Attachment att2 = Wiki.contents().attachment(m_engine, NAME2, "test2.");
m_provider.putAttachmentData(att2, new FileInputStream(in));
final List<Attachment> res = m_provider.listAllChanged(new Date(0L));
Assertions.assertEquals(2, res.size(), "list size");
// Most recently changed
final Attachment a2 = res.get(0);
// Least recently changed
final Attachment a1 = res.get(1);
Assertions.assertEquals(att.getName(), a1.getName(), "a1 name :: " + res);
Assertions.assertEquals(att2.getName(), a2.getName(), "a2 name :: " + res);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testListAll.
@Test
public void testListAll() throws Exception {
final File in = makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
m_provider.putAttachmentData(att, new FileInputStream(in));
awaitility().await("testListAll").until(attachmentIsSaved(att));
final Attachment att2 = Wiki.contents().attachment(m_engine, NAME2, "test2.txt");
m_provider.putAttachmentData(att2, new FileInputStream(in));
final List<Attachment> res = m_provider.listAllChanged(new Date(0L));
Assertions.assertEquals(2, res.size(), "list size");
// Most recently changed
final Attachment a2 = res.get(0);
// Least recently changed
final Attachment a1 = res.get(1);
Assertions.assertEquals(att.getName(), a1.getName(), "a1 name :: " + res);
Assertions.assertEquals(att2.getName(), a2.getName(), "a2 name :: " + res);
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class LuceneSearchProvider method luceneIndexPage.
/**
* Indexes page using the given IndexWriter.
*
* @param page WikiPage
* @param text Page text to index
* @param writer The Lucene IndexWriter to use for indexing
* @return the created index Document
* @throws IOException If there's an indexing problem
*/
protected Document luceneIndexPage(final Page page, final String text, final IndexWriter writer) throws IOException {
log.debug("Indexing {}...", page.getName());
// make a new, empty document
final Document doc = new Document();
if (text == null) {
return doc;
}
// be nice to Language Analyzers - cfr. JSPWIKI-893
final String indexedText = text.replace("__", " ");
// Raw name is the keyword we'll use to refer to this document for updates.
Field field = new Field(LUCENE_ID, page.getName(), StringField.TYPE_STORED);
doc.add(field);
// Body text. It is stored in the doc for search contexts.
field = new Field(LUCENE_PAGE_CONTENTS, indexedText, TextField.TYPE_STORED);
doc.add(field);
// Allow searching by page name. Both beautified and raw
final String unTokenizedTitle = StringUtils.replaceChars(page.getName(), TextUtil.PUNCTUATION_CHARS_ALLOWED, PUNCTUATION_TO_SPACES);
field = new Field(LUCENE_PAGE_NAME, TextUtil.beautifyString(page.getName()) + " " + unTokenizedTitle, TextField.TYPE_STORED);
doc.add(field);
// Allow searching by authorname
if (page.getAuthor() != null) {
field = new Field(LUCENE_AUTHOR, page.getAuthor(), TextField.TYPE_STORED);
doc.add(field);
}
// Now add the names of the attachments of this page
try {
final List<Attachment> attachments = m_engine.getManager(AttachmentManager.class).listAttachments(page);
final StringBuilder attachmentNames = new StringBuilder();
for (final Attachment att : attachments) {
attachmentNames.append(att.getName()).append(";");
}
field = new Field(LUCENE_ATTACHMENTS, attachmentNames.toString(), TextField.TYPE_STORED);
doc.add(field);
} catch (final ProviderException e) {
// Unable to read attachments
log.error("Failed to get attachments for page", e);
}
// also index page keywords, if available
if (page.getAttribute("keywords") != null) {
field = new Field(LUCENE_PAGE_KEYWORDS, page.getAttribute("keywords").toString(), TextField.TYPE_STORED);
doc.add(field);
}
synchronized (writer) {
writer.addDocument(doc);
}
return doc;
}
Aggregations