1   /**
2    * Copyright (c) 2000-2008 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.StringPool;
27  import com.liferay.portal.kernel.util.StringUtil;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.util.HttpUtil;
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              name = HttpUtil.encodeURL(name);
81              name = StringUtil.replace(name, StringPool.PLUS, "%20");
82  
83              _href += StringPool.SLASH + name;
84          }
85  
86          _displayName = displayName;
87  
88          if (createDate == null) {
89              _createDate = new Date();
90          }
91          else {
92              _createDate = createDate;
93          }
94  
95          if (modifiedDate == null) {
96              _modifiedDate = new Date();
97          }
98          else {
99              _modifiedDate = _createDate;
100         }
101 
102         _size = size;
103     }
104 
105     public String getHREF() {
106         return _href;
107     }
108 
109     public String getDisplayName() {
110         return _displayName;
111     }
112 
113     public boolean isCollection() {
114         return true;
115     }
116 
117     public String getCreateDate() {
118         return _createDateFormatter.format(_createDate);
119     }
120 
121     public String getModifiedDate() {
122         return _modifiedDateFormatter.format(_modifiedDate);
123     }
124 
125     public int getSize() {
126         return _size;
127     }
128 
129     public Object getModel() {
130         return _model;
131     }
132 
133     public void setModel(Object model) {
134         _model = model;
135     }
136 
137     public String getClassName() {
138         return _className;
139     }
140 
141     public void setClassName(String className) {
142         _className = className;
143     }
144 
145     public long getPrimaryKey() {
146         return _primaryKey;
147     }
148 
149     public void setPrimaryKey(long primaryKey) {
150         _primaryKey = primaryKey;
151     }
152 
153     public String getContentType() {
154         return ContentTypes.HTTPD_UNIX_DIRECTORY;
155     }
156 
157     public InputStream getContentAsStream() throws WebDAVException {
158         return null;
159     }
160 
161     private static DateFormat _createDateFormatter =
162         new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
163 
164     private static DateFormat _modifiedDateFormatter =
165         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
166 
167     private String _href;
168     private String _displayName;
169     private Date _createDate;
170     private Date _modifiedDate;
171     private int _size;
172     private Object _model;
173     private String _className;
174     private long _primaryKey = -1;
175 
176 }