KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jfm > FileWrapper


1 package de.jwi.jfm;
2
3 /*
4  * jFM - Java Web File Manager
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jFM.
9  *
10  * jFM is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jFM is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jFM; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25 import java.io.File JavaDoc;
26 import java.io.UnsupportedEncodingException JavaDoc;
27 import java.net.URLEncoder JavaDoc;
28 import java.text.DateFormat JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import org.apache.commons.io.FileUtils;
32
33 /**
34  * @author Jürgen Weber
35  * Source file created on 27.03.2004
36  */

37 public class FileWrapper
38 {
39
40     private Folder folder;
41
42     private File JavaDoc file;
43
44     private String JavaDoc url;
45
46     private String JavaDoc path;
47
48     private DateFormat JavaDoc dateFormat;
49
50     FileWrapper(Folder folder, File JavaDoc file, String JavaDoc url, String JavaDoc path)
51     {
52         this.folder = folder;
53         this.file = file;
54         this.url = url;
55         this.path = path;
56         dateFormat = DateFormat.getDateTimeInstance();
57     }
58
59     public File JavaDoc getFile()
60     {
61         return file;
62     }
63
64     public String JavaDoc getUrl()
65     {
66         return url;
67     }
68
69     public String JavaDoc getId()
70     {
71         String JavaDoc s = null;
72         try
73         {
74             s = URLEncoder.encode(file.getName() + "."
75                     + Long.toString(file.lastModified()), "UTF-8");
76         }
77         catch (UnsupportedEncodingException JavaDoc e)
78         {
79         }
80         return s;
81     }
82
83     public String JavaDoc getName()
84     {
85         return file.getName();
86     }
87
88     // return the virtual path
89
public String JavaDoc getPath()
90     {
91         return path;
92     }
93
94     public String JavaDoc toString()
95     {
96         return file.toString();
97     }
98
99     public String JavaDoc getSize()
100     {
101         long l;
102
103         l = file.length();
104
105         if (file.isDirectory() && folder.isCalcRecursiveFolderSize())
106         {
107             l = FileUtils.sizeOfDirectory(file);
108         }
109         return FileUtils.byteCountToDisplaySize(l);
110     }
111
112     public boolean getIsDirectory()
113     {
114         return file.isDirectory();
115     }
116
117     public boolean getIsZip()
118     {
119         if (file.isDirectory()) { return false; }
120         String JavaDoc s = file.getName().toLowerCase();
121
122         return s.endsWith(".zip");
123     }
124
125     public String JavaDoc getType()
126     {
127         return file.isDirectory() ? "dir" : "file";
128     }
129
130     public String JavaDoc getLastModified()
131     {
132         long l = file.lastModified();
133         String JavaDoc s = dateFormat.format(new Date JavaDoc(l));
134         return s;
135     }
136
137 }
Popular Tags