You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/11/13 03:48:58 UTC
svn commit: r835712 [11/19] - in
/myfaces/extensions/validator/branches/branch_for_jsf_2_0: ./ assembly/
assembly/src/ assembly/src/main/ assembly/src/main/assembly/
assembly/src/main/resources/ component-support/
component-support/generic-support/ com...
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,913 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
+import org.apache.myfaces.extensions.validator.core.ValidationModuleKey;
+import org.apache.myfaces.extensions.validator.core.InformationProviderBean;
+import org.apache.myfaces.extensions.validator.core.el.AbstractELHelperFactory;
+import org.apache.myfaces.extensions.validator.core.el.ELHelper;
+import org.apache.myfaces.extensions.validator.core.el.ValueBindingExpression;
+import org.apache.myfaces.extensions.validator.core.factory.ClassMappingFactory;
+import org.apache.myfaces.extensions.validator.core.factory.FacesMessageFactory;
+import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
+import org.apache.myfaces.extensions.validator.core.factory.NameMapperAwareFactory;
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfiguration;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfigurationEntry;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfigurationNames;
+import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.PropertyValidationInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.ValidationExceptionInterceptor;
+import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.ComponentMetaDataExtractorFactory;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+import org.apache.myfaces.extensions.validator.core.metadata.transformer.MetaDataTransformer;
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
+import org.apache.myfaces.extensions.validator.core.storage.FacesMessageStorage;
+import org.apache.myfaces.extensions.validator.core.storage.StorageManager;
+import org.apache.myfaces.extensions.validator.core.validation.SkipValidationEvaluator;
+import org.apache.myfaces.extensions.validator.core.validation.message.resolver.MessageResolver;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameterExtractor;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameterExtractorFactory;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverityInterpreter;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.MissingResourceException;
+import java.util.List;
+import java.util.ArrayList;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@SuppressWarnings({"unchecked"})
+@UsageInformation(UsageCategory.INTERNAL)
+public class ExtValUtils
+{
+ private static final Log LOGGER = LogFactory.getLog(ExtValUtils.class);
+
+ private static final String JAVAX_FACES_REQUIRED = "javax.faces.component.UIInput.REQUIRED";
+ private static final String JAVAX_FACES_REQUIRED_DETAIL = "javax.faces.component.UIInput.REQUIRED_detail";
+
+ private static final String JAVAX_FACES_MAXIMUM = "javax.faces.validator.LengthValidator.MAXIMUM";
+ private static final String JAVAX_FACES_MAXIMUM_DETAIL = "javax.faces.validator.LengthValidator.MAXIMUM_detail";
+
+ public static ValidationStrategy getValidationStrategyForMetaData(String metaDataKey)
+ {
+ return ((ClassMappingFactory<String, ValidationStrategy>) ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.VALIDATION_STRATEGY_FACTORY, ClassMappingFactory.class))
+ .create(metaDataKey);
+ }
+
+ public static void registerMetaDataToValidationStrategyNameMapper(
+ NameMapper<String> metaDataToValidationStrategyNameMapper)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.VALIDATION_STRATEGY_FACTORY, NameMapperAwareFactory.class))
+ .register(metaDataToValidationStrategyNameMapper);
+ }
+
+ public static void deregisterMetaDataToValidationStrategyNameMapper(
+ Class<? extends NameMapper> metaDataToValidationStrategyNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.VALIDATION_STRATEGY_FACTORY, NameMapperAwareFactory.class))
+ .deregister(metaDataToValidationStrategyNameMapperClass);
+ }
+
+ public static void denyMetaDataToValidationStrategyNameMapper(
+ Class<? extends NameMapper> metaDataToValidationStrategyNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.VALIDATION_STRATEGY_FACTORY, NameMapperAwareFactory.class))
+ .deny(metaDataToValidationStrategyNameMapperClass);
+ }
+
+ public static MetaDataTransformer getMetaDataTransformerForValidationStrategy(ValidationStrategy validationStrategy)
+ {
+ return ((ClassMappingFactory<ValidationStrategy, MetaDataTransformer>) ExtValContext
+ .getContext().getFactoryFinder()
+ .getFactory(FactoryNames.META_DATA_TRANSFORMER_FACTORY, ClassMappingFactory.class))
+ .create(validationStrategy);
+ }
+
+ public static void registerValidationStrategyToMetaDataTransformerNameMapper(
+ NameMapper<ValidationStrategy> validationStrategyToMetaDataTransformerNameMapper)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.META_DATA_TRANSFORMER_FACTORY, NameMapperAwareFactory.class))
+ .register(validationStrategyToMetaDataTransformerNameMapper);
+ }
+
+ public static void deregisterValidationStrategyToMetaDataTransformerNameMapper(
+ Class<? extends NameMapper> validationStrategyToMetaDataTransformerNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.META_DATA_TRANSFORMER_FACTORY, NameMapperAwareFactory.class))
+ .deregister(validationStrategyToMetaDataTransformerNameMapperClass);
+ }
+
+ public static void denyValidationStrategyToMetaDataTransformerNameMapper(
+ Class<? extends NameMapper> validationStrategyToMetaDataTransformerNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.META_DATA_TRANSFORMER_FACTORY, NameMapperAwareFactory.class))
+ .deny(validationStrategyToMetaDataTransformerNameMapperClass);
+ }
+
+ public static MetaDataExtractor getComponentMetaDataExtractor()
+ {
+ return ExtValContext.getContext().getFactoryFinder()
+ .getFactory(FactoryNames.COMPONENT_META_DATA_EXTRACTOR_FACTORY, ComponentMetaDataExtractorFactory.class)
+ .create();
+ }
+
+ public static MetaDataExtractor getComponentMetaDataExtractorFor(Class moduleKey)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ if(moduleKey != null)
+ {
+ properties.put(ValidationModuleKey.class.getName(), moduleKey);
+ }
+ return getComponentMetaDataExtractorWith(properties);
+ }
+
+ public static MetaDataExtractor getComponentMetaDataExtractorWith(Map<String, Object> properties)
+ {
+ return ExtValContext.getContext().getFactoryFinder()
+ .getFactory(FactoryNames.COMPONENT_META_DATA_EXTRACTOR_FACTORY, ComponentMetaDataExtractorFactory.class)
+ .createWith(properties);
+ }
+
+ public static void configureComponentWithMetaData(FacesContext facesContext,
+ UIComponent uiComponent,
+ Map<String, Object> metaData)
+ {
+ for (ComponentInitializer componentInitializer : ExtValContext.getContext().getComponentInitializers())
+ {
+ componentInitializer.configureComponent(facesContext, uiComponent, metaData);
+ }
+ }
+
+ public static boolean executeAfterThrowingInterceptors(UIComponent uiComponent,
+ MetaDataEntry metaDataEntry,
+ Object convertedObject,
+ ValidatorException validatorException,
+ ValidationStrategy validatorExceptionSource)
+ {
+ boolean result = true;
+
+ if (metaDataEntry == null)
+ {
+ metaDataEntry = new MetaDataEntry();
+ }
+
+ for (ValidationExceptionInterceptor validationExceptionInterceptor : ExtValContext.getContext()
+ .getValidationExceptionInterceptors())
+ {
+ if (!validationExceptionInterceptor.afterThrowing(
+ uiComponent, metaDataEntry, convertedObject, validatorException, validatorExceptionSource))
+ {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+ public static MetaDataExtractor createInterceptedMetaDataExtractor(final MetaDataExtractor metaDataExtractor)
+ {
+ return createInterceptedMetaDataExtractorWith(metaDataExtractor, null);
+ }
+
+ public static MetaDataExtractor createInterceptedMetaDataExtractorFor(
+ final MetaDataExtractor metaDataExtractor, Class moduleKey)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ if(moduleKey != null)
+ {
+ properties.put(ValidationModuleKey.class.getName(), moduleKey);
+ }
+ return createInterceptedMetaDataExtractorWith(metaDataExtractor, properties);
+ }
+
+ public static MetaDataExtractor createInterceptedMetaDataExtractorWith(
+ final MetaDataExtractor metaDataExtractor, final Map<String, Object> properties)
+ {
+ return new MetaDataExtractor()
+ {
+ public PropertyInformation extract(FacesContext facesContext, Object object)
+ {
+ PropertyInformation result = metaDataExtractor.extract(facesContext, object);
+
+ addProperties(result, properties);
+ invokeMetaDataExtractionInterceptors(result, properties);
+
+ return result;
+ }
+ };
+ }
+
+ private static void addProperties(PropertyInformation result, Map<String, Object> properties)
+ {
+ if(properties != null)
+ {
+ Map<String, Object> customProperties = getCustomProperties(result);
+ customProperties.putAll(properties);
+ }
+ }
+
+ private static Map<String, Object> getCustomProperties(PropertyInformation propertyInformation)
+ {
+ if(!propertyInformation.containsInformation(PropertyInformationKeys.CUSTOM_PROPERTIES))
+ {
+ propertyInformation.setInformation(
+ PropertyInformationKeys.CUSTOM_PROPERTIES, new HashMap<String, Object>());
+ }
+
+ return (Map<String, Object>) propertyInformation.getInformation(PropertyInformationKeys.CUSTOM_PROPERTIES);
+ }
+
+ private static void invokeMetaDataExtractionInterceptors(PropertyInformation result, Map<String, Object> properties)
+ {
+ for (MetaDataExtractionInterceptor metaDataExtractionInterceptor :
+ ExtValContext.getContext().getMetaDataExtractionInterceptorsWith(properties))
+ {
+ metaDataExtractionInterceptor.afterExtracting(result);
+ }
+ }
+
+ public static MessageResolver getMessageResolverForValidationStrategy(ValidationStrategy validationStrategy)
+ {
+ return ((ClassMappingFactory<ValidationStrategy, MessageResolver>) ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.MESSAGE_RESOLVER_FACTORY, ClassMappingFactory.class))
+ .create(validationStrategy);
+ }
+
+ public static void registerValidationStrategyToMessageResolverNameMapper(
+ NameMapper<ValidationStrategy> validationStrategyToMsgResolverNameMapper)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.MESSAGE_RESOLVER_FACTORY, NameMapperAwareFactory.class))
+ .register(validationStrategyToMsgResolverNameMapper);
+ }
+
+ public static void deregisterValidationStrategyToMessageResolverNameMapper(
+ Class<? extends NameMapper> validationStrategyToMessageResolverNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.MESSAGE_RESOLVER_FACTORY, NameMapperAwareFactory.class))
+ .deregister(validationStrategyToMessageResolverNameMapperClass);
+ }
+
+ public static void denyValidationStrategyToMessageResolverNameMapper(
+ Class<? extends NameMapper> validationStrategyToMessageResolverNameMapperClass)
+ {
+ (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.MESSAGE_RESOLVER_FACTORY, NameMapperAwareFactory.class))
+ .deny(validationStrategyToMessageResolverNameMapperClass);
+ }
+
+ public static ELHelper getELHelper()
+ {
+ return ExtValContext.getContext().getFactoryFinder()
+ .getFactory(FactoryNames.EL_HELPER_FACTORY, AbstractELHelperFactory.class).create();
+ }
+
+ public static FacesMessage createFacesMessage(String summary, String detail)
+ {
+ return createFacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);
+ }
+
+ public static FacesMessage createFacesMessage(FacesMessage.Severity severity, String summary, String detail)
+ {
+ return ExtValContext.getContext().getFactoryFinder()
+ .getFactory(FactoryNames.FACES_MESSAGE_FACTORY, FacesMessageFactory.class)
+ .create(severity, summary, detail);
+ }
+
+ public static FacesMessage convertFacesMessage(FacesMessage facesMessage)
+ {
+ return ExtValContext.getContext().getFactoryFinder()
+ .getFactory(FactoryNames.FACES_MESSAGE_FACTORY, FacesMessageFactory.class)
+ .convert(facesMessage);
+ }
+
+ public static PropertyDetails createPropertyDetailsForNewTarget(MetaDataEntry metaDataEntry,
+ String targetExpression)
+ {
+ Object baseObject;
+ if (getELHelper().isELTermWellFormed(targetExpression))
+ {
+ ValueBindingExpression vbe = new ValueBindingExpression(targetExpression);
+
+ String expression = vbe.getExpressionString();
+ baseObject = getELHelper().getValueOfExpression(FacesContext.getCurrentInstance(), vbe.getBaseExpression());
+ return new PropertyDetails(
+ expression.substring(2, expression.length() - 1), baseObject, vbe.getProperty());
+ }
+
+ PropertyDetails original = metaDataEntry.getProperty(
+ PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+
+ String newBaseKey = original.getKey().substring(0, original.getKey().lastIndexOf(".") + 1);
+ String newKey = newBaseKey + targetExpression;
+
+ baseObject = ReflectionUtils.getBaseOfPropertyChain(original.getBaseObject(), targetExpression);
+ return new PropertyDetails(
+ newKey, baseObject, targetExpression.substring(targetExpression.lastIndexOf(".") + 1,
+ targetExpression.length()));
+ }
+
+ @UsageInformation(UsageCategory.INTERNAL)
+ public static void tryToPlaceLabel(FacesMessage facesMessage, String label, int index)
+ {
+ if (facesMessage.getSummary() != null && facesMessage.getSummary().contains("{" + index + "}"))
+ {
+ facesMessage.setSummary(facesMessage.getSummary().replace("{" + index + "}", label));
+ }
+
+ if (facesMessage.getDetail() != null && facesMessage.getDetail().contains("{" + index + "}"))
+ {
+ facesMessage.setDetail(facesMessage.getDetail().replace("{" + index + "}", label));
+ }
+ }
+
+ @UsageInformation(UsageCategory.INTERNAL)
+ public static void replaceWithDefaultMaximumMessage(FacesMessage facesMessage, int maxLength)
+ {
+ String facesRequiredMessage = JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_MAXIMUM);
+ String facesRequiredMessageDetail = facesRequiredMessage;
+
+ //use try/catch for easier sync between trunk/branch
+ try
+ {
+ if (JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_MAXIMUM_DETAIL) != null)
+ {
+ facesRequiredMessageDetail = JsfUtils
+ .getDefaultFacesMessageBundle().getString(JAVAX_FACES_MAXIMUM_DETAIL);
+ }
+ }
+ catch (MissingResourceException missingResourceException)
+ {
+ //jsf 1.2 doesn't have a detail message
+ }
+
+ facesRequiredMessage = facesRequiredMessage.replace("{0}", "" + maxLength);
+ facesRequiredMessageDetail = facesRequiredMessageDetail.replace("{0}", "" + maxLength);
+
+ facesMessage.setSummary(facesRequiredMessage);
+ facesMessage.setDetail(facesRequiredMessageDetail);
+ }
+
+ @UsageInformation(UsageCategory.INTERNAL)
+ public static void replaceWithDefaultRequiredMessage(FacesMessage facesMessage)
+ {
+ String facesRequiredMessage = JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_REQUIRED);
+ String facesRequiredMessageDetail = facesRequiredMessage;
+
+ //use try/catch for easier sync between trunk/branch
+ try
+ {
+ if (JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_REQUIRED_DETAIL) != null)
+ {
+ facesRequiredMessageDetail = JsfUtils
+ .getDefaultFacesMessageBundle().getString(JAVAX_FACES_REQUIRED_DETAIL);
+ }
+ }
+ catch (MissingResourceException missingResourceException)
+ {
+ //jsf 1.2 doesn't have a detail message
+ }
+
+ facesMessage.setSummary(facesRequiredMessage);
+ facesMessage.setDetail(facesRequiredMessageDetail);
+ }
+
+ public static boolean isSkipableValidationStrategy(Class<? extends ValidationStrategy> targetClass)
+ {
+ for (Class currentClass : getSkipValidationSupportClassList())
+ {
+ if (isSkipValidationSupported(currentClass, targetClass))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean processMetaDataEntryAfterSkipValidation(
+ Class<? extends ValidationStrategy> targetClass, MetaDataEntry entry)
+ {
+ return isSkipableValidationStrategy(targetClass) &&
+ Boolean.TRUE.equals(entry.getProperty(PropertyInformationKeys.SKIP_VALIDATION, Boolean.class));
+ }
+
+ public static List<Class> getSkipValidationSupportClassList()
+ {
+ List<StaticConfiguration<String, String>> staticConfigurationList = ExtValContext.getContext()
+ .getStaticConfiguration(StaticConfigurationNames.SKIP_VALIDATION_SUPPORT_CONFIG);
+
+ List<Class> markerList = new ArrayList<Class>();
+
+ Class currentClass;
+ for (StaticConfiguration<String, String> currentEntry : staticConfigurationList)
+ {
+ for (StaticConfigurationEntry<String, String> currentConfigurationEntry : currentEntry.getMapping())
+ {
+ currentClass = ClassUtils.tryToLoadClassForName(currentConfigurationEntry.getTarget());
+
+ if (currentClass != null)
+ {
+ markerList.add(currentClass);
+ }
+ else
+ {
+ if (LOGGER.isWarnEnabled())
+ {
+ LOGGER.warn("configuration entry provides an invalid entry: "
+ + currentConfigurationEntry.getTarget());
+ }
+ }
+ }
+ }
+
+ return markerList;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static boolean isSkipValidationSupported(Class currentClass, Class targetClass)
+ {
+ if (currentClass.isAnnotation())
+ {
+ if (targetClass.isAnnotationPresent(currentClass))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (currentClass.isAssignableFrom(targetClass))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static ValidationParameterExtractor getValidationParameterExtractor()
+ {
+ return ExtValContext.getContext().getFactoryFinder().getFactory(
+ FactoryNames.VALIDATION_PARAMETER_EXTRACTOR_FACTORY, ValidationParameterExtractorFactory.class)
+ .create();
+ }
+
+ public static boolean executeLocalBeforeValidationInterceptors(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ String propertyKey,
+ Object properties,
+ Annotation annotation)
+ {
+ Map<String, Object> propertyMap = new HashMap<String, Object>();
+ List<PropertyValidationInterceptor> propertyValidationInterceptors = getValidationParameterExtractor().extract(
+ annotation, PropertyValidationInterceptor.class, PropertyValidationInterceptor.class);
+ boolean result = true;
+
+ if (properties != null)
+ {
+ propertyMap.put(propertyKey, properties);
+ }
+ propertyMap.put(Annotation.class.getName(), annotation);
+
+ for (PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+ {
+ if (!propertyValidationInterceptor
+ .beforeValidation(facesContext, uiComponent, convertedObject, propertyMap))
+ {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+ public static void executeLocalAfterValidationInterceptors(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ String propertyKey,
+ Object properties,
+ Annotation annotation)
+ {
+ Map<String, Object> propertyMap = new HashMap<String, Object>();
+ List<PropertyValidationInterceptor> propertyValidationInterceptors = getValidationParameterExtractor().extract(
+ annotation, PropertyValidationInterceptor.class, PropertyValidationInterceptor.class);
+
+ if (properties != null)
+ {
+ propertyMap.put(propertyKey, properties);
+ propertyMap.put(Annotation.class.getName(), annotation);
+ }
+
+ for (PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+ {
+ propertyValidationInterceptor.afterValidation(facesContext, uiComponent, convertedObject, propertyMap);
+ }
+ }
+
+ @ToDo(value = Priority.MEDIUM, description = "is renaming ok?")
+ public static boolean executeGlobalBeforeValidationInterceptors(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ String propertyKey,
+ Object properties,
+ Class moduleKey)
+ {
+ Map<String, Object> propertyMap = new HashMap<String, Object>();
+ boolean result = true;
+
+ if (properties != null)
+ {
+ propertyMap.put(propertyKey, properties);
+ }
+
+ List<PropertyValidationInterceptor> propertyValidationInterceptors =
+ ExtValContext.getContext().getPropertyValidationInterceptorsFor(moduleKey);
+
+ for (PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+ {
+ if (!propertyValidationInterceptor
+ .beforeValidation(facesContext, uiComponent, convertedObject, propertyMap))
+ {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+ @ToDo(value = Priority.MEDIUM, description = "is renaming ok?")
+ public static void executeGlobalAfterValidationInterceptors(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ String propertyKey,
+ Object properties,
+ Class moduleKey)
+ {
+ Map<String, Object> propertyMap = new HashMap<String, Object>();
+
+ if (properties != null)
+ {
+ propertyMap.put(propertyKey, properties);
+ }
+
+ List<PropertyValidationInterceptor> propertyValidationInterceptors =
+ ExtValContext.getContext().getPropertyValidationInterceptorsFor(moduleKey);
+
+ for (PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+ {
+ propertyValidationInterceptor.afterValidation(facesContext, uiComponent, convertedObject, propertyMap);
+ }
+ }
+
+ public static <T> T getStorage(Class<T> storageType, String storageName)
+ {
+ return (T) getStorageManagerFactory().create(storageType).create(storageName);
+ }
+
+ public static void resetStorage(Class storageType, String storageName)
+ {
+ getStorageManagerFactory().create(storageType).reset(storageName);
+ }
+
+ private static ClassMappingFactory<Class, StorageManager> getStorageManagerFactory()
+ {
+ return (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.STORAGE_MANAGER_FACTORY, ClassMappingFactory.class));
+ }
+
+ public static Map<String, Object> getTransformedMetaData(FacesContext facesContext, UIComponent uiComponent)
+ {
+ return getTransformedMetaDataFor(facesContext, uiComponent, null);
+ }
+
+ public static Map<String, Object> getTransformedMetaDataFor(
+ FacesContext facesContext, UIComponent uiComponent, Class moduleKey)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ if(moduleKey != null)
+ {
+ properties.put(ValidationModuleKey.class.getName(), moduleKey);
+ }
+
+ return getTransformedMetaDataWith(facesContext, uiComponent, properties);
+ }
+
+ public static Map<String, Object> getTransformedMetaDataWith(
+ FacesContext facesContext, UIComponent uiComponent, Map<String, Object> properties)
+ {
+ ValidationStrategy validationStrategy;
+
+ SkipValidationEvaluator skipValidationEvaluator = ExtValContext.getContext().getSkipValidationEvaluator();
+ MetaDataExtractor metaDataExtractor = getComponentMetaDataExtractorWith(properties);
+
+ Map<String, Object> metaData;
+ Map<String, Object> metaDataResult = new HashMap<String, Object>();
+
+ for (MetaDataEntry entry : metaDataExtractor.extract(facesContext, uiComponent).getMetaDataEntries())
+ {
+ metaData = new HashMap<String, Object>();
+ validationStrategy = getValidationStrategyForMetaData(entry.getKey());
+
+ if (validationStrategy != null)
+ {
+ metaData = transformMetaData(
+ facesContext, uiComponent, validationStrategy, skipValidationEvaluator, metaData, entry);
+
+ if (!isComponentInitializationSkipped(metaData, entry, validationStrategy))
+ {
+ //don't break maybe there are constraints which don't support the skip-mechanism
+ metaDataResult.putAll(metaData);
+ }
+ }
+ }
+
+ return metaDataResult;
+ }
+
+ private static Map<String, Object> transformMetaData(FacesContext facesContext,
+ UIComponent uiComponent,
+ ValidationStrategy validationStrategy,
+ SkipValidationEvaluator skipValidationEvaluator,
+ Map<String, Object> metaData, MetaDataEntry entry)
+ {
+ if (!skipValidationEvaluator.skipValidation(facesContext, uiComponent, validationStrategy, entry))
+ {
+ MetaDataTransformer metaDataTransformer = getMetaDataTransformerForValidationStrategy(validationStrategy);
+
+ if (metaDataTransformer != null)
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug(metaDataTransformer.getClass().getName() + " instantiated");
+ }
+
+ metaData = metaDataTransformer.convertMetaData(entry);
+ }
+ else
+ {
+ metaData = null;
+ }
+
+ if (metaData == null)
+ {
+ return new HashMap<String, Object>();
+ }
+ }
+ return metaData;
+ }
+
+ private static boolean isComponentInitializationSkipped(Map<String, Object> metaData, MetaDataEntry entry,
+ ValidationStrategy validationStrategy)
+ {
+ return metaData.isEmpty() ||
+ (Boolean.TRUE.equals(entry.getProperty(PropertyInformationKeys.SKIP_VALIDATION, Boolean.class)) &&
+ isSkipableValidationStrategy(validationStrategy.getClass()));
+ }
+
+ public static boolean interpretEmptyStringValuesAsNull()
+ {
+ //to deactivate: the parameter has to be explicitly false
+ return !"false".equalsIgnoreCase(WebXmlParameter.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL);
+ }
+
+ public static boolean validateEmptyFields()
+ {
+ return !"false".equalsIgnoreCase(WebXmlParameter.VALIDATE_EMPTY_FIELDS);
+ }
+
+ public static PropertyDetails getPropertyDetails(PropertyInformation propertyInformation)
+ {
+ return propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+ }
+
+ public static void tryToThrowValidatorExceptionForComponentId(
+ String clientId, FacesMessage facesMessage, Throwable throwable)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ tryToThrowValidatorExceptionForComponent(targetComponent, facesMessage, throwable);
+ }
+
+ public static void tryToThrowValidatorExceptionForComponent(
+ UIComponent uiComponent, FacesMessage facesMessage, Throwable throwable)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (interpreter.severityCausesValidatorException(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ if (throwable == null)
+ {
+ throw new ValidatorException(facesMessage);
+ }
+ else
+ {
+ throw new ValidatorException(facesMessage, throwable);
+ }
+ }
+ else
+ {
+ tryToAddViolationMessageForComponent(uiComponent, facesMessage);
+ }
+ }
+
+ public static void tryToAddViolationMessageForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ if (targetComponent == null && clientId != null)
+ {
+ tryToAddViolationMessageForTestClientId(clientId, facesMessage);
+ return;
+ }
+ tryToAddViolationMessageForComponent(targetComponent, facesMessage);
+ }
+
+ @ToDo(value = Priority.MEDIUM, description = "required for test frameworks - goal: remove it")
+ private static void tryToAddViolationMessageForTestClientId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (interpreter.severityCausesViolationMessage(facesContext, null, facesMessage.getSeverity()))
+ {
+ addFacesMessage(clientId, facesMessage);
+ }
+ tryToBlocksNavigationForComponent(null, facesMessage);
+ }
+
+ public static void tryToAddViolationMessageForComponent(UIComponent uiComponent, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (interpreter.severityCausesViolationMessage(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ if (uiComponent != null)
+ {
+ addFacesMessage(uiComponent.getClientId(facesContext), facesMessage);
+ }
+ else
+ {
+ addFacesMessage(null, facesMessage);
+ }
+ }
+ tryToBlocksNavigationForComponent(uiComponent, facesMessage);
+ }
+
+ public static void addFacesMessage(FacesMessage facesMessage)
+ {
+ addFacesMessage(null, facesMessage);
+ }
+
+ public static void addFacesMessage(String clientId, FacesMessage facesMessage)
+ {
+ FacesMessageStorage storage = getStorage(FacesMessageStorage.class, FacesMessageStorage.class.getName());
+
+ if (storage != null)
+ {
+ storage.addFacesMessage(clientId, facesMessage);
+ }
+ else
+ {
+ FacesContext.getCurrentInstance().addMessage(clientId, facesMessage);
+ }
+ }
+
+ public static void tryToBlocksNavigationForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ tryToBlocksNavigationForComponent(targetComponent, facesMessage);
+ }
+
+ public static void tryToBlocksNavigationForComponent(UIComponent uiComponent, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (interpreter.severityBlocksNavigation(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
+
+ public static boolean severityBlocksSubmitForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIComponent targetComponent = findComponent(clientId);
+
+ return interpreter.severityBlocksSubmit(facesContext, targetComponent, facesMessage.getSeverity());
+ }
+
+ //available for add-ons not used internally due to performance reasons
+ public static boolean severityShowsIndicationForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIComponent targetComponent = findComponent(clientId);
+
+ return interpreter.severityShowsIndication(facesContext, targetComponent, facesMessage.getSeverity());
+ }
+
+ private static UIComponent findComponent(String clientId)
+ {
+ UIComponent targetComponent = null;
+
+ if (clientId != null)
+ {
+ targetComponent = FacesContext.getCurrentInstance().getViewRoot().findComponent(clientId);
+ }
+ return targetComponent;
+ }
+
+ public static boolean isApplicationInitialized()
+ {
+ try
+ {
+ //simple test for early config in case of mojarra
+ ExtValUtils.getELHelper().getBean(InformationProviderBean.CUSTOM_BEAN.replace(".", "_"));
+ }
+ catch (Throwable e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.util;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class GroupUtils
+{
+ public static String getGroupKey(String viewId, String clientId)
+ {
+ return clientId == null ? viewId : viewId + "@" + clientId;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.util;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.storage.FacesInformationStorage;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.event.PhaseId;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class JsfUtils
+{
+ public static void deregisterPhaseListener(PhaseListener phaseListener)
+ {
+ LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+
+ String currentId;
+ Lifecycle currentLifecycle;
+ Iterator lifecycleIds = lifecycleFactory.getLifecycleIds();
+ while (lifecycleIds.hasNext())
+ {
+ currentId = (String) lifecycleIds.next();
+ currentLifecycle = lifecycleFactory.getLifecycle(currentId);
+ currentLifecycle.removePhaseListener(phaseListener);
+ }
+ }
+
+ public static void registerPhaseListener(PhaseListener phaseListener)
+ {
+ LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+
+ String currentId;
+ Lifecycle currentLifecycle;
+ Iterator lifecycleIds = lifecycleFactory.getLifecycleIds();
+ while (lifecycleIds.hasNext())
+ {
+ currentId = (String) lifecycleIds.next();
+ currentLifecycle = lifecycleFactory.getLifecycle(currentId);
+ currentLifecycle.addPhaseListener(phaseListener);
+ }
+ }
+
+ public static ResourceBundle getDefaultFacesMessageBundle()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ String bundleName = facesContext.getApplication().getMessageBundle();
+
+ if(bundleName == null)
+ {
+ bundleName = FacesMessage.FACES_MESSAGES;
+ }
+
+ return ResourceBundle.getBundle(bundleName, facesContext.getViewRoot().getLocale());
+ }
+
+ public static boolean isRenderResponsePhase()
+ {
+ return PhaseId.RENDER_RESPONSE.equals(getFacesInformationStorage().getCurrentPhaseId());
+ }
+
+ public static PhaseId getCurrentPhaseId()
+ {
+ return getFacesInformationStorage().getCurrentPhaseId();
+ }
+
+ private static FacesInformationStorage getFacesInformationStorage()
+ {
+ return ExtValUtils.getStorage(FacesInformationStorage.class, FacesInformationStorage.class.getName());
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ReflectionUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ReflectionUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/ReflectionUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.util;
+
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.StringTokenizer;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class ReflectionUtils
+{
+ public static Method tryToGetMethod(Class targetClass, String targetMethodName)
+ {
+ return tryToGetMethod(targetClass, targetMethodName, null);
+ }
+
+ public static Method tryToGetMethod(Class targetClass, String targetMethodName, Class... parameterTypes)
+ {
+ try
+ {
+ return getMethod(targetClass, targetMethodName, parameterTypes);
+ }
+ catch (Throwable t)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Method getMethod(Class targetClass, String targetMethodName)
+ throws NoSuchMethodException
+ {
+ return getMethod(targetClass, targetMethodName, null);
+ }
+
+ public static Method getMethod(Class targetClass, String targetMethodName, Class... parameterTypes)
+ throws NoSuchMethodException
+ {
+ Class currentClass = targetClass;
+ Method targetMethod = null;
+
+ while (!Object.class.getName().equals(currentClass.getName()))
+ {
+ try
+ {
+ targetMethod = currentClass.getDeclaredMethod(targetMethodName, parameterTypes);
+ break;
+ }
+ catch (NoSuchMethodException e)
+ {
+ currentClass = currentClass.getSuperclass();
+ }
+ }
+
+ if(targetMethod == null)
+ {
+ for (Class currentInterface : targetClass.getInterfaces())
+ {
+ currentClass = currentInterface;
+
+ while (currentClass != null)
+ {
+ try
+ {
+ targetMethod = currentClass.getDeclaredMethod(targetMethodName, parameterTypes);
+ break;
+ }
+ catch (NoSuchMethodException e)
+ {
+ currentClass = currentClass.getSuperclass();
+ }
+ }
+ }
+ }
+
+ if(targetMethod != null)
+ {
+ return targetMethod;
+ }
+
+ throw new NoSuchMethodException("there is no method with the name '" + targetMethodName + "'" +
+ " class: " + targetClass.getName());
+ }
+
+ public static Object tryToInvokeMethod(Object target, Method method)
+ {
+ return tryToInvokeMethod(target, method, null);
+ }
+
+ public static Object tryToInvokeMethodOfClass(Class target, Method method)
+ {
+ return tryToInvokeMethodOfClass(target, method, null);
+ }
+
+ public static Object tryToInvokeMethodOfClass(Class target, Method method, Object[] args)
+ {
+ try
+ {
+ return invokeMethodOfClass(target, method, args);
+ }
+ catch (Throwable e)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Object invokeMethodOfClass(Class target, Method method)
+ throws IllegalAccessException, InstantiationException, InvocationTargetException
+ {
+ return invokeMethod(target.newInstance(), method, null);
+ }
+
+ public static Object invokeMethodOfClass(Class target, Method method, Object... args)
+ throws IllegalAccessException, InstantiationException, InvocationTargetException
+ {
+ return invokeMethod(target.newInstance(), method, args);
+ }
+
+ public static Object tryToInvokeMethod(Object target, Method method, Object... args)
+ {
+ try
+ {
+ return invokeMethod(target, method, args);
+ }
+ catch (Throwable t)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Object invokeMethod(Object target, Method method)
+ throws InvocationTargetException, IllegalAccessException
+ {
+ return invokeMethod(target, method, null);
+ }
+
+ public static Object invokeMethod(Object target, Method method, Object... args)
+ throws InvocationTargetException, IllegalAccessException
+ {
+ method.setAccessible(true);
+ return method.invoke(target, args);
+ }
+
+ public static Object getBaseOfPropertyChain(Object baseObject, String propertyChain)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(propertyChain, ".");
+
+ Object currentBase = baseObject;
+ String currentProperty;
+ Method currentMethod;
+
+ while(tokenizer.hasMoreTokens())
+ {
+ currentProperty = tokenizer.nextToken();
+
+ //ignore the last property
+ if(!tokenizer.hasMoreTokens())
+ {
+ break;
+ }
+
+ //no is - it's only possible at properties not at bean level
+ currentMethod = tryToGetMethod(currentBase.getClass(),
+ "get" + currentProperty.substring(0, 1).toUpperCase() +
+ currentProperty.substring(1, currentProperty.length()));
+ currentBase = tryToInvokeMethod(currentBase, currentMethod);
+ }
+
+ return currentBase;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.util;
+
+import org.apache.myfaces.extensions.validator.ExtValInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class WebXmlUtils
+{
+ public static String getInitParameter(String key)
+ {
+ return getInitParameter(ExtValInformation.WEBXML_PARAM_PREFIX, key);
+ }
+
+ public static String getInitParameter(String prefix, String name)
+ {
+ String value = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(prefix + "." + name);
+ return (value != null) ? value.replace(" ", "").trim() : null;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/LICENSE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/LICENSE.txt?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/LICENSE.txt (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/LICENSE.txt Fri Nov 13 02:48:45 2009
@@ -0,0 +1,174 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/NOTICE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/NOTICE.txt?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/NOTICE.txt (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/main/resources/NOTICE.txt Fri Nov 13 02:48:45 2009
@@ -0,0 +1,9 @@
+Apache MyFaces Extensions Validator
+Copyright 2007-2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+------------------------------------------------------------------------
+See the file LICENSE.txt
+------------------------------------------------------------------------
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/site/apt/index.apt?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/site/apt/index.apt (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/core/src/site/apt/index.apt Fri Nov 13 02:48:45 2009
@@ -0,0 +1,10 @@
+ ------
+Apache MyFaces Extensions Validator Core Module
+ ------
+
+Apache MyFaces Extensions Validator Core Module Overview
+
+ MyFaces Extensions Validator Core Module provides an extensible validation platform to implement validation based on meta-data.
+ Based on this module it is possible to implement validation modules.
+
+ MyFaces Extensions Validator is compatible with JSF 1.1.x and JSF 1.2.x. Both versions require Java 1.5+
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/pom.xml?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/pom.xml (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/pom.xml Fri Nov 13 02:48:45 2009
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <name>Apache MyFaces Extensions Validator Examples Assembly</name>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>myfaces-extval-examples-assembly12</artifactId>
+
+ <parent>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>examples-project</artifactId>
+ <version>2.0.3-SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>dependency-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-war</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>examples-hello_world</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>examples-feature-set_01</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>${project.build.directory}/war</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-src</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>examples-hello_world</artifactId>
+ <version>${project.version}</version>
+ <type>java-source</type>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.myfaces.extensions.validator.examples</groupId>
+ <artifactId>examples-feature-set_01</artifactId>
+ <version>${project.version}</version>
+ <type>java-source</type>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>${project.build.directory}/src</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <!-- EXECUTE mvn package to generate assembly files -->
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.1</version>
+ <executions>
+ <execution>
+ <id>make_assembly_src</id>
+ <phase>package</phase>
+ <goals>
+ <goal>assembly</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/depsrc.xml</descriptor>
+ </descriptors>
+ <finalName>myfaces-extval-examples-${project.version}-src</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ <outputDirectory>${project.build.directory}/out</outputDirectory>
+ <workDirectory>${project.build.directory}/work</workDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>make_assembly_bin</id>
+ <phase>package</phase>
+ <goals>
+ <goal>assembly</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/dep.xml</descriptor>
+ </descriptors>
+ <finalName>myfaces-extval-examples-${project.version}</finalName>
+ <outputDirectory>${project.build.directory}/out</outputDirectory>
+ <workDirectory>${project.build.directory}/work</workDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.myfaces.maven</groupId>
+ <artifactId>wagon-maven-plugin</artifactId>
+ <version>1.0.1</version>
+ <configuration>
+ <id>myfaces-nightly-builds</id>
+ <url>scpexe://minotaur.apache.org/www/people.apache.org/builds/myfaces/nightly</url>
+ <inputDirectory>${project.build.directory}/out</inputDirectory>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+</project>
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/dep.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/dep.xml?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/dep.xml (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/dep.xml Fri Nov 13 02:48:45 2009
@@ -0,0 +1,17 @@
+<assembly>
+ <id>bin</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <fileSets>
+ <fileSet>
+ <directory>target/war</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.war</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/depsrc.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/depsrc.xml?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/depsrc.xml (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/examples/assembly/src/main/assembly/depsrc.xml Fri Nov 13 02:48:45 2009
@@ -0,0 +1,24 @@
+<assembly>
+ <id>src</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <fileSets>
+ <fileSet>
+ <directory>target/src</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.txt</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>