1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
36  public class RowChecker {
37  
38      public static final String ALIGN = "left";
39  
40      public static final String VALIGN = "middle";
41  
42      public static final int COLSPAN = 1;
43  
44      public static final String FORM_NAME = "fm";
45  
46      public static final String ALL_ROW_IDS = "allRowIds";
47  
48      public static final String ROW_IDS = "rowIds";
49  
50      public RowChecker(RenderResponse renderResponse) {
51          this(
52              renderResponse, ALIGN, VALIGN, COLSPAN, FORM_NAME, ALL_ROW_IDS,
53              ROW_IDS);
54      }
55  
56      public RowChecker(
57          RenderResponse renderResponse, String align, String valign,
58          String formName, String allRowsId, String rowId) {
59  
60          this(
61              renderResponse, align, valign, COLSPAN, formName, allRowsId, rowId);
62      }
63  
64      public RowChecker(
65          RenderResponse renderResponse, String align, String valign, int colspan,
66          String formName, String allRowsId, String rowId) {
67  
68          _align = align;
69          _valign = valign;
70          _colspan = colspan;
71          _formName = renderResponse.getNamespace() + formName;
72  
73          if (Validator.isNotNull(allRowsId)) {
74              _allRowsId = renderResponse.getNamespace() + allRowsId;
75          }
76  
77          _rowId = renderResponse.getNamespace() + rowId;
78      }
79  
80      public String getAlign() {
81          return _align;
82      }
83  
84      public String getValign() {
85          return _valign;
86      }
87  
88      public int getColspan() {
89          return _colspan;
90      }
91  
92      public String getFormName() {
93          return _formName;
94      }
95  
96      public String getAllRowsId() {
97          return _allRowsId;
98      }
99  
100     public String getRowId() {
101         return _rowId;
102     }
103 
104     public String getAllRowsCheckBox() {
105         if (Validator.isNull(_allRowsId)) {
106             return StringPool.BLANK;
107         }
108         else {
109             StringBuilder sb = new StringBuilder();
110 
111             sb.append("<input name=\"");
112             sb.append(_allRowsId);
113             sb.append("\" type=\"checkbox\" ");
114             sb.append("onClick=\"Liferay.Util.checkAll(");
115             sb.append(_formName);
116             sb.append(", '");
117             sb.append(_rowId);
118             sb.append("', this");
119             sb.append(");\">");
120 
121             return sb.toString();
122         }
123     }
124 
125     public String getRowCheckBox(boolean checked, String primaryKey) {
126         StringBuilder sb = new StringBuilder();
127 
128         sb.append("<input ");
129 
130         if (checked) {
131             sb.append("checked ");
132         }
133 
134         sb.append("name=\"");
135         sb.append(_rowId);
136         sb.append("\" type=\"checkbox\" value=\"");
137         sb.append(primaryKey);
138         sb.append("\" ");
139 
140         if (Validator.isNotNull(_allRowsId)) {
141             sb.append("onClick=\"Liferay.Util.checkAllBox(");
142             sb.append(_formName);
143             sb.append(", '");
144             sb.append(_rowId);
145             sb.append("', ");
146             sb.append(_allRowsId);
147             sb.append(");\"");
148         }
149 
150         sb.append(">");
151 
152         return sb.toString();
153     }
154 
155     public boolean isChecked(Object obj) {
156         return false;
157     }
158 
159     private String _align;
160     private String _valign;
161     private int _colspan;
162     private String _formName;
163     private String _allRowsId;
164     private String _rowId;
165 
166 }