use of org.apache.wiki.api.exceptions.ProviderException in project jspwiki by apache.
the class AttachmentsIteratorTag method doStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doStartTag() {
m_wikiContext = (WikiContext) pageContext.getAttribute(WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
WikiEngine engine = m_wikiContext.getEngine();
AttachmentManager mgr = engine.getAttachmentManager();
WikiPage page;
page = m_wikiContext.getPage();
if (!mgr.attachmentsEnabled()) {
return SKIP_BODY;
}
try {
if (page != null && engine.pageExists(page)) {
Collection atts = mgr.listAttachments(page);
if (atts == null) {
log.debug("No attachments to display.");
// There are no attachments included
return SKIP_BODY;
}
m_iterator = atts.iterator();
if (m_iterator.hasNext()) {
Attachment att = (Attachment) m_iterator.next();
WikiContext context = (WikiContext) m_wikiContext.clone();
context.setPage(att);
pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), att);
} else {
return SKIP_BODY;
}
} else {
return SKIP_BODY;
}
return EVAL_BODY_BUFFERED;
} catch (ProviderException e) {
log.fatal("Provider failed while trying to iterator through history", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.api.exceptions.ProviderException in project jspwiki by apache.
the class VersioningFileProvider method deleteVersion.
/**
* {@inheritDoc}
*
* Deleting versions has never really worked,
* JSPWiki assumes that version histories are "not gappy".
* Using deleteVersion() is definitely not recommended.
*/
public void deleteVersion(String page, int version) throws ProviderException {
File dir = findOldPageDir(page);
int latest = findLatestVersion(page);
if (version == WikiPageProvider.LATEST_VERSION || version == latest || (version == 1 && latest == -1)) {
//
try {
Properties props = getPageProperties(page);
props.remove(((latest > 0) ? latest : 1) + ".author");
putPageProperties(page, props);
} catch (IOException e) {
log.error("Unable to modify page properties", e);
throw new ProviderException("Could not modify page properties: " + e.getMessage());
}
// We can let the FileSystemProvider take care
// of the actual deletion
super.deleteVersion(page, WikiPageProvider.LATEST_VERSION);
//
// Copy the old file to the new location
//
latest = findLatestVersion(page);
File pageDir = findOldPageDir(page);
File previousFile = new File(pageDir, Integer.toString(latest) + FILE_EXT);
InputStream in = null;
OutputStream out = null;
try {
if (previousFile.exists()) {
in = new BufferedInputStream(new FileInputStream(previousFile));
File pageFile = findPage(page);
out = new BufferedOutputStream(new FileOutputStream(pageFile));
FileUtil.copyContents(in, out);
//
// We need also to set the date, since we rely on this.
//
pageFile.setLastModified(previousFile.lastModified());
}
} catch (IOException e) {
log.fatal("Something wrong with the page directory - you may have just lost data!", e);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
return;
}
File pageFile = new File(dir, "" + version + FILE_EXT);
if (pageFile.exists()) {
if (!pageFile.delete()) {
log.error("Unable to delete page.");
}
} else {
throw new NoSuchVersionException("Page " + page + ", version=" + version);
}
}
use of org.apache.wiki.api.exceptions.ProviderException in project jspwiki by apache.
the class VersioningFileProvider method readFile.
// FIXME: Should this really be here?
private String readFile(File pagedata) throws ProviderException {
String result = null;
InputStream in = null;
if (pagedata.exists()) {
if (pagedata.canRead()) {
try {
in = new FileInputStream(pagedata);
result = FileUtil.readContents(in, m_encoding);
} catch (IOException e) {
log.error("Failed to read", e);
throw new ProviderException("I/O error: " + e.getMessage());
} finally {
IOUtils.closeQuietly(in);
}
} else {
log.warn("Failed to read page from '" + pagedata.getAbsolutePath() + "', possibly a permissions problem");
throw new ProviderException("I cannot read the requested page.");
}
} else {
// This is okay.
// FIXME: is it?
log.info("New page");
}
return result;
}
use of org.apache.wiki.api.exceptions.ProviderException in project jspwiki by apache.
the class HasAttachmentsTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
AttachmentManager mgr = engine.getAttachmentManager();
try {
if (page != null && engine.pageExists(page) && mgr.attachmentsEnabled()) {
if (mgr.hasAttachments(page)) {
return EVAL_BODY_INCLUDE;
}
}
} catch (ProviderException e) {
log.fatal("Provider failed while trying to check for attachements", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.api.exceptions.ProviderException in project jspwiki by apache.
the class AttachmentManager method storeAttachment.
/**
* Stores an attachment directly from a stream.
* If the attachment did not exist previously, this method
* will create it. If it did exist, it stores a new version.
*
* @param att Attachment to store this under.
* @param in InputStream from which the attachment contents will be read.
*
* @throws IOException If writing the attachment failed.
* @throws ProviderException If something else went wrong.
*/
public void storeAttachment(Attachment att, InputStream in) throws IOException, ProviderException {
if (m_provider == null) {
return;
}
//
if (!m_engine.getPageManager().pageExists(att.getParentName())) {
// the caller should catch the exception and use the exception text as an i18n key
throw new ProviderException("attach.parent.not.exist");
}
m_provider.putAttachmentData(att, in);
m_engine.getReferenceManager().updateReferences(att.getName(), new Vector<String>());
WikiPage parent = new WikiPage(m_engine, att.getParentName());
m_engine.updateReferences(parent);
m_engine.getSearchManager().reindexPage(att);
}
Aggregations