001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }