Liferay额外研究(一):http://blog.csdn.net/james999/archive/2006/07/26/979938.aspx
Liferay额外研究(二):http://blog.csdn.net/james999/archive/2006/07/27/986386.aspx
Liferay额外研究(三):http://blog.csdn.net/james999/archive/2006/08/08/1037326.aspx
Liferay在用户第一次登陆后,都会为其产生一个默认的私有首页Layout。 在Liferay早期版本,可以在系统管理员管理界面中,配置默认的group layout。但是在4.1版本中已经没有这个功能,所以默认情况下,新注册的用户,在登陆后,首先看到的其私有place都是一样的内容,而这些内容都是liferay提供的。
对我们自定的Company来说,这肯定是不合适的,我们需要自己定义用户登录后,默认显示的内容和布局。
后来在Liferay forum中,找到了一篇帖子,给了解决此种问题的解决办法:在portlet-ext.properties中配置一个 default.user.layout.group 属性(自定义的),用于指明默认的layout-group。在ServicePreAction类的扩展修改 addDefaultLayouts 操作,满足特定的需求应用。这种扩展的方式就是,将指定layout-group拷贝给用户第一默认的,这样就不会再使用liferay默认的了。—— 当然这样的方式是比较简单的,可能在系统实施过程中,有比这更加复杂的需求。
新建默认的Community
首先,通过新增一个新的Community,命名为User_Default,并新增一个private的page与内容.
配置默认的Community
首先在ext项目的 ext-ejb目录下,修改portal-ext.properties文件,增加如下设置:
default.user.layout.group=User_Default
然后通过build,将portal-ext.properties移动到 ext项目的
ext\servers\tomcat\webapps\ROOT\WEB-INF\classes 目录下。
构造LayoutCopy类
public class LayoutCopy ...{ private static Log _log = LogFactory.getLog(LayoutCopy.class); private User user; private String ownerId; private Group userGroup; public LayoutCopy(User user) ...{ super(); this.user = user; this.ownerId = getOwnerId(user.getGroup().getGroupId(), false); this.userGroup = user.getGroup(); } public void copyDefaultUserLayout(HttpServletRequest httpReq) throws SystemException, PortalException ...{ // set in the portal-ext.properties: // default.user.layout.group=Default User // and create then group/community "Default User" // CWPPropsUtil.DEFUALT_USER_LAYOUT_GROUP = "default.user.layout.group" Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), PropsUtil.get("default.user.layout.group")); try ...{ String groupOwnerId = getOwnerId(group.getGroupId(), true); List privateLayouts = LayoutLocalServiceUtil .getLayouts(groupOwnerId); for (Iterator itr = privateLayouts.iterator(); itr.hasNext();) ...{ Layout layout = (Layout) itr.next(); Layout newLayout = copyLayout(layout); copyPreferences(httpReq, newLayout, layout); } } catch (PortalException e) ...{ _log.error("Cannot copy private layouts", e); } catch (Exception e) ...{ _log.error("Cannot copy public layouts", e); } try ...{ String groupOwnerId = getOwnerId(group.getGroupId(), false); List publicLayouts = LayoutLocalServiceUtil .getLayouts(groupOwnerId); for (Iterator itr = publicLayouts.iterator(); itr.hasNext();) ...{ Layout layout = (Layout) itr.next(); Layout newLayout = copyLayout(layout); copyPreferences(httpReq, newLayout, layout); } } catch (PortalException e) ...{ _log.error("Cannot copy public layouts", e); } catch (Exception e) ...{ _log.error("Cannot copy public layouts", e); } } public void resetLayout(HttpServletRequest httpReq) throws SystemException, PortalException ...{ String ownerId = getOwnerId(user.getGroup().getGroupId(), false); LayoutLocalServiceUtil.deleteLayouts(ownerId); PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId); ownerId = getOwnerId(user.getGroup().getGroupId(), true); LayoutLocalServiceUtil.deleteLayouts(ownerId); PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId); copyDefaultUserLayout(httpReq); } public Layout copyLayout(Layout groupDefaultLayout) throws SystemException, PortalException ...{ Layout layout = LayoutLocalServiceUtil.addLayout( userGroup.getGroupId(), user.getUserId(), groupDefaultLayout .isPrivateLayout(), groupDefaultLayout .getParentLayoutId(), groupDefaultLayout.getName(user .getLocale()), groupDefaultLayout.getType(), groupDefaultLayout.isHidden(), null); LayoutLocalServiceUtil.updateLayout(layout.getLayoutId(), layout .getOwnerId(), groupDefaultLayout.getTypeSettings()); layout = LayoutLocalServiceUtil.updateLookAndFeel(layout.getLayoutId(), layout.getOwnerId(), groupDefaultLayout.getThemeId(), groupDefaultLayout.getColorSchemeId()); // layoutMapping.put(groupDefaultLayout.getPrimaryKey(), // layout.getPrimaryKey()); return layout; } protected void copyPreferences(HttpServletRequest httpReq, Layout layout, Layout copyLayout) throws Exception ...{ String companyId = layout.getCompanyId(); LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout .getLayoutType(); List copyPortletIds = copyLayoutTypePortlet.getPortletIds(); for (int i = 0; i < copyPortletIds.size(); i++) ...{ String copyPortletId = (String) copyPortletIds.get(i); // Copy preference PortletPreferencesPK prefsPK = PortletPreferencesFactory .getPortletPreferencesPK(httpReq, copyPortletId, layout .getPlid()); PortletPreferencesLocalServiceUtil.getPreferences(companyId, prefsPK); PortletPreferencesPK copyPrefsPK = PortletPreferencesFactory .getPortletPreferencesPK(httpReq, copyPortletId, copyLayout .getPlid()); PortletPreferencesImpl copyPrefsImpl = (PortletPreferencesImpl) PortletPreferencesLocalServiceUtil .getPreferences(companyId, copyPrefsPK); PortletPreferencesLocalServiceUtil.updatePreferences(prefsPK, copyPrefsImpl); // Copy portlet setup prefsPK = new PortletPreferencesPK(copyPortletId, layout .getLayoutId(), layout.getOwnerId()); PortletPreferencesLocalServiceUtil.getPreferences(companyId, prefsPK); copyPrefsPK = new PortletPreferencesPK(copyPortletId, copyLayout .getLayoutId(), copyLayout.getOwnerId()); copyPrefsImpl = (PortletPreferencesImpl) PortletPreferencesLocalServiceUtil .getPreferences(companyId, copyPrefsPK); PortletPreferencesLocalServiceUtil.updatePreferences(prefsPK, copyPrefsImpl); } } private String getOwnerId(String groupId, boolean privateLayout) ...{ if (privateLayout) ...{ return Layout.PRIVATE + groupId; } else ...{ return Layout.PUBLIC + groupId; } }}修改com.liferay.portal.events.ServicePreAction类
是在 ext工程的 ext-ejb/src下修改,新建com.liferay.portal.events包,并把原始的ServicePreAction类拷贝至此,然后修改,修改后通过ext-ejb下的build.xml编译部署。
在ServicePreAction类中新增一个addDefaultLayouts方法:
protected void addDefaultLayouts(HttpServletRequest httpReq, User user)
throws PortalException, SystemException {
if (user.hasPrivateLayouts()) {
return;
}
(new LayoutCopy(user)).copyDefaultUserLayout(httpReq);
}
然后,修改run方法中对原始addDefaultLayouts方法的调用方法:
if (layoutsRequired) {
String user_layout_group = PropsUtil.get("default.user.layout.group");
if(user_layout_group==null || user_layout_group.length()==0){
addDefaultLayouts(user);
}else{
addDefaultLayouts(req, user);
}
}