Source for org.jfree.repository.zipwriter.ZipContentItem

   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:  * ZipContentItem.java
  27:  * ------------
  28:  * (C) Copyright 2006, by Pentaho Corporation.
  29:  */
  30: 
  31: package org.jfree.repository.zipwriter;
  32: 
  33: import java.io.IOException;
  34: import java.io.InputStream;
  35: import java.io.OutputStream;
  36: 
  37: import org.jfree.repository.ContentIOException;
  38: import org.jfree.repository.ContentItem;
  39: import org.jfree.repository.ContentLocation;
  40: import org.jfree.repository.Repository;
  41: import org.jfree.repository.RepositoryUtilities;
  42: 
  43: /**
  44:  * Creation-Date: 01.12.2006, 21:23:25
  45:  *
  46:  * @author Thomas Morgner
  47:  */
  48: public class ZipContentItem implements ContentItem
  49: {
  50:   private boolean newItem;
  51:   private String name;
  52:   private String contentId;
  53:   private ZipRepository repository;
  54:   private ZipContentLocation parent;
  55: 
  56:   public ZipContentItem(final String name,
  57:                         final ZipRepository repository,
  58:                         final ZipContentLocation parent)
  59:   {
  60:     this.name = name;
  61:     this.repository = repository;
  62:     this.parent = parent;
  63:     this.contentId = RepositoryUtilities.buildName(this, "/");
  64:     this.newItem = true;
  65:   }
  66: 
  67:   public String getMimeType() throws ContentIOException
  68:   {
  69:     return getRepository().getMimeRegistry().getMimeType(this);
  70:   }
  71: 
  72:   public OutputStream getOutputStream() throws ContentIOException, IOException
  73:   {
  74:     if (newItem == false)
  75:     {
  76:       throw new ContentIOException("This item is no longer writeable.");
  77:     }
  78:     newItem = false;
  79:     return new ZipEntryOutputStream(this);
  80:   }
  81: 
  82:   public InputStream getInputStream() throws ContentIOException, IOException
  83:   {
  84:     throw new ContentIOException("This item is not readable.");
  85:   }
  86: 
  87:   public boolean isReadable()
  88:   {
  89:     return false;
  90:   }
  91: 
  92:   public boolean isWriteable()
  93:   {
  94:     return newItem;
  95:   }
  96: 
  97:   public String getName()
  98:   {
  99:     return name;
 100:   }
 101: 
 102:   public Object getContentId()
 103:   {
 104:     return contentId;
 105:   }
 106: 
 107:   public Object getAttribute(final String domain, final String key)
 108:   {
 109:     return null;
 110:   }
 111: 
 112:   public boolean setAttribute(final String domain, final String key, final Object value)
 113:   {
 114:     return false;
 115:   }
 116: 
 117:   public Repository getRepository()
 118:   {
 119:     return repository;
 120:   }
 121: 
 122:   public ContentLocation getParent()
 123:   {
 124:     return parent;
 125:   }
 126: 
 127:   public boolean delete()
 128:   {
 129:     return false;
 130:   }
 131: }