Advertisement
Guest User

Untitled

a guest
Aug 30th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled
  2.  
  3. SitesUtil.mergeLayoutSetProtypeLayouts
  4.  
  5. public static void setupSitesFromSiteTemplate(long groupId, long publicSiteTemplateId,
  6. long privateSiteTemplateId) throws PortalException, SystemException {
  7. Group group = GroupLocalServiceUtil.getGroup(groupId);
  8. if (publicSiteTemplateId != 0) setSiteTemplate(group, publicSiteTemplateId, false);
  9. if (privateSiteTemplateId != 0) setSiteTemplate(group, privateSiteTemplateId, true);
  10. }
  11.  
  12. public static void setSiteTemplate(Group group, long siteTemplateId, boolean isPrivateLayout)
  13. throws PortalException, SystemException {
  14. long groupId = group.getGroupId();
  15. LayoutSetPrototype prototype = LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(siteTemplateId);
  16. boolean layoutSetPrototypeLinkEnabled = true;
  17. LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(groupId, isPrivateLayout,
  18. layoutSetPrototypeLinkEnabled, prototype.getUuid());
  19. try {
  20. LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, isPrivateLayout);
  21. mergeLayoutSetProtypeLayouts(group, layoutSet);
  22. } catch (Exception e) {
  23. if (_log.isWarnEnabled()) {
  24. String privatePublic = isPrivateLayout ? "private" : "public";
  25. _log.warn(String.format("Could not merge %s layouts for group[%d] from template[%d]", privatePublic,
  26. groupId, siteTemplateId));
  27. e.printStackTrace();
  28. }
  29. }
  30. }
  31.  
  32. public static void mergeLayoutSetProtypeLayouts(Group group, LayoutSet layoutSet) throws Exception {
  33.  
  34. MethodKey key = SitesUtilMethodKey("mergeLayoutSetProtypeLayouts", Group.class, LayoutSet.class);
  35. invokePortalClassMethod(key, group, layoutSet);
  36. }
  37. /*
  38. * copied from
  39. * http://www.liferay.com/community/forums/-/message_boards/view_message /10488983#_19_message_10488983
  40. * post by Jelmer Kuperus
  41. *
  42. * key: key of method to be called, e.g. com.liferay.portlet.sites.util.SitesUtil
  43. * arguments: arguments to be passed to the invoked method
  44. * returns: result of the invoked method
  45. */
  46. private static Object invokePortalClassMethod(MethodKey key, Object... arguments) throws PortalException {
  47. try {
  48. // noinspection unchecked
  49. return PortalClassInvoker.invoke(false, key, arguments);
  50. } catch (PortalException e) {
  51. throw e;
  52. } catch (Exception e) {
  53. throw new RuntimeException(e);
  54. }
  55. }
  56. private static final String SITES_UTIL_CLASS_NAME = "com.liferay.portlet.sites.util.SitesUtil";
  57. private static MethodKey SitesUtilMethodKey(String methodName, Class<?>... parameterTypes) {
  58. return new MethodKey(SITES_UTIL_CLASS_NAME, methodName, parameterTypes);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement