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  
27  import java.io.InputStream;
28  
29  import java.text.DateFormat;
30  import java.text.SimpleDateFormat;
31  
32  import java.util.Date;
33  import java.util.Locale;
34  
35  /**
36   * <a href="BaseResourceImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   * @author Alexander Chow
40   *
41   */
42  public class BaseResourceImpl implements Resource {
43  
44      public BaseResourceImpl(String href, String displayName) {
45          this(href, displayName, null, null);
46      }
47  
48      public BaseResourceImpl(
49          String href, String displayName, Date createDate, Date modifiedDate) {
50  
51          this(href, displayName, createDate, modifiedDate, 0);
52      }
53  
54      public BaseResourceImpl(
55          String href, String displayName, Date createDate, Date modifiedDate,
56          int size) {
57  
58          _href = href;
59          _displayName = displayName;
60  
61          if (createDate == null) {
62              _createDate = new Date();
63          }
64          else {
65              _createDate = createDate;
66          }
67  
68          if (modifiedDate == null) {
69              _modifiedDate = new Date();
70          }
71          else {
72              _modifiedDate = _createDate;
73          }
74  
75          _size = size;
76      }
77  
78      public String getHREF() {
79          return _href;
80      }
81  
82      public String getDisplayName() {
83          return _displayName;
84      }
85  
86      public boolean isCollection() {
87          return true;
88      }
89  
90      public String getCreateDate() {
91          return _createDateFormatter.format(_createDate);
92      }
93  
94      public String getModifiedDate() {
95          return _modifiedDateFormatter.format(_modifiedDate);
96      }
97  
98      public int getSize() {
99          return _size;
100     }
101 
102     public Object getModel() {
103         return _model;
104     }
105 
106     public void setModel(Object model) {
107         _model = model;
108     }
109 
110     public String getClassName() {
111         return _className;
112     }
113 
114     public void setClassName(String className) {
115         _className = className;
116     }
117 
118     public long getPrimaryKey() {
119         return _primaryKey;
120     }
121 
122     public void setPrimaryKey(long primaryKey) {
123         _primaryKey = primaryKey;
124     }
125 
126     public String getContentType() {
127         return ContentTypes.HTTPD_UNIX_DIRECTORY;
128     }
129 
130     public InputStream getContentAsStream() throws WebDAVException {
131         return null;
132     }
133 
134     private static DateFormat _createDateFormatter =
135         new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
136 
137     private static DateFormat _modifiedDateFormatter =
138         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
139 
140     private String _href;
141     private String _displayName;
142     private Date _createDate;
143     private Date _modifiedDate;
144     private int _size;
145     private Object _model;
146     private String _className;
147     private long _primaryKey = -1;
148 
149 }