content.store(slideToken, config.getFilesPath()+path,
revisionDescriptor, revisionContent);
try {
nat.commit();
} catch (Exception cme) {
throw new CascadingIOException("Could not commit the transaction",
cme);
}
} catch (ObjectNotFoundException e) {
// Todo : Check to see if parent exists
SubjectNode subject = new SubjectNode();
try {
// Creating an object
structure.create(slideToken, subject,
config.getFilesPath()+path);
} catch (SlideException se) {
throw new CascadingIOException(se);
}
NodeRevisionDescriptor revisionDescriptor = new NodeRevisionDescriptor(bytes.length);
// Resource type
revisionDescriptor.setResourceType("");
// Source
revisionDescriptor.setSource("");
// Get content language
revisionDescriptor.setContentLanguage("en");
// Get content length
revisionDescriptor.setContentLength(bytes.length);
// Get content type
String contentType = null;
try {
contentType = ((org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT)).getMimeType(path);
} catch (ContextException ce) {
this.logger.warn("Could not get context to determine the mime type.");
}
if (contentType==null) {
contentType = "application/octet-stream";
}
revisionDescriptor.setContentType(contentType);
// Last modification date
revisionDescriptor.setLastModified(new Date());
// Owner
revisionDescriptor.setOwner(slideToken.getCredentialsToken().getPublicCredentials());
// Creating revisionDescriptor associated with the object
NodeRevisionContent revisionContent = new NodeRevisionContent();
revisionContent.setContent(bytes);
try {
content.create(slideToken, config.getFilesPath()+path,
revisionDescriptor, revisionContent);
try {
nat.commit();
} catch (Exception cme) {
throw new CascadingIOException("Could not commit the transaction",
cme);
}
} catch (SlideException se) {
try {
nat.rollback();
} catch (Exception rbe) {
this.logger.warn("Could not rollback the transaction.",
rbe);
}
throw new CascadingIOException("Could not create source",
se);
}
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException) e;
}
throw new CascadingIOException("Could not create source", e);
} finally {
this.isClosed = true;
}
}