public String getMimeType() throws ContentIOException { final FileRepository fileRepository = (FileRepository) getRepository(); return fileRepository.getMimeRegistry().getMimeType( this ); }
public boolean isWriteable() { return getBackend().canWrite(); } }
/** * Returns the URL that represents this repository. The meaning of the URL returned here is implementation specific * and is probably not suitable to resolve names to global objects. * * @return the repository's URL. * @throws MalformedURLException if the URL could not be computed. */ public URL getURL() throws MalformedURLException { return root.getBackend().toURI().toURL(); } }
final FileRepository targetRepository = new FileRepository( targetDirectory ); final ContentLocation targetRoot = targetRepository.getRoot(); final FileRepository dataRepository = new FileRepository( dataDirectory ); final ContentLocation dataRoot = dataRepository.getRoot();
final File file = getBackend(); final File child = new File( file, name ); if ( child.exists() == false ) { return new FileContentLocation( this, child ); } else if ( child.isFile() ) { return new FileContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." );
public static void writeToDirectory( final File target, final DocumentBundle bundle ) throws ContentIOException, IOException { if ( target == null ) { throw new NullPointerException(); } if ( bundle == null ) { throw new NullPointerException(); } final FileRepository repository = new FileRepository( target ); writeToRepository( repository, bundle ); }
/** * Lists all content entities stored in this content-location. This method filters out all files that have an invalid * name (according to the repository rules). * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { final File file = getBackend(); final File[] files = file.listFiles(); final ContentEntity[] entities = new ContentEntity[ files.length ]; for ( int i = 0; i < files.length; i++ ) { final File child = files[ i ]; if ( RepositoryUtilities.isInvalidPathName( child.getName() ) ) { continue; } if ( child.isDirectory() ) { entities[ i ] = new FileContentLocation( this, child ); } else if ( child.isFile() ) { entities[ i ] = new FileContentLocation( this, child ); } } return entities; }
/** * Creates a new data item in the current location. This method must never return null. This method will fail if an * entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem( final String name ) throws ContentCreationException { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final File file = getBackend(); final File child = new File( file, name ); if ( child.exists() ) { if ( child.length() == 0 ) { // probably one of the temp files created by the pentaho-system return new FileContentItem( this, child ); } throw new ContentCreationException( "File already exists: " + child ); } try { if ( child.createNewFile() == false ) { throw new ContentCreationException( "Unable to create the file." ); } return new FileContentItem( this, child ); } catch ( IOException e ) { throw new ContentCreationException( "IOError while create", e ); } }
/** * Generates a new name for the location. The name-generator may use both the name-hint and mimetype to compute the * new name. * * @param nameHint the name hint, usually a identifier for the new filename (can be null). * @param mimeType the mime type of the new filename. Usually used to compute a suitable file-suffix. * @return the generated name, never null. * @throws org.pentaho.reporting.libraries.repository.ContentIOException if the name could not be generated for any * reason. */ public String generateName( final String nameHint, final String mimeType ) throws ContentIOException { final MimeRegistry mimeRegistry = fileContentLocation.getRepository().getMimeRegistry(); final File targetDirectory = fileContentLocation.getBackend(); final String suffix = mimeRegistry.getSuffix( mimeType ); try { final File tempFile = File.createTempFile( nameHint, "." + suffix, targetDirectory ); return tempFile.getName(); } catch ( IOException e ) { throw new ContentIOException( "Unable to generate a name for the data file", e ); } } }
/** * Creates a new repository for the given file. The file must point to a directory. * * @param file the directory, which should form the root of the repository. * @param mimeRegistry the mime registry to be used. * @throws ContentIOException if an error prevents the repository creation. */ public FileRepository( final File file, final MimeRegistry mimeRegistry ) throws ContentIOException { if ( mimeRegistry == null ) { throw new NullPointerException( "MimeRegistry must be given" ); } if ( file == null ) { throw new NullPointerException( "File must be given" ); } this.mimeRegistry = mimeRegistry; this.root = new FileContentLocation( this, file ); }
final FileRepository targetRepository = new FileRepository( targetDirectory ); final ContentLocation targetRoot = targetRepository.getRoot();
return null; final FileRepository repository = new FileRepository( directory ); final String bundleType = BundleUtilities.getBundleType( repository ); final String bundleMapping = BundleUtilities.getBundleMapping( bundleType );
/** * Creates a new content location in the current location. This method must never return null. This method will fail * if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentLocation createLocation( final String name ) throws ContentCreationException { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final File file = getBackend(); final File child = new File( file, name ); if ( child.exists() ) { throw new ContentCreationException( "File already exists." ); } if ( child.mkdir() == false ) { throw new ContentCreationException( "Unable to create the directory" ); } try { return new FileContentLocation( this, child ); } catch ( ContentIOException e ) { throw new ContentCreationException( "Failed to create the content-location", e ); } }
public InputStream getInputStream() throws ContentIOException, IOException { return new FileInputStream( getBackend() ); }
/** * Checks, whether an content entity with the given name exists in this content location. This method will report * invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists( final String name ) { if ( RepositoryUtilities.isInvalidPathName( name ) ) { return false; } final File file = getBackend(); final File child = new File( file, name ); return ( child.exists() ); } }
try { final FileRepository targetRepository = new FileRepository( targetDirectory ); final ContentLocation targetRoot = targetRepository.getRoot(); final FileRepository dataRepository = new FileRepository( dataDirectory ); final ContentLocation dataRoot = dataRepository.getRoot(); final ReportProcessor sp; if ( "pageable".equals( exportMethod ) ) { //$NON-NLS-1$
public OutputStream getOutputStream() throws ContentIOException, IOException { return new FileOutputStream( getBackend() ); }
final FileRepository targetRepository = new FileRepository( targetDirectory ); final ContentLocation targetRoot = targetRepository.getRoot();
public boolean isReadable() { return getBackend().canRead(); }