1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.webdav;
21  
22  import com.liferay.portal.kernel.util.ContentTypes;
23  import com.liferay.portal.kernel.util.HttpUtil;
24  import com.liferay.portal.kernel.util.StringPool;
25  import com.liferay.portal.kernel.util.StringUtil;
26  import com.liferay.portal.kernel.util.Validator;
27  
28  import java.io.InputStream;
29  
30  import java.text.DateFormat;
31  import java.text.SimpleDateFormat;
32  
33  import java.util.Date;
34  import java.util.Locale;
35  
36  /**
37   * <a href="BaseResourceImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   * @author Alexander Chow
41   *
42   */
43  public class BaseResourceImpl implements Resource {
44  
45      public BaseResourceImpl(
46          String parentPath, long name, long displayName) {
47  
48          this(parentPath, String.valueOf(name), String.valueOf(displayName));
49      }
50  
51      public BaseResourceImpl(
52          String parentPath, long name, String displayName) {
53  
54          this(parentPath, String.valueOf(name), displayName);
55      }
56  
57      public BaseResourceImpl(
58          String parentPath, String name, String displayName) {
59  
60          this(parentPath, name, displayName, null, null);
61      }
62  
63      public BaseResourceImpl(
64          String parentPath, String name, String displayName, Date createDate,
65          Date modifiedDate) {
66  
67          this(parentPath, name, displayName, createDate, modifiedDate, 0);
68      }
69  
70      public BaseResourceImpl(
71          String parentPath, String name, String displayName, Date createDate,
72          Date modifiedDate, int size) {
73  
74          _href = parentPath;
75  
76          if (Validator.isNotNull(name)) {
77              _href += StringPool.SLASH + name;
78          }
79  
80          _href = StringUtil.replace(_href, StringPool.SLASH, _TEMP_SLASH);
81          _href = HttpUtil.encodeURL(_href, true);
82          _href = StringUtil.replace(_href, _TEMP_SLASH, StringPool.SLASH);
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 boolean isLocked() {
116         return false;
117     }
118 
119     public String getCreateDate() {
120         return _createDateFormatter.format(_createDate);
121     }
122 
123     public String getModifiedDate() {
124         return _modifiedDateFormatter.format(_modifiedDate);
125     }
126 
127     public int getSize() {
128         return _size;
129     }
130 
131     public Object getModel() {
132         return _model;
133     }
134 
135     public void setModel(Object model) {
136         _model = model;
137     }
138 
139     public String getClassName() {
140         return _className;
141     }
142 
143     public void setClassName(String className) {
144         _className = className;
145     }
146 
147     public long getPrimaryKey() {
148         return _primaryKey;
149     }
150 
151     public void setPrimaryKey(long primaryKey) {
152         _primaryKey = primaryKey;
153     }
154 
155     public String getContentType() {
156         return ContentTypes.HTTPD_UNIX_DIRECTORY;
157     }
158 
159     public InputStream getContentAsStream() throws WebDAVException {
160         return null;
161     }
162 
163     private static final String _TEMP_SLASH = "_LIFERAY_TEMP_SLASH_";
164 
165     private static DateFormat _createDateFormatter =
166         new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
167 
168     private static DateFormat _modifiedDateFormatter =
169         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
170 
171     private String _href;
172     private String _displayName;
173     private Date _createDate;
174     private Date _modifiedDate;
175     private int _size;
176     private Object _model;
177     private String _className;
178     private long _primaryKey = -1;
179 
180 }