* @throws FileNotFoundException
*/
// have to accept anything for browsers to work
public RepositoryFileToStreamWrapper doGetFileAsInline( String pathId ) throws FileNotFoundException {
String path = null;
RepositoryFile repositoryFile = null;
// Check if the path is actually and ID
path = idToPath( pathId );
if ( isPath( path ) ) {
if ( !isPathValid( path ) ) {
throw new IllegalArgumentException();
}
repositoryFile = getRepository().getFile( path );
} else {
// Yes path provided is an ID
repositoryFile = getRepository().getFileById( pathId );
}
if ( repositoryFile == null ) {
// file does not exist or is not readable but we can't tell at this point
throw new FileNotFoundException();
}
// check whitelist acceptance of file (based on extension)
if ( !getWhitelist().accept( repositoryFile.getName() ) ) {
// if whitelist check fails, we can still inline if you have PublishAction, otherwise we're FORBIDDEN
if ( !getPolicy().isAllowed( PublishAction.NAME ) ) {
throw new IllegalArgumentException();
}
}
try {
SimpleRepositoryFileData fileData =
getRepository().getDataForRead( repositoryFile.getId(), SimpleRepositoryFileData.class );
final InputStream is = fileData.getInputStream();
// copy streaming output
StreamingOutput streamingOutput = getStreamingOutput( is );
RepositoryFileToStreamWrapper wrapper = new RepositoryFileToStreamWrapper();
wrapper.setOutputStream( streamingOutput );
wrapper.setRepositoryFile( repositoryFile );
return wrapper;
} catch ( Exception e ) {
logger.error( Messages.getInstance().getString(
"FileResource.EXPORT_FAILED", repositoryFile.getName() + " " + e.getMessage() ), e );
throw new InternalError();
}
}