/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getCollectionURI(java.lang.String, * java.lang.String) */ @Override public URI getCollectionURI(String collectionID, String fileName) { try { return new URI(getBaseUri() + COLLECTION_PATH_PREFIX + collectionID + "/" + PathSupport.toSafeName(fileName)); } catch (URISyntaxException e) { throw new IllegalStateException("Unable to create valid uri from " + collectionID + " and " + fileName); } }
/** * Transforms a URI into a workspace File. If the file comes from the working file repository, the path in the * workspace mirrors that of the repository. If the file comes from another source, directories are created for each * segment of the URL. Sub-directories may be created as needed. * * @param uri * the uri * @return the local file representation */ File toWorkspaceFile(URI uri) { // MH-11497: Fix for compatibility with stream security: the query parameters are deleted. // TODO Refactor this class to use the URI class and methods instead of String for handling URIs String uriString = UriBuilder.fromUri(uri).replaceQuery(null).build().toString(); String wfrPrefix = wfr.getBaseUri().toString(); String serverPath = FilenameUtils.getPath(uriString); if (uriString.startsWith(wfrPrefix)) { serverPath = serverPath.substring(wfrPrefix.length()); } else { serverPath = serverPath.replaceAll(":/*", "_"); } String wsDirectoryPath = PathSupport.concat(wsRoot, serverPath); File wsDirectory = new File(wsDirectoryPath); wsDirectory.mkdirs(); String safeFileName = PathSupport.toSafeName(FilenameUtils.getName(uriString)); if (StringUtils.isBlank(safeFileName)) safeFileName = UNKNOWN_FILENAME; return new File(wsDirectory, safeFileName); }
uri = UrlSupport.concat(uri, PathSupport.toSafeName(fileName)); uri = UrlSupport.concat(uri, PathSupport.toSafeName(fileName));
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getCollectionContents(java.lang.String) */ @Override public URI[] getCollectionContents(String collectionId) throws NotFoundException { File collectionDir = null; try { collectionDir = getCollectionDirectory(collectionId, false); if (collectionDir == null) throw new NotFoundException(collectionId); } catch (IOException e) { // We are not asking for the collection to be created, so this exception is never thrown } File[] files = collectionDir.listFiles(MD5_FINAME_FILTER); URI[] uris = new URI[files.length]; for (int i = 0; i < files.length; i++) { try { uris[i] = new URI(getBaseUri() + COLLECTION_PATH_PREFIX + collectionId + "/" + PathSupport.toSafeName(getSourceFile(files[i]).getName())); } catch (URISyntaxException e) { throw new IllegalStateException("Invalid URI for " + files[i]); } } return uris; }
File f = new File(dir, PathSupport.toSafeName(filename)); File md5File = getMd5File(f);
destFile = new File(destDir, PathSupport.toSafeName(toFileName)); FileSupport.link(source, destFile); createMd5(destFile);
checkPathSafe(fileName); File f = new File(PathSupport.concat(new String[]{rootDirectory, COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName)})); logger.debug("Attempting to write a file to {}", f.getAbsolutePath()); FileOutputStream out = null;
delete(toMediaPackage, toMediaPackageElement); } catch (NotFoundException e) { dest = new File(getElementDirectory(toMediaPackage, toMediaPackageElement), PathSupport.toSafeName(toFileName));
File sourceFile = new File(directory, PathSupport.toSafeName(fileName)); File md5File = getMd5File(sourceFile); if (!sourceFile.exists())
@Override public void deleteFromCollection(String collectionId, String fileName, boolean removeCollection) throws NotFoundException, IOException { // local delete final File f = workspaceFile(WorkingFileRepository.COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName)); FileUtils.deleteQuietly(f); if (removeCollection) { FileSupport.delete(f.getParentFile()); } // delete in WFR try { wfr.deleteFromCollection(collectionId, fileName, removeCollection); } catch (IllegalArgumentException e) { throw new NotFoundException(e); } // wait for WFR waitForResource(wfr.getCollectionURI(collectionId, fileName), SC_NOT_FOUND, "File %s does not disappear in WFR"); }
@Override public URI putInCollection(String collectionId, String fileName, InputStream in) throws IOException { String safeFileName = PathSupport.toSafeName(fileName); URI uri = wfr.getCollectionURI(collectionId, fileName);
@Override public URI put(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) throws IOException { String safeFileName = PathSupport.toSafeName(fileName); final URI uri = wfr.getURI(mediaPackageID, mediaPackageElementID, fileName); notNull(in, "in");