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.taglib.ui;
016    
017    import com.liferay.portal.kernel.dao.search.ButtonSearchEntry;
018    import com.liferay.portal.kernel.dao.search.ResultRow;
019    import com.liferay.portal.kernel.dao.search.SearchEntry;
020    import com.liferay.portal.kernel.util.ServerDetector;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.kernel.util.Validator;
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 row = searchContainerRowTag.getRow();
045    
046                            if (index <= -1) {
047                                    index = row.getEntries().size();
048                            }
049    
050                            ButtonSearchEntry buttonSearchEntry = new ButtonSearchEntry();
051    
052                            buttonSearchEntry.setAlign(getAlign());
053                            buttonSearchEntry.setColspan(getColspan());
054                            buttonSearchEntry.setCssClass(getCssClass());
055                            buttonSearchEntry.setHref((String)getHref());
056                            buttonSearchEntry.setName(getName());
057                            buttonSearchEntry.setValign(getValign());
058    
059                            row.addSearchEntry(index, buttonSearchEntry);
060    
061                            return EVAL_PAGE;
062                    }
063                    finally {
064                            index = -1;
065    
066                            if (!ServerDetector.isResin()) {
067                                    align = SearchEntry.DEFAULT_ALIGN;
068                                    colspan = SearchEntry.DEFAULT_COLSPAN;
069                                    cssClass = SearchEntry.DEFAULT_CSS_CLASS;
070                                    _href = null;
071                                    name = StringPool.BLANK;
072                                    valign = SearchEntry.DEFAULT_VALIGN;
073                            }
074                    }
075            }
076    
077            @Override
078            public int doStartTag() throws JspException {
079                    SearchContainerRowTag<R> searchContainerRowTag =
080                            (SearchContainerRowTag<R>)findAncestorWithClass(
081                                    this, SearchContainerRowTag.class);
082    
083                    if (searchContainerRowTag == null) {
084                            throw new JspTagException(
085                                    "Requires liferay-ui:search-container-row");
086                    }
087    
088                    if (!searchContainerRowTag.isHeaderNamesAssigned()) {
089                            List<String> headerNames = searchContainerRowTag.getHeaderNames();
090    
091                            headerNames.add(StringPool.BLANK);
092                    }
093    
094                    return EVAL_BODY_INCLUDE;
095            }
096    
097            public Object getHref() {
098                    if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
099                            _href = _href.toString();
100                    }
101    
102                    return _href;
103            }
104    
105            public void setHref(Object href) {
106                    _href = href;
107            }
108    
109            private Object _href;
110    
111    }