001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.kernel.util.WebKeys;
023    import com.liferay.portal.model.Layout;
024    import com.liferay.portal.service.LayoutLocalServiceUtil;
025    import com.liferay.portal.theme.ThemeDisplay;
026    import com.liferay.portal.util.PortalUtil;
027    import com.liferay.portlet.asset.model.BaseAssetRenderer;
028    
029    import java.util.Locale;
030    
031    import javax.portlet.PortletRequest;
032    import javax.portlet.PortletResponse;
033    import javax.portlet.RenderRequest;
034    import javax.portlet.RenderResponse;
035    
036    /**
037     * @author Eduardo Garcia
038     */
039    public class LayoutAssetRenderer extends BaseAssetRenderer {
040    
041            public LayoutAssetRenderer(Layout layout) {
042                    _layout = layout;
043            }
044    
045            @Override
046            public String getClassName() {
047                    return Layout.class.getName();
048            }
049    
050            @Override
051            public long getClassPK() {
052                    return _layout.getLayoutId();
053            }
054    
055            @Override
056            public long getGroupId() {
057                    return _layout.getGroupId();
058            }
059    
060            @Override
061            public String getSummary(
062                    PortletRequest portletRequest, PortletResponse portletResponse) {
063    
064                    Locale locale = getLocale(portletRequest);
065    
066                    StringBundler sb = new StringBundler(4);
067    
068                    sb.append("<strong>");
069                    sb.append(LanguageUtil.get(locale, "page"));
070                    sb.append(":</strong> ");
071                    sb.append(_layout.getHTMLTitle(locale));
072    
073                    return sb.toString();
074            }
075    
076            @Override
077            public String getTitle(Locale locale) {
078                    return _layout.getHTMLTitle(locale);
079            }
080    
081            @Override
082            public String getURLViewInContext(
083                    LiferayPortletRequest liferayPortletRequest,
084                    LiferayPortletResponse liferayPortletResponse,
085                    String noSuchEntryRedirect) {
086    
087                    try {
088                            ThemeDisplay themeDisplay =
089                                    (ThemeDisplay)liferayPortletRequest.getAttribute(
090                                            WebKeys.THEME_DISPLAY);
091    
092                            Layout layout = LayoutLocalServiceUtil.getLayout(_layout.getPlid());
093    
094                            return PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
095                    }
096                    catch (Exception e) {
097                            return StringPool.BLANK;
098                    }
099            }
100    
101            @Override
102            public long getUserId() {
103                    return _layout.getUserId();
104            }
105    
106            @Override
107            public String getUserName() {
108                    return _layout.getUserName();
109            }
110    
111            @Override
112            public String getUuid() {
113                    return null;
114            }
115    
116            @Override
117            public String render(
118                            RenderRequest renderRequest, RenderResponse renderResponse,
119                            String template)
120                    throws Exception {
121    
122                    if (template.equals(TEMPLATE_FULL_CONTENT)) {
123                            renderRequest.setAttribute(WebKeys.LAYOUT, _layout);
124    
125                            return "/html/portlet/layouts_admin/asset/" + template + ".jsp";
126                    }
127                    else {
128                            return null;
129                    }
130            }
131    
132            private final Layout _layout;
133    
134    }