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 @Override
059 public long getClassPK() {
060 return _layoutRevision.getLayoutRevisionId();
061 }
062
063 @Override
064 public long getGroupId() {
065 return _layoutRevision.getGroupId();
066 }
067
068 @Override
069 public String getSummary(Locale locale) {
070 StringBundler sb = new StringBundler(16);
071
072 sb.append("<strong>");
073 sb.append(LanguageUtil.get(locale, "page"));
074 sb.append(":</strong> ");
075 sb.append(_layoutRevision.getHTMLTitle(locale));
076 sb.append("<br /><strong>");
077 sb.append(LanguageUtil.get(locale, "site-pages-variation"));
078 sb.append(":</strong> ");
079 sb.append(LanguageUtil.get(locale, _layoutSetBranch.getName()));
080 sb.append("<br /><strong>");
081 sb.append(LanguageUtil.get(locale, "page-variation"));
082 sb.append(":</strong> ");
083 sb.append(LanguageUtil.get(locale, _layoutBranch.getName()));
084 sb.append("<br /><strong>");
085 sb.append(LanguageUtil.get(locale, "revision-id"));
086 sb.append(":</strong> ");
087 sb.append(_layoutRevision.getLayoutRevisionId());
088
089 return sb.toString();
090 }
091
092 @Override
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 @Override
127 public long getUserId() {
128 return _layoutRevision.getUserId();
129 }
130
131 @Override
132 public String getUserName() {
133 return _layoutRevision.getUserName();
134 }
135
136 @Override
137 public String getUuid() {
138 return null;
139 }
140
141 @Override
142 public boolean isPreviewInContext() {
143 return true;
144 }
145
146 @Override
147 public String render(
148 RenderRequest renderRequest, RenderResponse renderResponse,
149 String template)
150 throws Exception {
151
152 if (template.equals(TEMPLATE_FULL_CONTENT)) {
153 renderRequest.setAttribute(
154 WebKeys.LAYOUT_REVISION, _layoutRevision);
155
156 return "/html/portlet/layouts_admin/asset/" + template + ".jsp";
157 }
158 else {
159 return null;
160 }
161 }
162
163 private LayoutBranch _layoutBranch;
164 private LayoutRevision _layoutRevision;
165 private LayoutSetBranch _layoutSetBranch;
166
167 }