KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.springframework.validation.Errors;
24 import org.springframework.validation.Validator;
25
26 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource;
27 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JndiJdbcReportDataSource;
28 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportDataSource;
29 import com.jaspersoft.jasperserver.war.common.JasperServerConstImpl;
30 import com.jaspersoft.jasperserver.war.common.JasperServerUtil;
31 import com.jaspersoft.jasperserver.war.dto.OlapDataSourceWrapper;
32
33 /**
34  *
35  * OlapDataSourceValidator provides validation methods for the
36  * olapDataSourceFlow
37  *
38  * @author jshih
39  */

40 public class OlapDataSourceValidator extends ReportDataSourceValidator implements Validator {
41     private JasperServerConstImpl constants=new JasperServerConstImpl();
42     public boolean supports(Class JavaDoc clazz) {
43         return OlapDataSourceWrapper.class.isAssignableFrom(clazz);
44     }
45
46     public void validate(Object JavaDoc arg0, Errors arg1) {
47         // TODO Auto-generated method stub
48
}
49
50     public void chooseType(OlapDataSourceWrapper wrapper, Errors errors){
51         if(wrapper.getSource()==null)
52             errors.rejectValue("source",null,"Please select a Datasource type");
53     }
54
55     public void jndiPropsForm(OlapDataSourceWrapper wrapper, Errors errors){
56         // TODO
57
JndiJdbcReportDataSource jndiSource=(JndiJdbcReportDataSource)wrapper.getOlapDataSource();
58         if(jndiSource.getJndiName()==null || jndiSource.getJndiName().trim().length()==0) {
59             errors.rejectValue("olapDataSource.jndiName",null,"Please enter the JNDI name");
60         } else {
61             if(!JasperServerUtil.regExValidateJndiServiceName(jndiSource.getJndiName())) {
62                 errors.rejectValue(
63                         "olapDataSource.jndiName", null, "JNDI Name contains invalid characters");
64             }
65         }
66         namingForm(wrapper, errors);
67     }
68
69     public void namingForm(OlapDataSourceWrapper wrapper, Errors errors){
70         // TODO OlapDataSource
71
ReportDataSource ds=wrapper.getOlapDataSource();
72         if(ds.getName()==null || ds.getName().trim().length()==0) {
73             errors.rejectValue("olapDataSource.name",null,"Please enter the datasource Name");
74         } else {
75             if(!JasperServerUtil.regExValidateName(ds.getName())) {
76                 errors.rejectValue("olapDataSource.name", null, "Datasource Name contains invalid characters");
77             }
78         }
79
80         if(ds.getLabel()==null || ds.getLabel().trim().length()==0) {
81             errors.rejectValue("olapDataSource.label",null,"Please enter the datasource Label");
82         } else {
83             if(!JasperServerUtil.regExValidateLabel(ds.getLabel())) {
84                 errors.rejectValue("olapDataSource.label",null,"Datasource Label contains invalid characters");
85             }
86         }
87
88         if(ds.getDescription()==null || ds.getDescription().trim().length()>300)
89             errors.rejectValue("olapDataSource.description",null,"Datasource description can not be more than 300 characters");
90     }
91
92     public void jdbcPropsForm(OlapDataSourceWrapper wrapper, Errors errors){
93         JdbcReportDataSource ds=(JdbcReportDataSource)wrapper.getOlapDataSource();
94         if(ds.getDriverClass()==null || ds.getDriverClass().trim().length()==0) {
95             errors.rejectValue("olapDataSource.driverClass",null,"Please enter the driver class name");
96         } else {
97             if(!JasperServerUtil.regExValidateDbDriver(ds.getDriverClass())) {
98                 errors.rejectValue(
99                         "olapDataSource.driverClass", null, "driver contains invalid characters");
100             }
101         }
102
103         if(ds.getConnectionUrl()==null || ds.getConnectionUrl().trim().length()==0) {
104             errors.rejectValue("olapDataSource.connectionUrl", null, "Please enter the JDBC URL");
105         } else {
106             if(!JasperServerUtil.regExValidateJdbcURL(ds.getConnectionUrl())) {
107                 errors.rejectValue(
108                         "olapDataSource.connectionUrl", null, "Jdbc Url contains invalid characters");
109             }
110         }
111
112         if(ds.getUsername()==null || ds.getUsername().trim().length()==0) {
113             errors.rejectValue("olapDataSource.username",null,"Please enter an authorised username");
114         } else {
115             if(!JasperServerUtil.regExValidateName(ds.getUsername())) {
116                 errors.rejectValue(
117                         "olapDataSource.username", null, "username contains invalid characters");
118             }
119         }
120
121         if(ds.getPassword()==null || ds.getPassword().trim().length()==0)
122             errors.rejectValue("olapDataSource.password",null,"Please enter the password");
123
124         namingForm(wrapper, errors);
125     }
126
127     public void validateSource(OlapDataSourceWrapper wrapper, Errors errors){
128         if(constants.getFieldChoiceRepo().equals(wrapper.getSource())
129                 &&( wrapper.getSelectedUri()==null || wrapper.getSelectedUri().trim().length()==0))
130             errors.rejectValue("selectedUri",null,"Please select a Datasource");
131     }
132 }
133
Popular Tags