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