001
014
015 package com.liferay.portal.asset;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
019 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.model.LayoutBranch;
024 import com.liferay.portal.model.LayoutRevision;
025 import com.liferay.portal.model.LayoutSetBranch;
026 import com.liferay.portal.service.LayoutLocalServiceUtil;
027 import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
028 import com.liferay.portal.theme.ThemeDisplay;
029 import com.liferay.portal.util.PortalUtil;
030 import com.liferay.portal.util.WebKeys;
031 import com.liferay.portlet.asset.model.BaseAssetRenderer;
032
033 import java.util.Locale;
034
035 import javax.portlet.RenderRequest;
036 import javax.portlet.RenderResponse;
037
038
041 public class LayoutRevisionAssetRenderer extends BaseAssetRenderer {
042
043 public LayoutRevisionAssetRenderer(LayoutRevision layoutRevision) {
044 _layoutRevision = layoutRevision;
045
046 try {
047 _layoutBranch = layoutRevision.getLayoutBranch();
048
049 _layoutSetBranch =
050 LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
051 _layoutRevision.getLayoutSetBranchId());
052 }
053 catch (Exception e) {
054 throw new IllegalStateException(e);
055 }
056 }
057
058 public long getClassPK() {
059 return _layoutRevision.getLayoutRevisionId();
060 }
061
062 public long getGroupId() {
063 return _layoutRevision.getGroupId();
064 }
065
066 public String getSummary(Locale locale) {
067 StringBundler sb = new StringBundler(16);
068
069 sb.append("<strong>");
070 sb.append(LanguageUtil.get(locale, "page"));
071 sb.append(":</strong> ");
072 sb.append(_layoutRevision.getHTMLTitle(locale));
073 sb.append("<br /><strong>");
074 sb.append(LanguageUtil.get(locale, "site-pages-variation"));
075 sb.append(":</strong> ");
076 sb.append(LanguageUtil.get(locale, _layoutSetBranch.getName()));
077 sb.append("<br /><strong>");
078 sb.append(LanguageUtil.get(locale, "page-variation"));
079 sb.append(":</strong> ");
080 sb.append(LanguageUtil.get(locale, _layoutBranch.getName()));
081 sb.append("<br /><strong>");
082 sb.append(LanguageUtil.get(locale, "revision-id"));
083 sb.append(":</strong> ");
084 sb.append(_layoutRevision.getLayoutRevisionId());
085
086 return sb.toString();
087 }
088
089 public String getTitle(Locale locale) {
090 return _layoutRevision.getHTMLTitle(locale);
091 }
092
093 @Override
094 public String getURLViewInContext(
095 LiferayPortletRequest liferayPortletRequest,
096 LiferayPortletResponse liferayPortletResponse,
097 String noSuchEntryRedirect) {
098
099 try {
100 ThemeDisplay themeDisplay =
101 (ThemeDisplay)liferayPortletRequest.getAttribute(
102 WebKeys.THEME_DISPLAY);
103
104 Layout layout = LayoutLocalServiceUtil.getLayout(
105 _layoutRevision.getPlid());
106
107 StringBundler sb = new StringBundler(5);
108
109 sb.append(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));
110 sb.append("?layoutSetBranchId=");
111 sb.append(_layoutRevision.getLayoutSetBranchId());
112 sb.append("&layoutRevisionId=");
113 sb.append(_layoutRevision.getLayoutRevisionId());
114
115 return sb.toString();
116 }
117 catch (Exception e) {
118 return StringPool.BLANK;
119 }
120 }
121
122 public long getUserId() {
123 return _layoutRevision.getUserId();
124 }
125
126 public String getUserName() {
127 return _layoutRevision.getUserName();
128 }
129
130 public String getUuid() {
131 return null;
132 }
133
134 @Override
135 public boolean isPreviewInContext() {
136 return true;
137 }
138
139 public String render(
140 RenderRequest renderRequest, RenderResponse renderResponse,
141 String template)
142 throws Exception {
143
144 if (template.equals(TEMPLATE_FULL_CONTENT)) {
145 renderRequest.setAttribute(
146 WebKeys.LAYOUT_REVISION, _layoutRevision);
147
148 return "/html/portlet/layouts_admin/asset/" + template + ".jsp";
149 }
150 else {
151 return null;
152 }
153 }
154
155 private LayoutBranch _layoutBranch;
156 private LayoutRevision _layoutRevision;
157 private LayoutSetBranch _layoutSetBranch;
158
159 }