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 String getClassName() {
059 return LayoutRevision.class.getName();
060 }
061
062 public long getClassPK() {
063 return _layoutRevision.getLayoutRevisionId();
064 }
065
066 public long getGroupId() {
067 return _layoutRevision.getGroupId();
068 }
069
070 public String getSummary(Locale locale) {
071 StringBundler sb = new StringBundler(16);
072
073 sb.append("<strong>");
074 sb.append(LanguageUtil.get(locale, "page"));
075 sb.append(":</strong> ");
076 sb.append(_layoutRevision.getHTMLTitle(locale));
077 sb.append("<br /><strong>");
078 sb.append(LanguageUtil.get(locale, "site-pages-variation"));
079 sb.append(":</strong> ");
080 sb.append(LanguageUtil.get(locale, _layoutSetBranch.getName()));
081 sb.append("<br /><strong>");
082 sb.append(LanguageUtil.get(locale, "page-variation"));
083 sb.append(":</strong> ");
084 sb.append(LanguageUtil.get(locale, _layoutBranch.getName()));
085 sb.append("<br /><strong>");
086 sb.append(LanguageUtil.get(locale, "revision-id"));
087 sb.append(":</strong> ");
088 sb.append(_layoutRevision.getLayoutRevisionId());
089
090 return sb.toString();
091 }
092
093 public String getTitle(Locale locale) {
094 return _layoutRevision.getHTMLTitle(locale);
095 }
096
097 @Override
098 public String getURLViewInContext(
099 LiferayPortletRequest liferayPortletRequest,
100 LiferayPortletResponse liferayPortletResponse,
101 String noSuchEntryRedirect) {
102
103 try {
104 ThemeDisplay themeDisplay =
105 (ThemeDisplay)liferayPortletRequest.getAttribute(
106 WebKeys.THEME_DISPLAY);
107
108 Layout layout = LayoutLocalServiceUtil.getLayout(
109 _layoutRevision.getPlid());
110
111 StringBundler sb = new StringBundler(5);
112
113 sb.append(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));
114 sb.append("?layoutSetBranchId=");
115 sb.append(_layoutRevision.getLayoutSetBranchId());
116 sb.append("&layoutRevisionId=");
117 sb.append(_layoutRevision.getLayoutRevisionId());
118
119 return sb.toString();
120 }
121 catch (Exception e) {
122 return StringPool.BLANK;
123 }
124 }
125
126 public long getUserId() {
127 return _layoutRevision.getUserId();
128 }
129
130 public String getUserName() {
131 return _layoutRevision.getUserName();
132 }
133
134 public String getUuid() {
135 return null;
136 }
137
138 @Override
139 public boolean isPreviewInContext() {
140 return true;
141 }
142
143 public String render(
144 RenderRequest renderRequest, RenderResponse renderResponse,
145 String template)
146 throws Exception {
147
148 if (template.equals(TEMPLATE_FULL_CONTENT)) {
149 renderRequest.setAttribute(
150 WebKeys.LAYOUT_REVISION, _layoutRevision);
151
152 return "/html/portlet/layouts_admin/asset/" + template + ".jsp";
153 }
154 else {
155 return null;
156 }
157 }
158
159 private LayoutBranch _layoutBranch;
160 private LayoutRevision _layoutRevision;
161 private LayoutSetBranch _layoutSetBranch;
162
163 }