001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.context.helper;
016    
017    import com.liferay.portal.kernel.repository.model.FileVersion;
018    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
019    import com.liferay.portlet.documentlibrary.util.DLUtil;
020    
021    /**
022     * @author Iv??n Zaera
023     */
024    public class FileVersionDisplayContextHelper {
025    
026            public FileVersionDisplayContextHelper(FileVersion fileVersion) {
027                    _fileVersion = fileVersion;
028    
029                    if (_fileVersion == null) {
030                            _approved = false;
031                            _draft = false;
032                            _officeDoc = false;
033                            _pending = false;
034                    }
035            }
036    
037            public FileVersion getFileVersion() {
038                    return _fileVersion;
039            }
040    
041            public boolean isApproved() {
042                    if (_approved == null) {
043                            _approved = _fileVersion.isApproved();
044                    }
045    
046                    return _approved;
047            }
048    
049            public boolean isDLFileVersion() {
050                    if (_fileVersion.getModel() instanceof DLFileVersion) {
051                            return true;
052                    }
053    
054                    return false;
055            }
056    
057            public boolean isDraft() {
058                    if (_draft == null) {
059                            _draft = _fileVersion.isDraft();
060                    }
061    
062                    return _draft;
063            }
064    
065            public boolean isMsOffice() {
066                    if (_officeDoc == null) {
067                            _officeDoc = DLUtil.isOfficeExtension(_fileVersion.getExtension());
068                    }
069    
070                    return _officeDoc;
071            }
072    
073            public boolean isPending() {
074                    if (_pending == null) {
075                            _pending = _fileVersion.isPending();
076                    }
077    
078                    return _pending;
079            }
080    
081            private Boolean _approved;
082            private Boolean _draft;
083            private final FileVersion _fileVersion;
084            private Boolean _officeDoc;
085            private Boolean _pending;
086    
087    }