001    /**
002     * Copyright (c) 2000-2012 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.LayoutBranch;
020    import com.liferay.portal.model.LayoutRevision;
021    import com.liferay.portal.model.LayoutSetBranch;
022    import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
023    import com.liferay.portal.util.WebKeys;
024    import com.liferay.portlet.asset.model.BaseAssetRenderer;
025    
026    import java.util.Locale;
027    
028    import javax.portlet.RenderRequest;
029    import javax.portlet.RenderResponse;
030    
031    /**
032     * @author Raymond Augé
033     */
034    public class LayoutRevisionAssetRenderer extends BaseAssetRenderer {
035    
036            public LayoutRevisionAssetRenderer(LayoutRevision layoutRevision) {
037                    _layoutRevision = layoutRevision;
038    
039                    try {
040                            _layoutBranch = layoutRevision.getLayoutBranch();
041    
042                            _layoutSetBranch =
043                                    LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
044                                            _layoutRevision.getLayoutSetBranchId());
045                    }
046                    catch (Exception e) {
047                            throw new IllegalStateException(e);
048                    }
049            }
050    
051            public long getClassPK() {
052                    return _layoutRevision.getLayoutRevisionId();
053            }
054    
055            public long getGroupId() {
056                    return _layoutRevision.getGroupId();
057            }
058    
059            public String getSummary(Locale locale) {
060                    StringBundler sb = new StringBundler(16);
061    
062                    sb.append("<strong>");
063                    sb.append(LanguageUtil.get(locale, "page"));
064                    sb.append(":</strong> ");
065                    sb.append(_layoutRevision.getHTMLTitle(locale));
066                    sb.append("<br /><strong>");
067                    sb.append(LanguageUtil.get(locale, "site-pages-variation"));
068                    sb.append(":</strong> ");
069                    sb.append(LanguageUtil.get(locale, _layoutSetBranch.getName()));
070                    sb.append("<br /><strong>");
071                    sb.append(LanguageUtil.get(locale, "page-variation"));
072                    sb.append(":</strong> ");
073                    sb.append(LanguageUtil.get(locale, _layoutBranch.getName()));
074                    sb.append("<br /><strong>");
075                    sb.append(LanguageUtil.get(locale, "revision-id"));
076                    sb.append(":</strong> ");
077                    sb.append(_layoutRevision.getLayoutRevisionId());
078    
079                    return sb.toString();
080            }
081    
082            public String getTitle(Locale locale) {
083                    return _layoutRevision.getHTMLTitle(locale);
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 LayoutBranch _layoutBranch;
111            private LayoutRevision _layoutRevision;
112            private LayoutSetBranch _layoutSetBranch;
113    
114    }