001    /**
002     * Copyright (c) 2000-2011 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.util.StringBundler;
019    import com.liferay.portal.model.LayoutRevision;
020    import com.liferay.portal.model.LayoutSetBranch;
021    import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
022    import com.liferay.portal.util.WebKeys;
023    import com.liferay.portlet.asset.model.BaseAssetRenderer;
024    
025    import java.util.Locale;
026    
027    import javax.portlet.RenderRequest;
028    import javax.portlet.RenderResponse;
029    
030    /**
031     * @author Raymond Augé
032     */
033    public class LayoutRevisionAssetRenderer extends BaseAssetRenderer {
034    
035            public LayoutRevisionAssetRenderer(LayoutRevision layoutRevision) {
036                    _layoutRevision = layoutRevision;
037    
038                    try {
039                            _layoutSetBranch =
040                                    LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
041                                            _layoutRevision.getLayoutSetBranchId());
042                    }
043                    catch (Exception e) {
044                            throw new IllegalStateException(e);
045                    }
046            }
047    
048            public long getClassPK() {
049                    return _layoutRevision.getLayoutRevisionId();
050            }
051    
052            public long getGroupId() {
053                    return _layoutRevision.getGroupId();
054            }
055    
056            public String getSummary(Locale locale) {
057                    StringBundler sb = new StringBundler(12);
058    
059                    sb.append("<strong>");
060                    sb.append(LanguageUtil.get(locale, "layout"));
061                    sb.append(":</strong> ");
062                    sb.append(_layoutRevision.getHTMLTitle(locale));
063                    sb.append("<br /><strong>");
064                    sb.append(LanguageUtil.get(locale, "branch"));
065                    sb.append(":</strong> ");
066                    sb.append(_layoutSetBranch.getName());
067                    sb.append("<br /><strong>");
068                    sb.append(LanguageUtil.get(locale, "revision-id"));
069                    sb.append(":</strong> ");
070                    sb.append(_layoutRevision.getLayoutRevisionId());
071    
072                    return sb.toString();
073            }
074    
075            public String getTitle(Locale locale) {
076                    StringBundler sb = new StringBundler(4);
077    
078                    sb.append(_layoutRevision.getHTMLTitle(locale));
079                    sb.append(" [");
080                    sb.append(_layoutSetBranch.getName());
081                    sb.append("]");
082    
083                    return sb.toString();
084            }
085    
086            public long getUserId() {
087                    return _layoutRevision.getUserId();
088            }
089    
090            public String getUuid() {
091                    return null;
092            }
093    
094            public String render(
095                            RenderRequest renderRequest, RenderResponse renderResponse,
096                            String template)
097                    throws Exception {
098    
099                    if (template.equals(TEMPLATE_FULL_CONTENT)) {
100                            renderRequest.setAttribute(
101                                    WebKeys.LAYOUT_REVISION, _layoutRevision);
102    
103                            return "/html/portlet/layouts_admin/asset/" + template + ".jsp";
104                    }
105                    else {
106                            return null;
107                    }
108            }
109    
110            private LayoutRevision _layoutRevision;
111            private LayoutSetBranch _layoutSetBranch;
112    
113    }