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.JSPSearchEntry;
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    
023    import java.util.List;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpServletResponse;
027    import javax.servlet.jsp.JspException;
028    import javax.servlet.jsp.JspTagException;
029    
030    /**
031     * @author Raymond Augé
032     */
033    public class SearchContainerColumnJSPTag<R> extends SearchContainerColumnTag {
034    
035            @Override
036            public int doEndTag() {
037                    try {
038                            SearchContainerRowTag<R> searchContainerRowTag =
039                                    (SearchContainerRowTag<R>)findAncestorWithClass(
040                                            this, SearchContainerRowTag.class);
041    
042                            ResultRow row = searchContainerRowTag.getRow();
043    
044                            if (index <= -1) {
045                                    index = row.getEntries().size();
046                            }
047    
048                            JSPSearchEntry jspSearchEntry = new JSPSearchEntry();
049    
050                            jspSearchEntry.setAlign(getAlign());
051                            jspSearchEntry.setColspan(getColspan());
052                            jspSearchEntry.setCssClass(getCssClass());
053                            jspSearchEntry.setPath(getPath());
054                            jspSearchEntry.setRequest(
055                                    (HttpServletRequest)pageContext.getRequest());
056                            jspSearchEntry.setResponse(
057                                    (HttpServletResponse)pageContext.getResponse());
058                            jspSearchEntry.setServletContext(pageContext.getServletContext());
059                            jspSearchEntry.setValign(getValign());
060    
061                            row.addSearchEntry(index, jspSearchEntry);
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                                    name = StringPool.BLANK;
073                                    _path = null;
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(name);
094                    }
095    
096                    return EVAL_BODY_INCLUDE;
097            }
098    
099            public String getPath() {
100                    return _path;
101            }
102    
103            public void setPath(String path) {
104                    _path = path;
105            }
106    
107            private String _path;
108    
109    }