/** * 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; }
/** * Returns the current repository, to which tis entity belongs. * * @return the repository. */ public Repository getRepository() { return parent.getRepository(); }
/** * Returns the parent repository for this location. * * @return the repository. */ public Repository getRepository() { return parent.getRepository(); }
/** * Creates a new DummyContentLocation with the given parent and name. The location will inherit the repository from * its parent. * * @param parent the parent location. * @param name the name of this location. */ public DummyContentLocation( final ContentLocation parent, final String name ) { if ( parent == null ) { throw new NullPointerException( "Parent must not be null" ); } this.repository = parent.getRepository(); this.parent = parent; this.name = name; }
/** * 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 FileContentEntity( final ContentLocation parent, final File 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; }
private String getSuffixForType( final String mimeType, final ContentLocation location ) { final Repository repository = location.getRepository(); final MimeRegistry mimeRegistry = repository.getMimeRegistry(); return mimeRegistry.getSuffix( mimeType ); } }
private String getSuffixForType( final String mimeType, final ContentLocation location ) { final Repository repository = location.getRepository(); final MimeRegistry mimeRegistry = repository.getMimeRegistry(); return mimeRegistry.getSuffix( mimeType ); } }
/** * A helper method that tries to come up with a reasonalbe URLrewriter for common repository configurations. If there * is a URLRewriter defined already, that one will be used. If both the bulk and body location point to the same * repository backend, the SingleRepositoryURLRewriter is used. If both repositories are different but both are * UrlRepositories, a FilesystemURLRewriter is used. If everything else fails, the method will fall back to a * SingleRepositoryURLRewriter - hoping that it will work out. * * @return the computed URL rewriter. */ protected URLRewriter computeUrlRewriter() { final URLRewriter userRewriter = getUrlRewriter(); if ( userRewriter != null ) { return ( userRewriter ); } else { final ContentLocation bulkLocation = getBulkLocation(); if ( bulkLocation == null ) { return ( new SingleRepositoryURLRewriter() ); } else { final Repository bulkRepository = bulkLocation.getRepository(); final Repository bodyRepository = getBodyContentLocation().getRepository(); if ( bulkRepository == bodyRepository ) { return ( new SingleRepositoryURLRewriter() ); } else if ( bulkRepository instanceof UrlRepository && bodyRepository instanceof UrlRepository ) { return ( new FileSystemURLRewriter() ); } else { return ( new SingleRepositoryURLRewriter() ); } } } }
task.setBulkNameGenerator( bulkNameGenerator ); task.setBodyContentLocation( bodyContentLocation ); doReturn( bulkRepository ).when( bodyContentLocation ).getRepository(); doReturn( bulkRepository ).when( bulkLocation ).getRepository(); result = task.computeUrlRewriter(); assertThat( result, instanceOf( SingleRepositoryURLRewriter.class ) ); doReturn( bodyRepository ).when( bodyContentLocation ).getRepository(); result = task.computeUrlRewriter(); assertThat( result, instanceOf( FileSystemURLRewriter.class ) ); doReturn( mock( DummyRepository.class ) ).when( bulkLocation ).getRepository(); result = task.computeUrlRewriter(); assertThat( result, instanceOf( SingleRepositoryURLRewriter.class ) ); doReturn( bulkRepository ).when( bulkLocation ).getRepository(); doReturn( mock( DummyRepository.class ) ).when( bodyContentLocation ).getRepository(); result = task.computeUrlRewriter(); assertThat( result, instanceOf( SingleRepositoryURLRewriter.class ) );