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