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.journal.model.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.LocaleUtil;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.model.Image;
029: import com.liferay.portal.service.ImageLocalServiceUtil;
030: import com.liferay.portal.util.PortalUtil;
031: import com.liferay.portal.util.PropsUtil;
032: import com.liferay.portlet.journal.model.JournalArticle;
033: import com.liferay.portlet.journal.util.LocaleTransformerListener;
034: import com.liferay.util.LocalizationUtil;
035:
036: /**
037: * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class JournalArticleImpl extends JournalArticleModelImpl
043: implements JournalArticle {
044:
045: public static final double DEFAULT_VERSION = 1.0;
046:
047: public static final String[] TYPES = PropsUtil
048: .getArray(PropsUtil.JOURNAL_ARTICLE_TYPES);
049:
050: public static final String PORTLET = "portlet";
051:
052: public static final String STAND_ALONE = "stand-alone";
053:
054: public JournalArticleImpl() {
055: }
056:
057: public String getUserUuid() throws SystemException {
058: return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
059: }
060:
061: public void setUserUuid(String userUuid) {
062: _userUuid = userUuid;
063: }
064:
065: public String[] getAvailableLocales() {
066: return LocalizationUtil.getAvailableLocales(getContent());
067: }
068:
069: public String getContentByLocale(String languageId) {
070: LocaleTransformerListener listener = new LocaleTransformerListener();
071:
072: listener.setTemplateDriven(isTemplateDriven());
073: listener.setLanguageId(languageId);
074:
075: return listener.onXml(getContent());
076: }
077:
078: public String getDefaultLocale() {
079: String xml = getContent();
080:
081: if (xml == null) {
082: return StringPool.BLANK;
083: }
084:
085: if (isTemplateDriven()) {
086: String defaultLanguageId = LocaleUtil
087: .toLanguageId(LocaleUtil.getDefault());
088:
089: return defaultLanguageId;
090: } else {
091: return LocalizationUtil.getDefaultLocale(xml);
092: }
093: }
094:
095: public boolean isTemplateDriven() {
096: if (Validator.isNull(getStructureId())) {
097: return false;
098: } else {
099: return true;
100: }
101: }
102:
103: public String getApprovedByUserUuid() throws SystemException {
104: return PortalUtil.getUserValue(getApprovedByUserId(), "uuid",
105: _approvedByUserUuid);
106: }
107:
108: public void setApprovedByUserUuid(String approvedByUserUuid) {
109: _approvedByUserUuid = approvedByUserUuid;
110: }
111:
112: public String getSmallImageType() throws PortalException,
113: SystemException {
114: if (_smallImageType == null && isSmallImage()) {
115: Image smallImage = ImageLocalServiceUtil
116: .getImage(getSmallImageId());
117:
118: _smallImageType = smallImage.getType();
119: }
120:
121: return _smallImageType;
122: }
123:
124: public void setSmallImageType(String smallImageType) {
125: _smallImageType = smallImageType;
126: }
127:
128: private String _userUuid;
129: private String _approvedByUserUuid;
130: private String _smallImageType;
131:
132: }
|