KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > validation > QueryValidator


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.validation;
22
23 import java.math.BigDecimal JavaDoc;
24 import java.util.regex.Pattern JavaDoc;
25
26 import com.jaspersoft.jasperserver.war.dto.DataTypeWrapper;
27 import com.jaspersoft.jasperserver.war.dto.QueryWrapper;
28 import com.jaspersoft.jasperserver.war.common.JasperServerUtil;
29 import com.jaspersoft.jasperserver.api.metadata.common.domain.DataType;
30 import com.jaspersoft.jasperserver.api.metadata.common.domain.Query;
31 import org.springframework.validation.Errors;
32 import org.springframework.validation.Validator;
33
34 /**
35  * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
36  * @version $Id: QueryValidator.java 4008 2006-07-18 16:56:26Z inedelcu $
37  */

38 public class QueryValidator implements Validator
39 {
40     public boolean supports(Class JavaDoc klass)
41     {
42         return QueryWrapper.class.isAssignableFrom(klass);
43     }
44
45     public void validate(Object JavaDoc object, Errors errors)
46     {
47         QueryWrapper wrapper = (QueryWrapper) object;
48         Query query = wrapper.getQuery();
49         if (query.getName() == null || query.getName().trim().length() == 0) {
50             errors.rejectValue("query.name", "error.not.empty");
51         } else {
52             if(!JasperServerUtil.regExValidateName(query.getName())) {
53                 errors.rejectValue("query.name", null, "Name contains invalid characters");
54             }
55             if (query.getName().length() > 100) {
56                 errors.rejectValue("query.name", null, "Name is longer than 100 characters");
57             }
58         }
59
60         if (query.getLabel() == null || query.getLabel().trim().length() == 0) {
61             errors.rejectValue("query.label", "error.not.empty");
62         } else {
63             if(!JasperServerUtil.regExValidateLabel(query.getLabel())) {
64                 errors.rejectValue("query.label", null, "Label contains invalid characters");
65             }
66             if (query.getLabel().length() > 100) {
67                 errors.rejectValue("query.label", null, "Label is longer than 100 characters");
68             }
69         }
70
71         if (query.getDescription() != null && query.getDescription().length() > 250) {
72             errors.rejectValue("query.description", null, "Description is longer than 250 characters");
73         }
74
75     }
76 }
77
Popular Tags