1
14
15 package com.liferay.portal.kernel.webdav;
16
17 import com.liferay.portal.kernel.util.ContentTypes;
18 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
19 import com.liferay.portal.kernel.util.HttpUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.Validator;
22
23 import java.io.InputStream;
24
25 import java.text.Format;
26
27 import java.util.Date;
28 import java.util.Locale;
29
30
36 public class BaseResourceImpl implements Resource {
37
38 public BaseResourceImpl(
39 String parentPath, long name, long displayName) {
40
41 this(parentPath, String.valueOf(name), String.valueOf(displayName));
42 }
43
44 public BaseResourceImpl(
45 String parentPath, long name, String displayName) {
46
47 this(parentPath, String.valueOf(name), displayName);
48 }
49
50 public BaseResourceImpl(
51 String parentPath, String name, String displayName) {
52
53 this(parentPath, name, displayName, null, null);
54 }
55
56 public BaseResourceImpl(
57 String parentPath, String name, String displayName, Date createDate,
58 Date modifiedDate) {
59
60 this(parentPath, name, displayName, createDate, modifiedDate, 0);
61 }
62
63 public BaseResourceImpl(
64 String parentPath, String name, String displayName, Date createDate,
65 Date modifiedDate, long size) {
66
67 _href = parentPath;
68
69 if (Validator.isNotNull(name)) {
70 _href += StringPool.SLASH + name;
71 }
72
73 _href = HttpUtil.encodePath(_href);
74
75 _displayName = displayName;
76
77 if (createDate == null) {
78 _createDate = new Date();
79 }
80 else {
81 _createDate = createDate;
82 }
83
84 if (modifiedDate == null) {
85 _modifiedDate = new Date();
86 }
87 else {
88 _modifiedDate = _createDate;
89 }
90
91 _size = size;
92 }
93
94 public String getHREF() {
95 return _href;
96 }
97
98 public String getDisplayName() {
99 return _displayName;
100 }
101
102 public boolean isCollection() {
103 return true;
104 }
105
106 public boolean isLocked() {
107 return false;
108 }
109
110 public String getCreateDate() {
111 return _createDateFormatter.format(_createDate);
112 }
113
114 public String getModifiedDate() {
115 return _modifiedDateFormatter.format(_modifiedDate);
116 }
117
118 public long getSize() {
119 return _size;
120 }
121
122 public Object getModel() {
123 return _model;
124 }
125
126 public void setModel(Object model) {
127 _model = model;
128 }
129
130 public String getClassName() {
131 return _className;
132 }
133
134 public void setClassName(String className) {
135 _className = className;
136 }
137
138 public long getPrimaryKey() {
139 return _primaryKey;
140 }
141
142 public void setPrimaryKey(long primaryKey) {
143 _primaryKey = primaryKey;
144 }
145
146 public String getContentType() {
147 return ContentTypes.HTTPD_UNIX_DIRECTORY;
148 }
149
150 @SuppressWarnings("unused")
151 public InputStream getContentAsStream() throws WebDAVException {
152 return null;
153 }
154
155 private static Format _createDateFormatter =
156 FastDateFormatFactoryUtil.getSimpleDateFormat(
157 "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
158
159 private static Format _modifiedDateFormatter =
160 FastDateFormatFactoryUtil.getSimpleDateFormat(
161 "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
162
163 private String _href;
164 private String _displayName;
165 private Date _createDate;
166 private Date _modifiedDate;
167 private long _size;
168 private Object _model;
169 private String _className;
170 private long _primaryKey = -1;
171
172 }