/** * Creates a new repository for the given file. The file must point to a directory. This constructor uses the default * mime-registry. * * @param file the directory, which should form the root of the repository. * @throws ContentIOException if an error prevents the repository creation. */ public FileObjectRepository( final FileObject file ) throws ContentIOException { this( file, new DefaultMimeRegistry() ); }
/** * Creates a new content-entity for the given file using the given content location as parent. * * @param parent the content location representing the parent directory. * @param backend the file representing this entity. */ protected FileObjectContentEntity( final ContentLocation parent, final FileObject backend ) { if ( backend == null ) { throw new NullPointerException( "Backend file must be given." ); } if ( parent == null ) { throw new NullPointerException( "Parent file must be given." ); } this.repository = parent.getRepository(); this.parent = parent; this.backend = backend; }
public String getMimeType() throws ContentIOException { final FileObjectRepository fileRepository = (FileObjectRepository) getRepository(); return fileRepository.getMimeRegistry().getMimeType( this ); }
private String getSuffixForType( final String mimeType, final ContentLocation location ) { final Repository repository = location.getRepository(); final MimeRegistry mimeRegistry = repository.getMimeRegistry(); return mimeRegistry.getSuffix( mimeType ); } }
/** * 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." ); } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() ) { throw new ContentCreationException( "File already exists." ); } child.createFile(); try { return new FileObjectContentLocation( this, child ); } catch ( ContentIOException e ) { throw new ContentCreationException( "Failed to create the content-location", e ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
/** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry( final String name ) throws ContentIOException { try { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() == false ) { throw new ContentIOException( "Not found:" + child ); } if ( child.isFolder() ) { return new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { return new FileObjectContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
protected ReportProcessor createReportProcessor( OutputStream fout ) throws Exception { final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor(); final HtmlPrinter printer = new AllItemsHtmlPrinter( report.getResourceManager() ); printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, filename, suffix ) ); printer.setDataWriter( targetRoot, new DefaultNameGenerator( targetRoot, "content" ) ); printer.setUrlRewriter( new FileSystemURLRewriter() ); outputProcessor.setPrinter( printer ); return new FlowReportProcessor( report, outputProcessor ); } };
/** * Returns the mime type for the content entity. If the repository does not store mimetypes, this call usually uses * the repositories MimeRegistry to resolve the mimetype. * * @return the mime type. * @throws ContentIOException if an error occured. */ public String getMimeType() throws ContentIOException { return getRepository().getMimeRegistry().getMimeType( this ); }
/** * Writes the given repository to the given ZIP-output stream. * * @param zipOutputStream the output stream that represents the ZipFile to be generated. * @param repository the repository that should be written. * @throws IOException if an IO error prevents the writing of the file. * @throws ContentIOException if a repository related IO error occurs. */ public static void writeToZipStream( final ZipOutputStream zipOutputStream, final Repository repository ) throws IOException, ContentIOException { writeLocation( repository.getRoot(), zipOutputStream ); }
public ContentItem createItem( final String name, final String mimeType ) throws ContentIOException { return dataLocation.createItem( dataNameGenerator.generateName( name, mimeType ) ); }
/** * Creates a new root-location for the given repository and directory. * * @param repository the repository for which a location should be created. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileObjectContentLocation( final Repository repository, final FileObject backend ) throws ContentIOException { super( repository, backend ); boolean error; try { error = backend.exists() == false || backend.isFolder() == false; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } if ( error ) { throw new ContentIOException( "The given backend-file is not a directory." ); } }
/** * 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; } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); return child.exists(); } catch ( FileSystemException e ) { throw new RuntimeException( e ); } } }
/** * Returns the full pathname of the location. * * @return the full pathname. */ public Object getContentId() { return RepositoryUtilities.buildName( this, "/" ); }
/** * Returns the singleton instance of the boot-class. * * @return the singleton booter. */ public static synchronized LibRepositoryBoot getInstance() { if ( instance == null ) { instance = new LibRepositoryBoot(); } return instance; }
private String getSuffixForType( final String mimeType, final ContentLocation location ) { final Repository repository = location.getRepository(); final MimeRegistry mimeRegistry = repository.getMimeRegistry(); return mimeRegistry.getSuffix( mimeType ); } }
if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); throw new ContentCreationException( "File already exists: " + child ); return new FileObjectContentItem( this, child ); } catch ( IOException e ) { throw new ContentCreationException( "IOError while create", e );
/** * Creates a new repository for the given file. The file must point to a directory. This constructor uses the default * mime-registry. * * @param file the directory, which should form the root of the repository. * @throws ContentIOException if an error prevents the repository creation. */ public FileRepository( final File file ) throws ContentIOException { this( file, new DefaultMimeRegistry() ); }
protected ReportProcessor createReportProcessor( OutputStream fout ) throws Exception { ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor( report.getConfiguration() ); final HtmlPrinter printer = new AllItemsHtmlPrinter( report.getResourceManager() ); printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, filename, suffix ) ); printer.setDataWriter( null, null ); // $NON-NLS-1$ printer.setUrlRewriter( new FileSystemURLRewriter() ); outputProcessor.setPrinter( printer ); return new StreamReportProcessor( report, outputProcessor ); } else { FastHtmlContentItems printer = new FastHtmlContentItems(); printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, filename, suffix ) ); printer.setDataWriter( null, null ); // $NON-NLS-1$ printer.setUrlRewriter( new FileSystemURLRewriter() ); return new FastHtmlExportProcessor( report, printer ); } } };
/** * Creates a new location for the given parent and directory. * * @param parent the parent location. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileObjectContentLocation( final ContentLocation parent, final FileObject backend ) throws ContentIOException { super( parent, backend ); boolean error; try { error = backend.exists() == false || backend.isFolder() == false; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } if ( error ) { throw new ContentIOException( "The given backend-file is not a directory." ); } }
/** * 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 { try { final FileObject file = getBackend(); final FileObject[] files = file.getChildren(); final ContentEntity[] entities = new ContentEntity[files.length]; for ( int i = 0; i < files.length; i++ ) { final FileObject child = files[i]; if ( RepositoryUtilities.isInvalidPathName( child.getPublicURIString() ) ) { continue; } if ( child.isFolder() ) { entities[i] = new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { entities[i] = new FileObjectContentLocation( this, child ); } } return entities; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }