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.taglib.ui;
016    
017    import com.liferay.portal.kernel.dao.search.ResultRow;
018    import com.liferay.portal.kernel.dao.search.SearchEntry;
019    import com.liferay.portal.kernel.language.LanguageUtil;
020    import com.liferay.portal.kernel.util.ServerDetector;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.taglib.search.ButtonSearchEntry;
023    import com.liferay.taglib.util.TagResourceBundleUtil;
024    
025    import java.util.List;
026    import java.util.ResourceBundle;
027    
028    import javax.portlet.PortletURL;
029    
030    import javax.servlet.jsp.JspException;
031    import javax.servlet.jsp.JspTagException;
032    
033    /**
034     * @author Raymond Aug??
035     */
036    public class SearchContainerColumnButtonTag<R>
037            extends SearchContainerColumnTag {
038    
039            @Override
040            public int doEndTag() {
041                    try {
042                            SearchContainerRowTag<R> searchContainerRowTag =
043                                    (SearchContainerRowTag<R>)findAncestorWithClass(
044                                            this, SearchContainerRowTag.class);
045    
046                            ResultRow resultRow = searchContainerRowTag.getRow();
047    
048                            if (index <= -1) {
049                                    List<SearchEntry> searchEntries = resultRow.getEntries();
050    
051                                    index = searchEntries.size();
052                            }
053    
054                            ButtonSearchEntry buttonSearchEntry = new ButtonSearchEntry();
055    
056                            buttonSearchEntry.setAlign(getAlign());
057                            buttonSearchEntry.setColspan(getColspan());
058                            buttonSearchEntry.setCssClass(getCssClass());
059                            buttonSearchEntry.setHref(String.valueOf(getHref()));
060    
061                            ResourceBundle resourceBundle =
062                                    TagResourceBundleUtil.getResourceBundle(pageContext);
063    
064                            buttonSearchEntry.setName(
065                                    LanguageUtil.get(resourceBundle, getName()));
066    
067                            buttonSearchEntry.setValign(getValign());
068    
069                            resultRow.addSearchEntry(index, buttonSearchEntry);
070    
071                            return EVAL_PAGE;
072                    }
073                    finally {
074                            index = -1;
075    
076                            if (!ServerDetector.isResin()) {
077                                    align = SearchEntry.DEFAULT_ALIGN;
078                                    colspan = SearchEntry.DEFAULT_COLSPAN;
079                                    cssClass = SearchEntry.DEFAULT_CSS_CLASS;
080                                    _href = null;
081                                    name = StringPool.BLANK;
082                                    valign = SearchEntry.DEFAULT_VALIGN;
083                            }
084                    }
085            }
086    
087            @Override
088            public int doStartTag() throws JspException {
089                    SearchContainerRowTag<R> searchContainerRowTag =
090                            (SearchContainerRowTag<R>)findAncestorWithClass(
091                                    this, SearchContainerRowTag.class);
092    
093                    if (searchContainerRowTag == null) {
094                            throw new JspTagException(
095                                    "Requires liferay-ui:search-container-row");
096                    }
097    
098                    if (!searchContainerRowTag.isHeaderNamesAssigned()) {
099                            List<String> headerNames = searchContainerRowTag.getHeaderNames();
100    
101                            headerNames.add(StringPool.BLANK);
102                    }
103    
104                    return EVAL_BODY_INCLUDE;
105            }
106    
107            public Object getHref() {
108                    if (_href instanceof PortletURL) {
109                            _href = _href.toString();
110                    }
111    
112                    return _href;
113            }
114    
115            public void setHref(Object href) {
116                    _href = href;
117            }
118    
119            private Object _href;
120    
121    }