Search in sources :

Example 41 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class RPCHandler method getRecentChanges.

public Vector getRecentChanges(Date since) {
    checkPermission(PagePermission.VIEW);
    Collection<WikiPage> pages = m_engine.getRecentChanges();
    Vector<Hashtable<String, Object>> result = new Vector<Hashtable<String, Object>>();
    Calendar cal = Calendar.getInstance();
    cal.setTime(since);
    // 
    // Convert UTC to our time.
    // 
    cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0)));
    since = cal.getTime();
    for (WikiPage page : pages) {
        if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
            result.add(encodeWikiPage(page));
        }
    }
    return result;
}
Also used : Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Calendar(java.util.Calendar) Attachment(org.apache.wiki.attachment.Attachment) Vector(java.util.Vector)

Example 42 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class RPCHandlerUTF8 method getAllPages.

public Vector getAllPages() {
    checkPermission(PagePermission.VIEW);
    Collection<WikiPage> pages = m_engine.getRecentChanges();
    Vector<String> result = new Vector<String>();
    for (WikiPage p : pages) {
        if (!(p instanceof Attachment)) {
            result.add(p.getName());
        }
    }
    return result;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) Vector(java.util.Vector)

Example 43 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink3.

/**
 * Are attachments parsed correctly also when using gappy text?
 */
@Test
public void testAttachmentLink3() throws Exception {
    TestEngine testEngine2 = new TestEngine(props);
    testEngine2.saveText("TestPage", "foo ");
    created.addElement("TestPage");
    Attachment att = new Attachment(testEngine2, "TestPage", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
    String src = "[Test page/TestAtt.txt]";
    Assert.assertEquals("<a class=\"attachment\" href=\"/test/attach/TestPage/TestAtt.txt\">Test page/TestAtt.txt</a>" + "<a href=\"/test/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.Test)

Example 44 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink2.

@Test
public void testAttachmentLink2() throws Exception {
    props.setProperty("jspwiki.encoding", "ISO-8859-1");
    // TODO
    TestEngine testEngine2 = new TestEngine(props);
    testEngine2.saveText("Test", "foo ");
    created.addElement("Test");
    Attachment att = new Attachment(testEngine2, "Test", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
    String src = "This should be an [attachment link|Test/TestAtt.txt]";
    Assert.assertEquals("This should be an <a class=\"attachment\" href=\"/test/attach/Test/TestAtt.txt\">attachment link</a>" + "<a href=\"/test/PageInfo.jsp?page=Test/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.Test)

Example 45 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testAttachmentLink4.

@Test
public void testAttachmentLink4() throws Exception {
    TestEngine testEngine2 = new TestEngine(props);
    testEngine2.saveText("TestPage", "foo ");
    created.addElement("TestPage");
    Attachment att = new Attachment(testEngine2, "TestPage", "TestAtt.txt");
    att.setAuthor("FirstPost");
    testEngine2.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
    String src = "[" + testEngine2.beautifyTitle("TestPage/TestAtt.txt") + "]";
    Assert.assertEquals("<a class=\"attachment\" href=\"/test/attach/TestPage/TestAtt.txt\">Test Page/TestAtt.txt</a>" + "<a href=\"/test/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2, src));
}
Also used : Attachment(org.apache.wiki.attachment.Attachment) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.Test)

Aggregations

Attachment (org.apache.wiki.attachment.Attachment)62 WikiPage (org.apache.wiki.WikiPage)26 Test (org.junit.Test)23 File (java.io.File)20 ProviderException (org.apache.wiki.api.exceptions.ProviderException)17 Collection (java.util.Collection)13 Date (java.util.Date)11 Iterator (java.util.Iterator)10 WikiEngine (org.apache.wiki.WikiEngine)10 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)7 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 List (java.util.List)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)5 Hashtable (java.util.Hashtable)4 Element (net.sf.ehcache.Element)4 PagePermission (org.apache.wiki.auth.permissions.PagePermission)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3