/* (non-Javadoc) * @see uk.ac.ox.oucs.oxam.logic.PaperFileService#deposit(uk.ac.ox.oucs.oxam.logic.PaperFile, uk.ac.ox.oucs.oxam.logic.Callback) */ public void deposit(PaperFile paperFile, InputStream in) { PaperFileImpl impl = castToImpl(paperFile); String path = impl.getPath(); ContentResourceEdit resource = null; try { try { contentHostingService.checkResource(path); resource = contentHostingService.editResource(path); // Ignore PermissionException, IdUnusedException, TypeException // As they are too serious to continue. } catch (IdUnusedException iue) { // Will attempt to create containing folders. resource = contentHostingService.addResource(path); // Like the basename function. String filename = StringUtils.substringAfterLast(path, "/"); ResourceProperties props = resource.getPropertiesEdit(); props.addProperty(ResourceProperties.PROP_DISPLAY_NAME, filename); resource.setContentType(mimeTypes.getContentType(filename)); } resource.setContent(in); contentHostingService.commitResource(resource, NotificationService.NOTI_NONE); LOG.debug("Sucessfully copied file to: " + path); } catch (OverQuotaException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ServerOverloadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PermissionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InUseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TypeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdUsedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InconsistentException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // Close the stream here as this is where it's created. if (resource.isActiveEdit()) { contentHostingService.cancelResource(resource); } } }
public InputStream getInputStream(PaperFile paperFile) { PaperFileImpl impl = castToImpl(paperFile); String path = impl.getPath(); try { ContentResource resource = contentHostingService.getResource(path); return resource.streamContent(); } catch (Exception e) { LOG.info("Failed to get stream for: " + path); } return null; }
/* (non-Javadoc) * @see uk.ac.ox.oucs.oxam.logic.PaperFileService#exists(uk.ac.ox.oucs.oxam.logic.PaperFile) */ public boolean exists(PaperFile paperFile) { PaperFileImpl impl = castToImpl(paperFile); String path = impl.getPath(); try { contentHostingService.checkResource(path); return true; } catch (PermissionException e) { LOG.warn("Problem checking resource: " + path + " " + e.getMessage()); } catch (IdUnusedException e) { // Expected. } catch (TypeException e) { LOG.error("Wrong sort of resource at path: " + path + " " + e.getMessage()); } return false; }