001
014
015 package com.liferay.portlet.documentlibrary.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.util.UnicodeProperties;
022 import com.liferay.portal.security.auth.PrincipalThreadLocal;
023 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
024 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
025 import com.liferay.portlet.documentlibrary.model.DLFolder;
026 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
027 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
028 import com.liferay.portlet.documentlibrary.util.DLUtil;
029 import com.liferay.portlet.expando.model.ExpandoBridge;
030 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031
032 import java.io.IOException;
033 import java.io.InputStream;
034
035
039 public class DLFileVersionImpl extends DLFileVersionBaseImpl {
040
041 public DLFileVersionImpl() {
042 }
043
044 @Override
045 public InputStream getContentStream(boolean incrementCounter)
046 throws PortalException, SystemException {
047
048 return DLFileEntryLocalServiceUtil.getFileAsStream(
049 PrincipalThreadLocal.getUserId(), getFileEntryId(), getVersion(),
050 incrementCounter);
051 }
052
053 @Override
054 public ExpandoBridge getExpandoBridge() {
055 if (_expandoBridge == null) {
056 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(
057 getCompanyId(), DLFileEntry.class.getName(), getPrimaryKey());
058 }
059
060 return _expandoBridge;
061 }
062
063 @Override
064 public String getExtraSettings() {
065 if (_extraSettingsProperties == null) {
066 return super.getExtraSettings();
067 }
068 else {
069 return _extraSettingsProperties.toString();
070 }
071 }
072
073 @Override
074 public UnicodeProperties getExtraSettingsProperties() {
075 if (_extraSettingsProperties == null) {
076 _extraSettingsProperties = new UnicodeProperties(true);
077
078 try {
079 _extraSettingsProperties.load(super.getExtraSettings());
080 }
081 catch (IOException ioe) {
082 _log.error(ioe, ioe);
083 }
084 }
085
086 return _extraSettingsProperties;
087 }
088
089 @Override
090 public DLFileEntry getFileEntry() throws PortalException, SystemException {
091 return DLFileEntryLocalServiceUtil.getFileEntry(getFileEntryId());
092 }
093
094 @Override
095 public DLFolder getFolder() throws PortalException, SystemException {
096 if (getFolderId() <= 0) {
097 return new DLFolderImpl();
098 }
099
100 return DLFolderLocalServiceUtil.getFolder(getFolderId());
101 }
102
103 @Override
104 public String getIcon() {
105 return DLUtil.getFileIcon(getExtension());
106 }
107
108 @Override
109 public DLFolder getTrashContainer()
110 throws PortalException, SystemException {
111
112 DLFolder dlFolder = null;
113
114 try {
115 dlFolder = getFolder();
116 }
117 catch (NoSuchFolderException nsfe) {
118 return null;
119 }
120
121 if (dlFolder.isInTrash()) {
122 return dlFolder;
123 }
124
125 return dlFolder.getTrashContainer();
126 }
127
128 @Override
129 public boolean isInTrashContainer()
130 throws PortalException, SystemException {
131
132 if (getTrashContainer() != null) {
133 return true;
134 }
135 else {
136 return false;
137 }
138 }
139
140 @Override
141 public void setExtraSettings(String extraSettings) {
142 _extraSettingsProperties = null;
143
144 super.setExtraSettings(extraSettings);
145 }
146
147 @Override
148 public void setExtraSettingsProperties(
149 UnicodeProperties extraSettingsProperties) {
150
151 _extraSettingsProperties = extraSettingsProperties;
152
153 super.setExtraSettings(_extraSettingsProperties.toString());
154 }
155
156 private static Log _log = LogFactoryUtil.getLog(DLFileVersionImpl.class);
157
158 private transient ExpandoBridge _expandoBridge;
159 private UnicodeProperties _extraSettingsProperties;
160
161 }