--- /dev/null
+/*
+ * Copyright (C) 2016, 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.addressbook.converter.business.headquarters;
+
+import java.text.MessageFormat;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontactsbusiness.exceptions.headquarters.CompanyHeadquartersNotFoundException;
+import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData;
+
+/**
+ * Converter for converting company headquarters to and from id number
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter (value = "CompanyHeadquartersConverter")
+public class AddressbookCompanyHeadquartersConverter implements Converter<HeadquartersData> {
+
+ /**
+ * CompanyEmployee EJB
+ */
+ private static CompanyHeadquartersSessionBeanRemote COMPANY_HEADQUARTERS_BEAN;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookCompanyHeadquartersConverter () {
+ }
+
+ @Override
+ public HeadquartersData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Warning message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
+
+ // Return null
+ return null;
+ }
+
+ // Is the bean there?
+ // @TODO Requires this synchronization or is it (sync) confusing the container?
+ if (null == AddressbookCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ AddressbookCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN = (CompanyHeadquartersSessionBeanRemote) initialContext.lookup("java:global/jjobs-ejb/companyEmployee!org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+
+ // Init instance
+ HeadquartersData companyHeadquarters = null;
+
+ try {
+ // Try to parse the value as long
+ Long headquartersId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ companyHeadquarters = AddressbookCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN.findCompanyHeadquartersById(headquartersId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final CompanyHeadquartersNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return companyHeadquarters;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final HeadquartersData value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getHeadquartersId());
+ }
+
+}
--- /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.addressbook.validator.business.basicdata;
+
+import java.text.MessageFormat;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for company names
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator ("CompanyNameValidator")
+public class FinancialsCompanyNameValidator extends BaseStringValidator {
+
+ /**
+ * Business contact EJB
+ */
+ private static BusinessDataSessionBeanRemote BASIC_DATA_BEAN;
+
+ /**
+ * 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 {
+ // All accepted, required fields
+ 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)
+ 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
+ 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);
+ }
+
+ // Is the bean not yet set?
+ // @TODO Requires this synchronization or is it (sync) confusing the container?
+ if (null == FinancialsCompanyNameValidator.BASIC_DATA_BEAN) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ FinancialsCompanyNameValidator.BASIC_DATA_BEAN = (BusinessDataSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+
+ // Check if name is already used
+ Boolean nameExists = FinancialsCompanyNameValidator.BASIC_DATA_BEAN.isCompanyNameUsed(companyName);
+
+ // Is the user id valid?
+ if ((!nameExists) && (checkExisting)) {
+ // Format message
+ 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
+ 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
+ }
+ }
+
+}
/**
* Pattern matcher
*/
- private static final Pattern PATTERN_MATCHER = Pattern.compile(JobsEmailAddressValidator.EMAIL_REGEX);
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookEmailAddressValidator.EMAIL_REGEX);
/**
* Serial number
--- /dev/null
+/*
+ * Copyright (C) 2016, 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.addressbook.validator.url;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+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;
+
+/**
+ * A validator for URL vallidation (only regex, but allow empty value if
+ * allowed).
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator ("UrlValidator")
+public class AddressbookUrlValidator extends BaseStringValidator {
+
+ /**
+ * Pattern matcher
+ */
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookUrlValidator.URL_REGEX);
+
+ /**
+ * Email pattern
+ */
+ private static final String URL_REGEX = "(http|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?"; //NOI18N
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 187_536_745_607_193L;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUrlValidator () {
+ }
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // The required field
+ 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);
+
+ // Is the email address empty and allowed?
+ if (null == value && allowEmptyValue) {
+ // Then accept this here
+ return;
+ } else if (null == value) {
+ // Abort here
+ throw new ValidatorException(new FacesMessage("No empty URL allowed.")); //NOI18N
+ }
+
+ // Get string from object ... ;-)
+ String url = String.valueOf(value).trim();
+
+ // Checks if the email address matches a regex ("low-level" check)
+ // @TODO Should also be done by <f:validatorRegex />)
+ boolean matches = PATTERN_MATCHER.matcher(url).matches(); //NOI18N
+
+ // Is the email address valid?
+ if (!matches) {
+ // Generate message
+ String message = MessageFormat.format("URL {0} does not match regular expression.", url); //NOI18N
+
+ // Not matching
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
+ }
+ }
+
+}
+++ /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.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.ConverterException;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
-import org.mxchange.jcoreee.validator.string.BaseStringValidator;
-
-/**
- * A validator for company names
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesValidator ("CompanyNameValidator")
-public class FinancialsCompanyNameValidator extends BaseStringValidator {
-
- /**
- * Business contact EJB
- */
- private static BusinessDataSessionBeanRemote BASIC_DATA_BEAN;
-
- /**
- * 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 {
- // All accepted, required fields
- 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)
- 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
- 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);
- }
-
- // Is the bean not yet set?
- // @TODO Requires this synchronization or is it (sync) confusing the container?
- if (null == FinancialsCompanyNameValidator.BASIC_DATA_BEAN) {
- // Try to get it
- try {
- // Get initial context
- Context initialContext = new InitialContext();
-
- // ... and user controller
- FinancialsCompanyNameValidator.BASIC_DATA_BEAN = (BusinessDataSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
- }
-
- // Check if name is already used
- Boolean nameExists = FinancialsCompanyNameValidator.BASIC_DATA_BEAN.isCompanyNameUsed(companyName);
-
- // Is the user id valid?
- if ((!nameExists) && (checkExisting)) {
- // Format message
- 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
- 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) 2016, 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.jjobs.converter.business.headquarters;
-
-import java.text.MessageFormat;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.convert.FacesConverter;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontactsbusiness.exceptions.headquarters.CompanyHeadquartersNotFoundException;
-import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData;
-
-/**
- * Converter for converting company headquarters to and from id number
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesConverter (value = "CompanyHeadquartersConverter")
-public class JobsCompanyHeadquartersConverter implements Converter<HeadquartersData> {
-
- /**
- * CompanyEmployee EJB
- */
- private static CompanyHeadquartersSessionBeanRemote COMPANY_HEADQUARTERS_BEAN;
-
- /**
- * Default constructor
- */
- public JobsCompanyHeadquartersConverter () {
- }
-
- @Override
- public HeadquartersData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the value null or empty?
- if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Return null
- return null;
- }
-
- // Is the bean there?
- // @TODO Requires this synchronization or is it (sync) confusing the container?
- if (null == JobsCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN) {
- // Try to get it
- try {
- // Get initial context
- Context initialContext = new InitialContext();
-
- // ... and user controller
- JobsCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN = (CompanyHeadquartersSessionBeanRemote) initialContext.lookup("java:global/jjobs-ejb/companyEmployee!org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
- }
-
- // Init instance
- HeadquartersData companyHeadquarters = null;
-
- try {
- // Try to parse the value as long
- Long headquartersId = Long.valueOf(submittedValue);
-
- // Try to get user instance from it
- companyHeadquarters = JobsCompanyHeadquartersConverter.COMPANY_HEADQUARTERS_BEAN.findCompanyHeadquartersById(headquartersId);
- } catch (final NumberFormatException ex) {
- // Throw again
- throw new ConverterException(ex);
- } catch (final CompanyHeadquartersNotFoundException ex) {
- // Debug message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
- }
-
- // Return it
- return companyHeadquarters;
- }
-
- @Override
- public String getAsString (final FacesContext context, final UIComponent component, final HeadquartersData value) {
- // Is the object null?
- if ((null == value) || (String.valueOf(value).isEmpty())) {
- // Is null
- return ""; //NOI18N
- }
-
- // Return id number
- return String.valueOf(value.getHeadquartersId());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 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.jjobs.validator.url;
-
-import java.text.MessageFormat;
-import java.util.regex.Pattern;
-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;
-
-/**
- * A validator for URL vallidation (only regex, but allow empty value if
- * allowed).
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesValidator ("UrlValidator")
-public class JobsUrlValidator extends BaseStringValidator {
-
- /**
- * Pattern matcher
- */
- private static final Pattern PATTERN_MATCHER = Pattern.compile(JobsUrlValidator.URL_REGEX);
-
- /**
- * Email pattern
- */
- private static final String URL_REGEX = "(http|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?"; //NOI18N
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 187_536_745_607_193L;
-
- /**
- * Default constructor
- */
- public JobsUrlValidator () {
- }
-
- @Override
- public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // The required field
- 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);
-
- // Is the email address empty and allowed?
- if (null == value && allowEmptyValue) {
- // Then accept this here
- return;
- } else if (null == value) {
- // Abort here
- throw new ValidatorException(new FacesMessage("No empty URL allowed.")); //NOI18N
- }
-
- // Get string from object ... ;-)
- String url = String.valueOf(value).trim();
-
- // Checks if the email address matches a regex ("low-level" check)
- // @TODO Should also be done by <f:validatorRegex />)
- boolean matches = PATTERN_MATCHER.matcher(url).matches(); //NOI18N
-
- // Is the email address valid?
- if (!matches) {
- // Generate message
- String message = MessageFormat.format("URL {0} does not match regular expression.", url); //NOI18N
-
- // Not matching
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
- }
- }
-
-}