001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.webdav;
022:
023: import com.liferay.portal.kernel.util.ContentTypes;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.util.HttpUtil;
028:
029: import java.io.InputStream;
030:
031: import java.text.DateFormat;
032: import java.text.SimpleDateFormat;
033:
034: import java.util.Date;
035: import java.util.Locale;
036:
037: /**
038: * <a href="BaseResourceImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: * @author Alexander Chow
042: *
043: */
044: public class BaseResourceImpl implements Resource {
045:
046: public BaseResourceImpl(String parentPath, long name,
047: long displayName) {
048:
049: this (parentPath, String.valueOf(name), String
050: .valueOf(displayName));
051: }
052:
053: public BaseResourceImpl(String parentPath, long name,
054: String displayName) {
055:
056: this (parentPath, String.valueOf(name), displayName);
057: }
058:
059: public BaseResourceImpl(String parentPath, String name,
060: String displayName) {
061:
062: this (parentPath, name, displayName, null, null);
063: }
064:
065: public BaseResourceImpl(String parentPath, String name,
066: String displayName, Date createDate, Date modifiedDate) {
067:
068: this (parentPath, name, displayName, createDate, modifiedDate, 0);
069: }
070:
071: public BaseResourceImpl(String parentPath, String name,
072: String displayName, Date createDate, Date modifiedDate,
073: int size) {
074:
075: _href = parentPath;
076:
077: if (Validator.isNotNull(name)) {
078: name = HttpUtil.encodeURL(name);
079: name = StringUtil.replace(name, StringPool.PLUS, "%20");
080:
081: _href += StringPool.SLASH + name;
082: }
083:
084: _displayName = displayName;
085:
086: if (createDate == null) {
087: _createDate = new Date();
088: } else {
089: _createDate = createDate;
090: }
091:
092: if (modifiedDate == null) {
093: _modifiedDate = new Date();
094: } else {
095: _modifiedDate = _createDate;
096: }
097:
098: _size = size;
099: }
100:
101: public String getHREF() {
102: return _href;
103: }
104:
105: public String getDisplayName() {
106: return _displayName;
107: }
108:
109: public boolean isCollection() {
110: return true;
111: }
112:
113: public String getCreateDate() {
114: return _createDateFormatter.format(_createDate);
115: }
116:
117: public String getModifiedDate() {
118: return _modifiedDateFormatter.format(_modifiedDate);
119: }
120:
121: public int getSize() {
122: return _size;
123: }
124:
125: public Object getModel() {
126: return _model;
127: }
128:
129: public void setModel(Object model) {
130: _model = model;
131: }
132:
133: public String getClassName() {
134: return _className;
135: }
136:
137: public void setClassName(String className) {
138: _className = className;
139: }
140:
141: public long getPrimaryKey() {
142: return _primaryKey;
143: }
144:
145: public void setPrimaryKey(long primaryKey) {
146: _primaryKey = primaryKey;
147: }
148:
149: public String getContentType() {
150: return ContentTypes.HTTPD_UNIX_DIRECTORY;
151: }
152:
153: public InputStream getContentAsStream() throws WebDAVException {
154: return null;
155: }
156:
157: private static DateFormat _createDateFormatter = new SimpleDateFormat(
158: "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
159:
160: private static DateFormat _modifiedDateFormatter = new SimpleDateFormat(
161: "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
162:
163: private String _href;
164: private String _displayName;
165: private Date _createDate;
166: private Date _modifiedDate;
167: private int _size;
168: private Object _model;
169: private String _className;
170: private long _primaryKey = -1;
171:
172: }
|