/** * Computes the declared Zip-Compression level for the given content-item. If the content-items attributes do not * contain a definition, the default compression is used instead. * * @param item the content item for which the compression factor should be computed. * @return the compression level. */ public static int getZipLevel( final ContentItem item ) { final Object method = item.getAttribute( LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE ); if ( method instanceof Number == false ) { return Deflater.DEFAULT_COMPRESSION; } final Number n = (Number) method; final int level = n.intValue(); if ( level < 0 || level > 9 ) { return Deflater.DEFAULT_COMPRESSION; } return level; }
/** * Computes the declared Zip-Compression mode for the given content-item. If the content-items attributes do not * contain a valid definition, the default compression is used instead. * * @param item the content item for which the compression mode should be computed. * @return the compression mode, either ZipOutputStream.DEFLATED or ZipOutputStream.STORED. */ public static int getZipMethod( final ContentItem item ) { final Object method = item.getAttribute( LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE ); if ( method instanceof Number == false ) { return ZipOutputStream.DEFLATED; } final Number n = (Number) method; final int level = n.intValue(); if ( level != ZipOutputStream.STORED ) { return ZipOutputStream.DEFLATED; } return ZipOutputStream.STORED; }
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; }