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