001 /** 002 * =========================================================== 003 * LibRepository : a free Java content repository access layer 004 * =========================================================== 005 * 006 * Project Info: http://jfreereport.pentaho.org/librepository/ 007 * 008 * (C) Copyright 2006, by Pentaho Corporation and Contributors. 009 * 010 * This library is free software; you can redistribute it and/or modify it under the terms 011 * of the GNU Lesser General Public License as published by the Free Software Foundation; 012 * either version 2.1 of the License, or (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public License along with this 019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307, USA. 021 * 022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 023 * in the United States and other countries.] 024 * 025 * ------------ 026 * ZipContentItem.java 027 * ------------ 028 * (C) Copyright 2006, by Pentaho Corporation. 029 */ 030 031 package org.jfree.repository.zipwriter; 032 033 import java.io.IOException; 034 import java.io.InputStream; 035 import java.io.OutputStream; 036 037 import org.jfree.repository.ContentIOException; 038 import org.jfree.repository.ContentItem; 039 import org.jfree.repository.ContentLocation; 040 import org.jfree.repository.Repository; 041 import org.jfree.repository.RepositoryUtilities; 042 043 /** 044 * Creation-Date: 01.12.2006, 21:23:25 045 * 046 * @author Thomas Morgner 047 */ 048 public class ZipContentItem implements ContentItem 049 { 050 private boolean newItem; 051 private String name; 052 private String contentId; 053 private ZipRepository repository; 054 private ZipContentLocation parent; 055 056 public ZipContentItem(final String name, 057 final ZipRepository repository, 058 final ZipContentLocation parent) 059 { 060 this.name = name; 061 this.repository = repository; 062 this.parent = parent; 063 this.contentId = RepositoryUtilities.buildName(this, "/"); 064 this.newItem = true; 065 } 066 067 public String getMimeType() throws ContentIOException 068 { 069 return getRepository().getMimeRegistry().getMimeType(this); 070 } 071 072 public OutputStream getOutputStream() throws ContentIOException, IOException 073 { 074 if (newItem == false) 075 { 076 throw new ContentIOException("This item is no longer writeable."); 077 } 078 newItem = false; 079 return new ZipEntryOutputStream(this); 080 } 081 082 public InputStream getInputStream() throws ContentIOException, IOException 083 { 084 throw new ContentIOException("This item is not readable."); 085 } 086 087 public boolean isReadable() 088 { 089 return false; 090 } 091 092 public boolean isWriteable() 093 { 094 return newItem; 095 } 096 097 public String getName() 098 { 099 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 }