001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.documentlibrary.model.impl;
022:
023: import com.liferay.portal.SystemException;
024: import com.liferay.portal.kernel.util.GetterUtil;
025: import com.liferay.portal.kernel.util.NullSafeProperties;
026: import com.liferay.portal.kernel.util.PropertiesUtil;
027: import com.liferay.portal.kernel.util.StringMaker;
028: import com.liferay.portal.kernel.util.StringPool;
029: import com.liferay.portal.util.PortalUtil;
030: import com.liferay.portlet.documentlibrary.model.DLFileEntry;
031: import com.liferay.portlet.documentlibrary.model.DLFolder;
032: import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
033: import com.liferay.util.FileUtil;
034:
035: import java.io.IOException;
036:
037: import java.util.Iterator;
038: import java.util.Map;
039: import java.util.Properties;
040:
041: import org.apache.commons.logging.Log;
042: import org.apache.commons.logging.LogFactory;
043:
044: /**
045: * <a href="DLFileEntryImpl.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Brian Wing Shun Chan
048: * @author Alexander Chow
049: *
050: */
051: public class DLFileEntryImpl extends DLFileEntryModelImpl implements
052: DLFileEntry {
053:
054: public static final double DEFAULT_VERSION = 1.0;
055:
056: public static final int DEFAULT_READ_COUNT = 0;
057:
058: public static String stripExtension(String name, String title) {
059: String extension = FileUtil.getExtension(name);
060:
061: if (extension == null) {
062: return title;
063: }
064:
065: int pos = title.toLowerCase().lastIndexOf(
066: StringPool.PERIOD + extension);
067:
068: if (pos > 0) {
069: title = title.substring(0, pos);
070: }
071:
072: return title;
073: }
074:
075: public DLFileEntryImpl() {
076: }
077:
078: public String getUserUuid() throws SystemException {
079: return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
080: }
081:
082: public void setUserUuid(String userUuid) {
083: _userUuid = userUuid;
084: }
085:
086: public DLFolder getFolder() {
087: DLFolder folder = null;
088:
089: try {
090: folder = DLFolderLocalServiceUtil.getFolder(getFolderId());
091: } catch (Exception e) {
092: folder = new DLFolderImpl();
093:
094: _log.error(e);
095: }
096:
097: return folder;
098: }
099:
100: public String getTitleWithExtension() {
101: StringMaker sm = new StringMaker();
102:
103: sm.append(getTitle());
104: sm.append(StringPool.PERIOD);
105: sm.append(FileUtil.getExtension(getName()));
106:
107: return sm.toString();
108: }
109:
110: public String getExtraSettings() {
111: if (_extraSettingsProperties == null) {
112: return super .getExtraSettings();
113: } else {
114: return PropertiesUtil.toString(_extraSettingsProperties);
115: }
116: }
117:
118: public void setExtraSettings(String extraSettings) {
119: _extraSettingsProperties = null;
120:
121: super .setExtraSettings(extraSettings);
122: }
123:
124: public Properties getExtraSettingsProperties() {
125: if (_extraSettingsProperties == null) {
126: _extraSettingsProperties = new NullSafeProperties();
127:
128: try {
129: PropertiesUtil.load(_extraSettingsProperties, super
130: .getExtraSettings());
131: } catch (IOException ioe) {
132: _log.error(ioe);
133: }
134: }
135:
136: return _extraSettingsProperties;
137: }
138:
139: public void setExtraSettingsProperties(
140: Properties extraSettingsProperties) {
141: _extraSettingsProperties = extraSettingsProperties;
142:
143: super .setExtraSettings(PropertiesUtil
144: .toString(_extraSettingsProperties));
145: }
146:
147: public String getLuceneProperties() {
148: StringMaker sm = new StringMaker();
149:
150: sm.append(getTitle());
151: sm.append(StringPool.SPACE);
152: sm.append(getDescription());
153: sm.append(StringPool.SPACE);
154:
155: Properties extraSettingsProps = getExtraSettingsProperties();
156:
157: Iterator itr = (Iterator) extraSettingsProps.entrySet()
158: .iterator();
159:
160: while (itr.hasNext()) {
161: Map.Entry entry = (Map.Entry) itr.next();
162:
163: String value = GetterUtil.getString((String) entry
164: .getValue());
165:
166: sm.append(value);
167: }
168:
169: return sm.toString();
170: }
171:
172: private static Log _log = LogFactory.getLog(DLFileEntryImpl.class);
173:
174: private Properties _extraSettingsProperties = null;
175: private String _userUuid;
176:
177: }
|