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