/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
* enumeration as class type.
*/
public FinancialsDayOfTheWeekConverter () {
+ // Call other constructor with class type
super(DayOfTheWeek.class);
}
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
* enumeration as class type.
*/
public FinancialsPaymentTypeConverter () {
+ // Call other constructor with class type
super(PaymentType.class);
}
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@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) {
+ }
+
+}
/*
- * 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
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@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
- }
- }
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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
+ }
+ }
+
+}
/*
- * 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
*/
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
+ * <p>
+ * @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) {
/*
- * 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
*/
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
+ * <p>
+ * @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) {
/*
- * 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
*/
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
+ * <p>
+ * @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) {
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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
+ * <p>
+ * @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 <f:validatorRegex />)
+ 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));
+ }
+ }
+
+}
/*
- * 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
*/
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
+ * <p>
+ * @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) {
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
*/
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
+ * <p>
+ * @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) {
/*
- * 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