public Object getAttribute( final String key ) { if ( key == null ) { throw new NullPointerException(); } if ( contentItem == null ) { return null; } if ( ResourceData.CONTENT_TYPE.equals( key ) ) { try { return contentItem.getMimeType(); } catch ( ContentIOException e ) { return null; } } else if ( ResourceData.CONTENT_LENGTH.equals( key ) ) { return contentItem.getAttribute( LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.SIZE_ATTRIBUTE ); } else if ( ResourceData.FILENAME.equals( key ) ) { return contentItem.getName(); } return null; }
/** * Checks, whether an content entity with the given name exists in this content location. * * @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 ( contentItem != null ) { return contentItem.getName().equals( name ); } final WrappedInputStream in = repository.getInputStream(); if ( in != null ) { // if we are in input mode, the content name must not be null. return repository.getContentName().equals( name ); } return false; }
/** * Queries the mime-type for a given content-item. Some repositories store mime-type information along with the * content data, while others might resort to heuristics based on the filename or actual data stored in the item. * * @param item the content item for which Mime-Data should be queried. * @return the mime-type never null. */ public String getMimeType( final ContentItem item ) { final String name = item.getName(); if ( name == null ) { return defaultMimeType; } final String extension = IOUtils.getInstance().getFileExtension( name ).toLowerCase(); return configuration.getConfigProperty( SUFFIX_KEY_PREFIX + extension, "application/octet-stream" ); }
/** * 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 { final WrappedInputStream in = repository.getInputStream(); if ( in != null && contentItem == null ) { this.contentItem = new StreamContentItem ( repository.getContentName(), this, in, repository.getOutputStream() ); } if ( contentItem == null ) { throw new ContentIOException( "No such item" ); } if ( contentItem.getName().equals( name ) ) { return contentItem; } throw new ContentIOException( "No such item" ); }