public void setContentStream(Resource resource, InputStream in, String mimetype) throws IOException {
try {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
MediaContentItem mci = FacadingFactory.createFacading(conn).createFacade(resource, MediaContentItem.class);
String path = mci.getContentPath();
if(path == null) {
if(resource instanceof KiWiUriResource && ((KiWiUriResource)resource).stringValue().startsWith("file:")) {
try {
URI uri = new URI(((KiWiUriResource)resource).stringValue());
path = uri.getPath();
} catch(Exception ex) {}
} else {
// we store all other resources in the default directory; create a random file name and store it in the hasContentLocation
// property
String extension = null;
MimeEntry entry = MimeTable.getDefaultTable().find(mimetype);
if(entry != null && entry.getExtensions().length > 0) {
extension = entry.getExtensions()[0];
}
String fileName = UUID.randomUUID().toString();
path = defaultDir + File.separator +
fileName.substring(0,2) + File.separator +
fileName.substring(2,4) + File.separator +
fileName.substring(4,6) + File.separator +
fileName + (extension != null ? extension : "");
mci.setContentPath(path);
}
}
if(path != null) {
if(!path.startsWith(defaultDir)) {