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; }
public InputStream getEntryAsStream( final String name ) throws IOException { if ( name == null ) { throw new NullPointerException(); } try { final String[] splitName = RepositoryUtilities.split( name, "/" ); final ContentEntity contentEntity = RepositoryUtilities.getEntity( zipRepository, splitName ); if ( contentEntity instanceof ContentItem ) { final ContentItem contentItem = (ContentItem) contentEntity; return contentItem.getInputStream(); } } catch ( ContentIOException cioe ) { if ( logger.isDebugEnabled() ) { logger.debug( "Failed to lookup entry for entry " + name, cioe ); } throw new IOException( "Failure while looking up the stream: " + cioe ); } throw new IOException( "No such stream: " + name ); }
public OutputStream createEntry( final String path, final String mimetype ) throws IOException { if ( path == null ) { throw new NullPointerException(); } if ( mimetype == null ) { throw new NullPointerException( "Invalid Bundle: There is no mime-type for entry " + path ); } final String[] name = RepositoryUtilities.splitPath( path, "/" ); try { final ContentItem contentItem = RepositoryUtilities.createItem( zipRepository, name ); metaData.setEntryMimeType( path, mimetype ); return contentItem.getOutputStream(); } catch ( ContentIOException cioe ) { logger.warn( "Failed to create content item " + path, cioe ); throw new IOException( "Failed to create content item " + path ); } }
if ( item.isWriteable() ) { item.setAttribute( LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.CONTENT_TYPE, mimeType ); final OutputStream outputStream = new BufferedOutputStream( item.getOutputStream() ); try { IOUtils.getInstance().copyStreams( stream, outputStream );
final ContentItem contentItem = RepositoryUtilities.createItem ( repository, RepositoryUtilities.splitPath( "mimetype", "/" ) ); contentItem.setAttribute ( LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE, LibRepositoryBoot.ZIP_METHOD_STORED ); final byte[] rawData = bundleType.getBytes( "ASCII" ); final OutputStream outputStream = contentItem.getOutputStream(); try { outputStream.write( rawData ); final ContentItem manifestItem = RepositoryUtilities.createItem ( repository, RepositoryUtilities.splitPath( "META-INF/manifest.xml", "/" ) ); final OutputStream manifestStream = manifestItem.getOutputStream(); try { metaDataWriter.writeManifest( manifestStream ); final OutputStream metaDataStream = metaDataItem.getOutputStream(); try { metaDataWriter.writeMetaData( metaDataStream ); final OutputStream dataStream = dataItem.getOutputStream(); try { final InputStream inStream = bundle.getEntryAsStream( entryName );
/** * 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; }
/** * 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 String getEntryMimeType( final String name ) { if ( name == null ) { throw new NullPointerException(); } final String definedMimeType = documentMetaData.getEntryMimeType( name ); if ( definedMimeType != null ) { return definedMimeType; } try { final String[] splitName = RepositoryUtilities.split( name, "/" ); final ContentEntity contentEntity = RepositoryUtilities.getEntity( repository, splitName ); if ( contentEntity instanceof ContentItem ) { final ContentItem contentItem = (ContentItem) contentEntity; return contentItem.getMimeType(); } } catch ( ContentIOException cioe ) { // ignored. if ( logger.isDebugEnabled() ) { logger.debug( "Failed to lookup entry mime-type for entry " + name, cioe ); } } return ""; }
/** * 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" ); }
/** * 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; }
public String getEntryMimeType( final String name ) { if ( name == null ) { throw new NullPointerException(); } final String definedMimeType = metaData.getEntryMimeType( name ); if ( definedMimeType != null ) { return definedMimeType; } try { final String[] splitName = RepositoryUtilities.split( name, "/" ); final ContentEntity contentEntity = RepositoryUtilities.getEntity( zipRepository, splitName ); if ( contentEntity instanceof ContentItem ) { final ContentItem contentItem = (ContentItem) contentEntity; return contentItem.getMimeType(); } return ""; // for directories .. } catch ( ContentIOException cioe ) { // ignored. if ( logger.isDebugEnabled() ) { logger.debug( "Failed to lookup entry mime-type for entry " + name, cioe ); } return null; } }
final OutputStream out = new BufferedOutputStream( dataFile.getOutputStream() ); try { out.write( data.getImageData() );
public InputStream getEntryAsStream( final String name ) throws IOException { if ( name == null ) { throw new NullPointerException(); } try { final String[] splitName = RepositoryUtilities.split( name, "/" ); final ContentEntity contentEntity = RepositoryUtilities.getEntity( repository, splitName ); if ( contentEntity instanceof ContentItem ) { final ContentItem contentItem = (ContentItem) contentEntity; return contentItem.getInputStream(); } } catch ( ContentIOException cioe ) { if ( logger.isDebugEnabled() ) { logger.debug( "Failed to lookup entry for entry " + name, cioe ); } throw new IOException( "Failure while looking up the stream: " + cioe ); } throw new IOException( "No such stream: " + name ); }
/** * 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" ); }
final OutputStream out = documentContentItem.getOutputStream();
public InputStream getResourceAsStream( final ResourceManager caller ) throws ResourceLoadingException { if ( caller == null ) { throw new NullPointerException(); } if ( contentItem == null ) { throw new ResourceLoadingException( "Failure: Missing data" ); } try { return contentItem.getInputStream(); } catch ( ContentIOException cioe ) { throw new ResourceLoadingException( "Failure", cioe ); } catch ( IOException e ) { throw new ResourceLoadingException( "Failure", e ); } }
.getConfigProperty( HtmlTableModule.ENCODING, EncodingRegistry.getPlatformDefaultEncoding() ); final Writer styleOut = new OutputStreamWriter( new BufferedOutputStream( styleFile.getOutputStream() ), encoding ); getStyleManager().write( styleOut ); styleOut.flush();
public static String getBundleType( final Repository repository ) { if ( repository == null ) { throw new NullPointerException(); } try { final ContentEntity mimeTypeContentEntity = repository.getRoot().getEntry( "mimetype" ); if ( mimeTypeContentEntity instanceof ContentItem ) { final ContentItem mimeTypeItem = (ContentItem) mimeTypeContentEntity; final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final InputStream in = mimeTypeItem.getInputStream(); try { IOUtils.getInstance().copyStreams( in, bout ); } finally { in.close(); } return bout.toString( "ASCII" ); } return null; } catch ( Exception e ) { return null; } }
final NameGenerator nameGenerator = getBodyNameGenerator(); final ContentItem contentItem = contentLocation.createItem( nameGenerator.generateName( null, "text/xml" ) ); final OutputStream outputStream = contentItem.getOutputStream();
final InputStream inputStream = item.getInputStream(); try { IOUtils.getInstance().copyStreams( inputStream, outputStream );