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 getHREF() {
090 return _href;
091 }
092
093 public String getDisplayName() {
094 return _displayName;
095 }
096
097 public Lock getLock() {
098 return null;
099 }
100
101 public boolean isCollection() {
102 return true;
103 }
104
105 public boolean isLocked() {
106 return false;
107 }
108
109 public String getCreateDate() {
110 return _createDateFormatter.format(_createDate);
111 }
112
113 public String getModifiedDate() {
114 return _modifiedDateFormatter.format(_modifiedDate);
115 }
116
117 public long getSize() {
118 return _size;
119 }
120
121 public Object getModel() {
122 return _model;
123 }
124
125 public void setModel(Object model) {
126 _model = model;
127 }
128
129 public String getClassName() {
130 return _className;
131 }
132
133 public void setClassName(String className) {
134 _className = className;
135 }
136
137 public long getPrimaryKey() {
138 return _primaryKey;
139 }
140
141 public void setPrimaryKey(long primaryKey) {
142 _primaryKey = primaryKey;
143 }
144
145 public String getContentType() {
146 return ContentTypes.HTTPD_UNIX_DIRECTORY;
147 }
148
149 @SuppressWarnings("unused")
150 public InputStream getContentAsStream() throws WebDAVException {
151 return null;
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 _href;
163 private String _displayName;
164 private Date _createDate;
165 private Date _modifiedDate;
166 private long _size;
167 private Object _model;
168 private String _className;
169 private long _primaryKey = -1;
170
171 }