1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.cms.core;
17
18 import java.text.ParseException;
19 import java.text.SimpleDateFormat;
20 import java.util.Date;
21 import java.util.Properties;
22 import java.util.TimeZone;
23
24 import com.isenshi.util.CharUtil;
25
26 /***
27 * @author nishioka
28 */
29 public class ResourceImpl implements Resource, Cloneable{
30
31 private String path;
32
33 private String siteName;
34
35 private String creationUser;
36
37 private String creationDate;
38
39 private String modificationUser;
40
41 private String modificationDate;
42
43 private int contentLength;
44
45 private String contentType;
46
47 private boolean folder = false;
48
49 private boolean persistent = true;
50
51 private volatile int hashCode = 0;
52
53 private String version;
54
55 private Properties properties;
56
57 /***
58 * From NodeRevisionDescriptor source, this format is copied. Because access
59 * to "creationDateFormat" is restricted within protected scope. It is
60 * exposed to the danger of change of format of slide itself.
61 */
62 public static final SimpleDateFormat CREATIONDATE_FORMAT = new SimpleDateFormat(
63 "yyyy-MM-dd'T'HH:mm:ss'Z'");
64 static {
65 CREATIONDATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
66 }
67
68 public ResourceImpl(String siteName, String path, String contentType){
69 this(siteName,path,contentType,false);
70 }
71
72 public ResourceImpl(String siteName, String path, String contentType, boolean folder){
73 this.siteName = siteName;
74 this.path = CharUtil.charpop(path, '/');
75 this.path = CharUtil.chartrim(this.path,'/');
76 this.contentType = contentType;
77 this.folder = folder;
78 if(folder){
79 this.path = this.path + "/";
80 }
81 }
82
83 public String getContentType() {
84 return contentType;
85 }
86
87 public void setContentType(String contentType) {
88 this.contentType = contentType;
89 }
90
91 public String getCreationDate() {
92 Date date = getCreationDateAsDate();
93 return (date == null) ? creationDate: CmsConstants.DATEFORMAT.format(date);
94 }
95
96 public Date getCreationDateAsDate(){
97 Date date = null;
98 if(creationDate != null){
99 try {
100 date = CREATIONDATE_FORMAT.parse(creationDate);
101
102 } catch (ParseException pe) {
103
104 }catch(NumberFormatException e){
105
106 }
107 }
108 return date;
109 }
110
111 public void setCreationDate(String creationDate) {
112 this.creationDate = creationDate;
113 }
114
115 public String getCreationUser() {
116 return creationUser;
117 }
118
119 public void setCreationUser(String creationUser) {
120 this.creationUser = creationUser;
121 }
122
123 public boolean isFolder() {
124 return folder;
125 }
126
127 public void setFolder(boolean folder) {
128 this.folder = folder;
129 }
130
131 public boolean isFile(){
132 return !this.folder;
133 }
134
135 public String getModificationUser() {
136 return modificationUser;
137 }
138
139 public void setModificationUser(String modificationUser) {
140 this.modificationUser = modificationUser;
141 }
142
143 public String getModificationDate() {
144 Date date = getModificationDateAsDate();
145 return (date == null) ? modificationDate: CmsConstants.DATEFORMAT.format(date);
146 }
147
148 public Date getModificationDateAsDate() {
149 Date date = null;
150 if(modificationDate != null){
151 try {
152 date = CREATIONDATE_FORMAT.parse(modificationDate);
153 } catch (ParseException pe) {
154
155 }catch(NumberFormatException e){
156
157 }
158 }
159 return date;
160 }
161
162 public void setModificationDate(String modificationDate) {
163 this.modificationDate = modificationDate;
164 }
165
166 public String getPath() {
167 return path;
168 }
169
170 public void setPath(String path) {
171 this.path = path;
172 }
173
174 public String getSiteName() {
175 return siteName;
176 }
177
178 public void setSiteName(String siteName) {
179 this.siteName = siteName;
180 }
181
182 public String getParentPath(){
183 int idx = CharUtil.chartrim(path, '/').lastIndexOf('/');
184 return (idx != -1)? path.substring(0, idx): "" ;
185 }
186
187 public String getPageName(){
188 String[] names = path.split("/");
189 return names[names.length-1];
190 }
191
192 public boolean isPersistent() {
193 return persistent;
194 }
195
196 public void setPersistent(boolean persistent) {
197 this.persistent = persistent;
198 }
199
200 public void setVersion(String version) {
201 this.version = version;
202 }
203
204 public String getVersion() {
205 return version;
206 }
207
208 public int getContentLength() {
209 return contentLength;
210 }
211
212 public void setContentLength(int contentLength) {
213 this.contentLength = contentLength;
214 }
215
216 public void setProperties(Properties properties) {
217 this.properties = properties;
218 }
219
220 public Properties getProperties() {
221 return properties;
222 }
223
224 public String getProperty(String key){
225 if(properties == null) return null;
226 return properties.getProperty(key);
227 }
228
229 public boolean equals(Object obj) {
230 if (obj == this)
231 return true;
232 if (!(obj instanceof ResourceImpl))
233 return false;
234
235 ResourceImpl o = (ResourceImpl)obj;
236 return this.path.equals(o.path) && this.siteName.equals(o.siteName);
237 }
238
239 public int hashCode() {
240
241 int seed = 17;
242 int weight = 37;
243
244 if (this.hashCode == 0) {
245 this.hashCode = seed;
246 this.hashCode += weight * this.path.hashCode();
247 this.hashCode += weight * this.siteName.hashCode();
248 }
249 return this.hashCode;
250 }
251
252 public Resource getClone(){
253 try {
254 return (Resource) super.clone();
255 } catch (CloneNotSupportedException e) {
256 e.printStackTrace();
257 return null;
258 }
259 }
260 }