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.Validator;
22 import com.liferay.portal.model.Lock;
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 = HttpUtil.encodePath(_href);
75
76 _displayName = displayName;
77
78 if (createDate == null) {
79 _createDate = new Date();
80 }
81 else {
82 _createDate = createDate;
83 }
84
85 if (modifiedDate == null) {
86 _modifiedDate = new Date();
87 }
88 else {
89 _modifiedDate = _createDate;
90 }
91
92 _size = size;
93 }
94
95 public String getHREF() {
96 return _href;
97 }
98
99 public String getDisplayName() {
100 return _displayName;
101 }
102
103 public Lock getLock() {
104 return null;
105 }
106
107 public boolean isCollection() {
108 return true;
109 }
110
111 public boolean isLocked() {
112 return false;
113 }
114
115 public String getCreateDate() {
116 return _createDateFormatter.format(_createDate);
117 }
118
119 public String getModifiedDate() {
120 return _modifiedDateFormatter.format(_modifiedDate);
121 }
122
123 public int getSize() {
124 return _size;
125 }
126
127 public Object getModel() {
128 return _model;
129 }
130
131 public void setModel(Object model) {
132 _model = model;
133 }
134
135 public String getClassName() {
136 return _className;
137 }
138
139 public void setClassName(String className) {
140 _className = className;
141 }
142
143 public long getPrimaryKey() {
144 return _primaryKey;
145 }
146
147 public void setPrimaryKey(long primaryKey) {
148 _primaryKey = primaryKey;
149 }
150
151 public String getContentType() {
152 return ContentTypes.HTTPD_UNIX_DIRECTORY;
153 }
154
155 @SuppressWarnings("unused")
156 public InputStream getContentAsStream() throws WebDAVException {
157 return null;
158 }
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 }