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.portal.service.impl;
022:
023: import com.liferay.portal.LayoutSetVirtualHostException;
024: import com.liferay.portal.NoSuchCompanyException;
025: import com.liferay.portal.NoSuchLayoutException;
026: import com.liferay.portal.NoSuchLayoutSetException;
027: import com.liferay.portal.PortalException;
028: import com.liferay.portal.SystemException;
029: import com.liferay.portal.kernel.util.StringPool;
030: import com.liferay.portal.kernel.util.Validator;
031: import com.liferay.portal.model.Group;
032: import com.liferay.portal.model.Layout;
033: import com.liferay.portal.model.LayoutSet;
034: import com.liferay.portal.model.impl.ColorSchemeImpl;
035: import com.liferay.portal.model.impl.LayoutImpl;
036: import com.liferay.portal.model.impl.ThemeImpl;
037: import com.liferay.portal.service.base.LayoutSetLocalServiceBaseImpl;
038: import com.liferay.portal.util.PrefsPropsUtil;
039: import com.liferay.portal.util.PropsUtil;
040: import com.liferay.portal.util.PropsValues;
041: import com.liferay.util.Http;
042:
043: import java.io.File;
044:
045: import java.util.Iterator;
046: import java.util.List;
047:
048: /**
049: * <a href="LayoutSetLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
050: *
051: * @author Brian Wing Shun Chan
052: *
053: */
054: public class LayoutSetLocalServiceImpl extends
055: LayoutSetLocalServiceBaseImpl {
056:
057: public LayoutSet addLayoutSet(long groupId, boolean privateLayout)
058: throws PortalException, SystemException {
059:
060: Group group = groupPersistence.findByPrimaryKey(groupId);
061:
062: long layoutSetId = counterLocalService.increment();
063:
064: LayoutSet layoutSet = layoutSetPersistence.create(layoutSetId);
065:
066: layoutSet.setGroupId(groupId);
067: layoutSet.setCompanyId(group.getCompanyId());
068: layoutSet.setPrivateLayout(privateLayout);
069: layoutSet.setThemeId(ThemeImpl.getDefaultRegularThemeId());
070: layoutSet.setColorSchemeId(ColorSchemeImpl
071: .getDefaultRegularColorSchemeId());
072: layoutSet.setWapThemeId(ThemeImpl.getDefaultWapThemeId());
073: layoutSet.setWapColorSchemeId(ColorSchemeImpl
074: .getDefaultWapColorSchemeId());
075: layoutSet.setCss(StringPool.BLANK);
076:
077: layoutSetPersistence.update(layoutSet);
078:
079: return layoutSet;
080: }
081:
082: public void deleteLayoutSet(long groupId, boolean privateLayout)
083: throws PortalException, SystemException {
084:
085: LayoutSet layoutSet = layoutSetPersistence.findByG_P(groupId,
086: privateLayout);
087:
088: // Layouts
089:
090: List layouts = layoutPersistence.findByG_P_P(groupId,
091: privateLayout, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
092:
093: Iterator itr = layouts.iterator();
094:
095: while (itr.hasNext()) {
096: Layout layout = (Layout) itr.next();
097:
098: try {
099: layoutLocalService.deleteLayout(layout, false);
100: } catch (NoSuchLayoutException nsle) {
101: }
102: }
103:
104: // Logo
105:
106: ImageLocalUtil.deleteImage(layoutSet.getLogoId());
107:
108: // Layout set
109:
110: layoutSetPersistence.removeByG_P(groupId, privateLayout);
111: }
112:
113: public LayoutSet getLayoutSet(long groupId, boolean privateLayout)
114: throws PortalException, SystemException {
115:
116: return layoutSetPersistence.findByG_P(groupId, privateLayout);
117: }
118:
119: public LayoutSet getLayoutSet(String virtualHost)
120: throws PortalException, SystemException {
121:
122: virtualHost = virtualHost.trim().toLowerCase();
123:
124: return layoutSetPersistence.findByVirtualHost(virtualHost);
125: }
126:
127: public void updateLogo(long groupId, boolean privateLayout,
128: boolean logo, File file) throws PortalException,
129: SystemException {
130:
131: LayoutSet layoutSet = layoutSetPersistence.findByG_P(groupId,
132: privateLayout);
133:
134: layoutSet.setLogo(logo);
135:
136: if (logo) {
137: long logoId = layoutSet.getLogoId();
138:
139: if (logoId <= 0) {
140: logoId = counterLocalService.increment();
141:
142: layoutSet.setLogoId(logoId);
143: }
144: }
145:
146: layoutSetPersistence.update(layoutSet);
147:
148: if (logo) {
149: ImageLocalUtil.updateImage(layoutSet.getLogoId(), file);
150: } else {
151: ImageLocalUtil.deleteImage(layoutSet.getLogoId());
152: }
153: }
154:
155: public LayoutSet updateLookAndFeel(long groupId,
156: boolean privateLayout, String themeId,
157: String colorSchemeId, String css, boolean wapTheme)
158: throws PortalException, SystemException {
159:
160: LayoutSet layoutSet = layoutSetPersistence.findByG_P(groupId,
161: privateLayout);
162:
163: if (wapTheme) {
164: layoutSet.setWapThemeId(themeId);
165: layoutSet.setWapColorSchemeId(colorSchemeId);
166: } else {
167: layoutSet.setThemeId(themeId);
168: layoutSet.setColorSchemeId(colorSchemeId);
169: layoutSet.setCss(css);
170: }
171:
172: layoutSetPersistence.update(layoutSet);
173:
174: if (PrefsPropsUtil.getBoolean(PropsUtil.THEME_SYNC_ON_GROUP,
175: PropsValues.THEME_SYNC_ON_GROUP)) {
176:
177: LayoutSet otherLayoutSet = layoutSetPersistence
178: .findByG_P(layoutSet.getGroupId(), layoutSet
179: .isPrivateLayout());
180:
181: if (wapTheme) {
182: otherLayoutSet.setWapThemeId(themeId);
183: otherLayoutSet.setWapColorSchemeId(colorSchemeId);
184: } else {
185: otherLayoutSet.setThemeId(themeId);
186: otherLayoutSet.setColorSchemeId(colorSchemeId);
187: }
188:
189: layoutSetPersistence.update(otherLayoutSet);
190: }
191:
192: return layoutSet;
193: }
194:
195: public LayoutSet updatePageCount(long groupId, boolean privateLayout)
196: throws PortalException, SystemException {
197:
198: int pageCount = layoutPersistence.countByG_P(groupId,
199: privateLayout);
200:
201: LayoutSet layoutSet = layoutSetPersistence.findByG_P(groupId,
202: privateLayout);
203:
204: layoutSet.setPageCount(pageCount);
205:
206: layoutSetPersistence.update(layoutSet);
207:
208: return layoutSet;
209: }
210:
211: public LayoutSet updateVirtualHost(long groupId,
212: boolean privateLayout, String virtualHost)
213: throws PortalException, SystemException {
214:
215: virtualHost = virtualHost.trim().toLowerCase();
216:
217: if (virtualHost.startsWith(Http.HTTP_WITH_SLASH)
218: || virtualHost.startsWith(Http.HTTPS_WITH_SLASH)) {
219:
220: throw new LayoutSetVirtualHostException();
221: }
222:
223: LayoutSet layoutSet = layoutSetPersistence.findByG_P(groupId,
224: privateLayout);
225:
226: if (Validator.isNotNull(virtualHost)) {
227: try {
228: LayoutSet virtualHostLayoutSet = getLayoutSet(virtualHost);
229:
230: if (!layoutSet.equals(virtualHostLayoutSet)) {
231: throw new LayoutSetVirtualHostException();
232: }
233: } catch (NoSuchLayoutSetException nslse) {
234: }
235:
236: try {
237: companyLocalService
238: .getCompanyByVirtualHost(virtualHost);
239:
240: throw new LayoutSetVirtualHostException();
241: } catch (NoSuchCompanyException nsce) {
242: }
243: }
244:
245: layoutSet.setVirtualHost(virtualHost);
246:
247: layoutSetPersistence.update(layoutSet);
248:
249: return layoutSet;
250: }
251:
252: }
|