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