001    /**
002     * Copyright (c) 2000-2011 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.portlet.documentlibrary.webdav;
016    
017    import com.liferay.portal.kernel.repository.model.FileEntry;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.webdav.BaseResourceImpl;
020    import com.liferay.portal.kernel.webdav.WebDAVException;
021    import com.liferay.portal.kernel.webdav.WebDAVRequest;
022    import com.liferay.portal.model.Lock;
023    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
024    
025    import java.io.InputStream;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class DLFileEntryResourceImpl extends BaseResourceImpl {
031    
032            public DLFileEntryResourceImpl(
033                    WebDAVRequest webDavRequest, FileEntry fileEntry, String parentPath,
034                    String name) {
035    
036                    super(
037                            parentPath, name, fileEntry.getTitle(), fileEntry.getCreateDate(),
038                            fileEntry.getModifiedDate(), fileEntry.getSize());
039    
040                    setModel(fileEntry);
041                    setClassName(DLFileEntry.class.getName());
042                    setPrimaryKey(fileEntry.getPrimaryKey());
043    
044                    //_webDavRequest = webDavRequest;
045                    _fileEntry = fileEntry;
046            }
047    
048            @Override
049            public boolean isCollection() {
050                    return false;
051            }
052    
053            @Override
054            public Lock getLock() {
055                    try {
056                            return _fileEntry.getLock();
057                    }
058                    catch (Exception e) {
059                    }
060    
061                    return null;
062            }
063    
064            @Override
065            public boolean isLocked() {
066                    try {
067                            return _fileEntry.hasLock();
068                    }
069                    catch (Exception e) {
070                    }
071    
072                    return false;
073            }
074    
075            @Override
076            public String getContentType() {
077                    return _fileEntry.getMimeType();
078            }
079    
080            @Override
081            public InputStream getContentAsStream() throws WebDAVException {
082                    try {
083                            String version = StringPool.BLANK;
084    
085                            return _fileEntry.getContentStream(version);
086                    }
087                    catch (Exception e) {
088                            throw new WebDAVException(e);
089                    }
090            }
091    
092            private FileEntry _fileEntry;
093    
094    }