001    /**
002     * Copyright (c) 2000-2010 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.servlet.PipingServletResponse;
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.jsp.JspException;
026    import javax.servlet.jsp.JspTagException;
027    
028    /**
029     * @author Raymond Augé
030     */
031    public class SearchContainerColumnJSPTag extends SearchContainerColumnTag {
032    
033            public int doEndTag() {
034                    try {
035                            SearchContainerRowTag parentTag =
036                                    (SearchContainerRowTag)findAncestorWithClass(
037                                            this, SearchContainerRowTag.class);
038    
039                            ResultRow row = parentTag.getRow();
040    
041                            if (index <= -1) {
042                                    index = row.getEntries().size();
043                            }
044    
045                            row.addJSP(
046                                    index, getAlign(), getValign(), getColspan(), getPath(),
047                                    pageContext.getServletContext(), getServletRequest(),
048                                    new PipingServletResponse(pageContext));
049    
050                            return EVAL_PAGE;
051                    }
052                    finally {
053                            index = -1;
054    
055                            if (!ServerDetector.isResin()) {
056                                    align = SearchEntry.DEFAULT_ALIGN;
057                                    colspan = SearchEntry.DEFAULT_COLSPAN;
058                                    name = StringPool.BLANK;
059                                    _path = null;
060                                    valign = SearchEntry.DEFAULT_VALIGN;
061                            }
062                    }
063            }
064    
065            public int doStartTag() throws JspException {
066                    SearchContainerRowTag parentRowTag =
067                            (SearchContainerRowTag)findAncestorWithClass(
068                                    this, SearchContainerRowTag.class);
069    
070                    if (parentRowTag == null) {
071                            throw new JspTagException(
072                                    "Requires liferay-ui:search-container-row");
073                    }
074    
075                    if (!parentRowTag.isHeaderNamesAssigned()) {
076                            List<String> headerNames = parentRowTag.getHeaderNames();
077    
078                            headerNames.add(name);
079                    }
080    
081                    return EVAL_BODY_INCLUDE;
082            }
083    
084            public String getPath() {
085                    return _path;
086            }
087    
088            public void setPath(String path) {
089                    _path = path;
090            }
091    
092            private String _path;
093    
094    }