1 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.BeanReportDataSource; 27 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource; 28 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JndiJdbcReportDataSource; 29 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportDataSource; 30 import com.jaspersoft.jasperserver.war.common.JasperServerConstImpl; 31 import com.jaspersoft.jasperserver.war.common.JasperServerUtil; 32 import com.jaspersoft.jasperserver.war.dto.ReportDataSourceWrapper; 33 34 public class ReportDataSourceValidator implements Validator { 35 private JasperServerConstImpl constants=new JasperServerConstImpl(); 36 public boolean supports(Class clazz) { 37 return ReportDataSourceWrapper.class.isAssignableFrom(clazz); 38 } 39 40 public void validate(Object arg0, Errors arg1) { 41 } 43 44 public void chooseType(ReportDataSourceWrapper wrapper, Errors errors){ 45 if(wrapper.getSource()==null) 46 errors.rejectValue("source",null,"Please select a Datasource type"); 47 } 48 49 public void jndiPropsForm(ReportDataSourceWrapper wrapper, Errors errors){ 50 JndiJdbcReportDataSource jndiSource=(JndiJdbcReportDataSource)wrapper.getReportDataSource(); 51 if(jndiSource.getJndiName()==null || jndiSource.getJndiName().trim().length()==0) { 52 errors.rejectValue("reportDataSource.jndiName",null,"Please enter the JNDI name"); 53 } else { 54 if(!JasperServerUtil.regExValidateJndiServiceName(jndiSource.getJndiName())) { 55 errors.rejectValue("reportDataSource.jndiName", null, "JNDI Name contains invalid characters"); 56 } 57 } 58 namingForm(wrapper, errors); 59 } 60 61 public void namingForm(ReportDataSourceWrapper wrapper, Errors errors){ 62 ReportDataSource ds=wrapper.getReportDataSource(); 63 if(ds.getName()==null || ds.getName().trim().length()==0) { 64 errors.rejectValue("reportDataSource.name",null,"Please enter the datasource Name"); 65 } else { 66 if(!JasperServerUtil.regExValidateName(ds.getName())) { 67 errors.rejectValue("reportDataSource.name", null, "Datasource Name contains invalid characters"); 68 } 69 } 70 71 if(ds.getLabel()==null || ds.getLabel().trim().length()==0) { 72 errors.rejectValue("reportDataSource.label",null,"Please enter the datasource Label"); 73 } else { 74 if(!JasperServerUtil.regExValidateLabel(ds.getLabel())) { 75 errors.rejectValue("reportDataSource.label",null,"Datasource Label contains invalid characters"); 76 } 77 } 78 79 if(ds.getDescription()==null || ds.getDescription().trim().length()>250) 80 errors.rejectValue("reportDataSource.description",null,"Datasource description can not be more than 250 characters"); 81 } 82 83 public void jdbcPropsForm(ReportDataSourceWrapper wrapper, Errors errors){ 84 JdbcReportDataSource ds=(JdbcReportDataSource)wrapper.getReportDataSource(); 85 if(ds.getDriverClass()==null || ds.getDriverClass().trim().length()==0) { 86 errors.rejectValue("reportDataSource.driverClass",null,"Please enter the driver class name"); 87 } else { 88 ds.setDriverClass(ds.getDriverClass().trim()); 89 if(!JasperServerUtil.regExValidateDbDriver(ds.getDriverClass())) { 90 errors.rejectValue("reportDataSource.driverClass", null, "driver contains invalid characters"); 91 } 92 } 93 94 if(ds.getConnectionUrl()==null || ds.getConnectionUrl().trim().length()==0) { 95 errors.rejectValue("reportDataSource.connectionUrl", null, "Please enter the JDBC URL"); 96 } else { 97 if(!JasperServerUtil.regExValidateJdbcURL(ds.getConnectionUrl())) { 98 errors.rejectValue("reportDataSource.connectionUrl", null, "Jdbc Url contains invalid characters"); 99 } 100 } 101 102 if(ds.getUsername()==null || ds.getUsername().trim().length()==0) { 103 errors.rejectValue("reportDataSource.username",null,"Please enter an authorised username"); 104 } else { 105 if(!JasperServerUtil.regExValidateName(ds.getUsername())) { 106 errors.rejectValue("reportDataSource.username", null, "username contains invalid characters"); 107 } 108 } 109 110 if(ds.getPassword()==null || ds.getPassword().trim().length()==0) 111 errors.rejectValue("reportDataSource.password",null,"Please enter the password"); 112 113 namingForm(wrapper, errors); 114 } 115 116 public void beanPropsForm(ReportDataSourceWrapper wrapper, Errors errors){ 117 BeanReportDataSource beanSource=(BeanReportDataSource)wrapper.getReportDataSource(); 118 if(beanSource.getBeanName()==null || beanSource.getBeanName().trim().length()==0) { 119 errors.rejectValue("reportDataSource.beanName",null,"Please enter the bean name"); 120 } else { 121 } 125 namingForm(wrapper, errors); 126 } 127 128 public void validateSource(ReportDataSourceWrapper wrapper, Errors errors){ 129 if(constants.getFieldChoiceRepo().equals(wrapper.getSource()) 130 &&( wrapper.getSelectedUri()==null || wrapper.getSelectedUri().trim().length()==0)) 131 errors.rejectValue("selectedUri",null,"Please select a Datasource"); 132 } 133 } 134 | Popular Tags |