From: Roland Häder Date: Tue, 20 Mar 2018 23:49:37 +0000 (+0100) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=954e2f6338b5a36580b74c1b97475a5e44601bd5;p=jfinancials-war.git Please cherry-pick: - added ServletContextListener implementation for (later) pre-initialize JS107 cache before any page is served - added validators for basic company data, headquarter data and branch office's email addresses - rewrote converters which have allowEmptyValue flag to handle it correctly (need that validators.jsf.taglib.xml for this to work) - renamed company name validator as this is for basic company data ... ;-) - updated/changed copyright year to Free Software Foundation Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java index 560e3dfe..b083696f 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/business/branchoffice/FinancialsBranchOfficeConverter.java b/src/java/org/mxchange/jfinancials/converter/business/branchoffice/FinancialsBranchOfficeConverter.java index 0c8d018d..fecbc631 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/branchoffice/FinancialsBranchOfficeConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/branchoffice/FinancialsBranchOfficeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/business/department/FinancialsDepartmentConverter.java b/src/java/org/mxchange/jfinancials/converter/business/department/FinancialsDepartmentConverter.java index e852832c..2ff0466a 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/department/FinancialsDepartmentConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/department/FinancialsDepartmentConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/business/employee/FinancialsEmployeeConverter.java b/src/java/org/mxchange/jfinancials/converter/business/employee/FinancialsEmployeeConverter.java index fa1780a5..16f7e29c 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/employee/FinancialsEmployeeConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/employee/FinancialsEmployeeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java b/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java index c75af1cc..aec94af5 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/business/opening_time/FinancialsCompanyOpeningTimeConverter.java b/src/java/org/mxchange/jfinancials/converter/business/opening_time/FinancialsCompanyOpeningTimeConverter.java index 8d4e1ba9..3ed4cf3f 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/opening_time/FinancialsCompanyOpeningTimeConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/opening_time/FinancialsCompanyOpeningTimeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/contact/FinancialsContactConverter.java b/src/java/org/mxchange/jfinancials/converter/contact/FinancialsContactConverter.java index 96051326..7686c8c1 100644 --- a/src/java/org/mxchange/jfinancials/converter/contact/FinancialsContactConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/contact/FinancialsContactConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java b/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java index b671dec4..622b0d2c 100644 --- a/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/dayofweek/FinancialsDayOfTheWeekConverter.java b/src/java/org/mxchange/jfinancials/converter/dayofweek/FinancialsDayOfTheWeekConverter.java index 6f74301d..fa1a00aa 100644 --- a/src/java/org/mxchange/jfinancials/converter/dayofweek/FinancialsDayOfTheWeekConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/dayofweek/FinancialsDayOfTheWeekConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -33,6 +33,7 @@ public class FinancialsDayOfTheWeekConverter extends EnumConverter { * enumeration as class type. */ public FinancialsDayOfTheWeekConverter () { + // Call other constructor with class type super(DayOfTheWeek.class); } diff --git a/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java index 2904f48c..e2468223 100644 --- a/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java index 2c62837d..f9aa1c92 100644 --- a/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/landline/FinancialsLandLineNumberConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java index 3fb62941..46479609 100644 --- a/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileNumberConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/mobileprovider/FinancialsMobileProviderConverter.java b/src/java/org/mxchange/jfinancials/converter/mobileprovider/FinancialsMobileProviderConverter.java index a3036e57..11880df3 100644 --- a/src/java/org/mxchange/jfinancials/converter/mobileprovider/FinancialsMobileProviderConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/mobileprovider/FinancialsMobileProviderConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/payment_type/FinancialsPaymentTypeConverter.java b/src/java/org/mxchange/jfinancials/converter/payment_type/FinancialsPaymentTypeConverter.java index 1925c0ec..d8ca865a 100644 --- a/src/java/org/mxchange/jfinancials/converter/payment_type/FinancialsPaymentTypeConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/payment_type/FinancialsPaymentTypeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -33,6 +33,7 @@ public class FinancialsPaymentTypeConverter extends EnumConverter { * enumeration as class type. */ public FinancialsPaymentTypeConverter () { + // Call other constructor with class type super(PaymentType.class); } diff --git a/src/java/org/mxchange/jfinancials/converter/personal_title/FinancialsPersonalTitleConverter.java b/src/java/org/mxchange/jfinancials/converter/personal_title/FinancialsPersonalTitleConverter.java index 7e0da8a9..36be68d9 100644 --- a/src/java/org/mxchange/jfinancials/converter/personal_title/FinancialsPersonalTitleConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/personal_title/FinancialsPersonalTitleConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/profile_mode/FinancialsProfileModeConverter.java b/src/java/org/mxchange/jfinancials/converter/profile_mode/FinancialsProfileModeConverter.java index fe8d8021..dbeebe70 100644 --- a/src/java/org/mxchange/jfinancials/converter/profile_mode/FinancialsProfileModeConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/profile_mode/FinancialsProfileModeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/user/FinancialsUserConverter.java b/src/java/org/mxchange/jfinancials/converter/user/FinancialsUserConverter.java index 82edd6bf..39b0591a 100644 --- a/src/java/org/mxchange/jfinancials/converter/user/FinancialsUserConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/user/FinancialsUserConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/converter/user_account_status/FinancialsUserAccountStatusConverter.java b/src/java/org/mxchange/jfinancials/converter/user_account_status/FinancialsUserAccountStatusConverter.java index 0f457029..381896a2 100644 --- a/src/java/org/mxchange/jfinancials/converter/user_account_status/FinancialsUserAccountStatusConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/user_account_status/FinancialsUserAccountStatusConverter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/listener/FinancialsWebApplicationListener.java b/src/java/org/mxchange/jfinancials/listener/FinancialsWebApplicationListener.java new file mode 100644 index 00000000..ad4b9df1 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/listener/FinancialsWebApplicationListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017, 2018 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.listener; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; +import org.mxchange.jcoreee.bean.faces.BaseFacesBean; + +/** + * A web-application listener for de-/initialization stuff + *

