忍了很久了,好久都没有看liferay的文档了,今天又有朋友问我liferay的问题,我就把之前的文档找出来了,翻译了下,嘿嘿,大家分享下。
// 初始化
portal.servlet.MainServlet.init()
portal.events.StartupAction.run()
// 初始化portlets.
String[] xmls = new String[] {
Http.URLtoString(ctx.getResource(
"/WEB-INF/" + PortalUtil.PORTLET_XML_FILE_NAME_CUSTOM)),
Http.URLtoString(ctx.getResource(
"/WEB-INF/portlet-ext.xml")),
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-portlet.xml")),
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-portlet-ext.xml")),
Http.URLtoString(ctx.getResource("/WEB-INF/web.xml"))
};
PortletLocalServiceUtil.initEAR(xmls, pluginPackage);
// 初始化layout模板.
String[] xmls = new String[] {
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-layout-templates.xml")),
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-layout-templates-ext.xml"))
};
LayoutTemplateLocalUtil.init(ctx, xmls, pluginPackage);
// 初始化Theme.
String[] xmls = new String[] {
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-look-and-feel.xml")),
Http.URLtoString(ctx.getResource(
"/WEB-INF/liferay-look-and-feel-ext.xml"))
};
ThemeLocalUtil.init(ctx, null, true, xmls, pluginPackage);
// 响应服务
portal.servlet.MainServlet.service()
// get portalContext
ServletContext ctx = getServletContext();
ServletContext portalCtx = ctx.getContext(
PrefsPropsUtil.getString(_companyId, PropsUtil.PORTAL_CTX));
// Struts module config
ModuleConfig moduleConfig = getModuleConfig(req);
// Portlet Request Processor - 在struts.config中定义.
portletReqProcessor = PortletRequestProcessor.getInstance(this, moduleConfig);
/html/portal/layout.jsp - portal布局页面.
<%= request.getAttribute(WebKeys.LAYOUT_CONTENT) %>
// 处理模板
portlet.layoutconfiguration.util.RuntimePortletUtil.processTemplate(
application, pageContext, request, response, content);
// 注入模板处理程序
TemplateProcessor processor = new TemplateProcessor(ctx, req, res, portletId);
VelocityContext context = new VelocityContext();
context.put("processor", processor);
// 处理模板
Velocity.evaluate(context, pageContext.getOut(),
RuntimePortletUtil.class.getName(), content);
// 处理各列
portlet.layoutconfiguration.util.velocity.TemplateProcessor.processColumn(
String columnId) throws Exception {
HashMap attributes = new HashMap();
attributes.put("id", columnId);
RuntimeLogic logic = new PortletColumnLogic(_ctx, _req, _res);
StringBuffer sb = new StringBuffer();
logic.processContent(sb, attributes);
return sb.toString();
}
// 处理列内容
portlet.layoutconfiguration.util.velocity.PortletColumnLogic.processContent(
StringBuffer sb, Map attributes) throws Exception {
String columnId = (String)attributes.get("id");
sb.append("<div id=/"layout-column_");
sb.append(columnId);
sb.append("/">");
LayoutTypePortlet layoutTypePortlet =
_themeDisplay.getLayoutTypePortlet();
// 取得当前列的所有portlet.
List portlets = layoutTypePortlet.getAllPortlets(columnId);
// 处理各portlet.
for (int i = 0; i < portlets.size(); i++) {
Portlet portlet = (Portlet)portlets.get(i);
String rootPortletId = portlet.getRootPortletId();
String instanceId = portlet.getInstanceId();
RuntimePortletUtil.processPortlet(
sb, _ctx, _req, _res, null, null, rootPortletId, instanceId,
columnId, new Integer(i), new Integer(portlets.size()));
}
sb.append("<div class=/"layout-blank-portlet/"></div>");
sb.append("</div>");
}
// 处理Portlet.
portlet.layoutconfiguration.util.RuntimePortletUtil.processPortlet(
StringBuffer sb, ServletContext ctx, HttpServletRequest req,
HttpServletResponse res, RenderRequest renderRequest,
RenderResponse renderResponse, String portletId, String instanceId,
String columnId, Integer columnPos, Integer columnCount)
throws Exception {
ThemeDisplay themeDisplay =
(ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
Portlet portlet = PortletLocalServiceUtil.getPortletById(
themeDisplay.getCompanyId(), portletId);
if ((portlet != null) && portlet.isInstanceable()) {
if (Validator.isNotNull(instanceId) &&
Validator.isPassword(instanceId) &&
(instanceId.length() == 4)) {
portletId +=
Portlet.INSTANCE_SEPARATOR + instanceId;
portlet = PortletLocalServiceUtil.getPortletById(
themeDisplay.getCompanyId(), portletId);
}
else {
if (_log.isDebugEnabled()) {
_log.debug(
"Portlet " + portlet.getPortletId() +
" is instanceable but does not have a " +
"valid instance id");
}
portlet = null;
}
}
if (portlet == null) {
return;
}
// Capture the current portlet's settings to reset them once the child
// portlet is rendered
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
PortletDisplay portletDisplayClone =
(PortletDisplay)portletDisplay.clone();
PortletConfig portletConfig =
(PortletConfig)req.getAttribute(WebKeys.JAVAX_PORTLET_CONFIG);
try {
PortalUtil.renderPortlet(
sb, ctx, req, res, portlet, columnId, columnPos, columnCount);
}
finally {
portletDisplay.copyFrom(portletDisplayClone);
PortletDisplayFactory.recycle(portletDisplayClone);
_defineObjects(
req, portletConfig, renderRequest, renderResponse);
}
}
portal.util.PortalUtil.renderPortlet(
StringBuffer sb, ServletContext ctx, HttpServletRequest req,
HttpServletResponse res, Portlet portlet, String columnId,
Integer columnPos, Integer columnCount)
throws IOException, ServletException {
columnId = GetterUtil.getString(columnId);
if (columnPos == null) {
columnPos = new Integer(0);
}
if (columnCount == null) {
columnCount = new Integer(0);
}
req.setAttribute(WebKeys.RENDER_PORTLET, portlet);
req.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_ID, columnId);
req.setAttribute(WeRTLET_CbKeys.RENDER_POOLUMN_POS, columnPos);
req.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_COUNT, columnCount);
RequestDispatcher rd = ctx.getRequestDispatcher(
"/html/portal/render_portlet.jsp");
if (sb != null) {
StringServletResponse stringServletRes =
new StringServletResponse(res);
rd.include(req, stringServletRes);
sb.append(stringServletRes.getString());
}
else {
// LEP-766
String strutsCharEncoding =
PropsUtil.get(PropsUtil.STRUTS_CHAR_ENCODING);
req.setCharacterEncoding(strutsCharEncoding);
res.setContentType(Constants.TEXT_HTML + "; charset=UTF-8");
rd.include(req, res);
}
}
/html/portal/render_portlet.jsp - Portlet输出页面。
Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
CachePortlet cachePortlet = PortletInstanceFactory.create(portlet, application);
PortletPreferences portletPrefs = PortletPreferencesLocalServiceUtil.getPreferences(
company.getCompanyId(), PortletPreferencesFactory.getPortletPreferencesPK(request, portletId));
PortletConfig portletConfig = PortletConfigFactory.create(portlet, application);
PortletContext portletCtx = portletConfig.getPortletContext();
HttpServletRequest originalReq = PortalUtil.getOriginalServletRequest(request);
RenderRequestImpl renderRequestImpl = RenderRequestFactory.create(
originalReq, portlet, cachePortlet, portletCtx, windowState, portletMode, portletPrefs, plid);
StringServletResponse stringServletRes = new StringServletResponse(response);
RenderResponseImpl renderResponseImpl = RenderResponseFactory.create(
renderRequestImpl, stringServletRes, portletId, company.getCompanyId(), plid);
renderRequestImpl.defineObjects(portletConfig, renderResponseImpl);
if (portlet.isActive() && access) {
try {
cachePortlet.render(renderRequestImpl, renderResponseImpl);
}
catch (UnavailableException ue) {
portletException = true;
PortletInstanceFactory.destroy(portlet);
}
}
%>
<div id="p_p_id<%= renderResponseImpl.getNamespace() %>"
class="portlet-boundary portlet-boundary<%= PortalUtil.getPortletNamespace(portlet.getRootPortletId()) %>">
<a name="p_<%= portletId %>"></a>
<script type="text/javascript">
var portletEl = document.getElementById("p_p_id<%= renderResponseImpl.getNamespace() %>");
portletEl.portletId = "<%= portletId %>";
portletEl.isStatic = <%= portlet.isStatic() || !showMoveIcon %>;
portletEl.isStaticStart = <%= portlet.isStaticStart() %>;
portletEl.isStaticEnd = <%= portlet.isStaticEnd() %>;
</script>
<c:choose>
<c:when test="<%= !access && !portlet.isShowPortletAccessDenied() %>">
</c:when>
<c:when test="<%= !portlet.isActive() && !portlet.isShowPortletInactive() %>">
</c:when>
<c:otherwise>
<%
boolean useDefaultTemplate = portlet.isUseDefaultTemplate();
Boolean useDefaultTemplateObj = renderResponseImpl.getUseDefaultTemplate();
if (useDefaultTemplateObj != null) {
useDefaultTemplate = useDefaultTemplateObj.booleanValue();
}
//cachePortlet不为空并且为StrutsPortlet.
if ((cachePortlet != null) && cachePortlet.isStrutsPortlet()) {
if (!access || portletException) { // 不能访问或出错!
String templatePath = Constants.TEXT_HTML_DIR + "/common/themes/portlet.jsp";
if (definition != null) {
templatePath = Constants.TEXT_HTML_DIR + definition.getPath();
}
%>
<tiles:insert template="<%= templatePath %>" flush="false">
<tiles:put name="portlet_content" value="/portal/portlet_error.jsp" />
</tiles:insert>
<%
}
else {
if (useDefaultTemplate) {
// 通过Tiles输出portlet内容.
renderRequestImpl.setAttribute(WebKeys.PORTLET_CONTENT, stringServletRes.getString());
%>
<tiles:insert template='<%= Constants.TEXT_HTML_DIR + "/common/themes/portlet.jsp" %>' flush="false">
<tiles:put name="portlet_content" value="<%= StringPool.BLANK %>" />
</tiles:insert>
<%
}
else { // 直接输出portlet内容.
pageContext.getOut().print(stringServletRes.getString());
}
}
}
else {
renderRequestImpl.setAttribute(WebKeys.PORTLET_CONTENT, stringServletRes.getString());
String portletContent = StringPool.BLANK;
if (portletException) {
portletContent = "/portal/portlet_error.jsp";
}
%>
<c:choose>
<c:when test="<%= useDefaultTemplate || portletException %>">
<tiles:insert template='<%= Constants.TEXT_HTML_DIR + "/common/themes/portlet.jsp" %>' flush="false">
<tiles:put name="portlet_content" value="<%= portletContent %>" />
</tiles:insert>
</c:when>
<c:otherwise>
<%= renderRequestImpl.getAttribute(WebKeys.PORTLET_CONTENT) %>
</c:otherwise>
</c:choose>
<%
}
%>
</c:otherwise>
</c:choose>
</div>
/html/common/themes/portlet.jsp - Portlet主题页面
// 处理tilesPortletContent
<tiles:useAttribute id="tilesPortletContent" name="portlet_content" classname="java.lang.String" ignore="true" />
<tiles:useAttribute id="tilesPortletDecorate" name="portlet_decorate" classname="java.lang.String" ignore="true" />
<tiles:useAttribute id="tilesPortletPadding" name="portlet_padding" classname="java.lang.String" ignore="true" />
<%
Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
PortletPreferences portletSetup = PortletPreferencesFactory.getPortletSetup(
request, portletDisplay.getId(), true, true);
RenderResponseImpl renderResponseImpl = (RenderResponseImpl)renderResponse;
String currentURL = PortletURLUtil.getCurrent(renderRequest, renderResponse).toString();
// Portlet decorate
boolean tilesPortletDecorateBoolean = GetterUtil.getBoolean(tilesPortletDecorate, true);
boolean portletDecorate = GetterUtil.getBoolean(
portletSetup.getValue("portlet-setup-show-borders", String.valueOf(tilesPortletDecorateBoolean)));
Properties cssProps = PropertiesUtil.load(portletSetup.getValue("portlet-setup-css", StringPool.BLANK));
%>
<c:if test="<%= (cssProps != null) && (cssProps.size() > 0) %>">
<%@ include file="/html/common/themes/portlet_css.jsp" %>
</c:if>
// portlet选择
/html/portlet/layout_configuration/view.jsp
<%
PortletCategory portletCategory = (PortletCategory)WebAppPool.get(
company.getCompanyId(), WebKeys.PORTLET_CATEGORY);
// 读取所有的portlet根类别.
List categories = ListUtil.fromCollection(portletCategory.getCategories());
// 排序,
Collections.sort(categories, new PortletCategoryComparator(company.getCompanyId(), locale));
Iterator itr = categories.iterator();
while (itr.hasNext()) {
request.setAttribute(WebKeys.PORTLET_CATEGORY, itr.next());
%>
<liferay-util:include page="/html/portlet/layout_configuration/view_category.jsp" />
<% } %>
/html/portlet/layout_configuration/view-category.jsp
<%
PortletCategory portletCategory = (PortletCategory)request.getAttribute(WebKeys.PORTLET_CATEGORY);
String oldCategoryPath = (String)request.getAttribute(WebKeys.PORTLET_CATEGORY_PATH);
String newCategoryPath = LanguageUtil.get(pageContext, portletCategory.getName());
if (Validator.isNotNull(oldCategoryPath)) {
newCategoryPath = oldCategoryPath + ":" + newCategoryPath;
}
// 读取子类别,
List categories = ListUtil.fromCollection(portletCategory.getCategories());
// 排序
Collections.sort(categories, new PortletCategoryComparator(company.getCompanyId(), locale));
List portlets = new ArrayList();
// 读取类别下的所有portlet定义。
Iterator itr1 = portletCategory.getPortlets().iterator();
while (itr1.hasNext()) {
String portletId = (String)itr1.next();
Portlet portlet = PortletLocalServiceUtil.getPortletById(user.getCompanyId(), portletId);
if (portlet != null) { // 检查portlet是否为可选择的?
if (portlet.isSystem()) {
}
else if (!portlet.isActive()) {
}
else if (!portlet.isInstanceable() && layoutTypePortlet.hasPortletId(portlet.getPortletId())) {
}
else if (!portlet.hasAddPortletPermission(user.getUserId())) {
}
else {
portlets.add(portlet);
}
}
}
// 排序.
Collections.sort(portlets, new PortletTitleComparator(application, locale));
if ((categories.size() > 0) || (portlets.size() > 0)) {
%>
<div class="layout_configuration_category_pane" style="display: none;">
<%
// 遍历子类别.
Iterator itr2 = categories.iterator();
while (itr2.hasNext()) {
request.setAttribute(WebKeys.PORTLET_CATEGORY, itr2.next());
request.setAttribute(WebKeys.PORTLET_CATEGORY_PATH, newCategoryPath);
%>
<liferay-util:include page="/html/portlet/layout_configuration/view_category.jsp" />
<%
request.setAttribute(WebKeys.PORTLET_CATEGORY_PATH, oldCategoryPath);
}
itr2 = portlets.iterator();
while (itr2.hasNext()) {
// 输出可选择的portlet.
Portlet portlet = (Portlet)itr2.next();
%>
<div class="layout_configuration_portlet" id="<%= newCategoryPath %>:<%= PortalUtil.getPortletTitle(portlet, application, locale) %>">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td width="99%">
<%= PortalUtil.getPortletTitle(portlet, application, locale) %></td>
<td align="right">
<input class="portlet-form-button" type="button" value="<%= LanguageUtil.get(pageContext, "add") %>"
onClick="
addPortlet('<%= plid %>', '<%= portlet.getPortletId() %>');
if (<%= !portlet.isInstanceable() %>) {
var div = document.getElementById('<%= StringUtil.replace(newCategoryPath + ":" + PortalUtil.getPortletTitle(portlet, application, locale), "'", "//'") %>');
div.parentNode.removeChild(div);
};">
</td>
</tr>
</table>
</div>
<% } %>
</div>
<% } %>
// 更新layout.
com.com.liferay.portal.action.UpdateLayoutAction
public class UpdateLayoutAction extends Action {
public ActionForward execute(
ActionMapping mapping, ActionForm form, HttpServletRequest req,
HttpServletResponse res)
throws Exception {
Layout layout = (Layout)req.getAttribute(WebKeys.LAYOUT);
LayoutTypePortlet layoutTypePortlet =
(LayoutTypePortlet)layout.getLayoutType();
String cmd = ParamUtil.getString(req, Constants.CMD);
String portletId = ParamUtil.getString(req, "p_p_id");
if (cmd.equals(Constants.ADD)) { // 添加portlet到layout.
portletId = layoutTypePortlet.addPortletId(
req.getRemoteUser(), portletId);
}
else if (cmd.equals(Constants.DELETE)) { // 从layout删除指定portlet.
layoutTypePortlet.removePortletId(portletId);
}
else if (cmd.equals("minimize")) { // portlet最小化.
boolean restore = ParamUtil.getBoolean(req, "p_p_restore");
if (restore) {
layoutTypePortlet.removeStateMinPortletId(portletId);
}
else {
layoutTypePortlet.addStateMinPortletId(portletId);
}
}
else if (cmd.equals("move")) { // 移动portlet的位置.
String columnId = ParamUtil.getString(req, "p_p_col_id");
int columnPos = ParamUtil.getInteger(req, "p_p_col_pos");
layoutTypePortlet.movePortletId(
req.getRemoteUser(), portletId, columnId, columnPos);
}
else if (cmd.equals("template")) { // 更改layout的模板.
String layoutTemplateId = ParamUtil.getString(
req, "layoutTemplateId");
layoutTypePortlet.setLayoutTemplateId(layoutTemplateId);
}
// 更新到数据库.
LayoutServiceUtil.updateLayout(
layout.getLayoutId(), layout.getOwnerId(),
layout.getTypeSettings());
if (ParamUtil.getBoolean(req, "refresh")) {
return mapping.findForward(Constants.COMMON_REFERER);
}
else {
if (cmd.equals(Constants.ADD) && (portletId != null)) {
// 输出portlet.
}
return null;
}
}
}
// layout的应用,
/html/portal/layout/view/portlet.jsp
<%
boolean layoutMaximized = layoutTypePortlet.hasStateMax();
if (!layoutMaximized) {
String content = LayoutTemplateLocalUtil.getContent(
layoutTypePortlet.getLayoutTemplateId(), false, theme.getThemeId());
RuntimePortletUtil.processTemplate(application,
pageContext, request, response, content);
}
else {
String content = LayoutTemplateLocalUtil.getContent(
"max", true, theme.getThemeId());
RuntimePortletUtil.processTemplate(
application, pageContext, request, response,
StringUtil.split(layoutTypePortlet.getStateMax())[0], content);
}
List columns = layoutTypePortlet.getLayoutTemplate().getColumns();
%>
上面使用到的layoutTypePortlet是通过自定义Tag来定义的,
有关portlet的输出处理请参考本站的liferay流程处理一文。
// layout相关对象的定义,
在/html/common/init.jsp中有如下定义:
<liferay-theme:defineObjects />
com.liferay.taglib.theme.DefineObjectsTag
public class DefineObjectsTag extends TagSupport {
public int doStartTag() {
ServletRequest req = pageContext.getRequest();
ThemeDisplay themeDisplay =
(ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
if (themeDisplay != null) {
pageContext.setAttribute("themeDisplay", themeDisplay);
pageContext.setAttribute("company", themeDisplay.getCompany());
pageContext.setAttribute("account", themeDisplay.getAccount());
pageContext.setAttribute("user", themeDisplay.getUser());
pageContext.setAttribute("contact", themeDisplay.getContact());
if (themeDisplay.getLayout() != null) {
pageContext.setAttribute("layout", themeDisplay.getLayout());
}
if (themeDisplay.getLayouts() != null) {
pageContext.setAttribute("layouts", themeDisplay.getLayouts());
}
pageContext.setAttribute("plid", themeDisplay.getPlid());
if (themeDisplay.getLayoutTypePortlet() != null) {
pageContext.setAttribute(
"layoutTypePortlet", themeDisplay.getLayoutTypePortlet());
}
pageContext.setAttribute(
"portletGroupId", themeDisplay.getPortletGroupId());
pageContext.setAttribute(
"permissionChecker", themeDisplay.getPermissionChecker());
pageContext.setAttribute("locale", themeDisplay.getLocale());
pageContext.setAttribute("timeZone", themeDisplay.getTimeZone());
pageContext.setAttribute("theme", themeDisplay.getTheme());
pageContext.setAttribute(
"colorScheme", themeDisplay.getColorScheme());
pageContext.setAttribute(
"portletDisplay", themeDisplay.getPortletDisplay());
}
return SKIP_BODY;
}
}
上面定义了themeDisplay, layout, portletDiaplay, locale, timeZone等与UI相关的对象.
// layout相关对象的读取,
layout相关对象是在服务前置处理事件ServicePreAction中初始化的,事件(Event)是liferay中的一种扩展机制。
com.liferay.portal.events.ServicePreAction
public class ServicePreAction extends Action {
public void run(HttpServletRequest req, HttpServletResponse res)
throws ActionException {
try {
HttpSession ses = req.getSession();
// Company
Company company = PortalUtil.getCompany(req);
String companyId = company.getCompanyId();
// Paths
String contextPath = PrefsPropsUtil.getString(
companyId, PropsUtil.PORTAL_CTX);
if (contextPath.equals(StringPool.SLASH)) {
contextPath = StringPool.BLANK;
}
String rootPath = (String)req.getAttribute(WebKeys.ROOT_PATH);
String mainPath = (String)req.getAttribute(WebKeys.MAIN_PATH);
String friendlyURLPrivatePath =
(String)req.getAttribute(WebKeys.FRIENDLY_URL_PRIVATE_PATH);
String friendlyURLPublicPath =
(String)req.getAttribute(WebKeys.FRIENDLY_URL_PUBLIC_PATH);
String imagePath = (String)req.getAttribute(WebKeys.IMAGE_PATH);
// Company logo
String companyLogo =
imagePath + "/company_logo?img_id=" + companyId;
// User
User user = null;
try {
user = PortalUtil.getUser(req);
}
catch (NoSuchUserException nsue) {
return;
}
// Is the user signed in? (用户是否登录?)
boolean signedIn = false;
if (user == null) {
user = company.getDefaultUser();
}
else {
signedIn = true;
}
// Permission checker (权限检查器)
PermissionChecker permissionChecker =
PermissionCheckerFactory.create(user, signedIn, true);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
// Locale (语言)
Locale locale = (Locale)ses.getAttribute(Globals.LOCALE_KEY);
// Cookie support - cookie支持
CookieKeys.addSupportCookie(res);
// Time zone (时区)
TimeZone timeZone = user.getTimeZone();
if (timeZone == null) {
timeZone = company.getTimeZone();
}
// Layouts (布局)
if (signedIn) {
boolean layoutsRequired = user.isLayoutsRequired();
if (layoutsRequired) {
addDefaultLayouts(user);
}
else {
deleteDefaultLayouts(user);
}
}
Layout layout = null;
List layouts = null;
String plid = ParamUtil.getString(req, "p_l_id");
String layoutId = Layout.getLayoutId(plid);
String ownerId = Layout.getOwnerId(plid);
if ((layoutId != null) && (ownerId != null)) {
try {
layout = LayoutLocalServiceUtil.getLayout(
layoutId, ownerId);
if (!isViewableCommunity(user, ownerId)) {
layout = null;
}
else {
layouts = LayoutLocalServiceUtil.getLayouts(
ownerId, Layout.DEFAULT_PARENT_LAYOUT_ID);
}
}
catch (NoSuchLayoutException nsle) {
}
}
if (layout == null) {
Object[] defaultLayout = getDefaultLayout(user, signedIn);
layout = (Layout)defaultLayout[0];
layouts = (List)defaultLayout[1];
}
Object[] viewableLayouts = getViewableLayouts(
layout, layouts, permissionChecker, req);
layout = (Layout)viewableLayouts[0];
layouts = (List)viewableLayouts[1];
if (layout != null) {
plid = layout.getPlid();
layoutId = layout.getLayoutId();
ownerId = layout.getOwnerId();
}
if ((layout != null) && layout.isShared()) {
layout = (Layout)layout.clone();
}
LayoutTypePortlet layoutTypePortlet = null;
if (layout != null) {
req.setAttribute(WebKeys.LAYOUT, layout);
req.setAttribute(WebKeys.LAYOUTS, layouts);
layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
if (layout.isPrivateLayout()) {
permissionChecker.setCheckGuest(false);
}
}
String portletGroupId = PortalUtil.getPortletGroupId(plid);
// Theme and color scheme (主题和色彩)
Theme theme = null;
ColorScheme colorScheme = null;
if (layout != null) {
theme = layout.getTheme();
colorScheme = layout.getColorScheme();
}
else {
theme = ThemeLocalUtil.getTheme(
companyId,
PrefsPropsUtil.getString(
companyId, PropsUtil.DEFAULT_THEME_ID));
colorScheme = ThemeLocalUtil.getColorScheme(
companyId, theme.getThemeId(),
PrefsPropsUtil.getString(
companyId, PropsUtil.DEFAULT_COLOR_SCHEME_ID));
}
req.setAttribute(WebKeys.THEME, theme);
req.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
// Resolution
int resolution = Resolution.FULL_RESOLUTION;
String resolutionKey = user.getResolution();
if (resolutionKey.equals(Resolution.S1024X768_KEY)) {
resolution = Resolution.S1024X768_RESOLUTION;
}
else if (resolutionKey.equals(Resolution.S800X600_KEY)) {
resolution = Resolution.S800X600_RESOLUTION;
}
// Theme display
String protocol = Http.getProtocol(req) + "://";
ThemeDisplay themeDisplay = ThemeDisplayFactory.create();
themeDisplay.setCompany(company);
themeDisplay.setCompanyLogo(companyLogo);
themeDisplay.setUser(user);
themeDisplay.setLayout(layout);
themeDisplay.setLayouts(layouts);
themeDisplay.setPlid(plid);
themeDisplay.setLayoutTypePortlet(layoutTypePortlet);
themeDisplay.setPortletGroupId(portletGroupId);
themeDisplay.setSignedIn(signedIn);
themeDisplay.setPermissionChecker(permissionChecker);
themeDisplay.setLocale(locale);
themeDisplay.setTimeZone(timeZone);
themeDisplay.setLookAndFeel(contextPath, theme, colorScheme);
themeDisplay.setResolution(resolution);
themeDisplay.setStatePopUp(LiferayWindowState.isPopUp(req));
themeDisplay.setPathApplet(contextPath + "/applets");
themeDisplay.setPathContext(contextPath);
themeDisplay.setPathFlash(contextPath + "/flash");
themeDisplay.setPathFriendlyURLPrivate(friendlyURLPrivatePath);
themeDisplay.setPathFriendlyURLPublic(friendlyURLPublicPath);
themeDisplay.setPathImage(imagePath);
themeDisplay.setPathJavaScript(contextPath + "/html/js");
themeDisplay.setPathMain(mainPath);
themeDisplay.setPathRoot(rootPath);
themeDisplay.setPathSound(contextPath + "/html/sound");
// URLs
themeDisplay.setShowAddContentIcon(false);
themeDisplay.setShowHomeIcon(true);
themeDisplay.setShowMyAccountIcon(signedIn);
themeDisplay.setShowPageSettingsIcon(false);
themeDisplay.setShowPortalIcon(true);
themeDisplay.setShowSignInIcon(!signedIn);
themeDisplay.setShowSignOutIcon(signedIn);
themeDisplay.setURLHome(protocol + company.getHomeURL());
if (layout != null) {
boolean hasManageLayoutsPermission =
GroupPermission.contains(
permissionChecker, portletGroupId,
ActionKeys.MANAGE_LAYOUTS);
boolean hasUpdateLayoutPermission =
LayoutPermission.contains(
permissionChecker, layout, ActionKeys.UPDATE);
if (hasManageLayoutsPermission || hasUpdateLayoutPermission) {
themeDisplay.setShowAddContentIcon(true);
themeDisplay.setURLAddContent(
"LayoutConfiguration.toggle('" +
PortletKeys.LAYOUT_CONFIGURATION + "', '" + plid +
"', '" + mainPath + "','" +
themeDisplay.getPathThemeImage() + "');");
}
if (hasManageLayoutsPermission) {
themeDisplay.setShowPageSettingsIcon(true);
PortletURL pageSettingsURL = new PortletURLImpl(
req, PortletKeys.LAYOUT_MANAGEMENT, plid, false);
pageSettingsURL.setWindowState(WindowState.MAXIMIZED);
pageSettingsURL.setPortletMode(PortletMode.VIEW);
pageSettingsURL.setParameter(
"struts_action", "/layout_management/edit_pages");
if (layout.isPrivateLayout()) {
pageSettingsURL.setParameter("tabs2", "private");
}
else {
pageSettingsURL.setParameter("tabs2", "public");
}
pageSettingsURL.setParameter("groupId", portletGroupId);
pageSettingsURL.setParameter("selPlid", plid);
themeDisplay.setURLPageSettings(pageSettingsURL);
}
PortletURL myAccountURL = new PortletURLImpl(
req, PortletKeys.MY_ACCOUNT, plid, false);
myAccountURL.setWindowState(WindowState.MAXIMIZED);
myAccountURL.setPortletMode(PortletMode.VIEW);
myAccountURL.setParameter(
"struts_action", "/my_account/edit_user");
themeDisplay.setURLMyAccount(myAccountURL);
}
themeDisplay.setURLPortal(protocol + company.getPortalURL());
themeDisplay.setURLSignIn(mainPath + "/portal/login");
themeDisplay.setURLSignOut(
mainPath + "/portal/logout?referer=" + mainPath);
req.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
// Fix state
fixState(req, themeDisplay);
}
catch (Exception e) {
_log.error(StackTraceUtil.getStackTrace(e));
throw new ActionException(e);
}
}
}