View Javadoc

1   package net.sourceforge.blogentis.slide;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: SlideMemoryFile.java,v 1.1 2004/10/22 17:34:16 tassos Exp $
23  //
24  
25  import java.io.ByteArrayInputStream;
26  import java.io.FileNotFoundException;
27  import java.io.InputStream;
28  import java.util.Date;
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  import net.sourceforge.blogentis.om.Blog;
33  import net.sourceforge.blogentis.storage.AbstractFileResource;
34  
35  /***
36   * A memory-based AbstractFileResource. It is mainly used for saving to the
37   * slide store.
38   * 
39   * @author abas
40   */
41  public class SlideMemoryFile
42          implements AbstractFileResource {
43      private byte[] byteSource = null;
44      private InputStream streamSource = null;
45      private int length = 0;
46      private String path;
47      private Blog blog;
48      private String mimeType = null;
49      private Date lastModified = null;
50      /* package */Map properties = new HashMap()/package-summary.html">class="comment"> package */Map properties = new HashMap();
51  
52      public SlideMemoryFile(Blog blog, String path) {
53          this.blog = blog;
54          this.path = path;
55      }
56  
57      public void setContents(byte[] contents) {
58          byteSource = contents;
59          streamSource = null;
60          length = contents.length;
61      }
62  
63      public void setContents(InputStream contents) {
64          byteSource = null;
65          streamSource = contents;
66          length = -1;
67      }
68  
69      public String getPath() {
70          return path;
71      }
72  
73      public boolean exists() {
74          return false;
75      }
76  
77      public int getSize() {
78          return length;
79      }
80  
81      public Date getLastModified() {
82          return lastModified;
83      }
84  
85      public String getMimeType() {
86          return mimeType;
87      }
88  
89      public InputStream getFileAsInputStream()
90              throws FileNotFoundException {
91          if (streamSource != null)
92              return streamSource;
93          if (byteSource != null)
94              return new ByteArrayInputStream(byteSource);
95          throw new FileNotFoundException("No input set!");
96      }
97  
98      public String getFileAsString()
99              throws FileNotFoundException {
100         return null;
101     }
102 
103     public Blog getBlog() {
104         return blog;
105     }
106 
107     public void setLastModified(Date lastModified) {
108         this.lastModified = lastModified;
109     }
110 
111     public void setMimeType(String mimeType) {
112         this.mimeType = mimeType;
113     }
114 
115     public boolean isOriginal() {
116         return false;
117     }
118 
119     public String getProperty(String propertyName) {
120         return (String)properties.get(propertyName);
121     }
122 
123     public void setProperty(String propertyName, String propertyContents) {
124         properties.put(propertyName, propertyContents);
125     }
126 
127     public boolean isDirectory() {
128         return false;
129     }
130 }