Source for org.jfree.repository.stream.StreamContentItem

   1: /**
   2:  * ===========================================================
   3:  * LibRepository : a free Java content repository access layer
   4:  * ===========================================================
   5:  *
   6:  * Project Info:  http://jfreereport.pentaho.org/librepository/
   7:  *
   8:  * (C) Copyright 2006, by Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * StreamContentItem.java
  27:  * ------------
  28:  * (C) Copyright 2006, by Pentaho Corporation.
  29:  */
  30: 
  31: package org.jfree.repository.stream;
  32: 
  33: import java.io.OutputStream;
  34: import java.io.IOException;
  35: import java.io.InputStream;
  36: 
  37: import org.jfree.repository.ContentItem;
  38: import org.jfree.repository.ContentLocation;
  39: import org.jfree.repository.ContentIOException;
  40: import org.jfree.repository.Repository;
  41: 
  42: /**
  43:  * Creation-Date: 13.11.2006, 17:27:04
  44:  *
  45:  * @author Thomas Morgner
  46:  */
  47: public class StreamContentItem implements ContentItem
  48: {
  49:   private WrappedInputStream inputStream;
  50:   private WrappedOutputStream outputStream;
  51:   private ContentLocation parent;
  52:   private String name;
  53: 
  54:   public StreamContentItem(final String name,
  55:                            final ContentLocation parent,
  56:                            final WrappedInputStream inputStream,
  57:                            final WrappedOutputStream outputStream)
  58:   {
  59:     this.name = name;
  60:     this.parent = parent;
  61:     this.inputStream = inputStream;
  62:     this.outputStream = outputStream;
  63:   }
  64: 
  65:   public boolean isReadable()
  66:   {
  67:     if (inputStream == null)
  68:     {
  69:       return false;
  70:     }
  71:     return inputStream.isClosed() == false;
  72:   }
  73: 
  74:   public boolean isWriteable()
  75:   {
  76:     if (outputStream == null)
  77:     {
  78:       return false;
  79:     }
  80:     return outputStream.isClosed() == false;
  81:   }
  82: 
  83:   public String getMimeType() throws ContentIOException
  84:   {
  85:     return getRepository().getMimeRegistry().getMimeType(this);
  86:   }
  87: 
  88:   public OutputStream getOutputStream() throws ContentIOException, IOException
  89:   {
  90:     return outputStream;
  91:   }
  92: 
  93:   public InputStream getInputStream() throws ContentIOException, IOException
  94:   {
  95:     return inputStream;
  96:   }
  97: 
  98:   public String getName()
  99:   {
 100:     return name;
 101:   }
 102: 
 103:   public Object getContentId()
 104:   {
 105:     return name;
 106:   }
 107: 
 108:   public Object getAttribute(final String domain, final String key)
 109:   {
 110:     return null;
 111:   }
 112: 
 113:   public boolean setAttribute(final String domain, final String key, final Object value)
 114:   {
 115:     return false;
 116:   }
 117: 
 118:   public ContentLocation getParent()
 119:   {
 120:     return parent;
 121:   }
 122: 
 123:   public Repository getRepository()
 124:   {
 125:     return parent.getRepository();
 126:   }
 127: 
 128:   public boolean delete()
 129:   {
 130:     return false;
 131:   }
 132: }