1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.StringUtil;
29  import com.liferay.portal.kernel.util.Validator;
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  /**
40   * <a href="BaseResourceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   * @author Alexander Chow
44   *
45   */
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              _href += StringPool.SLASH + name;
81          }
82  
83          _href = StringUtil.replace(_href, StringPool.SLASH, _TEMP_SLASH);
84          _href = HttpUtil.encodeURL(_href, true);
85          _href = StringUtil.replace(_href, _TEMP_SLASH, StringPool.SLASH);
86  
87          _displayName = displayName;
88  
89          if (createDate == null) {
90              _createDate = new Date();
91          }
92          else {
93              _createDate = createDate;
94          }
95  
96          if (modifiedDate == null) {
97              _modifiedDate = new Date();
98          }
99          else {
100             _modifiedDate = _createDate;
101         }
102 
103         _size = size;
104     }
105 
106     public String getHREF() {
107         return _href;
108     }
109 
110     public String getDisplayName() {
111         return _displayName;
112     }
113 
114     public boolean isCollection() {
115         return true;
116     }
117 
118     public boolean isLocked() {
119         return false;
120     }
121 
122     public String getCreateDate() {
123         return _createDateFormatter.format(_createDate);
124     }
125 
126     public String getModifiedDate() {
127         return _modifiedDateFormatter.format(_modifiedDate);
128     }
129 
130     public int getSize() {
131         return _size;
132     }
133 
134     public Object getModel() {
135         return _model;
136     }
137 
138     public void setModel(Object model) {
139         _model = model;
140     }
141 
142     public String getClassName() {
143         return _className;
144     }
145 
146     public void setClassName(String className) {
147         _className = className;
148     }
149 
150     public long getPrimaryKey() {
151         return _primaryKey;
152     }
153 
154     public void setPrimaryKey(long primaryKey) {
155         _primaryKey = primaryKey;
156     }
157 
158     public String getContentType() {
159         return ContentTypes.HTTPD_UNIX_DIRECTORY;
160     }
161 
162     public InputStream getContentAsStream() throws WebDAVException {
163         return null;
164     }
165 
166     private static final String _TEMP_SLASH = "_LIFERAY_TEMP_SLASH_";
167 
168     private static DateFormat _createDateFormatter =
169         new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
170 
171     private static DateFormat _modifiedDateFormatter =
172         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
173 
174     private String _href;
175     private String _displayName;
176     private Date _createDate;
177     private Date _modifiedDate;
178     private int _size;
179     private Object _model;
180     private String _className;
181     private long _primaryKey = -1;
182 
183 }