Search in sources :

Example 21 with Attachment

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;
}
Also used : Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Engine(org.apache.wiki.api.core.Engine)

Example 22 with Attachment

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"));
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Test(org.junit.jupiter.api.Test)

Example 23 with Attachment

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");
}
Also used : Hashtable(java.util.Hashtable) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Vector(java.util.Vector) Test(org.junit.jupiter.api.Test)

Example 24 with Attachment

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));
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Example 25 with Attachment

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);
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) File(java.io.File) FileInputStream(java.io.FileInputStream) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (org.apache.wiki.api.core.Attachment)76 Test (org.junit.jupiter.api.Test)37 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)35 Page (org.apache.wiki.api.core.Page)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)20 PageManager (org.apache.wiki.pages.PageManager)19 File (java.io.File)15 Date (java.util.Date)10 Engine (org.apache.wiki.api.core.Engine)10 ReferenceManager (org.apache.wiki.references.ReferenceManager)9 InputStream (java.io.InputStream)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 StringWriter (java.io.StringWriter)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)6 Permission (java.security.Permission)4 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4