2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.kernel.webdav;
\r
17 import com.liferay.portal.kernel.util.ContentTypes;
\r
18 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
\r
19 import com.liferay.portal.kernel.util.HttpUtil;
\r
20 import com.liferay.portal.kernel.util.StringPool;
\r
21 import com.liferay.portal.kernel.util.Validator;
\r
22 import com.liferay.portal.model.Lock;
\r
24 import java.io.InputStream;
\r
26 import java.text.Format;
\r
28 import java.util.Date;
\r
29 import java.util.Locale;
\r
32 * @author Brian Wing Shun Chan
\r
33 * @author Alexander Chow
\r
35 public class BaseResourceImpl implements Resource {
\r
37 public BaseResourceImpl(String parentPath, long name, long displayName) {
\r
38 this(parentPath, String.valueOf(name), String.valueOf(displayName));
\r
41 public BaseResourceImpl(String parentPath, long name, String displayName) {
\r
42 this(parentPath, String.valueOf(name), displayName);
\r
45 public BaseResourceImpl(
\r
46 String parentPath, String name, String displayName) {
\r
48 this(parentPath, name, displayName, null, null);
\r
51 public BaseResourceImpl(
\r
52 String parentPath, String name, String displayName, Date createDate,
\r
53 Date modifiedDate) {
\r
55 this(parentPath, name, displayName, createDate, modifiedDate, 0);
\r
58 public BaseResourceImpl(
\r
59 String parentPath, String name, String displayName, Date createDate,
\r
60 Date modifiedDate, long size) {
\r
62 _href = HttpUtil.decodeURL(parentPath);
\r
64 if (Validator.isNotNull(name)) {
\r
65 _href += StringPool.SLASH + name;
\r
68 _href = HttpUtil.encodePath(_href);
\r
70 _displayName = displayName;
\r
72 if (createDate == null) {
\r
73 _createDate = new Date();
\r
76 _createDate = createDate;
\r
79 if (modifiedDate == null) {
\r
80 _modifiedDate = new Date();
\r
83 _modifiedDate = _createDate;
\r
89 public String getClassName() {
\r
93 @SuppressWarnings("unused")
\r
94 public InputStream getContentAsStream() throws WebDAVException {
\r
98 public String getContentType() {
\r
99 return ContentTypes.HTTPD_UNIX_DIRECTORY;
\r
102 public String getCreateDate() {
\r
103 return _createDateFormatter.format(_createDate);
\r
106 public String getDisplayName() {
\r
107 return _displayName;
\r
110 public String getHREF() {
\r
114 public Object getModel() {
\r
118 public String getModifiedDate() {
\r
119 return _modifiedDateFormatter.format(_modifiedDate);
\r
122 public long getPrimaryKey() {
\r
123 return _primaryKey;
\r
126 public long getSize() {
\r
130 public boolean isCollection() {
\r
134 public boolean isLocked() {
\r
135 return _lock != null;
\r
138 public void setClassName(String className) {
\r
139 _className = className;
\r
142 public void setModel(Object model) {
\r
146 public void setPrimaryKey(long primaryKey) {
\r
147 _primaryKey = primaryKey;
\r
150 public Lock getLock() {
\r
154 public void setLock(Lock lock) {
\r
158 private static Format _createDateFormatter =
\r
159 FastDateFormatFactoryUtil.getSimpleDateFormat(
\r
160 "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
\r
162 private static Format _modifiedDateFormatter =
\r
163 FastDateFormatFactoryUtil.getSimpleDateFormat(
\r
164 "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
\r
166 private String _className;
\r
167 private Date _createDate;
\r
168 private String _displayName;
\r
169 private String _href;
\r
170 private Object _model;
\r
171 private Date _modifiedDate;
\r
172 private long _primaryKey = -1;
\r
173 private long _size;
\r
174 private Lock _lock;
\r