View Javadoc
1   //
2   // $Id$
3   //
4   // jupload - A file upload applet.
5   //
6   // Copyright 2010 The JUpload Team
7   //
8   // Created: 5 fevr. 2010
9   // Creator: etienne_sf
10  // Last modified: $Date$
11  //
12  // This program is free software; you can redistribute it and/or modify
13  // it under the terms of the GNU General Public License as published by
14  // the Free Software Foundation; either version 2 of the License, or
15  // (at your option) any later version.
16  //
17  // This program is distributed in the hope that it will be useful,
18  // but WITHOUT ANY WARRANTY; without even the implied warranty of
19  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  // GNU General Public License for more details.
21  //
22  // You should have received a copy of the GNU General Public License
23  // along with this program; if not, write to the Free Software
24  // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  
26  package wjhk.jupload2.testhelpers;
27  
28  import java.io.ByteArrayInputStream;
29  import java.io.File;
30  import java.io.InputStream;
31  import java.util.Date;
32  
33  import wjhk.jupload2.exception.JUploadException;
34  import wjhk.jupload2.exception.JUploadIOException;
35  import wjhk.jupload2.filedata.DefaultFileData;
36  import wjhk.jupload2.gui.filepanel.treeview.TreeFileDataNode;
37  import wjhk.jupload2.policies.UploadPolicy;
38  import wjhk.jupload2.upload.AbstractJUploadTestHelper;
39  import wjhk.jupload2.upload.helper.ByteArrayEncoder;
40  
41  /**
42   * @author etienne_sf
43   */
44  public class FileDataTestHelper extends DefaultFileData {
45  
46      public final static String FILE_CONTENT_PREFIX = "This is the file content for the file number ";
47  
48      /**	 */
49      public static String RELATIVE_DIR = File.separator + "files";
50  
51      /** */
52      public String fileName;
53  
54      /** */
55      // public File file;
56  
57      /** */
58      public int fileNumber;
59  
60      /** */
61      public String fileContent;
62  
63      /** */
64      public static String FILE_EXTENSION = "txt";
65  
66      /** */
67      public String md5sum = null;
68  
69      /** */
70      public String mimeType = "text/plain";
71  
72      /** */
73      public Date lastModified = new Date();
74  
75      /** */
76      public boolean preparedForUpload = true;
77  
78      /** */
79      public boolean uploadFlag = true;
80  
81      /**
82       * @param fileNumber
83       */
84      public FileDataTestHelper(int fileNumber, UploadPolicy uploadPolicy) {
85          super(AbstractJUploadTestHelper.getTestFile(RELATIVE_DIR + File.separator + fileNumber + "." + FILE_EXTENSION),
86                  uploadPolicy);
87          this.fileNumber = fileNumber;
88          this.fileName = fileNumber + "." + FILE_EXTENSION;
89          this.fileContent = FILE_CONTENT_PREFIX + fileNumber;
90      }
91  
92      /** */
93      public void afterUpload() {
94          // No action
95      }
96  
97      /**
98       * @param bae
99       * @param index
100      * @throws JUploadIOException
101      */
102     public void appendFileProperties(ByteArrayEncoder bae, int index) throws JUploadIOException {
103         throw new UnsupportedOperationException(this.getClass()
104                 + ".appendFileProperties() is not implemented in tests cases");
105     }
106 
107     /**
108      * @throws JUploadException
109      */
110     public void beforeUpload(String root) throws JUploadException {
111         // No action
112     }
113 
114     /**
115      * @return canRead
116      */
117     public boolean canRead() {
118         return true;
119     }
120 
121     /**
122      * @return dir
123      */
124     public String getDirectory() {
125         return this.file.getParent();
126     }
127 
128     /**
129      * @return file
130      */
131     public File getFile() {
132         return this.file;
133     }
134 
135     /**
136      * @return extention
137      */
138     public String getFileExtension() {
139         return FILE_EXTENSION;
140     }
141 
142     /**
143      * @return length
144      */
145     public long getFileLength() {
146         return this.fileContent.length();
147     }
148 
149     /**
150      * @return filename
151      */
152     public String getFileName() {
153         return this.fileName;
154     }
155 
156     /**
157      * @return inputStream
158      * @throws JUploadException
159      */
160     public InputStream getInputStream() throws JUploadException {
161         return new ByteArrayInputStream(this.fileContent.getBytes());
162     }
163 
164     /**
165      * @return last modified
166      */
167     public Date getLastModified() {
168         return this.lastModified;
169     }
170 
171     /**
172      * @see wjhk.jupload2.filedata.FileData#getMD5()
173      */
174     public String getMD5() throws JUploadException {
175         return this.md5sum;
176     }
177 
178     /**
179      * @return mime type
180      */
181     public String getMimeType() {
182         return this.mimeType;
183     }
184 
185     /**
186      * @return rel dir
187      */
188     public String getRelativeDir() {
189         return RELATIVE_DIR;
190     }
191 
192     /**
193      * @return rel dir
194      */
195     public String getAbsolutePath() {
196         return this.file.getAbsolutePath();
197     }
198 
199     /**
200      * @return upload length
201      */
202     public long getUploadLength() {
203         return this.fileContent.length();
204     }
205 
206     /**
207      * @return is prepared
208      */
209     public boolean isPreparedForUpload() {
210         return this.preparedForUpload;
211     }
212 
213     public boolean getUploadFlag() {
214         return uploadFlag;
215     }
216 
217     public void setUploadFlag(boolean uploadFlag) {
218         this.uploadFlag = uploadFlag;
219     }
220 
221     public TreeFileDataNode getTreeFileDataNode() {
222         // TODO Auto-generated method stub
223         return null;
224     }
225 
226     public void setTreeFileDataNode(TreeFileDataNode node) {
227         // TODO Auto-generated method stub
228 
229     }
230 
231 }