001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.webdav;
016    
017    import com.liferay.portal.kernel.util.ContentTypes;
018    import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
019    import com.liferay.portal.kernel.util.HttpUtil;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.model.Lock;
023    
024    import java.io.InputStream;
025    
026    import java.text.Format;
027    
028    import java.util.Date;
029    import java.util.Locale;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Alexander Chow
034     */
035    public class BaseResourceImpl implements Resource {
036    
037            public BaseResourceImpl(
038                    String parentPath, long name, long displayName) {
039    
040                    this(parentPath, String.valueOf(name), String.valueOf(displayName));
041            }
042    
043            public BaseResourceImpl(
044                    String parentPath, long name, String displayName) {
045    
046                    this(parentPath, String.valueOf(name), displayName);
047            }
048    
049            public BaseResourceImpl(
050                    String parentPath, String name, String displayName) {
051    
052                    this(parentPath, name, displayName, null, null);
053            }
054    
055            public BaseResourceImpl(
056                    String parentPath, String name, String displayName, Date createDate,
057                    Date modifiedDate) {
058    
059                    this(parentPath, name, displayName, createDate, modifiedDate, 0);
060            }
061    
062            public BaseResourceImpl(
063                    String parentPath, String name, String displayName, Date createDate,
064                    Date modifiedDate, long size) {
065    
066                    _href = parentPath;
067    
068                    if (Validator.isNotNull(name)) {
069                            _href += StringPool.SLASH + name;
070                    }
071    
072                    _href = HttpUtil.encodePath(_href);
073    
074                    _displayName = displayName;
075    
076                    if (createDate == null) {
077                            _createDate = new Date();
078                    }
079                    else {
080                            _createDate = createDate;
081                    }
082    
083                    if (modifiedDate == null) {
084                            _modifiedDate = new Date();
085                    }
086                    else {
087                            _modifiedDate = _createDate;
088                    }
089    
090                    _size = size;
091            }
092    
093            public String getHREF() {
094                    return _href;
095            }
096    
097            public String getDisplayName() {
098                    return _displayName;
099            }
100    
101            public Lock getLock() {
102                    return null;
103            }
104    
105            public boolean isCollection() {
106                    return true;
107            }
108    
109            public boolean isLocked() {
110                    return false;
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 long 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            /**
154             * @throws WebDAVException
155             */
156            public InputStream getContentAsStream() throws WebDAVException {
157                    return null;
158            }
159    
160            private static Format _createDateFormatter =
161                    FastDateFormatFactoryUtil.getSimpleDateFormat(
162                            "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
163    
164            private static Format _modifiedDateFormatter =
165                    FastDateFormatFactoryUtil.getSimpleDateFormat(
166                            "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
167    
168            private String _href;
169            private String _displayName;
170            private Date _createDate;
171            private Date _modifiedDate;
172            private long _size;
173            private Object _model;
174            private String _className;
175            private long _primaryKey = -1;
176    
177    }