001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.LayoutFriendlyURLException;
018 import com.liferay.portal.LayoutHiddenException;
019 import com.liferay.portal.LayoutNameException;
020 import com.liferay.portal.LayoutParentLayoutIdException;
021 import com.liferay.portal.LayoutTypeException;
022 import com.liferay.portal.NoSuchLayoutException;
023 import com.liferay.portal.RequiredLayoutException;
024 import com.liferay.portal.kernel.dao.orm.Criterion;
025 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
026 import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
027 import com.liferay.portal.kernel.dao.orm.Junction;
028 import com.liferay.portal.kernel.dao.orm.Projection;
029 import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
030 import com.liferay.portal.kernel.dao.orm.Property;
031 import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
032 import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
033 import com.liferay.portal.kernel.exception.PortalException;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
036 import com.liferay.portal.kernel.language.LanguageUtil;
037 import com.liferay.portal.kernel.util.FileUtil;
038 import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
039 import com.liferay.portal.kernel.util.GetterUtil;
040 import com.liferay.portal.kernel.util.ListUtil;
041 import com.liferay.portal.kernel.util.LocaleUtil;
042 import com.liferay.portal.kernel.util.LocalizationUtil;
043 import com.liferay.portal.kernel.util.ParamUtil;
044 import com.liferay.portal.kernel.util.StringBundler;
045 import com.liferay.portal.kernel.util.StringPool;
046 import com.liferay.portal.kernel.util.UnicodeProperties;
047 import com.liferay.portal.kernel.util.Validator;
048 import com.liferay.portal.kernel.workflow.WorkflowConstants;
049 import com.liferay.portal.lar.LayoutExporter;
050 import com.liferay.portal.lar.LayoutImporter;
051 import com.liferay.portal.lar.PortletExporter;
052 import com.liferay.portal.lar.PortletImporter;
053 import com.liferay.portal.model.Group;
054 import com.liferay.portal.model.Layout;
055 import com.liferay.portal.model.LayoutConstants;
056 import com.liferay.portal.model.LayoutReference;
057 import com.liferay.portal.model.LayoutSet;
058 import com.liferay.portal.model.LayoutSetPrototype;
059 import com.liferay.portal.model.LayoutTypePortlet;
060 import com.liferay.portal.model.Portlet;
061 import com.liferay.portal.model.PortletConstants;
062 import com.liferay.portal.model.PortletPreferences;
063 import com.liferay.portal.model.Resource;
064 import com.liferay.portal.model.ResourceConstants;
065 import com.liferay.portal.model.ResourcePermission;
066 import com.liferay.portal.model.User;
067 import com.liferay.portal.model.UserGroup;
068 import com.liferay.portal.model.impl.LayoutImpl;
069 import com.liferay.portal.model.impl.PortletPreferencesImpl;
070 import com.liferay.portal.service.ServiceContext;
071 import com.liferay.portal.service.base.LayoutLocalServiceBaseImpl;
072 import com.liferay.portal.util.PortalUtil;
073 import com.liferay.portal.util.PortletKeys;
074 import com.liferay.portal.util.PropsValues;
075 import com.liferay.portal.util.comparator.LayoutComparator;
076 import com.liferay.portal.util.comparator.LayoutPriorityComparator;
077 import com.liferay.portlet.PortletPreferencesFactoryUtil;
078 import com.liferay.portlet.expando.model.ExpandoBridge;
079
080 import java.io.File;
081 import java.io.IOException;
082 import java.io.InputStream;
083
084 import java.util.ArrayList;
085 import java.util.Date;
086 import java.util.HashMap;
087 import java.util.HashSet;
088 import java.util.LinkedHashSet;
089 import java.util.List;
090 import java.util.Locale;
091 import java.util.Map;
092 import java.util.Set;
093
094 import javax.portlet.PortletException;
095
096
107 public class LayoutLocalServiceImpl extends LayoutLocalServiceBaseImpl {
108
109
116 public static String getCounterName(long groupId, boolean privateLayout) {
117 StringBundler sb = new StringBundler();
118
119 sb.append(Layout.class.getName());
120 sb.append(StringPool.POUND);
121 sb.append(groupId);
122 sb.append(StringPool.POUND);
123 sb.append(privateLayout);
124
125 return sb.toString();
126 }
127
128
182 public Layout addLayout(
183 long userId, long groupId, boolean privateLayout,
184 long parentLayoutId, Map<Locale, String> nameMap,
185 Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
186 Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
187 String type, boolean hidden, String friendlyURL,
188 ServiceContext serviceContext)
189 throws PortalException, SystemException {
190
191
192
193 User user = userPersistence.findByPrimaryKey(userId);
194 long layoutId = getNextLayoutId(groupId, privateLayout);
195 parentLayoutId = getParentLayoutId(
196 groupId, privateLayout, parentLayoutId);
197 String name = nameMap.get(LocaleUtil.getDefault());
198 friendlyURL = getFriendlyURL(
199 groupId, privateLayout, layoutId, name, friendlyURL);
200 int priority = getNextPriority(groupId, privateLayout, parentLayoutId);
201
202 validate(
203 groupId, privateLayout, layoutId, parentLayoutId, name, type,
204 hidden, friendlyURL);
205
206 Date now = new Date();
207
208 long plid = counterLocalService.increment();
209
210 Layout layout = layoutPersistence.create(plid);
211
212 layout.setUuid(serviceContext.getUuid());
213 layout.setGroupId(groupId);
214 layout.setCompanyId(user.getCompanyId());
215 layout.setCreateDate(serviceContext.getCreateDate(now));
216 layout.setModifiedDate(serviceContext.getModifiedDate(now));
217 layout.setPrivateLayout(privateLayout);
218 layout.setLayoutId(layoutId);
219 layout.setParentLayoutId(parentLayoutId);
220 layout.setNameMap(nameMap);
221 layout.setTitleMap(titleMap);
222 layout.setDescriptionMap(descriptionMap);
223 layout.setKeywordsMap(keywordsMap);
224 layout.setRobotsMap(robotsMap);
225 layout.setType(type);
226 layout.setHidden(hidden);
227 layout.setFriendlyURL(friendlyURL);
228 layout.setPriority(priority);
229
230 boolean layoutUpdateable = ParamUtil.getBoolean(
231 serviceContext, "layoutUpdateable", true);
232
233 if (!layoutUpdateable) {
234 UnicodeProperties typeSettingsProperties =
235 layout.getTypeSettingsProperties();
236
237 typeSettingsProperties.put(
238 "layoutUpdateable", String.valueOf(layoutUpdateable));
239
240 layout.setTypeSettingsProperties(typeSettingsProperties);
241 }
242
243 String layoutPrototypeUuid = ParamUtil.getString(
244 serviceContext, "layoutPrototypeUuid");
245 boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(
246 serviceContext, "layoutPrototypeLinkEnabled", true);
247
248 if (Validator.isNotNull(layoutPrototypeUuid)) {
249 layout.setLayoutPrototypeUuid(layoutPrototypeUuid);
250 layout.setLayoutPrototypeLinkEnabled(layoutPrototypeLinkEnabled);
251 }
252
253 if (type.equals(LayoutConstants.TYPE_PORTLET)) {
254 LayoutTypePortlet layoutTypePortlet =
255 (LayoutTypePortlet)layout.getLayoutType();
256
257 layoutTypePortlet.setLayoutTemplateId(
258 0, PropsValues.LAYOUT_DEFAULT_TEMPLATE_ID, false);
259 }
260
261 layoutPersistence.update(layout, false);
262
263
264
265 boolean addGroupPermissions = true;
266
267 Group group = groupLocalService.getGroup(groupId);
268
269 if (privateLayout && group.isUser()) {
270 addGroupPermissions = false;
271 }
272
273 boolean addGuestPermissions = false;
274
275 if (!privateLayout ||
276 type.equals(LayoutConstants.TYPE_CONTROL_PANEL) ||
277 group.isLayoutSetPrototype()) {
278
279 addGuestPermissions = true;
280 }
281
282 resourceLocalService.addResources(
283 user.getCompanyId(), groupId, user.getUserId(),
284 Layout.class.getName(), layout.getPlid(), false,
285 addGroupPermissions, addGuestPermissions);
286
287
288
289 groupLocalService.updateSite(groupId, true);
290
291
292
293 layoutSetLocalService.updatePageCount(groupId, privateLayout);
294
295 LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(
296 groupId, privateLayout);
297
298 layout.setLayoutSet(layoutSet);
299
300
301
302 ExpandoBridge expandoBridge = layout.getExpandoBridge();
303
304 expandoBridge.setAttributes(serviceContext);
305
306
307
308 if (PropsValues.LAYOUT_COMMENTS_ENABLED) {
309 mbMessageLocalService.addDiscussionMessage(
310 userId, user.getFullName(), groupId, Layout.class.getName(),
311 plid, WorkflowConstants.ACTION_PUBLISH);
312 }
313
314 return layout;
315 }
316
317
372 public Layout addLayout(
373 long userId, long groupId, boolean privateLayout,
374 long parentLayoutId, String name, String title, String description,
375 String type, boolean hidden, String friendlyURL,
376 ServiceContext serviceContext)
377 throws PortalException, SystemException {
378
379 Map<Locale, String> localeNamesMap = new HashMap<Locale, String>();
380
381 Locale defaultLocale = LocaleUtil.getDefault();
382
383 localeNamesMap.put(defaultLocale, name);
384
385 return addLayout(
386 userId, groupId, privateLayout, parentLayoutId, localeNamesMap,
387 new HashMap<Locale, String>(), new HashMap<Locale, String>(),
388 new HashMap<Locale, String>(), new HashMap<Locale, String>(), type,
389 hidden, friendlyURL, serviceContext);
390 }
391
392
402 public void deleteLayout(
403 Layout layout, boolean updateLayoutSet,
404 ServiceContext serviceContext)
405 throws PortalException, SystemException {
406
407
408
409 if (layout.getParentLayoutId() ==
410 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
411
412 List<Layout> rootLayouts = layoutPersistence.findByG_P_P(
413 layout.getGroupId(), layout.isPrivateLayout(),
414 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0, 2);
415
416 if (rootLayouts.size() > 1) {
417 Layout firstLayout = rootLayouts.get(0);
418
419 if (firstLayout.getLayoutId() == layout.getLayoutId()) {
420 Layout secondLayout = rootLayouts.get(1);
421
422 validateFirstLayout(secondLayout.getType());
423 }
424 }
425 }
426
427
428
429 List<Layout> childLayouts = layoutPersistence.findByG_P_P(
430 layout.getGroupId(), layout.isPrivateLayout(),
431 layout.getLayoutId());
432
433 for (Layout childLayout : childLayouts) {
434 deleteLayout(childLayout, updateLayoutSet, serviceContext);
435 }
436
437
438
439 portletPreferencesLocalService.deletePortletPreferences(
440 PortletKeys.PREFS_OWNER_ID_DEFAULT,
441 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid());
442
443
444
445 ratingsStatsLocalService.deleteStats(
446 Layout.class.getName(), layout.getPlid());
447
448
449
450 mbMessageLocalService.deleteDiscussionMessages(
451 Layout.class.getName(), layout.getPlid());
452
453
454
455 journalArticleLocalService.deleteLayoutArticleReferences(
456 layout.getGroupId(), layout.getUuid());
457
458
459
460 journalContentSearchLocalService.deleteLayoutContentSearches(
461 layout.getGroupId(), layout.isPrivateLayout(),
462 layout.getLayoutId());
463
464
465
466 expandoValueLocalService.deleteValues(
467 Layout.class.getName(), layout.getPlid());
468
469
470
471 imageLocalService.deleteImage(layout.getIconImageId());
472
473
474
475 Group scopeGroup = layout.getScopeGroup();
476
477 if (scopeGroup != null) {
478 groupLocalService.deleteGroup(scopeGroup.getGroupId());
479 }
480
481
482
483 String primKey =
484 layout.getPlid() + PortletConstants.LAYOUT_SEPARATOR + "%";
485
486 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
487 List<ResourcePermission> resourcePermissions =
488 resourcePermissionPersistence.findByC_P(
489 layout.getCompanyId(), primKey);
490
491 for (ResourcePermission resourcePermission : resourcePermissions) {
492 resourcePermissionLocalService.deleteResourcePermission(
493 resourcePermission);
494 }
495 }
496 else {
497 List<Resource> resources = resourceFinder.findByC_P(
498 layout.getCompanyId(), primKey);
499
500 for (Resource resource : resources) {
501 resourceLocalService.deleteResource(resource);
502 }
503 }
504
505 resourceLocalService.deleteResource(
506 layout.getCompanyId(), Layout.class.getName(),
507 ResourceConstants.SCOPE_INDIVIDUAL, layout.getPlid());
508
509
510
511 layoutPersistence.remove(layout);
512
513
514
515 if (updateLayoutSet) {
516 layoutSetLocalService.updatePageCount(
517 layout.getGroupId(), layout.isPrivateLayout());
518 }
519 }
520
521
533 public void deleteLayout(
534 long groupId, boolean privateLayout, long layoutId,
535 ServiceContext serviceContext)
536 throws PortalException, SystemException {
537
538 Layout layout = layoutPersistence.findByG_P_L(
539 groupId, privateLayout, layoutId);
540
541 deleteLayout(layout, true, serviceContext);
542 }
543
544
554 public void deleteLayout(long plid, ServiceContext serviceContext)
555 throws PortalException, SystemException {
556
557 Layout layout = layoutPersistence.findByPrimaryKey(plid);
558
559 deleteLayout(layout, true, serviceContext);
560 }
561
562
574 public void deleteLayouts(
575 long groupId, boolean privateLayout, ServiceContext serviceContext)
576 throws PortalException, SystemException {
577
578
579
580 List<Layout> layouts = layoutPersistence.findByG_P_P(
581 groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
582
583 for (Layout layout : layouts) {
584 try {
585 deleteLayout(layout, false, serviceContext);
586 }
587 catch (NoSuchLayoutException nsle) {
588 }
589 }
590
591
592
593 layoutSetLocalService.updatePageCount(groupId, privateLayout);
594
595
596
597 counterLocalService.reset(getCounterName(groupId, privateLayout));
598 }
599
600
617 public byte[] exportLayouts(
618 long groupId, boolean privateLayout, long[] layoutIds,
619 Map<String, String[]> parameterMap, Date startDate, Date endDate)
620 throws PortalException, SystemException {
621
622 File file = exportLayoutsAsFile(
623 groupId, privateLayout, layoutIds, parameterMap, startDate,
624 endDate);
625
626 try {
627 return FileUtil.getBytes(file);
628 }
629 catch (IOException ioe) {
630 throw new SystemException(ioe);
631 }
632 finally {
633 file.delete();
634 }
635 }
636
637
653 public byte[] exportLayouts(
654 long groupId, boolean privateLayout,
655 Map<String, String[]> parameterMap, Date startDate, Date endDate)
656 throws PortalException, SystemException {
657
658 return exportLayouts(
659 groupId, privateLayout, null, parameterMap, startDate, endDate);
660 }
661
662
680 public File exportLayoutsAsFile(
681 long groupId, boolean privateLayout, long[] layoutIds,
682 Map<String, String[]> parameterMap, Date startDate, Date endDate)
683 throws PortalException, SystemException {
684
685 try {
686 LayoutExporter layoutExporter = new LayoutExporter();
687
688 return layoutExporter.exportLayoutsAsFile(
689 groupId, privateLayout, layoutIds, parameterMap, startDate,
690 endDate);
691 }
692 catch (PortalException pe) {
693 throw pe;
694 }
695 catch (SystemException se) {
696 throw se;
697 }
698 catch (Exception e) {
699 throw new SystemException(e);
700 }
701 }
702
703
721 public byte[] exportPortletInfo(
722 long plid, long groupId, String portletId,
723 Map<String, String[]> parameterMap, Date startDate, Date endDate)
724 throws PortalException, SystemException {
725
726 File file = exportPortletInfoAsFile(
727 plid, groupId, portletId, parameterMap, startDate, endDate);
728
729 try {
730 return FileUtil.getBytes(file);
731 }
732 catch (IOException ioe) {
733 throw new SystemException(ioe);
734 }
735 finally {
736 file.delete();
737 }
738 }
739
740
758 public File exportPortletInfoAsFile(
759 long plid, long groupId, String portletId,
760 Map<String, String[]> parameterMap, Date startDate, Date endDate)
761 throws PortalException, SystemException {
762
763 try {
764 PortletExporter portletExporter = new PortletExporter();
765
766 return portletExporter.exportPortletInfoAsFile(
767 plid, groupId, portletId, parameterMap, startDate, endDate);
768 }
769 catch (PortalException pe) {
770 throw pe;
771 }
772 catch (SystemException se) {
773 throw se;
774 }
775 catch (Exception e) {
776 throw new SystemException(e);
777 }
778 }
779
780 public Layout fetchFirstLayout(
781 long groupId, boolean privateLayout, long parentLayoutId)
782 throws SystemException {
783
784 Layout firstLayout = null;
785
786 try {
787 firstLayout = layoutPersistence.findByG_P_P_First(
788 groupId, privateLayout, parentLayoutId,
789 new LayoutPriorityComparator());
790 }
791 catch (NoSuchLayoutException nsle) {
792 }
793
794 return firstLayout;
795 }
796
797
807 public Layout fetchLayoutByUuidAndGroupId(String uuid, long groupId)
808 throws SystemException {
809
810 return layoutPersistence.fetchByUUID_G(uuid, groupId);
811 }
812
813
821 public long getDefaultPlid(long groupId) throws SystemException {
822 if (groupId > 0) {
823 List<Layout> layouts = layoutPersistence.findByGroupId(
824 groupId, 0, 1);
825
826 if (layouts.size() > 0) {
827 Layout layout = layouts.get(0);
828
829 return layout.getPlid();
830 }
831 }
832
833 return LayoutConstants.DEFAULT_PLID;
834 }
835
836
845 public long getDefaultPlid(long groupId, boolean privateLayout)
846 throws SystemException {
847
848 if (groupId > 0) {
849 List<Layout> layouts = layoutPersistence.findByG_P(
850 groupId, privateLayout, 0, 1);
851
852 if (layouts.size() > 0) {
853 Layout layout = layouts.get(0);
854
855 return layout.getPlid();
856 }
857 }
858
859 return LayoutConstants.DEFAULT_PLID;
860 }
861
862
875 public long getDefaultPlid(
876 long groupId, boolean privateLayout, String portletId)
877 throws PortalException, SystemException {
878
879 if (groupId > 0) {
880 List<Layout> layouts = layoutPersistence.findByG_P(
881 groupId, privateLayout);
882
883 for (Layout layout : layouts) {
884 if (layout.isTypePortlet()) {
885 LayoutTypePortlet layoutTypePortlet =
886 (LayoutTypePortlet)layout.getLayoutType();
887
888 if (layoutTypePortlet.hasPortletId(portletId)) {
889 return layout.getPlid();
890 }
891 }
892 }
893 }
894
895 return LayoutConstants.DEFAULT_PLID;
896 }
897
898
909 public Layout getFriendlyURLLayout(
910 long groupId, boolean privateLayout, String friendlyURL)
911 throws PortalException, SystemException {
912
913 if (Validator.isNull(friendlyURL)) {
914 throw new NoSuchLayoutException();
915 }
916
917 friendlyURL = getFriendlyURL(friendlyURL);
918
919 Layout layout = layoutPersistence.fetchByG_P_F(
920 groupId, privateLayout, friendlyURL);
921
922 if ((layout == null) &&
923 (friendlyURL.startsWith(StringPool.SLASH)) &&
924 (Validator.isNumber(friendlyURL.substring(1)))) {
925
926 long layoutId = GetterUtil.getLong(friendlyURL.substring(1));
927
928 layout = layoutPersistence.fetchByG_P_L(
929 groupId, privateLayout, layoutId);
930 }
931
932 if (layout == null) {
933 throw new NoSuchLayoutException();
934 }
935
936 return layout;
937 }
938
939
949 @Override
950 public Layout getLayout(long plid)
951 throws PortalException, SystemException {
952
953 return layoutPersistence.findByPrimaryKey(plid);
954 }
955
956
967 public Layout getLayout(long groupId, boolean privateLayout, long layoutId)
968 throws PortalException, SystemException {
969
970 return layoutPersistence.findByG_P_L(groupId, privateLayout, layoutId);
971 }
972
973
983 public Layout getLayoutByIconImageId(long iconImageId)
984 throws PortalException, SystemException {
985
986 return layoutPersistence.findByIconImageId(iconImageId);
987 }
988
989
999 @Override
1000 public Layout getLayoutByUuidAndGroupId(String uuid, long groupId)
1001 throws PortalException, SystemException {
1002
1003 return layoutPersistence.findByUUID_G(uuid, groupId);
1004 }
1005
1006
1015 public List<Layout> getLayouts(long groupId, boolean privateLayout)
1016 throws SystemException {
1017
1018 return layoutPersistence.findByG_P(groupId, privateLayout);
1019 }
1020
1021
1032 public List<Layout> getLayouts(
1033 long groupId, boolean privateLayout, long parentLayoutId)
1034 throws SystemException {
1035
1036 return layoutPersistence.findByG_P_P(
1037 groupId, privateLayout, parentLayoutId);
1038 }
1039
1040
1064 public List<Layout> getLayouts(
1065 long groupId, boolean privateLayout, long parentLayoutId,
1066 boolean incomplete, int start, int end)
1067 throws SystemException {
1068
1069 return layoutPersistence.findByG_P_P(
1070 groupId, privateLayout, parentLayoutId, start, end);
1071 }
1072
1073
1086 public List<Layout> getLayouts(
1087 long groupId, boolean privateLayout, long[] layoutIds)
1088 throws PortalException, SystemException {
1089
1090 List<Layout> layouts = new ArrayList<Layout>();
1091
1092 for (long layoutId : layoutIds) {
1093 Layout layout = getLayout(groupId, privateLayout, layoutId);
1094
1095 layouts.add(layout);
1096 }
1097
1098 return layouts;
1099 }
1100
1101
1112 public List<Layout> getLayouts(
1113 long groupId, boolean privateLayout, String type)
1114 throws SystemException {
1115
1116 return layoutPersistence.findByG_P_T(groupId, privateLayout, type);
1117 }
1118
1119
1130 public LayoutReference[] getLayouts(
1131 long companyId, String portletId, String preferencesKey,
1132 String preferencesValue)
1133 throws SystemException {
1134
1135 List<LayoutReference> layoutReferences = layoutFinder.findByC_P_P(
1136 companyId, portletId, preferencesKey, preferencesValue);
1137
1138 return layoutReferences.toArray(
1139 new LayoutReference[layoutReferences.size()]);
1140 }
1141
1142 public int getLayoutsCount(Group group, boolean privateLayout)
1143 throws PortalException, SystemException {
1144
1145 LayoutSet layoutSet = layoutSetPersistence.findByG_P(
1146 group.getGroupId(), privateLayout);
1147
1148 int count = layoutSet.getPageCount();
1149
1150 if (group.isUser()) {
1151 List<UserGroup> userGroups = userPersistence.getUserGroups(
1152 group.getClassPK());
1153
1154 if (!userGroups.isEmpty()) {
1155 long userGroupClassNameId =
1156 classNameLocalService.getClassNameId(UserGroup.class);
1157
1158 for (UserGroup userGroup : userGroups) {
1159 Group userGroupGroup = groupPersistence.findByC_C_C(
1160 group.getCompanyId(), userGroupClassNameId,
1161 userGroup.getUserGroupId());
1162
1163 layoutSet = layoutSetPersistence.findByG_P(
1164 userGroupGroup.getGroupId(), privateLayout);
1165
1166 count += layoutSet.getPageCount();
1167 }
1168 }
1169 }
1170
1171 return count;
1172 }
1173
1174 public int getLayoutsCount(User user, boolean privateLayout)
1175 throws PortalException, SystemException {
1176
1177 long classNameId = classNameLocalService.getClassNameId(User.class);
1178
1179 Group group = groupPersistence.findByC_C_C(
1180 user.getCompanyId(), classNameId, user.getUserId());
1181
1182 return getLayoutsCount(group, privateLayout);
1183 }
1184
1185
1193 public long getNextLayoutId(long groupId, boolean privateLayout)
1194 throws SystemException {
1195
1196 long nextLayoutId = counterLocalService.increment(
1197 getCounterName(groupId, privateLayout));
1198
1199 if (nextLayoutId == 1) {
1200 List<Layout> layouts = layoutPersistence.findByG_P(
1201 groupId, privateLayout, 0, 1, new LayoutComparator());
1202
1203 if (!layouts.isEmpty()) {
1204 Layout layout = layouts.get(0);
1205
1206 nextLayoutId = layout.getLayoutId() + 1;
1207
1208 counterLocalService.reset(
1209 getCounterName(groupId, privateLayout), nextLayoutId);
1210 }
1211 }
1212
1213 return nextLayoutId;
1214 }
1215
1216
1222 public List<Layout> getNullFriendlyURLLayouts() throws SystemException {
1223 return layoutFinder.findByNullFriendlyURL();
1224 }
1225
1226
1234 public List<Layout> getScopeGroupLayouts(
1235 long groupId, boolean privateLayout)
1236 throws SystemException {
1237
1238 return layoutFinder.findByScopeGroup(groupId, privateLayout);
1239 }
1240
1241 public boolean hasLayouts(Group group, boolean privateLayout)
1242 throws PortalException, SystemException {
1243
1244 LayoutSet layoutSet = layoutSetPersistence.findByG_P(
1245 group.getGroupId(), privateLayout);
1246
1247 if (layoutSet.getPageCount() > 0) {
1248 return true;
1249 }
1250
1251 if (group.isUser()) {
1252 List<UserGroup> userGroups = userPersistence.getUserGroups(
1253 group.getClassPK());
1254
1255 if (!userGroups.isEmpty()) {
1256 long userGroupClassNameId =
1257 classNameLocalService.getClassNameId(UserGroup.class);
1258
1259 for (UserGroup userGroup : userGroups) {
1260 Group userGroupGroup = groupPersistence.findByC_C_C(
1261 group.getCompanyId(), userGroupClassNameId,
1262 userGroup.getUserGroupId());
1263
1264 layoutSet = layoutSetPersistence.findByG_P(
1265 userGroupGroup.getGroupId(), privateLayout);
1266
1267 if (layoutSet.getPageCount() > 0) {
1268 return true;
1269 }
1270 }
1271 }
1272 }
1273
1274 return false;
1275 }
1276
1277
1288 public boolean hasLayouts(
1289 long groupId, boolean privateLayout, long parentLayoutId)
1290 throws SystemException {
1291
1292 return layoutPersistence.countByG_P_P(
1293 groupId, privateLayout, parentLayoutId) > 0;
1294 }
1295
1296 public boolean hasLayouts(User user, boolean privateLayout)
1297 throws PortalException, SystemException {
1298
1299 long classNameId = classNameLocalService.getClassNameId(User.class);
1300
1301 Group group = groupPersistence.findByC_C_C(
1302 user.getCompanyId(), classNameId, user.getUserId());
1303
1304 return hasLayouts(group, privateLayout);
1305 }
1306
1307 public boolean hasLayoutSetPrototypeLayout(
1308 long layoutSetPrototypeId, String layoutUuid)
1309 throws PortalException, SystemException {
1310
1311 LayoutSetPrototype layoutSetPrototype =
1312 layoutSetPrototypeLocalService.getLayoutSetPrototype(
1313 layoutSetPrototypeId);
1314
1315 return hasLayoutSetPrototypeLayout(layoutSetPrototype, layoutUuid);
1316 }
1317
1318 public boolean hasLayoutSetPrototypeLayout(
1319 String layoutSetPrototypeUuid, String layoutUuid)
1320 throws PortalException, SystemException {
1321
1322 LayoutSetPrototype layoutSetPrototype =
1323 layoutSetPrototypeLocalService.getLayoutSetPrototypeByUuid(
1324 layoutSetPrototypeUuid);
1325
1326 return hasLayoutSetPrototypeLayout(layoutSetPrototype, layoutUuid);
1327 }
1328
1329
1345 public void importLayouts(
1346 long userId, long groupId, boolean privateLayout,
1347 Map<String, String[]> parameterMap, byte[] bytes)
1348 throws PortalException, SystemException {
1349
1350 importLayouts(
1351 userId, groupId, privateLayout, parameterMap,
1352 new UnsyncByteArrayInputStream(bytes));
1353 }
1354
1355
1371 public void importLayouts(
1372 long userId, long groupId, boolean privateLayout,
1373 Map<String, String[]> parameterMap, File file)
1374 throws PortalException, SystemException {
1375
1376 try {
1377 LayoutImporter layoutImporter = new LayoutImporter();
1378
1379 layoutImporter.importLayouts(
1380 userId, groupId, privateLayout, parameterMap, file);
1381 }
1382 catch (PortalException pe) {
1383 throw pe;
1384 }
1385 catch (SystemException se) {
1386 throw se;
1387 }
1388 catch (Exception e) {
1389 throw new SystemException(e);
1390 }
1391 }
1392
1393
1409 public void importLayouts(
1410 long userId, long groupId, boolean privateLayout,
1411 Map<String, String[]> parameterMap, InputStream is)
1412 throws PortalException, SystemException {
1413
1414 try {
1415 File file = FileUtil.createTempFile("lar");
1416
1417 FileUtil.write(file, is);
1418
1419 importLayouts(userId, groupId, privateLayout, parameterMap, file);
1420 }
1421 catch (IOException e) {
1422 throw new SystemException(e);
1423 }
1424 }
1425
1426
1443 public void importPortletInfo(
1444 long userId, long plid, long groupId, String portletId,
1445 Map<String, String[]> parameterMap, File file)
1446 throws PortalException, SystemException {
1447
1448 try {
1449 PortletImporter portletImporter = new PortletImporter();
1450
1451 portletImporter.importPortletInfo(
1452 userId, plid, groupId, portletId, parameterMap, file);
1453 }
1454 catch (PortalException pe) {
1455 throw pe;
1456 }
1457 catch (SystemException se) {
1458 throw se;
1459 }
1460 catch (Exception e) {
1461 throw new SystemException(e);
1462 }
1463 }
1464
1465
1482 public void importPortletInfo(
1483 long userId, long plid, long groupId, String portletId,
1484 Map<String, String[]> parameterMap, InputStream is)
1485 throws PortalException, SystemException {
1486
1487 try {
1488 File file = FileUtil.createTempFile("lar");
1489
1490 FileUtil.write(file, is);
1491
1492 importPortletInfo(
1493 userId, plid, groupId, portletId, parameterMap, file);
1494 }
1495 catch (IOException e) {
1496 throw new SystemException(e);
1497 }
1498 }
1499
1500
1515 public void setLayouts(
1516 long groupId, boolean privateLayout, long parentLayoutId,
1517 long[] layoutIds, ServiceContext serviceContext)
1518 throws PortalException, SystemException {
1519
1520 if (layoutIds == null) {
1521 return;
1522 }
1523
1524 if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
1525 if (layoutIds.length < 1) {
1526 throw new RequiredLayoutException(
1527 RequiredLayoutException.AT_LEAST_ONE);
1528 }
1529
1530 Layout layout = layoutPersistence.findByG_P_L(
1531 groupId, privateLayout, layoutIds[0]);
1532
1533 if (!PortalUtil.isLayoutFirstPageable(layout.getType())) {
1534 throw new RequiredLayoutException(
1535 RequiredLayoutException.FIRST_LAYOUT_TYPE);
1536 }
1537
1538 if (layout.isHidden()) {
1539 throw new RequiredLayoutException(
1540 RequiredLayoutException.FIRST_LAYOUT_HIDDEN);
1541 }
1542 }
1543
1544 Set<Long> layoutIdsSet = new LinkedHashSet<Long>();
1545
1546 for (long layoutId : layoutIds) {
1547 layoutIdsSet.add(layoutId);
1548 }
1549
1550 Set<Long> newLayoutIdsSet = new HashSet<Long>();
1551
1552 List<Layout> layouts = layoutPersistence.findByG_P_P(
1553 groupId, privateLayout, parentLayoutId);
1554
1555 for (Layout layout : layouts) {
1556 if (!layoutIdsSet.contains(layout.getLayoutId())) {
1557 deleteLayout(layout, true, serviceContext);
1558 }
1559 else {
1560 newLayoutIdsSet.add(layout.getLayoutId());
1561 }
1562 }
1563
1564 int priority = 0;
1565
1566 for (long layoutId : layoutIdsSet) {
1567 Layout layout = layoutPersistence.findByG_P_L(
1568 groupId, privateLayout, layoutId);
1569
1570 layout.setPriority(priority++);
1571
1572 layoutPersistence.update(layout, false);
1573 }
1574
1575 layoutSetLocalService.updatePageCount(groupId, privateLayout);
1576 }
1577
1578
1588 public Layout updateFriendlyURL(long plid, String friendlyURL)
1589 throws PortalException, SystemException {
1590
1591 Date now = new Date();
1592
1593 Layout layout = layoutPersistence.findByPrimaryKey(plid);
1594
1595 friendlyURL = getFriendlyURL(
1596 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
1597 StringPool.BLANK, friendlyURL);
1598
1599 validateFriendlyURL(
1600 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
1601 friendlyURL);
1602
1603 layout.setModifiedDate(now);
1604 layout.setFriendlyURL(friendlyURL);
1605
1606 layoutPersistence.update(layout, false);
1607
1608 return layout;
1609 }
1610
1611
1659 public Layout updateLayout(
1660 long groupId, boolean privateLayout, long layoutId,
1661 long parentLayoutId, Map<Locale, String> nameMap,
1662 Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
1663 Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
1664 String type, boolean hidden, String friendlyURL, Boolean iconImage,
1665 byte[] iconBytes, ServiceContext serviceContext)
1666 throws PortalException, SystemException {
1667
1668
1669
1670 parentLayoutId = getParentLayoutId(
1671 groupId, privateLayout, parentLayoutId);
1672 String name = nameMap.get(LocaleUtil.getDefault());
1673 friendlyURL = getFriendlyURL(
1674 groupId, privateLayout, layoutId, StringPool.BLANK, friendlyURL);
1675
1676 validate(
1677 groupId, privateLayout, layoutId, parentLayoutId, name, type,
1678 hidden, friendlyURL);
1679
1680 validateParentLayoutId(
1681 groupId, privateLayout, layoutId, parentLayoutId);
1682
1683 Date now = new Date();
1684
1685 Layout layout = layoutPersistence.findByG_P_L(
1686 groupId, privateLayout, layoutId);
1687
1688 List<Locale> modifiedLocales = LocalizationUtil.getModifiedLocales(
1689 layout.getNameMap(), nameMap);
1690
1691 if (parentLayoutId != layout.getParentLayoutId()) {
1692 layout.setPriority(
1693 getNextPriority(groupId, privateLayout, parentLayoutId));
1694 }
1695
1696 layout.setModifiedDate(serviceContext.getModifiedDate(now));
1697 layout.setParentLayoutId(parentLayoutId);
1698 layout.setNameMap(nameMap);
1699 layout.setTitleMap(titleMap);
1700 layout.setDescriptionMap(descriptionMap);
1701 layout.setKeywordsMap(keywordsMap);
1702 layout.setRobotsMap(robotsMap);
1703 layout.setType(type);
1704 layout.setHidden(hidden);
1705 layout.setFriendlyURL(friendlyURL);
1706
1707 if (iconImage != null) {
1708 layout.setIconImage(iconImage.booleanValue());
1709
1710 if (iconImage.booleanValue()) {
1711 long iconImageId = layout.getIconImageId();
1712
1713 if (iconImageId <= 0) {
1714 iconImageId = counterLocalService.increment();
1715
1716 layout.setIconImageId(iconImageId);
1717 }
1718 }
1719 }
1720
1721 boolean layoutUpdateable = GetterUtil.getBoolean(
1722 serviceContext.getAttribute("layoutUpdateable"), true);
1723
1724 UnicodeProperties typeSettingsProperties =
1725 layout.getTypeSettingsProperties();
1726
1727 typeSettingsProperties.put(
1728 "layoutUpdateable", String.valueOf(layoutUpdateable));
1729
1730 layout.setTypeSettingsProperties(typeSettingsProperties);
1731
1732 String layoutPrototypeUuid = ParamUtil.getString(
1733 serviceContext, "layoutPrototypeUuid");
1734 boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(
1735 serviceContext, "layoutPrototypeLinkEnabled");
1736
1737 if (Validator.isNotNull(layoutPrototypeUuid)) {
1738 layout.setLayoutPrototypeUuid(layoutPrototypeUuid);
1739 layout.setLayoutPrototypeLinkEnabled(layoutPrototypeLinkEnabled);
1740 }
1741
1742 layoutPersistence.update(layout, false);
1743
1744
1745
1746 if (iconImage != null) {
1747 if (!iconImage.booleanValue()) {
1748 imageLocalService.deleteImage(layout.getIconImageId());
1749 }
1750 else if ((iconBytes != null) && (iconBytes.length > 0)) {
1751 imageLocalService.updateImage(
1752 layout.getIconImageId(), iconBytes);
1753 }
1754 }
1755
1756
1757
1758 if (!modifiedLocales.isEmpty()) {
1759 updateScopedPortletNames(
1760 groupId, privateLayout, layoutId, nameMap, modifiedLocales);
1761 }
1762
1763
1764
1765 ExpandoBridge expandoBridge = layout.getExpandoBridge();
1766
1767 expandoBridge.setAttributes(serviceContext);
1768
1769 return layout;
1770 }
1771
1772
1785 public Layout updateLayout(
1786 long groupId, boolean privateLayout, long layoutId,
1787 String typeSettings)
1788 throws PortalException, SystemException {
1789
1790 Date now = new Date();
1791
1792 UnicodeProperties typeSettingsProperties = new UnicodeProperties();
1793
1794 typeSettingsProperties.fastLoad(typeSettings);
1795
1796 Layout layout = layoutPersistence.findByG_P_L(
1797 groupId, privateLayout, layoutId);
1798
1799 layout.setModifiedDate(now);
1800 layout.setTypeSettings(typeSettingsProperties.toString());
1801
1802 layoutPersistence.update(layout, false);
1803
1804 return layout;
1805 }
1806
1807
1821 public Layout updateLookAndFeel(
1822 long groupId, boolean privateLayout, long layoutId, String themeId,
1823 String colorSchemeId, String css, boolean wapTheme)
1824 throws PortalException, SystemException {
1825
1826 Date now = new Date();
1827
1828 Layout layout = layoutPersistence.findByG_P_L(
1829 groupId, privateLayout, layoutId);
1830
1831 layout.setModifiedDate(now);
1832
1833 if (wapTheme) {
1834 layout.setWapThemeId(themeId);
1835 layout.setWapColorSchemeId(colorSchemeId);
1836 }
1837 else {
1838 layout.setThemeId(themeId);
1839 layout.setColorSchemeId(colorSchemeId);
1840 layout.setCss(css);
1841 }
1842
1843 layoutPersistence.update(layout, false);
1844
1845 return layout;
1846 }
1847
1848
1859 public Layout updateName(Layout layout, String name, String languageId)
1860 throws PortalException, SystemException {
1861
1862 Date now = new Date();
1863
1864 validateName(name, languageId);
1865
1866 layout.setModifiedDate(now);
1867 layout.setName(name, LocaleUtil.fromLanguageId(languageId));
1868
1869 layoutPersistence.update(layout, false);
1870
1871 return layout;
1872 }
1873
1874
1889 public Layout updateName(
1890 long groupId, boolean privateLayout, long layoutId, String name,
1891 String languageId)
1892 throws PortalException, SystemException {
1893
1894 Layout layout = layoutPersistence.findByG_P_L(
1895 groupId, privateLayout, layoutId);
1896
1897 return layoutLocalService.updateName(layout, name, languageId);
1898 }
1899
1900
1912 public Layout updateName(long plid, String name, String languageId)
1913 throws PortalException, SystemException {
1914
1915 Layout layout = layoutPersistence.findByPrimaryKey(plid);
1916
1917 return layoutLocalService.updateName(layout, name, languageId);
1918 }
1919
1920
1934 public Layout updateParentLayoutId(
1935 long groupId, boolean privateLayout, long layoutId,
1936 long parentLayoutId)
1937 throws PortalException, SystemException {
1938
1939 parentLayoutId = getParentLayoutId(
1940 groupId, privateLayout, parentLayoutId);
1941
1942 validateParentLayoutId(
1943 groupId, privateLayout, layoutId, parentLayoutId);
1944
1945 Date now = new Date();
1946
1947 Layout layout = layoutPersistence.findByG_P_L(
1948 groupId, privateLayout, layoutId);
1949
1950 if (parentLayoutId != layout.getParentLayoutId()) {
1951 layout.setPriority(
1952 getNextPriority(groupId, privateLayout, parentLayoutId));
1953 }
1954
1955 layout.setModifiedDate(now);
1956 layout.setParentLayoutId(parentLayoutId);
1957
1958 layoutPersistence.update(layout, false);
1959
1960 return layout;
1961 }
1962
1963
1977 public Layout updateParentLayoutId(long plid, long parentPlid)
1978 throws PortalException, SystemException {
1979
1980 Date now = new Date();
1981
1982 Layout layout = layoutPersistence.findByPrimaryKey(plid);
1983
1984 long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
1985
1986 if (parentPlid > 0) {
1987 Layout parentLayout = layoutPersistence.fetchByPrimaryKey(
1988 parentPlid);
1989
1990 if (parentLayout != null) {
1991 parentLayoutId = parentLayout.getLayoutId();
1992 }
1993 }
1994
1995 parentLayoutId = getParentLayoutId(
1996 layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);
1997
1998 validateParentLayoutId(
1999 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
2000 parentLayoutId);
2001
2002 if (parentLayoutId != layout.getParentLayoutId()) {
2003 int priority = getNextPriority(
2004 layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);
2005
2006 layout.setPriority(priority);
2007 }
2008
2009 layout.setModifiedDate(now);
2010 layout.setParentLayoutId(parentLayoutId);
2011
2012 layoutPersistence.update(layout, false);
2013
2014 return layout;
2015 }
2016
2017
2025 public Layout updatePriority(Layout layout, int priority)
2026 throws SystemException {
2027
2028 if (layout.getPriority() == priority) {
2029 return layout;
2030 }
2031
2032 Date now = new Date();
2033
2034 boolean lessThan = false;
2035
2036 if (layout.getPriority() < priority) {
2037 lessThan = true;
2038 }
2039
2040 layout.setModifiedDate(now);
2041 layout.setPriority(priority);
2042
2043 layoutPersistence.update(layout, false);
2044
2045 priority = 0;
2046
2047 List<Layout> layouts = layoutPersistence.findByG_P_P(
2048 layout.getGroupId(), layout.isPrivateLayout(),
2049 layout.getParentLayoutId());
2050
2051 layouts = ListUtil.sort(
2052 layouts, new LayoutPriorityComparator(layout, lessThan));
2053
2054 for (Layout curLayout : layouts) {
2055 curLayout.setModifiedDate(now);
2056 curLayout.setPriority(priority++);
2057
2058 layoutPersistence.update(curLayout, false);
2059
2060 if (curLayout.equals(layout)) {
2061 layout = curLayout;
2062 }
2063 }
2064
2065 return layout;
2066 }
2067
2068
2080 public Layout updatePriority(
2081 long groupId, boolean privateLayout, long layoutId, int priority)
2082 throws PortalException, SystemException {
2083
2084 Layout layout = layoutPersistence.findByG_P_L(
2085 groupId, privateLayout, layoutId);
2086
2087 return updatePriority(layout, priority);
2088 }
2089
2090
2100 public Layout updatePriority(long plid, int priority)
2101 throws PortalException, SystemException {
2102
2103 Layout layout = layoutPersistence.findByPrimaryKey(plid);
2104
2105 return updatePriority(layout, priority);
2106 }
2107
2108 public void updateScopedPortletNames(
2109 long groupId, boolean privateLayout, long layoutId,
2110 Map<Locale, String> nameMap, List<Locale> nameMapModifiedLocales)
2111 throws PortalException, SystemException {
2112
2113 Layout layout = layoutPersistence.findByG_P_L(
2114 groupId, privateLayout, layoutId);
2115
2116 DynamicQuery portletPreferencesDynamicQuery =
2117 DynamicQueryFactoryUtil.forClass(
2118 PortletPreferences.class, PortletPreferencesImpl.TABLE_NAME);
2119
2120 Property plidProperty = PropertyFactoryUtil.forName("plid");
2121
2122 DynamicQuery layoutDynamicQuery = DynamicQueryFactoryUtil.forClass(
2123 Layout.class, LayoutImpl.TABLE_NAME);
2124
2125 Projection plidProjection = ProjectionFactoryUtil.property("plid");
2126
2127 layoutDynamicQuery.setProjection(plidProjection);
2128
2129 Property groupIdProperty = PropertyFactoryUtil.forName("groupId");
2130
2131 layoutDynamicQuery.add(groupIdProperty.eq(groupId));
2132
2133 Property privateLayoutProperty = PropertyFactoryUtil.forName(
2134 "privateLayout");
2135
2136 layoutDynamicQuery.add(privateLayoutProperty.eq(privateLayout));
2137
2138 portletPreferencesDynamicQuery.add(plidProperty.in(layoutDynamicQuery));
2139
2140 Junction junction = RestrictionsFactoryUtil.disjunction();
2141
2142 List<Portlet> scopablePortlets =
2143 portletLocalService.getScopablePortlets();
2144
2145 for (Portlet scopablePortlet :scopablePortlets) {
2146 if (scopablePortlet.isInstanceable()) {
2147 Criterion criterion = RestrictionsFactoryUtil.like(
2148 "portletId",
2149 scopablePortlet.getPortletId() +
2150 PortletConstants.INSTANCE_SEPARATOR +
2151 StringPool.PERCENT);
2152
2153 junction.add(criterion);
2154 }
2155 else{
2156 Criterion criterion = RestrictionsFactoryUtil.eq(
2157 "portletId", scopablePortlet.getPortletId());
2158
2159 junction.add(criterion);
2160 }
2161 }
2162
2163 portletPreferencesDynamicQuery.add(junction);
2164
2165 List<PortletPreferences> portletPreferencesList =
2166 portletPreferencesLocalService.dynamicQuery(
2167 portletPreferencesDynamicQuery);
2168
2169 for (PortletPreferences portletPreferences : portletPreferencesList) {
2170 if ((portletPreferences.getPortletId() == null)) {
2171 continue;
2172 }
2173
2174 Layout curLayout = layoutPersistence.findByPrimaryKey(
2175 portletPreferences.getPlid());
2176
2177 javax.portlet.PortletPreferences jxPreferences =
2178 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
2179 curLayout, portletPreferences.getPortletId());
2180
2181 String scopeLayoutUuid = GetterUtil.getString(
2182 jxPreferences.getValue("lfrScopeLayoutUuid", null));
2183
2184 if (!scopeLayoutUuid.equals(layout.getUuid())) {
2185 continue;
2186 }
2187
2188 for (Locale locale : nameMapModifiedLocales) {
2189 String languageId = LanguageUtil.getLanguageId(locale);
2190
2191 String portletTitle = PortalUtil.getPortletTitle(
2192 PortletConstants.getRootPortletId(
2193 portletPreferences.getPortletId()), languageId);
2194
2195 String newPortletTitle = PortalUtil.getNewPortletTitle(
2196 portletTitle, curLayout.getName(languageId),
2197 nameMap.get(locale));
2198
2199 if (newPortletTitle.equals(portletTitle)) {
2200 continue;
2201 }
2202
2203 try {
2204 jxPreferences.setValue(
2205 "portletSetupTitle_" + languageId, newPortletTitle);
2206 jxPreferences.setValue(
2207 "portletSetupUseCustomTitle", Boolean.TRUE.toString());
2208
2209 jxPreferences.store();
2210 }
2211 catch (IOException ioe) {
2212 throw new SystemException(ioe);
2213 }
2214 catch (PortletException pe) {
2215 throw new SystemException(pe);
2216 }
2217 }
2218 }
2219 }
2220
2221
2235 public void updateScopedPortletNames(
2236 long groupId, boolean privateLayout, long layoutId, String name,
2237 String languageId)
2238 throws PortalException, SystemException {
2239
2240 Map<Locale, String> map = new HashMap<Locale, String>();
2241
2242 Locale locale = LocaleUtil.fromLanguageId(languageId);
2243
2244 map.put(locale, name);
2245
2246 List<Locale> locales = new ArrayList<Locale>();
2247
2248 locales.add(locale);
2249
2250 updateScopedPortletNames(
2251 groupId, privateLayout, layoutId, map, locales);
2252 }
2253
2254 protected String getFriendlyURL(
2255 long groupId, boolean privateLayout, long layoutId, String name,
2256 String friendlyURL)
2257 throws PortalException, SystemException {
2258
2259 friendlyURL = getFriendlyURL(friendlyURL);
2260
2261 if (Validator.isNull(friendlyURL)) {
2262 friendlyURL = StringPool.SLASH + getFriendlyURL(name);
2263
2264 String originalFriendlyURL = friendlyURL;
2265
2266 for (int i = 1;; i++) {
2267 try {
2268 validateFriendlyURL(
2269 groupId, privateLayout, layoutId, friendlyURL);
2270
2271 break;
2272 }
2273 catch (LayoutFriendlyURLException lfurle) {
2274 int type = lfurle.getType();
2275
2276 if (type == LayoutFriendlyURLException.DUPLICATE) {
2277 friendlyURL = originalFriendlyURL + i;
2278 }
2279 else {
2280 friendlyURL = StringPool.SLASH + layoutId;
2281
2282 break;
2283 }
2284 }
2285 }
2286 }
2287
2288 return friendlyURL;
2289 }
2290
2291 protected String getFriendlyURL(String friendlyURL) {
2292 return FriendlyURLNormalizerUtil.normalize(friendlyURL);
2293 }
2294
2295 protected int getNextPriority(
2296 long groupId, boolean privateLayout, long parentLayoutId)
2297 throws SystemException {
2298
2299 List<Layout> layouts = layoutPersistence.findByG_P_P(
2300 groupId, privateLayout, parentLayoutId);
2301
2302 if (layouts.size() == 0) {
2303 return 0;
2304 }
2305
2306 Layout layout = layouts.get(layouts.size() - 1);
2307
2308 return layout.getPriority() + 1;
2309 }
2310
2311 protected long getParentLayoutId(
2312 long groupId, boolean privateLayout, long parentLayoutId)
2313 throws SystemException {
2314
2315 if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2316
2317
2318
2319 Layout parentLayout = layoutPersistence.fetchByG_P_L(
2320 groupId, privateLayout, parentLayoutId);
2321
2322 if (parentLayout == null) {
2323 parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
2324 }
2325 }
2326
2327 return parentLayoutId;
2328 }
2329
2330 protected boolean hasLayoutSetPrototypeLayout(
2331 LayoutSetPrototype layoutSetPrototype, String layoutUuid)
2332 throws PortalException, SystemException {
2333
2334 Group group = layoutSetPrototype.getGroup();
2335
2336 Layout layout = layoutPersistence.fetchByUUID_G(
2337 layoutUuid, group.getGroupId());
2338
2339 if (layout != null) {
2340 return true;
2341 }
2342
2343 return false;
2344 }
2345
2346 protected void validate(
2347 long groupId, boolean privateLayout, long layoutId,
2348 long parentLayoutId, String name, String type, boolean hidden,
2349 String friendlyURL)
2350 throws PortalException, SystemException {
2351
2352 validateName(name);
2353
2354 boolean firstLayout = false;
2355
2356 if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2357 List<Layout> layouts = layoutPersistence.findByG_P_P(
2358 groupId, privateLayout, parentLayoutId, 0, 1);
2359
2360 if (layouts.size() == 0) {
2361 firstLayout = true;
2362 }
2363 else {
2364 long firstLayoutId = layouts.get(0).getLayoutId();
2365
2366 if (firstLayoutId == layoutId) {
2367 firstLayout = true;
2368 }
2369 }
2370 }
2371
2372 if (firstLayout) {
2373 validateFirstLayout(type);
2374 }
2375
2376 if (!PortalUtil.isLayoutParentable(type)) {
2377 if (layoutPersistence.countByG_P_P(
2378 groupId, privateLayout, layoutId) > 0) {
2379
2380 throw new LayoutTypeException(
2381 LayoutTypeException.NOT_PARENTABLE);
2382 }
2383 }
2384
2385 validateFriendlyURL(groupId, privateLayout, layoutId, friendlyURL);
2386 }
2387
2388 protected void validateFirstLayout(String type)
2389 throws PortalException {
2390
2391 if (Validator.isNull(type) || !PortalUtil.isLayoutFirstPageable(type)) {
2392 LayoutTypeException lte = new LayoutTypeException(
2393 LayoutTypeException.FIRST_LAYOUT);
2394
2395 lte.setLayoutType(type);
2396
2397 throw lte;
2398 }
2399 }
2400
2401 protected void validateFriendlyURL(
2402 long groupId, boolean privateLayout, long layoutId,
2403 String friendlyURL)
2404 throws PortalException, SystemException {
2405
2406 if (Validator.isNull(friendlyURL)) {
2407 return;
2408 }
2409
2410 int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
2411
2412 if (exceptionType != -1) {
2413 throw new LayoutFriendlyURLException(exceptionType);
2414 }
2415
2416 Layout layout = layoutPersistence.fetchByG_P_F(
2417 groupId, privateLayout, friendlyURL);
2418
2419 if ((layout != null) && (layout.getLayoutId() != layoutId)) {
2420 throw new LayoutFriendlyURLException(
2421 LayoutFriendlyURLException.DUPLICATE);
2422 }
2423
2424 LayoutImpl.validateFriendlyURLKeyword(friendlyURL);
2425
2426
2440
2441 String layoutIdFriendlyURL = friendlyURL.substring(1);
2442
2443 if (Validator.isNumber(layoutIdFriendlyURL) &&
2444 !layoutIdFriendlyURL.equals(String.valueOf(layoutId))) {
2445
2446 LayoutFriendlyURLException lfurle = new LayoutFriendlyURLException(
2447 LayoutFriendlyURLException.POSSIBLE_DUPLICATE);
2448
2449 lfurle.setKeywordConflict(layoutIdFriendlyURL);
2450
2451 throw lfurle;
2452 }
2453 }
2454
2455 protected void validateName(String name) throws PortalException {
2456 if (Validator.isNull(name)) {
2457 throw new LayoutNameException();
2458 }
2459 }
2460
2461 protected void validateName(String name, String languageId)
2462 throws PortalException {
2463
2464 String defaultLanguageId = LocaleUtil.toLanguageId(
2465 LocaleUtil.getDefault());
2466
2467 if (defaultLanguageId.equals(languageId)) {
2468 validateName(name);
2469 }
2470 }
2471
2472 protected void validateParentLayoutId(
2473 long groupId, boolean privateLayout, long layoutId,
2474 long parentLayoutId)
2475 throws PortalException, SystemException {
2476
2477 Layout layout = layoutPersistence.findByG_P_L(
2478 groupId, privateLayout, layoutId);
2479
2480 if (parentLayoutId != layout.getParentLayoutId()) {
2481
2482
2483
2484 if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2485 return;
2486 }
2487
2488
2489
2490 Layout parentLayout = layoutPersistence.findByG_P_L(
2491 groupId, privateLayout, parentLayoutId);
2492
2493 if (!PortalUtil.isLayoutParentable(parentLayout)) {
2494 throw new LayoutParentLayoutIdException(
2495 LayoutParentLayoutIdException.NOT_PARENTABLE);
2496 }
2497
2498
2499
2500 if (PortalUtil.isLayoutDescendant(layout, parentLayoutId)) {
2501 throw new LayoutParentLayoutIdException(
2502 LayoutParentLayoutIdException.SELF_DESCENDANT);
2503 }
2504
2505
2506
2507 if (layout.getParentLayoutId() ==
2508 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2509
2510 List<Layout> layouts = layoutPersistence.findByG_P_P(
2511 groupId, privateLayout,
2512 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0, 2);
2513
2514
2515
2516
2517 long firstLayoutId = layouts.get(0).getLayoutId();
2518
2519 if (firstLayoutId == layoutId) {
2520 Layout secondLayout = layouts.get(1);
2521
2522 try {
2523 validateFirstLayout(secondLayout.getType());
2524 }
2525 catch (LayoutHiddenException lhe) {
2526 throw new LayoutParentLayoutIdException(
2527 LayoutParentLayoutIdException.FIRST_LAYOUT_HIDDEN);
2528 }
2529 catch (LayoutTypeException lte) {
2530 throw new LayoutParentLayoutIdException(
2531 LayoutParentLayoutIdException.FIRST_LAYOUT_TYPE);
2532 }
2533 }
2534 }
2535 }
2536 }
2537
2538 }