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