+ * @author Roland Haeder + */ +@WebListener +public class FinancialsWebApplicationListener implements ServletContextListener { + + @Override + public void contextDestroyed (final ServletContextEvent sce) { + // Remove all bundles + BaseFacesBean.removeBundles(); + } + + @Override + public void contextInitialized (final ServletContextEvent sce) { + } + +} diff --git a/src/java/org/mxchange/jfinancials/validator/birthday/FinancialsBirthdayValidator.java b/src/java/org/mxchange/jfinancials/validator/birthday/FinancialsBirthdayValidator.java index 80dcdaf2..fe4e44a1 100644 --- a/src/java/org/mxchange/jfinancials/validator/birthday/FinancialsBirthdayValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/birthday/FinancialsBirthdayValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsBasicDataCompanyNameValidator.java b/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsBasicDataCompanyNameValidator.java new file mode 100644 index 00000000..6044ea03 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsBasicDataCompanyNameValidator.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2017, 2018 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.validator.business.basicdata; + +import java.text.MessageFormat; +import javax.enterprise.inject.spi.CDI; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.ValidatorException; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jfinancials.beans.business.basicdata.FinancialsBasicDataWebRequestBean; +import org.mxchange.jfinancials.beans.business.basicdata.FinancialsBasicDataWebRequestController; + +/** + * A validator for basic data company names + *

+ * @author Roland Häder + */ +@FacesValidator (value = "BasicDataCompanyNameValidator") +public class FinancialsBasicDataCompanyNameValidator extends BaseStringValidator { + + /** + * Business basic data backing bean + */ + private static FinancialsBasicDataWebRequestController BASIC_DATA_CONTROLLER; + + /** + * Serial number + */ + private static final long serialVersionUID = 57_283_657_476_561L; + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Is the instance there? + if (null == BASIC_DATA_CONTROLLER) { + // Get bean from CDI directly + BASIC_DATA_CONTROLLER = CDI.current().select(FinancialsBasicDataWebRequestBean.class).get(); + } + + // All accepted, required fields + final String[] requiredFields = {"companyName"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + super.preValidate(context, component, value, requiredFields, false); + + // Convert name to string (now securely checked in BaseStringValidator) + final String companyName = (String) value; + + // Default is to check on existing names + Boolean checkExisting = Boolean.TRUE; + + // Is attribute "allowEmptyRequiredData" set? + if (component.getAttributes().containsKey("checkExisting")) { //NOI18N + // Get attribute + final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N + + // Make sure, it is Boolean as no String is accepted anymore + if (!(attribute instanceof String)) { + // Not valid attribute, please use "true" or "false" (default) + throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N + } + + // Securely cast it + checkExisting = Boolean.parseBoolean((String) attribute); + } + + // Check if name is already used + final Boolean nameExists = BASIC_DATA_CONTROLLER.isCompanyNameUsed(companyName); + + // Is the user id valid? + if ((!nameExists) && (checkExisting)) { + // Format message + final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName); + + // Name does not exist + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N + } else if ((nameExists) && (!checkExisting)) { + // Format message + final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName); + + // Name already exists + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java b/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java deleted file mode 100644 index f93f8cf7..00000000 --- a/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.validator.business.basicdata; - -import java.text.MessageFormat; -import javax.enterprise.inject.spi.CDI; -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.validator.FacesValidator; -import javax.faces.validator.ValidatorException; -import org.mxchange.jcoreee.validator.string.BaseStringValidator; -import org.mxchange.jfinancials.beans.business.basicdata.FinancialsBasicDataWebRequestBean; -import org.mxchange.jfinancials.beans.business.basicdata.FinancialsBasicDataWebRequestController; - -/** - * A validator for company names - *

- * @author Roland Häder - */ -@FacesValidator (value = "CompanyNameValidator") -public class FinancialsCompanyNameValidator extends BaseStringValidator { - - /** - * Business basic data backing bean - */ - private static FinancialsBasicDataWebRequestController BASIC_DATA_CONTROLLER; - - /** - * Serial number - */ - private static final long serialVersionUID = 57_283_657_476_561L; - - @Override - public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Is the instance there? - if (null == BASIC_DATA_CONTROLLER) { - // Get bean from CDI directly - BASIC_DATA_CONTROLLER = CDI.current().select(FinancialsBasicDataWebRequestBean.class).get(); - } - - // All accepted, required fields - final String[] requiredFields = {"companyName"}; //NOI18N - - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, false); - - // Convert name to string (now securely checked in BaseStringValidator) - final String companyName = (String) value; - - // Default is to check on existing names - Boolean checkExisting = Boolean.TRUE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("checkExisting")) { //NOI18N - // Get attribute - final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - checkExisting = Boolean.parseBoolean((String) attribute); - } - - // Check if name is already used - final Boolean nameExists = BASIC_DATA_CONTROLLER.isCompanyNameUsed(companyName); - - // Is the user id valid? - if ((!nameExists) && (checkExisting)) { - // Format message - final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName); - - // Name does not exist - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N - } else if ((nameExists) && (!checkExisting)) { - // Format message - final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName); - - // Name already exists - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N - } - } - -} diff --git a/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java b/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java new file mode 100644 index 00000000..3a9134be --- /dev/null +++ b/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2017, 2018 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.validator.business.headquarter; + +import java.text.MessageFormat; +import javax.enterprise.inject.spi.CDI; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.ValidatorException; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestBean; +import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestController; + +/** + * A validator for headquarter company names + *

+ * @author Roland Häder + */ +@FacesValidator (value = "HeadquarterCompanyNameValidator") +public class FinancialsHeadquarterCompanyNameValidator extends BaseStringValidator { + + /** + * Headquarter backing bean + */ + private static FinancialsHeadquarterWebRequestController HEADQUARTER_CONTROLLER; + + /** + * Serial number + */ + private static final long serialVersionUID = 57_283_657_476_561L; + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Is the instance there? + if (null == HEADQUARTER_CONTROLLER) { + // Get bean from CDI directly + HEADQUARTER_CONTROLLER = CDI.current().select(FinancialsHeadquarterWebRequestBean.class).get(); + } + + // All accepted, required fields + final String[] requiredFields = {"companyName"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + super.preValidate(context, component, value, requiredFields, false); + + // Convert name to string (now securely checked in BaseStringValidator) + final String companyName = (String) value; + + // Default is to check on existing names + Boolean checkExisting = Boolean.TRUE; + + // Is attribute "allowEmptyRequiredData" set? + if (component.getAttributes().containsKey("checkExisting")) { //NOI18N + // Get attribute + final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N + + // Make sure, it is Boolean as no String is accepted anymore + if (!(attribute instanceof String)) { + // Not valid attribute, please use "true" or "false" (default) + throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N + } + + // Securely cast it + checkExisting = Boolean.parseBoolean((String) attribute); + } + + // Check if name is already used + final Boolean nameExists = HEADQUARTER_CONTROLLER.isCompanyNameUsed(companyName); + + // Is the user id valid? + if ((!nameExists) && (checkExisting)) { + // Format message + final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName); + + // Name does not exist + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N + } else if ((nameExists) && (!checkExisting)) { + // Format message + final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName); + + // Name already exists + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java index 7f54b429..8f0e39c2 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -56,34 +56,37 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator { */ private static final long serialVersionUID = 187_536_745_607_192L; + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsEmailAddressValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { // The required field final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N - // Default is to reject empty email address fields - Boolean allowEmptyValue = Boolean.FALSE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N - // Get attribute - final Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - allowEmptyValue = Boolean.parseBoolean((String) attribute); - } - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmptyValue); + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); // Is the email address empty and allowed? - if (null == value && allowEmptyValue) { + if (null == value && this.allowEmptyRequiredData) { // Then accept this here return; } else if (null == value) { diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/basicdata/FinancialsBasicDataEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/basicdata/FinancialsBasicDataEmailAddressValidator.java index cb392b53..b42b24c5 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/basicdata/FinancialsBasicDataEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/basicdata/FinancialsBasicDataEmailAddressValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -56,34 +56,37 @@ public class FinancialsBasicDataEmailAddressValidator extends BaseStringValidato */ private static final long serialVersionUID = 187_536_745_607_195L; + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsBasicDataEmailAddressValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { // The required field final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N - // Default is to reject empty email address fields - Boolean allowEmptyValue = Boolean.FALSE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N - // Get attribute - final Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - allowEmptyValue = Boolean.parseBoolean((String) attribute); - } - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmptyValue); + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); // Is the email address empty and allowed? - if (null == value && allowEmptyValue) { + if (null == value && this.allowEmptyRequiredData) { // Then accept this here return; } else if (null == value) { diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/branchoffice/FinancialsBranchOfficeEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/branchoffice/FinancialsBranchOfficeEmailAddressValidator.java index 0432de1a..a3952b1a 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/branchoffice/FinancialsBranchOfficeEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/branchoffice/FinancialsBranchOfficeEmailAddressValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -56,34 +56,37 @@ public class FinancialsBranchOfficeEmailAddressValidator extends BaseStringValid */ private static final long serialVersionUID = 187_536_745_607_195L; + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsBranchOfficeEmailAddressValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { // The required field final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N - // Default is to reject empty email address fields - Boolean allowEmptyValue = Boolean.FALSE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N - // Get attribute - final Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - allowEmptyValue = Boolean.parseBoolean((String) attribute); - } - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmptyValue); + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); // Is the email address empty and allowed? - if (null == value && allowEmptyValue) { + if (null == value && this.allowEmptyRequiredData) { // Then accept this here return; } else if (null == value) { diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/employee/FinancialsEmployeeEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/employee/FinancialsEmployeeEmailAddressValidator.java new file mode 100644 index 00000000..6ac26e2f --- /dev/null +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/employee/FinancialsEmployeeEmailAddressValidator.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2016 - 2018 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.validator.emailaddress.employee; + +import java.text.MessageFormat; +import java.util.regex.Pattern; +import javax.enterprise.inject.spi.CDI; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.ValidatorException; +import org.mxchange.jcoreee.validator.string.BaseStringValidator; +import org.mxchange.jfinancials.beans.business.employee.FinancialsEmployeeWebRequestBean; +import org.mxchange.jfinancials.beans.business.employee.FinancialsEmployeeWebRequestController; + +/** + * A validator for employee email address validation + *

+ * @author Roland Häder + */ +@FacesValidator (value = "EmployeeEmailAddressValidator") +public class FinancialsEmployeeEmailAddressValidator extends BaseStringValidator { + + /** + * Email pattern + */ + private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N + + /** + * Employee backing bean + */ + private static FinancialsEmployeeWebRequestController EMPLOYEE_CONTROLLER; + + /** + * Pattern matcher + */ + private static final Pattern PATTERN_MATCHER = Pattern.compile(FinancialsEmployeeEmailAddressValidator.EMAIL_REGEX); + + /** + * Serial number + */ + private static final long serialVersionUID = 187_536_745_607_196L; + + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsEmployeeEmailAddressValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + + @Override + public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // The required field + final String[] requiredFields = {"employeeEmailAddress"}; //NOI18N + + // Pre-validation (example: not null, not a string, empty string ...) + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); + + // Is the email address empty and allowed? + if (null == value && this.allowEmptyRequiredData) { + // Then accept this here + return; + } else if (null == value) { + // Abort here + throw new ValidatorException(new FacesMessage("No empty email address allowed.")); //NOI18N + } + + // Get string from object ... ;-) + // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat + final String emailAddress = String.valueOf(value).trim(); + + // Checks if the email address matches a regex ("low-level" check) + // @TODO Should also be done by ) + final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N + + // Is the email address valid? + if (!matches) { + // Generate message + String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N + + // Not matching + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); + } + + // Get client id (aka form id) + final String clientId = component.getClientId(); + + // Is the instance there? + if (null == EMPLOYEE_CONTROLLER) { + // Get bean from CDI directly + EMPLOYEE_CONTROLLER = CDI.current().select(FinancialsEmployeeWebRequestBean.class).get(); + } + + // Is it registered? + final Boolean isRegistered = EMPLOYEE_CONTROLLER.isEmailAddressRegistered(emailAddress); + + // Is the email address already registered? + if ((!clientId.endsWith("resendEmailAddress")) && (isRegistered)) { //NOI18N + // Generate message + final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N + + // No, then abort here + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); + } else if ((clientId.endsWith("resendEmailAddress")) && (!isRegistered)) { //NOI18N + // Generate message + final String message = MessageFormat.format("Email address {0} is not registered.", emailAddress); //NOI18N + + // No, then abort here + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java index bb157d02..3bf96872 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -56,34 +56,37 @@ public class FinancialsHeadquarterEmailAddressValidator extends BaseStringValida */ private static final long serialVersionUID = 187_536_745_607_194L; + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsHeadquarterEmailAddressValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { // The required field final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N - // Default is to reject empty email address fields - Boolean allowEmptyValue = Boolean.FALSE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N - // Get attribute - final Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - allowEmptyValue = Boolean.parseBoolean((String) attribute); - } - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmptyValue); + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); // Is the email address empty and allowed? - if (null == value && allowEmptyValue) { + if (null == value && this.allowEmptyRequiredData) { // Then accept this here return; } else if (null == value) { diff --git a/src/java/org/mxchange/jfinancials/validator/names/FinancialsNameValidator.java b/src/java/org/mxchange/jfinancials/validator/names/FinancialsNameValidator.java index 62b4e744..e4212ba2 100644 --- a/src/java/org/mxchange/jfinancials/validator/names/FinancialsNameValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/names/FinancialsNameValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/java/org/mxchange/jfinancials/validator/password/FinancialsUserPasswordValidator.java b/src/java/org/mxchange/jfinancials/validator/password/FinancialsUserPasswordValidator.java index 82bc15e5..c8c87ee9 100644 --- a/src/java/org/mxchange/jfinancials/validator/password/FinancialsUserPasswordValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/password/FinancialsUserPasswordValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as diff --git a/src/java/org/mxchange/jfinancials/validator/phone/abroad/FinancialsAbroadDialValidator.java b/src/java/org/mxchange/jfinancials/validator/phone/abroad/FinancialsAbroadDialValidator.java index 2cdd20bc..d0129d63 100644 --- a/src/java/org/mxchange/jfinancials/validator/phone/abroad/FinancialsAbroadDialValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/phone/abroad/FinancialsAbroadDialValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/java/org/mxchange/jfinancials/validator/phone/number/FinancialsPhoneNumberValidator.java b/src/java/org/mxchange/jfinancials/validator/phone/number/FinancialsPhoneNumberValidator.java index bb8c20c5..13605ab4 100644 --- a/src/java/org/mxchange/jfinancials/validator/phone/number/FinancialsPhoneNumberValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/phone/number/FinancialsPhoneNumberValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/java/org/mxchange/jfinancials/validator/privacy_terms/FinancialsPrivacyTermsCheckboxValidator.java b/src/java/org/mxchange/jfinancials/validator/privacy_terms/FinancialsPrivacyTermsCheckboxValidator.java index 0ebd2e4f..a4681411 100644 --- a/src/java/org/mxchange/jfinancials/validator/privacy_terms/FinancialsPrivacyTermsCheckboxValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/privacy_terms/FinancialsPrivacyTermsCheckboxValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/java/org/mxchange/jfinancials/validator/url/FinancialsUrlValidator.java b/src/java/org/mxchange/jfinancials/validator/url/FinancialsUrlValidator.java index e4dcdf30..3bba2ab1 100644 --- a/src/java/org/mxchange/jfinancials/validator/url/FinancialsUrlValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/url/FinancialsUrlValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -49,34 +49,37 @@ public class FinancialsUrlValidator extends BaseStringValidator { */ private static final long serialVersionUID = 187_536_745_607_193L; + /** + * Whether empty data is allowed + */ + private Boolean allowEmptyRequiredData; + + /** + * Default constructor + */ + public FinancialsUrlValidator () { + this.allowEmptyRequiredData = Boolean.FALSE; + } + + /** + * Setter for allowEmptyRequiredData flag + *

+ * @param allowEmptyRequiredData Whether empty values are allowed + */ + public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) { + this.allowEmptyRequiredData = allowEmptyRequiredData; + } + @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { // The required field final String[] requiredFields = {"companyWebsiteUrl"}; //NOI18N - // Default is to reject empty email address fields - Boolean allowEmptyValue = Boolean.FALSE; - - // Is attribute "allowEmptyValue" set? - if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N - // Get attribute - Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - - // Make sure, it is Boolean as no String is accepted anymore - if (!(attribute instanceof String)) { - // Not valid attribute, please use "true" or "false" (default) - throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N - } - - // Securely cast it - allowEmptyValue = Boolean.parseBoolean((String) attribute); - } - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmptyValue); + super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData); // Is the email address empty and allowed? - if (null == value && allowEmptyValue) { + if (null == value && this.allowEmptyRequiredData) { // Then accept this here return; } else if (null == value) { diff --git a/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java b/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java index 7af9f53e..68616095 100644 --- a/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by