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