use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class WikiEngineTest method testDeletePageAndAttachments2.
@Test
public void testDeletePageAndAttachments2() throws Exception {
m_engine.saveText(NAME1, "Test");
Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
m_engine.getAttachmentManager().storeAttachment(att, m_engine.makeAttachmentFile());
String files = props.getProperty(FileSystemProvider.PROP_PAGEDIR);
File saved = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
String atts = props.getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
File attfile = new File(atts, NAME1 + "-att/TestAtt.txt-dir");
Assert.assertTrue("Didn't create it!", saved.exists());
Assert.assertTrue("Attachment dir does not exist", attfile.exists());
WikiPage page = m_engine.getPage(NAME1, WikiProvider.LATEST_VERSION);
Assert.assertNotNull("page", page);
att = m_engine.getAttachmentManager().getAttachmentInfo(NAME1 + "/TestAtt.txt");
m_engine.deletePage(att.getName());
m_engine.deletePage(NAME1);
Assert.assertNull("Page not removed", m_engine.getPage(NAME1));
Assert.assertNull("Att not removed", m_engine.getPage(NAME1 + "/TestAtt.txt"));
Collection refs = m_engine.getReferenceManager().findReferrers(NAME1);
Assert.assertNull("referrers", refs);
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class WikiEngineTest method testAttachmentRefs3.
/**
* Checks, if ReferenceManager is informed if a link to an attachment is added.
*/
@Test
public void testAttachmentRefs3() throws Exception {
ReferenceManager refMgr = m_engine.getReferenceManager();
AttachmentManager attMgr = m_engine.getAttachmentManager();
m_engine.saveText(NAME1, "fooBar");
Attachment att = new Attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
attMgr.storeAttachment(att, m_engine.makeAttachmentFile());
m_engine.saveText(NAME1, " [" + NAME1 + "/TestAtt.txt] ");
try {
// and check post-conditions
Collection c = refMgr.findUncreated();
Assert.assertTrue("attachment exists", c == null || c.size() == 0);
c = refMgr.findUnreferenced();
Assert.assertEquals("unreferenced count", c.size(), 1);
Assert.assertTrue("unreferenced", ((String) c.iterator().next()).equals(NAME1));
} finally {
// do cleanup
String files = props.getProperty(FileSystemProvider.PROP_PAGEDIR);
TestEngine.deleteAll(new File(files, NAME1 + BasicAttachmentProvider.DIR_EXTENSION));
}
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class TestEngine method addAttachment.
/**
* Adds an attachment to a page for testing purposes.
* @param pageName
* @param attachmentName
* @param data
*/
public void addAttachment(String pageName, String attachmentName, byte[] data) throws ProviderException, IOException {
Attachment att = new Attachment(this, pageName, attachmentName);
getAttachmentManager().storeAttachment(att, new ByteArrayInputStream(data));
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class BasicAttachmentProvider method listAllChanged.
/**
* {@inheritDoc}
*/
// FIXME: Very unoptimized.
public List listAllChanged(Date timestamp) throws ProviderException {
File attDir = new File(m_storageDir);
if (!attDir.exists()) {
throw new ProviderException("Specified attachment directory " + m_storageDir + " does not exist!");
}
ArrayList<Attachment> list = new ArrayList<Attachment>();
String[] pagesWithAttachments = attDir.list(new AttachmentFilter());
for (int i = 0; i < pagesWithAttachments.length; i++) {
String pageId = unmangleName(pagesWithAttachments[i]);
pageId = pageId.substring(0, pageId.length() - DIR_EXTENSION.length());
Collection c = listAttachments(new WikiPage(m_engine, pageId));
for (Iterator it = c.iterator(); it.hasNext(); ) {
Attachment att = (Attachment) it.next();
if (att.getLastModified().after(timestamp)) {
list.add(att);
}
}
}
Collections.sort(list, new PageTimeComparator());
return list;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class CachingAttachmentProvider method getAttachmentInfo.
/**
* {@inheritDoc}
*/
public Attachment getAttachmentInfo(WikiPage page, String name, int version) throws ProviderException {
if (log.isDebugEnabled()) {
log.debug("Getting attachments for " + page + ", name=" + name + ", version=" + version);
}
//
if (version != WikiProvider.LATEST_VERSION) {
log.debug("...we don't cache old versions");
return m_provider.getAttachmentInfo(page, name, version);
}
Collection<Attachment> c = null;
Element element = m_cache.get(page.getName());
if (element == null) {
log.debug(page.getName() + " wasn't in the cache");
c = refresh(page);
// No such attachment
if (c == null)
return null;
} else {
log.debug(page.getName() + " FOUND in the cache");
c = (Collection<Attachment>) element.getObjectValue();
}
return findAttachmentFromCollection(c, name);
}
Aggregations