use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class PageNameTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null) {
if (page instanceof Attachment) {
pageContext.getOut().print(TextUtil.replaceEntities(((Attachment) page).getFileName()));
} else {
pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(m_wikiContext.getName()));
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class TikaSearchProviderTest method testGetAttachmentContent.
@Test
void testGetAttachmentContent() throws Exception {
engine.saveText("Test-tika", "blablablabla");
final byte[] filePdf = Files.readAllBytes(Paths.get(TikaSearchProviderTest.class.getClassLoader().getResource("aaa-diagram.pdf").toURI()));
final byte[] filePng = Files.readAllBytes(Paths.get(TikaSearchProviderTest.class.getClassLoader().getResource("favicon.png").toURI()));
engine.addAttachment("Test-tika", "aaa-diagram.pdf", filePdf);
engine.addAttachment("Test-tika", "favicon.png", filePng);
final TikaSearchProvider tsp = (TikaSearchProvider) engine.getManager(SearchManager.class).getSearchEngine();
final Attachment attPdf = engine.getManager(AttachmentManager.class).getAttachmentInfo("Test-tika/aaa-diagram.pdf");
final String pdfIndexed = tsp.getAttachmentContent(attPdf);
Assertions.assertTrue(pdfIndexed.contains("aaa-diagram.pdf"));
Assertions.assertTrue(pdfIndexed.contains("WebContainerAuthorizer"));
final Attachment attPng = engine.getManager(AttachmentManager.class).getAttachmentInfo("Test-tika/favicon.png");
final String pngIndexed = tsp.getAttachmentContent(attPng);
Assertions.assertTrue(pngIndexed.contains("favicon.png"));
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class RPCHandlerTest method testListLinksWithAttachments.
@Test
public void testListLinksWithAttachments() throws Exception {
final String text = "[Foobar] [Test/TestAtt.txt]";
final String pageName = NAME1;
m_engine.saveText(pageName, text);
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
m_engine.getManager(AttachmentManager.class).storeAttachment(att, m_engine.makeAttachmentFile());
// Test.
final Vector links = m_handler.listLinks(pageName);
Assertions.assertEquals(2, links.size(), "link count");
Hashtable linkinfo = (Hashtable) links.elementAt(0);
Assertions.assertEquals("Foobar", linkinfo.get("page"), "edit name");
Assertions.assertEquals("local", linkinfo.get("type"), "edit type");
Assertions.assertEquals("/test/Edit.jsp?page=Foobar", linkinfo.get("href"), "edit href");
linkinfo = (Hashtable) links.elementAt(1);
Assertions.assertEquals(NAME1 + "/TestAtt.txt", linkinfo.get("page"), "att name");
Assertions.assertEquals("local", linkinfo.get("type"), "att type");
Assertions.assertEquals("/test/attach/" + NAME1 + "/TestAtt.txt", linkinfo.get("href"), "att href");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testGetAttachmentDataRaisesProviderExceptionIfInexistentFileOnDisk.
@Test
public void testGetAttachmentDataRaisesProviderExceptionIfInexistentFileOnDisk() {
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "test1.txt");
Assertions.assertThrows(ProviderException.class, () -> m_provider.getAttachmentData(att));
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class BasicAttachmentProviderTest method testListAllExtrafileInAttachmentDir.
/**
* Check that the system does not Assertions.fail if there are extra files in the attachment directory.
*/
@Test
public void testListAllExtrafileInAttachmentDir() 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));
makeExtraFile(attDir, "ping.pong");
awaitility().await("testListAllExtrafileInAttachmentDir").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);
}
Aggregations