1
22
23 package com.liferay.portal.webdav;
24
25 import com.liferay.portal.kernel.util.ContentTypes;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.util.HttpUtil;
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 name = HttpUtil.encodeURL(name);
81 name = StringUtil.replace(name, StringPool.PLUS, "%20");
82
83 _href += StringPool.SLASH + name;
84 }
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 String getCreateDate() {
118 return _createDateFormatter.format(_createDate);
119 }
120
121 public String getModifiedDate() {
122 return _modifiedDateFormatter.format(_modifiedDate);
123 }
124
125 public int getSize() {
126 return _size;
127 }
128
129 public Object getModel() {
130 return _model;
131 }
132
133 public void setModel(Object model) {
134 _model = model;
135 }
136
137 public String getClassName() {
138 return _className;
139 }
140
141 public void setClassName(String className) {
142 _className = className;
143 }
144
145 public long getPrimaryKey() {
146 return _primaryKey;
147 }
148
149 public void setPrimaryKey(long primaryKey) {
150 _primaryKey = primaryKey;
151 }
152
153 public String getContentType() {
154 return ContentTypes.HTTPD_UNIX_DIRECTORY;
155 }
156
157 public InputStream getContentAsStream() throws WebDAVException {
158 return null;
159 }
160
161 private static DateFormat _createDateFormatter =
162 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
163
164 private static DateFormat _modifiedDateFormatter =
165 new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
166
167 private String _href;
168 private String _displayName;
169 private Date _createDate;
170 private Date _modifiedDate;
171 private int _size;
172 private Object _model;
173 private String _className;
174 private long _primaryKey = -1;
175
176 }