001
014
015 package com.liferay.portal.kernel.webdav;
016
017 import com.liferay.portal.kernel.util.ContentTypes;
018 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
019 import com.liferay.portal.kernel.util.HttpUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.Validator;
022
023 import java.io.InputStream;
024
025 import java.text.Format;
026
027 import java.util.Date;
028 import java.util.Locale;
029
030
034 public class BaseResourceImpl implements Resource {
035
036 public BaseResourceImpl(
037 String parentPath, long name, long displayName) {
038
039 this(parentPath, String.valueOf(name), String.valueOf(displayName));
040 }
041
042 public BaseResourceImpl(
043 String parentPath, long name, String displayName) {
044
045 this(parentPath, String.valueOf(name), displayName);
046 }
047
048 public BaseResourceImpl(
049 String parentPath, String name, String displayName) {
050
051 this(parentPath, name, displayName, null, null);
052 }
053
054 public BaseResourceImpl(
055 String parentPath, String name, String displayName, Date createDate,
056 Date modifiedDate) {
057
058 this(parentPath, name, displayName, createDate, modifiedDate, 0);
059 }
060
061 public BaseResourceImpl(
062 String parentPath, String name, String displayName, Date createDate,
063 Date modifiedDate, long size) {
064
065 _href = parentPath;
066
067 if (Validator.isNotNull(name)) {
068 _href += StringPool.SLASH + name;
069 }
070
071 _href = HttpUtil.encodePath(_href);
072
073 _displayName = displayName;
074
075 if (createDate == null) {
076 _createDate = new Date();
077 }
078 else {
079 _createDate = createDate;
080 }
081
082 if (modifiedDate == null) {
083 _modifiedDate = new Date();
084 }
085 else {
086 _modifiedDate = _createDate;
087 }
088
089 _size = size;
090 }
091
092 public String getHREF() {
093 return _href;
094 }
095
096 public String getDisplayName() {
097 return _displayName;
098 }
099
100 public boolean isCollection() {
101 return true;
102 }
103
104 public boolean isLocked() {
105 return false;
106 }
107
108 public String getCreateDate() {
109 return _createDateFormatter.format(_createDate);
110 }
111
112 public String getModifiedDate() {
113 return _modifiedDateFormatter.format(_modifiedDate);
114 }
115
116 public long getSize() {
117 return _size;
118 }
119
120 public Object getModel() {
121 return _model;
122 }
123
124 public void setModel(Object model) {
125 _model = model;
126 }
127
128 public String getClassName() {
129 return _className;
130 }
131
132 public void setClassName(String className) {
133 _className = className;
134 }
135
136 public long getPrimaryKey() {
137 return _primaryKey;
138 }
139
140 public void setPrimaryKey(long primaryKey) {
141 _primaryKey = primaryKey;
142 }
143
144 public String getContentType() {
145 return ContentTypes.HTTPD_UNIX_DIRECTORY;
146 }
147
148
151 public InputStream getContentAsStream() throws WebDAVException {
152 return null;
153 }
154
155 private static Format _createDateFormatter =
156 FastDateFormatFactoryUtil.getSimpleDateFormat(
157 "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
158
159 private static Format _modifiedDateFormatter =
160 FastDateFormatFactoryUtil.getSimpleDateFormat(
161 "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
162
163 private String _href;
164 private String _displayName;
165 private Date _createDate;
166 private Date _modifiedDate;
167 private long _size;
168 private Object _model;
169 private String _className;
170 private long _primaryKey = -1;
171
172 }