1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.dao.search;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.Validator;
24  
25  import javax.portlet.RenderResponse;
26  
27  /**
28   * <a href="RowChecker.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   *
32   */
33  public class RowChecker {
34  
35      public static final String ALIGN = "left";
36  
37      public static final String VALIGN = "middle";
38  
39      public static final int COLSPAN = 1;
40  
41      public static final String FORM_NAME = "fm";
42  
43      public static final String ALL_ROW_IDS = "allRowIds";
44  
45      public static final String ROW_IDS = "rowIds";
46  
47      public RowChecker(RenderResponse renderResponse) {
48          this(
49              renderResponse, ALIGN, VALIGN, COLSPAN, FORM_NAME, ALL_ROW_IDS,
50              ROW_IDS);
51      }
52  
53      public RowChecker(
54          RenderResponse renderResponse, String align, String valign,
55          String formName, String allRowsId, String rowId) {
56  
57          this(
58              renderResponse, align, valign, COLSPAN, formName, allRowsId, rowId);
59      }
60  
61      public RowChecker(
62          RenderResponse renderResponse, String align, String valign, int colspan,
63          String formName, String allRowsId, String rowId) {
64  
65          _align = align;
66          _valign = valign;
67          _colspan = colspan;
68          _formName = renderResponse.getNamespace() + formName;
69  
70          if (Validator.isNotNull(allRowsId)) {
71              _allRowsId = renderResponse.getNamespace() + allRowsId;
72          }
73  
74          _rowId = renderResponse.getNamespace() + rowId;
75      }
76  
77      public String getAlign() {
78          return _align;
79      }
80  
81      public String getValign() {
82          return _valign;
83      }
84  
85      public int getColspan() {
86          return _colspan;
87      }
88  
89      public String getFormName() {
90          return _formName;
91      }
92  
93      public String getAllRowsId() {
94          return _allRowsId;
95      }
96  
97      public String getRowId() {
98          return _rowId;
99      }
100 
101     public String getAllRowsCheckBox() {
102         if (Validator.isNull(_allRowsId)) {
103             return StringPool.BLANK;
104         }
105         else {
106             StringBuilder sb = new StringBuilder();
107 
108             sb.append("<input name=\"");
109             sb.append(_allRowsId);
110             sb.append("\" type=\"checkbox\" ");
111             sb.append("onClick=\"Liferay.Util.checkAll(");
112             sb.append(_formName);
113             sb.append(", '");
114             sb.append(_rowId);
115             sb.append("', this");
116             sb.append(");\">");
117 
118             return sb.toString();
119         }
120     }
121 
122     public String getRowCheckBox(boolean checked, String primaryKey) {
123         StringBuilder sb = new StringBuilder();
124 
125         sb.append("<input ");
126 
127         if (checked) {
128             sb.append("checked ");
129         }
130 
131         sb.append("name=\"");
132         sb.append(_rowId);
133         sb.append("\" type=\"checkbox\" value=\"");
134         sb.append(primaryKey);
135         sb.append("\" ");
136 
137         if (Validator.isNotNull(_allRowsId)) {
138             sb.append("onClick=\"Liferay.Util.checkAllBox(");
139             sb.append(_formName);
140             sb.append(", '");
141             sb.append(_rowId);
142             sb.append("', ");
143             sb.append(_allRowsId);
144             sb.append(");\"");
145         }
146 
147         sb.append(">");
148 
149         return sb.toString();
150     }
151 
152     public boolean isChecked(Object obj) {
153         return false;
154     }
155 
156     private String _align;
157     private String _valign;
158     private int _colspan;
159     private String _formName;
160     private String _allRowsId;
161     private String _rowId;
162 
163 }