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