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