001    /**
002     * Copyright (c) 2000-2013 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.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Sergio Gonz??lez
025     */
026    public class HeaderTag extends IncludeTag {
027    
028            public void setBackLabel(String backLabel) {
029                    _backLabel = backLabel;
030            }
031    
032            public void setBackURL(String backURL) {
033                    _backURL = backURL;
034            }
035    
036            public void setCssClass(String cssClass) {
037                    _cssClass = cssClass;
038            }
039    
040            public void setEscapeXml(boolean escapeXml) {
041                    _escapeXml = escapeXml;
042            }
043    
044            public void setLocalizeTitle(boolean localizeTitle) {
045                    _localizeTitle = localizeTitle;
046            }
047    
048            public void setShowBackURL(boolean showBackURL) {
049                    _showBackURL = showBackURL;
050            }
051    
052            public void setTitle(String title) {
053                    _title = title;
054            }
055    
056            @Override
057            protected void cleanUp() {
058                    _backLabel = null;
059                    _backURL = null;
060                    _cssClass = null;
061                    _escapeXml = true;
062                    _localizeTitle = true;
063                    _showBackURL = true;
064                    _title = null;
065            }
066    
067            @Override
068            protected String getPage() {
069                    return _PAGE;
070            }
071    
072            @Override
073            protected boolean isCleanUpSetAttributes() {
074                    return _CLEAN_UP_SET_ATTRIBUTES;
075            }
076    
077            @Override
078            protected void setAttributes(HttpServletRequest request) {
079                    request.setAttribute("liferay-ui:header:backLabel", _backLabel);
080    
081                    String redirect = ParamUtil.getString(request, "redirect");
082    
083                    if (Validator.isNull(_backURL) && Validator.isNotNull(redirect)) {
084                            request.setAttribute("liferay-ui:header:backURL", redirect);
085                    }
086                    else {
087                            request.setAttribute("liferay-ui:header:backURL", _backURL);
088                    }
089    
090                    request.setAttribute("liferay-ui:header:cssClass", _cssClass);
091                    request.setAttribute(
092                            "liferay-ui:header:escapeXml", String.valueOf(_escapeXml));
093                    request.setAttribute(
094                            "liferay-ui:header:localizeTitle", String.valueOf(_localizeTitle));
095                    request.setAttribute(
096                            "liferay-ui:header:showBackURL", String.valueOf(_showBackURL));
097                    request.setAttribute("liferay-ui:header:title", _title);
098            }
099    
100            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
101    
102            private static final String _PAGE = "/html/taglib/ui/header/page.jsp";
103    
104            private String _backLabel;
105            private String _backURL;
106            private String _cssClass;
107            private boolean _escapeXml = true;
108            private boolean _localizeTitle = true;
109            private boolean _showBackURL = true;
110            private String _title;
111    
112    }