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 [14/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/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,142 @@
+/*
+ * 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.beanval.startup;
+
+import org.apache.myfaces.extensions.validator.beanval.BeanValidationInterceptor;
+import org.apache.myfaces.extensions.validator.beanval.HtmlCoreComponentsComponentInitializer;
+import org.apache.myfaces.extensions.validator.beanval.interceptor.ExtValBeanValidationMetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.beanval.interceptor.BeanValidationExceptionInterceptor;
+import org.apache.myfaces.extensions.validator.beanval.validation.ModelValidationPhaseListener;
+import org.apache.myfaces.extensions.validator.beanval.metadata.transformer.mapper.SizeNameMapper;
+import org.apache.myfaces.extensions.validator.beanval.metadata.transformer.mapper.NotNullNameMapper;
+import org.apache.myfaces.extensions.validator.beanval.storage.DefaultModelValidationStorageManager;
+import org.apache.myfaces.extensions.validator.beanval.storage.ModelValidationStorage;
+import org.apache.myfaces.extensions.validator.beanval.storage.mapper.BeanValidationGroupStorageNameMapper;
+import org.apache.myfaces.extensions.validator.beanval.storage.mapper.ModelValidationStorageNameMapper;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.core.factory.AbstractNameMapperAwareFactory;
+import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
+import org.apache.myfaces.extensions.validator.core.startup.AbstractStartupListener;
+import org.apache.myfaces.extensions.validator.core.storage.GroupStorage;
+import org.apache.myfaces.extensions.validator.core.storage.StorageManager;
+import org.apache.myfaces.extensions.validator.core.storage.StorageManagerHolder;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.JsfUtils;
+
+import javax.validation.ValidatorFactory;
+import javax.validation.Validation;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class BeanValidationStartupListener extends AbstractStartupListener
+{
+ private static final long serialVersionUID = -5025748399876833394L;
+
+ protected void init()
+ {
+ registerValidatorFactory();
+ registerBeanValidationInterceptor();
+ registerMetaDataTransformerNameMapper();
+ registerGroupStorageNameMapper();
+ registerModelValidationStorageNameMapper();
+ registerComponentInitializers();
+ registerMetaDataExtractionInterceptors();
+ registerPhaseListeners();
+ registerExceptionInterceptor();
+ }
+
+ protected void registerValidatorFactory()
+ {
+ ExtValContext.getContext().addGlobalProperty(
+ ValidatorFactory.class.getName(), Validation.buildDefaultValidatorFactory(), false);
+ }
+
+ protected void registerBeanValidationInterceptor()
+ {
+ ExtValContext.getContext().registerRendererInterceptor(new BeanValidationInterceptor());
+ }
+
+ protected void registerMetaDataTransformerNameMapper()
+ {
+ ExtValUtils.registerValidationStrategyToMetaDataTransformerNameMapper(new SizeNameMapper());
+ ExtValUtils.registerValidationStrategyToMetaDataTransformerNameMapper(new NotNullNameMapper());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void registerGroupStorageNameMapper()
+ {
+ StorageManager storageManager = getStorageManagerHolder().getStorageManager(GroupStorage.class);
+
+ if (storageManager instanceof AbstractNameMapperAwareFactory)
+ {
+ ((AbstractNameMapperAwareFactory<String>) storageManager)
+ .register(new BeanValidationGroupStorageNameMapper());
+ }
+ else
+ {
+ if (this.logger.isWarnEnabled())
+ {
+ this.logger.warn(storageManager.getClass().getName() +
+ " has to implement AbstractNameMapperAwareFactory " + getClass().getName() +
+ " couldn't register " + BeanValidationGroupStorageNameMapper.class.getName());
+ }
+ }
+ }
+
+ protected void registerModelValidationStorageNameMapper()
+ {
+ DefaultModelValidationStorageManager modelValidationStorageManager = new DefaultModelValidationStorageManager();
+ modelValidationStorageManager.register(new ModelValidationStorageNameMapper());
+ getStorageManagerHolder().setStorageManager(ModelValidationStorage.class, modelValidationStorageManager, false);
+ }
+
+ protected void registerComponentInitializers()
+ {
+ ExtValContext.getContext().addComponentInitializer(new HtmlCoreComponentsComponentInitializer());
+ }
+
+ protected StorageManagerHolder getStorageManagerHolder()
+ {
+ return (ExtValContext.getContext()
+ .getFactoryFinder()
+ .getFactory(FactoryNames.STORAGE_MANAGER_FACTORY, StorageManagerHolder.class));
+ }
+
+ protected void registerMetaDataExtractionInterceptors()
+ {
+ ExtValContext.getContext()
+ .addMetaDataExtractionInterceptor(new ExtValBeanValidationMetaDataExtractionInterceptor());
+ }
+
+ protected void registerPhaseListeners()
+ {
+ JsfUtils.registerPhaseListener(new ModelValidationPhaseListener());
+ JsfUtils.registerPhaseListener(new ModelValidationPhaseListener());
+ }
+
+ protected void registerExceptionInterceptor()
+ {
+ ExtValContext.getContext().addValidationExceptionInterceptor(new BeanValidationExceptionInterceptor());
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/JSF2AwareBeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/JSF2AwareBeanValidationStartupListener.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/JSF2AwareBeanValidationStartupListener.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/JSF2AwareBeanValidationStartupListener.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.beanval.startup;
+
+import org.apache.myfaces.extensions.validator.core.startup.AbstractStartupListener;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.beanval.interceptor.ResetBeanValidationRendererInterceptor;
+import org.apache.myfaces.extensions.validator.beanval.interceptor.BeanValidationTagAwareValidationInterceptor;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+/**
+ * @author Gerhard Petracek
+ * @since 2.x.3
+ */
+@ToDo(value = Priority.HIGH, description = "add optional web.xml param to deactivate")
+@UsageInformation(UsageCategory.INTERNAL)
+public class JSF2AwareBeanValidationStartupListener extends AbstractStartupListener
+{
+ private static final long serialVersionUID = -5025748399876833393L;
+
+ protected void init()
+ {
+ ExtValContext.getContext().registerRendererInterceptor(new ResetBeanValidationRendererInterceptor());
+ ExtValContext.getContext().addPropertyValidationInterceptor(new BeanValidationTagAwareValidationInterceptor());
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultBeanValidationGroupStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultBeanValidationGroupStorage.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultBeanValidationGroupStorage.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultBeanValidationGroupStorage.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.beanval.storage;
+
+import org.apache.myfaces.extensions.validator.core.storage.DefaultGroupStorage;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+
+/**
+ * default storage implementation for bean-validation groups
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(INTERNAL)
+public class DefaultBeanValidationGroupStorage extends DefaultGroupStorage
+{
+ @Override
+ public Class[] getGroups(String viewId, String clientId)
+ {
+ Class[] result = super.getGroups(viewId, clientId);
+
+ if(result == null)
+ {
+ //the default group will be validated automatically
+ return new Class[] {};
+ }
+
+ return result;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,191 @@
+/*
+ * 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.beanval.storage;
+
+import org.apache.myfaces.extensions.validator.util.GroupUtils;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+
+import javax.faces.context.FacesContext;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+/**
+ * storage implementation for model-validation entries
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(INTERNAL)
+public class DefaultModelValidationStorage implements ModelValidationStorage
+{
+ private Map<String, List<ModelValidationEntry>> modelValidationEntries =
+ new HashMap<String, List<ModelValidationEntry>>();
+
+ private List<String> componentsOfRequest = new ArrayList<String>();
+
+ public void addModelValidationEntry(ModelValidationEntry modelValidationEntry)
+ {
+ String clientId = getCurrentClientId(modelValidationEntry);
+
+ List<ModelValidationEntry> modelValidationEntryList = resolveModelValidationEntryList(
+ modelValidationEntry, clientId);
+
+ addModelValidationEntry(modelValidationEntryList, modelValidationEntry);
+ }
+
+ private String getCurrentClientId(ModelValidationEntry modelValidationEntry)
+ {
+ String clientId = null;
+
+ if(modelValidationEntry.getComponent() != null)
+ {
+ clientId = modelValidationEntry.getComponent().getClientId(FacesContext.getCurrentInstance());
+
+ if(!this.componentsOfRequest.contains(clientId))
+ {
+ this.componentsOfRequest.add(clientId);
+ }
+ }
+ return clientId;
+ }
+
+ private List<ModelValidationEntry> resolveModelValidationEntryList(
+ ModelValidationEntry modelValidationEntry, String clientId)
+ {
+ List<ModelValidationEntry> modelValidationEntryList =
+ this.modelValidationEntries.get(GroupUtils.getGroupKey(
+ modelValidationEntry.getViewId(), clientId));
+
+ if(modelValidationEntryList == null)
+ {
+ modelValidationEntryList = new ArrayList<ModelValidationEntry>();
+ this.modelValidationEntries.put(GroupUtils.getGroupKey(
+ modelValidationEntry.getViewId(), clientId), modelValidationEntryList);
+ }
+ return modelValidationEntryList;
+ }
+
+ private void addModelValidationEntry(
+ List<ModelValidationEntry> modelValidationEntryList, ModelValidationEntry modelValidationEntry)
+ {
+ if(!modelValidationEntryList.contains(modelValidationEntry))
+ {
+ modelValidationEntryList.add(modelValidationEntry);
+ }
+ }
+
+ public List<ModelValidationEntry> getModelValidationEntriesToValidate()
+ {
+ String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
+ List<ModelValidationEntry> result = new ArrayList<ModelValidationEntry>();
+
+ addEntriesForComponents(viewId, result);
+
+ addEntriesForPage(viewId, result);
+
+ return result;
+ }
+
+ private void addEntriesForComponents(String viewId, List<ModelValidationEntry> result)
+ {
+ for(String currentClientId : this.componentsOfRequest)
+ {
+ result.addAll(getModelValidationEntries(viewId, currentClientId));
+ }
+ }
+
+ private void addEntriesForPage(String viewId, List<ModelValidationEntry> result)
+ {
+ result.addAll(getModelValidationEntries(viewId));
+ }
+
+ private List<ModelValidationEntry> buildModelValidationEntryList(
+ String key, Map<String, List<ModelValidationEntry>> groupStorage)
+ {
+ List<ModelValidationEntry> list;
+
+ if(key != null && key.endsWith("*"))
+ {
+ list = new ArrayList<ModelValidationEntry>();
+ for(Map.Entry<String,List<ModelValidationEntry>> entry : groupStorage.entrySet())
+ {
+ if(entry.getKey().substring(0, entry.getKey().indexOf("@"))
+ .equals(key.substring(0, key.indexOf("@"))))
+ {
+ list.addAll(entry.getValue());
+ }
+ }
+ return list;
+ }
+
+ list = groupStorage.get(key);
+ return (list != null) ? list : new ArrayList<ModelValidationEntry>();
+ }
+
+ private List<ModelValidationEntry> getModelValidationEntries(String viewId)
+ {
+ return getModelValidationEntries(viewId, null);
+ }
+
+ private List<ModelValidationEntry> getModelValidationEntries(String viewId, String clientId)
+ {
+ if(this.modelValidationEntries.size() < 1)
+ {
+ return new ArrayList<ModelValidationEntry>();
+ }
+
+ //add found groups
+ String key;
+ List<ModelValidationEntry> resultListForPage = null;
+
+ if(!"*".equals(clientId))
+ {
+ key = GroupUtils.getGroupKey(viewId, null);
+ resultListForPage =
+ buildModelValidationEntryList(key, this.modelValidationEntries);
+ }
+
+ key = GroupUtils.getGroupKey(viewId, clientId);
+ List<ModelValidationEntry> resultListForComponent =
+ buildModelValidationEntryList(key, this.modelValidationEntries);
+
+ if(resultListForPage == null || resultListForPage.isEmpty())
+ {
+ return resultListForComponent;
+ }
+ else if(resultListForComponent.isEmpty())
+ {
+ return resultListForPage;
+ }
+
+ return mergeResults(resultListForPage, resultListForComponent);
+ }
+
+ private List<ModelValidationEntry> mergeResults(
+ List<ModelValidationEntry> resultListForPage, List<ModelValidationEntry> resultListForComponent)
+ {
+ List<ModelValidationEntry> mergedResult = new ArrayList<ModelValidationEntry>();
+ mergedResult.addAll(resultListForPage);
+ mergedResult.addAll(resultListForComponent);
+ return mergedResult;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorageManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorageManager.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorageManager.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorageManager.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,40 @@
+/*
+ * 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.beanval.storage;
+
+import org.apache.myfaces.extensions.validator.core.storage.StorageManager;
+import org.apache.myfaces.extensions.validator.core.storage.AbstractRequestScopeAwareStorageManager;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+
+/**
+ * default storage-manager for model-validation entries
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(INTERNAL)
+public class DefaultModelValidationStorageManager
+ extends AbstractRequestScopeAwareStorageManager<ModelValidationStorage>
+{
+ public String getStorageManagerKey()
+ {
+ return StorageManager.class.getName() + "_FOR_MODEL_VALIDATION:KEY";
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,197 @@
+/*
+ * 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.beanval.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(INTERNAL)
+public class ModelValidationEntry
+{
+ private UIComponent component;
+ private List<Class> groups = new ArrayList<Class>();
+ private List<Object> validationTargets = new ArrayList<Object>();
+ private boolean displayMessageInline = false;
+ private String customMessage = ModelValidation.DEFAULT_MESSAGE;
+
+ //the original source where the extval-bv meta-data has been found
+ private Object metaDataSourceObject;
+ private String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
+
+ public void addGroup(Class group)
+ {
+ if(!this.groups.contains(group))
+ {
+ if(!(this.groups instanceof ArrayList))
+ {
+ List<Class> newGroupList = new ArrayList<Class>();
+
+ for(Class currentClass : this.groups)
+ {
+ newGroupList.add(currentClass);
+ }
+ this.groups = newGroupList;
+ }
+
+ this.groups.add(group);
+ }
+ }
+
+ public void removeGroup(Class group)
+ {
+ this.groups.remove(group);
+ }
+
+ public void addValidationTarget(Object target)
+ {
+ if(!this.validationTargets.contains(target))
+ {
+ if(!(this.validationTargets instanceof ArrayList))
+ {
+ List<Object> validationTargetList = new ArrayList<Object>();
+
+ for(Object currentTarget : this.validationTargets)
+ {
+ validationTargetList.add(currentTarget);
+ }
+ this.validationTargets = validationTargetList;
+ }
+
+ this.validationTargets.add(target);
+ }
+ }
+
+ /*
+ * generated
+ */
+ public UIComponent getComponent()
+ {
+ return component;
+ }
+
+ public void setComponent(UIComponent component)
+ {
+ this.component = component;
+ }
+
+ public Class[] getGroups()
+ {
+ return this.groups.toArray(new Class[this.groups.size()]);
+ }
+
+ public void setGroups(List<Class> groups)
+ {
+ this.groups = groups;
+ }
+
+ public List<Object> getValidationTargets()
+ {
+ return validationTargets;
+ }
+
+ public Object getMetaDataSourceObject()
+ {
+ return metaDataSourceObject;
+ }
+
+ public void setMetaDataSourceObject(Object metaDataSourceObject)
+ {
+ this.metaDataSourceObject = metaDataSourceObject;
+ }
+
+ @SuppressWarnings({"RedundantIfStatement"})
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ModelValidationEntry that = (ModelValidationEntry) o;
+
+ if (component != null ? !component.equals(that.component) : that.component != null)
+ {
+ return false;
+ }
+ if (!groups.equals(that.groups))
+ {
+ return false;
+ }
+ if (!validationTargets.equals(that.validationTargets))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean isDisplayMessageInline()
+ {
+ return displayMessageInline;
+ }
+
+ public void setDisplayMessageInline(boolean displayMessageInline)
+ {
+ this.displayMessageInline = displayMessageInline;
+ }
+
+ public String getCustomMessage()
+ {
+ return customMessage;
+ }
+
+ public void setCustomMessage(String customMessage)
+ {
+ this.customMessage = customMessage;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = component != null ? component.hashCode() : 0;
+ result = 31 * result + groups.hashCode();
+ result = 31 * result + validationTargets.hashCode();
+ return result;
+ }
+
+ public String getViewId()
+ {
+ return viewId;
+ }
+
+ public void setViewId(String viewId)
+ {
+ this.viewId = viewId;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationStorage.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationStorage.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationStorage.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,40 @@
+/*
+ * 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.beanval.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import java.util.List;
+
+/**
+ * suggested interface for a model-validation storage
+ * <p/>
+ * it allows to manage model-validation-entries for the current request
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface ModelValidationStorage
+{
+ void addModelValidationEntry(ModelValidationEntry modelValidationEntry);
+
+ List<ModelValidationEntry> getModelValidationEntriesToValidate();
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/BeanValidationGroupStorageNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/BeanValidationGroupStorageNameMapper.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/BeanValidationGroupStorageNameMapper.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/BeanValidationGroupStorageNameMapper.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.beanval.storage.mapper;
+
+import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
+import org.apache.myfaces.extensions.validator.beanval.storage.DefaultBeanValidationGroupStorage;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@InvocationOrder(200)
+@UsageInformation(INTERNAL)
+public class BeanValidationGroupStorageNameMapper implements NameMapper<String>
+{
+ public String createName(String key)
+ {
+ return (BeanValidation.class.getName().equals(key)) ?
+ DefaultBeanValidationGroupStorage.class.getName() : null;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/ModelValidationStorageNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/ModelValidationStorageNameMapper.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/ModelValidationStorageNameMapper.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/mapper/ModelValidationStorageNameMapper.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.beanval.storage.mapper;
+
+import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
+import org.apache.myfaces.extensions.validator.beanval.storage.DefaultModelValidationStorage;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@InvocationOrder(200)
+@UsageInformation(INTERNAL)
+public class ModelValidationStorageNameMapper implements NameMapper<String>
+{
+ public String createName(String key)
+ {
+ return (ModelValidation.class.getName().equals(key)) ?
+ DefaultModelValidationStorage.class.getName() : null;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,147 @@
+/*
+ * 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.beanval.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.beanval.storage.ModelValidationEntry;
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.validation.message.FacesMessageHolder;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+import javax.validation.ConstraintViolation;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class BeanValidationUtils
+{
+ private static final Log LOG = LogFactory.getLog(BeanValidationUtils.class);
+ private static ExtValBeanValidationMetaDataInternals bvmi = new ExtValBeanValidationMetaDataInternals(LOG);
+
+ public static void addMetaDataToContext(
+ UIComponent component, PropertyDetails propertyDetails, boolean processModelValidation)
+ {
+ String[] key = propertyDetails.getKey().split("\\.");
+
+ Object firstBean = ExtValUtils.getELHelper().getBean(key[0]);
+
+ List<Class> foundGroupsForPropertyValidation = new ArrayList<Class>();
+ List<Class> restrictedGroupsForPropertyValidation = new ArrayList<Class>();
+ List<ModelValidationEntry> modelValidationEntryList = new ArrayList<ModelValidationEntry>();
+ List<Class> restrictedGroupsForModelValidation = new ArrayList<Class>();
+
+ bvmi.extractExtValBeanValidationMetaData(propertyDetails,
+ processModelValidation,
+ key,
+ firstBean,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+
+ bvmi.processExtValBeanValidationMetaData(component,
+ propertyDetails,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+ }
+
+ public static void processConstraintViolations(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ Set<ConstraintViolation> violations)
+ {
+ List<FacesMessageHolder> facesMessageHolderList = new ArrayList<FacesMessageHolder>();
+
+ FacesMessage facesMessage;
+ for (ConstraintViolation violation : violations)
+ {
+ facesMessage = createFacesMessageForConstraintViolation(uiComponent, convertedObject, violation);
+
+ if (facesMessage == null)
+ {
+ continue;
+ }
+
+ bvmi.processFacesMessage(facesContext, uiComponent, facesMessageHolderList, facesMessage);
+ }
+
+ processViolationMessages(facesMessageHolderList);
+ }
+
+ public static FacesMessage createFacesMessageForConstraintViolation(UIComponent uiComponent,
+ Object convertedObject,
+ ConstraintViolation violation)
+ {
+ String violationMessage = violation.getMessage();
+
+ String labeledMessageSummary = bvmi.createLabeledMessage(violationMessage, false);
+ String labeledMessageDetail = bvmi.createLabeledMessage(violationMessage, true);
+
+ FacesMessage.Severity severity = bvmi.calcSeverity(violation);
+
+ ValidatorException validatorException = bvmi
+ .createValidatorException(labeledMessageSummary, labeledMessageDetail, severity);
+
+ if (!bvmi.executeAfterThrowingInterceptors(uiComponent, convertedObject, validatorException))
+ {
+ return null;
+ }
+
+ if (bvmi.isMessageTextUnchanged(validatorException, labeledMessageSummary, labeledMessageDetail))
+ {
+ return ExtValUtils.createFacesMessage(severity, violationMessage, violationMessage);
+ }
+ else
+ {
+ return ExtValUtils.createFacesMessage(severity,
+ validatorException.getFacesMessage().getSummary(),
+ validatorException.getFacesMessage().getDetail());
+ }
+ }
+
+ public static void processViolationMessages(List<FacesMessageHolder> violationMessageHolderList)
+ {
+ if (violationMessageHolderList == null || violationMessageHolderList.isEmpty())
+ {
+ return;
+ }
+
+ List<FacesMessageHolder> facesMessageListWithLowSeverity =
+ bvmi.getFacesMessageListWithLowSeverity(violationMessageHolderList);
+ List<FacesMessageHolder> facesMessageListWithHighSeverity =
+ bvmi.getFacesMessageListWithHighSeverity(violationMessageHolderList);
+
+ bvmi.addMessages(facesMessageListWithHighSeverity);
+ bvmi.addMessages(facesMessageListWithLowSeverity);
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,648 @@
+/*
+ * 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.beanval.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.myfaces.extensions.validator.beanval.ExtValBeanValidationContext;
+import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
+import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
+import org.apache.myfaces.extensions.validator.beanval.annotation.extractor.DefaultGroupControllerScanningExtractor;
+import org.apache.myfaces.extensions.validator.beanval.payload.ViolationSeverity;
+import org.apache.myfaces.extensions.validator.beanval.storage.ModelValidationEntry;
+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.metadata.MetaDataEntry;
+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.validation.message.FacesMessageHolder;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+import javax.validation.ConstraintViolation;
+import javax.validation.Payload;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+class ExtValBeanValidationMetaDataInternals
+{
+ private Log logger;
+ private LabeledMessageInternals labeledMessageInternals = new LabeledMessageInternals();
+
+ ExtValBeanValidationMetaDataInternals(Log logger)
+ {
+ this.logger = logger;
+ }
+
+ void extractExtValBeanValidationMetaData(PropertyDetails propertyDetails,
+ boolean processModelValidation,
+ String[] key,
+ Object firstBean,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ inspectFirstBean(processModelValidation,
+ firstBean,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+
+ inspectFirstProperty(processModelValidation,
+ key,
+ firstBean,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+
+ inspectBaseOfProperty(propertyDetails,
+ processModelValidation,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+
+ inspectLastProperty(propertyDetails,
+ processModelValidation,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+ }
+
+ void processExtValBeanValidationMetaData(UIComponent component,
+ PropertyDetails propertyDetails,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ ExtValBeanValidationContext extValBeanValidationContext = ExtValBeanValidationContext.getCurrentInstance();
+ String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
+
+ String clientId = component.getClientId(FacesContext.getCurrentInstance());
+
+ processFoundGroups(extValBeanValidationContext, currentViewId, clientId,
+ foundGroupsForPropertyValidation);
+
+ processRestrictedGroups(extValBeanValidationContext, currentViewId, clientId,
+ restrictedGroupsForPropertyValidation);
+
+ initModelValidation(extValBeanValidationContext, component, propertyDetails,
+ modelValidationEntryList, restrictedGroupsForModelValidation);
+ }
+
+ private void inspectFirstBean(boolean processModelValidation,
+ Object firstBean,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ processClass(firstBean,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+
+ private void inspectFirstProperty(boolean processModelValidation,
+ String[] key,
+ Object firstBean,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ processFieldsAndProperties(key[0] + "." + key[1],
+ firstBean,
+ key[1],
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+
+ private void inspectBaseOfProperty(PropertyDetails propertyDetails,
+ boolean processModelValidation,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ processClass(propertyDetails.getBaseObject(),
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+
+ private void inspectLastProperty(PropertyDetails propertyDetails,
+ boolean processModelValidation,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ processFieldsAndProperties(
+ propertyDetails.getKey(),
+ propertyDetails.getBaseObject(),
+ propertyDetails.getProperty(),
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+
+ private void processClass(Object objectToInspect,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ Class classToInspect = objectToInspect.getClass();
+ while (!Object.class.getName().equals(classToInspect.getName()))
+ {
+ transferGroupValidationInformationToFoundGroups(objectToInspect,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+
+ processInterfaces(objectToInspect.getClass(), objectToInspect,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+
+ classToInspect = classToInspect.getSuperclass();
+ }
+ }
+
+ private void processFieldsAndProperties(String key,
+ Object base,
+ String property,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ PropertyInformation propertyInformation = new DefaultGroupControllerScanningExtractor()
+ .extract(FacesContext.getCurrentInstance(), new PropertyDetails(key, base, property));
+
+ for (MetaDataEntry metaDataEntry : propertyInformation.getMetaDataEntries())
+ {
+ if (metaDataEntry.getValue() instanceof BeanValidation)
+ {
+ tryToProcessMetaData((BeanValidation) metaDataEntry.getValue(),
+ tryToCreateNewTarget(base, property),
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+ else if (metaDataEntry.getValue() instanceof BeanValidation.List)
+ {
+ for (BeanValidation currentBeanValidation : ((BeanValidation.List) metaDataEntry.getValue()).value())
+ {
+ tryToProcessMetaData(currentBeanValidation,
+ tryToCreateNewTarget(base, property),
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+ }
+ }
+ }
+
+ private Object tryToCreateNewTarget(Object base, String property)
+ {
+ Object result = getValueOfProperty(base, property);
+
+ if (result == null)
+ {
+ return base;
+ }
+
+ return result;
+ }
+
+ private Object getValueOfProperty(Object base, String property)
+ {
+ property = property.substring(0, 1).toUpperCase() + property.substring(1, property.length());
+ Method targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "get" + property);
+
+ if (targetMethod == null)
+ {
+ targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "is" + property);
+ }
+
+ if (targetMethod == null)
+ {
+ throw new IllegalStateException(
+ "class " + base.getClass() + " has no public get/is " + property.toLowerCase());
+ }
+ return ReflectionUtils.tryToInvokeMethod(base, targetMethod);
+ }
+
+ private void processFoundGroups(ExtValBeanValidationContext extValBeanValidationContext,
+ String currentViewId,
+ String clientId,
+ List<Class> foundGroupsForPropertyValidation)
+ {
+ /*
+ * add found groups to context
+ */
+ for (Class currentGroupClass : foundGroupsForPropertyValidation)
+ {
+ extValBeanValidationContext.addGroup(currentGroupClass, currentViewId, clientId);
+ }
+ }
+
+ private void processRestrictedGroups(ExtValBeanValidationContext extValBeanValidationContext,
+ String currentViewId,
+ String clientId,
+ List<Class> restrictedGroupsForPropertyValidation)
+ {
+ /*
+ * add restricted groups
+ */
+ for (Class currentGroupClass : restrictedGroupsForPropertyValidation)
+ {
+ extValBeanValidationContext.restrictGroup(currentGroupClass, currentViewId, clientId);
+ }
+ }
+
+ private void initModelValidation(ExtValBeanValidationContext extValBeanValidationContext,
+ UIComponent component,
+ PropertyDetails propertyDetails,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ /*
+ * add model validation entry list
+ */
+ for (ModelValidationEntry modelValidationEntry : modelValidationEntryList)
+ {
+ for (Class restrictedGroup : restrictedGroupsForModelValidation)
+ {
+ modelValidationEntry.removeGroup(restrictedGroup);
+ }
+
+ if (modelValidationEntry.getGroups().length > 0)
+ {
+ if (modelValidationEntry.getValidationTargets().isEmpty())
+ {
+ modelValidationEntry.addValidationTarget(propertyDetails.getBaseObject());
+ }
+ modelValidationEntry.setComponent(component);
+ extValBeanValidationContext.addModelValidationEntry(modelValidationEntry);
+ }
+ }
+ }
+
+ private void transferGroupValidationInformationToFoundGroups(
+ Object objectToInspect,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ if (objectToInspect.getClass().isAnnotationPresent(BeanValidation.class))
+ {
+ tryToProcessMetaData(objectToInspect.getClass().getAnnotation(BeanValidation.class),
+ objectToInspect,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+ else if (objectToInspect.getClass().isAnnotationPresent(BeanValidation.List.class))
+ {
+ for (BeanValidation currentBeanValidation :
+ (objectToInspect.getClass().getAnnotation(BeanValidation.List.class)).value())
+ {
+ tryToProcessMetaData(currentBeanValidation,
+ objectToInspect,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+ }
+ }
+
+ private void processInterfaces(Class currentClass,
+ Object metaDataSourceObject,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ for (Class currentInterface : currentClass.getInterfaces())
+ {
+ transferGroupValidationInformationToFoundGroups(metaDataSourceObject,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+
+ processInterfaces(currentInterface, metaDataSourceObject,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ }
+ }
+
+ private void tryToProcessMetaData(BeanValidation beanValidation,
+ Object metaDataSourceObject,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ for (String currentViewId : beanValidation.viewIds())
+ {
+ if (useMetaDataForViewId(beanValidation, currentViewId))
+ {
+ processMetaData(beanValidation,
+ metaDataSourceObject,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation,
+ processModelValidation);
+ break;
+ }
+ }
+ }
+
+ private boolean useMetaDataForViewId(BeanValidation beanValidation, String currentViewId)
+ {
+ return (currentViewId.equals(FacesContext.getCurrentInstance().getViewRoot().getViewId()) ||
+ currentViewId.equals("*")) && isValidationPermitted(beanValidation);
+ }
+
+ private void processMetaData(BeanValidation beanValidation,
+ Object metaDataSourceObject,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation,
+ boolean processModelValidation)
+ {
+ if (processModelValidation && isModelValidation(beanValidation))
+ {
+ addModelValidationEntry(
+ beanValidation, metaDataSourceObject,
+ modelValidationEntryList, restrictedGroupsForModelValidation);
+ }
+ else if (!isModelValidation(beanValidation))
+ {
+ processGroups(
+ beanValidation, foundGroupsForPropertyValidation, restrictedGroupsForPropertyValidation);
+ }
+ }
+
+ private boolean isValidationPermitted(BeanValidation beanValidation)
+ {
+ ELHelper elHelper = ExtValUtils.getELHelper();
+
+ for (String condition : beanValidation.conditions())
+ {
+ if (elHelper.isELTermWellFormed(condition) &&
+ elHelper.isELTermValid(FacesContext.getCurrentInstance(), condition))
+ {
+ if (Boolean.TRUE.equals(elHelper.getValueOfExpression(
+ FacesContext.getCurrentInstance(), new ValueBindingExpression(condition))))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (this.logger.isErrorEnabled())
+ {
+ this.logger.error("an invalid condition is used: " + condition);
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isModelValidation(BeanValidation beanValidation)
+ {
+ return beanValidation.modelValidation().isActive();
+ }
+
+ private void addModelValidationEntry(BeanValidation beanValidation,
+ Object metaDataSourceObject,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ ModelValidationEntry modelValidationEntry = new ModelValidationEntry();
+
+ modelValidationEntry.setGroups(Arrays.asList(beanValidation.useGroups()));
+ modelValidationEntry.setDisplayMessageInline(beanValidation.modelValidation().displayInline());
+ modelValidationEntry.setCustomMessage(beanValidation.modelValidation().message());
+ modelValidationEntry.setMetaDataSourceObject(metaDataSourceObject);
+
+ Object validationTarget;
+ for (String validationTargetExpression : beanValidation.modelValidation().validationTargets())
+ {
+ if (ModelValidation.DEFAULT_TARGET.equals(validationTargetExpression))
+ {
+ continue;
+ }
+
+ validationTarget = tryToResolveValidationTargetExpression(validationTargetExpression);
+ if (validationTarget != null)
+ {
+ modelValidationEntry.addValidationTarget(validationTarget);
+ }
+ }
+
+ if (beanValidation.restrictGroups().length > 0)
+ {
+ restrictedGroupsForModelValidation.addAll(Arrays.asList(beanValidation.restrictGroups()));
+ }
+
+ if (modelValidationEntry.getValidationTargets().isEmpty())
+ {
+ modelValidationEntry.addValidationTarget(metaDataSourceObject);
+ }
+
+ modelValidationEntryList.add(modelValidationEntry);
+ }
+
+ private Object tryToResolveValidationTargetExpression(String validationTargetExpression)
+ {
+ ValueBindingExpression valueBindingExpression = new ValueBindingExpression(validationTargetExpression);
+ return ExtValUtils.getELHelper()
+ .getValueOfExpression(FacesContext.getCurrentInstance(), valueBindingExpression);
+ }
+
+ private void processGroups(BeanValidation beanValidation,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation)
+ {
+ foundGroupsForPropertyValidation.addAll(Arrays.asList(beanValidation.useGroups()));
+
+ if (beanValidation.restrictGroups().length > 0)
+ {
+ restrictedGroupsForPropertyValidation.addAll(Arrays.asList(beanValidation.restrictGroups()));
+ }
+ }
+
+ String createLabeledMessage(String violationMessage, boolean isDetailMessage)
+ {
+ return this.labeledMessageInternals.createLabeledMessage(violationMessage, isDetailMessage);
+ }
+
+ FacesMessage.Severity calcSeverity(ConstraintViolation<?> violation)
+ {
+ for (Class<? extends Payload> payload : violation.getConstraintDescriptor().getPayload())
+ {
+ if (ViolationSeverity.Warn.class.isAssignableFrom(payload))
+ {
+ return FacesMessage.SEVERITY_WARN;
+ }
+ else if (ViolationSeverity.Info.class.isAssignableFrom(payload))
+ {
+ return FacesMessage.SEVERITY_INFO;
+ }
+ else if (ViolationSeverity.Fatal.class.isAssignableFrom(payload))
+ {
+ return FacesMessage.SEVERITY_FATAL;
+ }
+ }
+ return FacesMessage.SEVERITY_ERROR;
+ }
+
+ void processFacesMessage(FacesContext facesContext, UIComponent uiComponent,
+ List<FacesMessageHolder> facesMessageHolderList, FacesMessage facesMessage)
+ {
+ FacesMessageHolder facesMessageHolder = new FacesMessageHolder(facesMessage);
+
+ facesMessageHolder.setClientId(uiComponent.getClientId(facesContext));
+
+ facesMessageHolderList.add(facesMessageHolder);
+ }
+
+ boolean executeAfterThrowingInterceptors(UIComponent uiComponent,
+ Object convertedObject,
+ ValidatorException validatorException)
+ {
+ return ExtValUtils.executeAfterThrowingInterceptors(
+ uiComponent,
+ null,
+ convertedObject,
+ validatorException,
+ null);
+ }
+
+ boolean isMessageTextUnchanged(
+ ValidatorException validatorException, String violationSummaryMessage, String violationDetailMessage)
+ {
+ return violationSummaryMessage.equals(validatorException.getFacesMessage().getSummary()) &&
+ violationDetailMessage.equals(validatorException.getFacesMessage().getDetail());
+ }
+
+ ValidatorException createValidatorException(
+ String violationSummaryMessage, String violationDetailMessage, FacesMessage.Severity severity)
+ {
+ return new ValidatorException(
+ ExtValUtils.createFacesMessage(severity, violationSummaryMessage, violationDetailMessage));
+ }
+
+ List<FacesMessageHolder> getFacesMessageListWithLowSeverity(
+ List<FacesMessageHolder> violationMessages)
+ {
+ List<FacesMessageHolder> result = new ArrayList<FacesMessageHolder>();
+
+ for (FacesMessageHolder facesMessageHolder : violationMessages)
+ {
+ if (FacesMessage.SEVERITY_WARN.equals(facesMessageHolder.getFacesMessage().getSeverity()) ||
+ FacesMessage.SEVERITY_INFO.equals(facesMessageHolder.getFacesMessage().getSeverity()))
+ {
+ result.add(facesMessageHolder);
+ }
+ }
+ return result;
+ }
+
+ List<FacesMessageHolder> getFacesMessageListWithHighSeverity(
+ List<FacesMessageHolder> violationMessageHolderList)
+ {
+ List<FacesMessageHolder> result = new ArrayList<FacesMessageHolder>();
+
+ for (FacesMessageHolder facesMessageHolder : violationMessageHolderList)
+ {
+ if (FacesMessage.SEVERITY_ERROR.equals(facesMessageHolder.getFacesMessage().getSeverity()) ||
+ FacesMessage.SEVERITY_FATAL.equals(facesMessageHolder.getFacesMessage().getSeverity()))
+ {
+ result.add(facesMessageHolder);
+ }
+ }
+ return result;
+ }
+
+ void addMessages(List<FacesMessageHolder> facesMessageHolderListWithLowSeverity)
+ {
+ for (FacesMessageHolder facesMessageHolder : facesMessageHolderListWithLowSeverity)
+ {
+ ExtValUtils.tryToAddViolationMessageForComponentId(
+ facesMessageHolder.getClientId(), facesMessageHolder.getFacesMessage());
+ }
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java?rev=835712&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java Fri Nov 13 02:48:45 2009
@@ -0,0 +1,108 @@
+/*
+ * 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.beanval.util;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.util.JsfUtils;
+
+import java.util.MissingResourceException;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+class LabeledMessageInternals
+{
+ //there is no concurrency issue here - it always leads to the same result
+ private final String defaultSummaryMessageTemplate = "{1}: {0}";
+ private final String defaultDetailMessageTemplate = "{1}: {0}";
+ private String summaryMessageTemplate = defaultSummaryMessageTemplate;
+ private String detailMessageTemplate = defaultDetailMessageTemplate;
+ private static final String JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE =
+ "javax.faces.validator.BeanValidator.MESSAGE";
+ private static final String JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE_DETAIL =
+ "javax.faces.validator.BeanValidator.MESSAGE_detail";
+
+ String createLabeledMessage(String violationMessage, boolean isDetailMessage)
+ {
+ if(isDetailMessage)
+ {
+ return tryToResolveDetailMessage(violationMessage);
+ }
+ else
+ {
+ return tryToResolveSummaryMessage(violationMessage);
+ }
+ }
+
+ private String tryToResolveSummaryMessage(String violationMessage)
+ {
+ if(summaryMessageTemplate == null)
+ {
+ return this.defaultSummaryMessageTemplate.replace("{0}", violationMessage);
+ }
+
+ this.summaryMessageTemplate = loadStandardMessageTemplate(false);
+
+ if(summaryMessageTemplate == null)
+ {
+ return createLabeledMessage(violationMessage, false);
+ }
+ return summaryMessageTemplate.replace("{0}", violationMessage);
+ }
+
+ private String tryToResolveDetailMessage(String violationMessage)
+ {
+ if(detailMessageTemplate == null)
+ {
+ return this.defaultDetailMessageTemplate.replace("{0}", violationMessage);
+ }
+
+ this.detailMessageTemplate = loadStandardMessageTemplate(true);
+
+ if(detailMessageTemplate == null)
+ {
+ return createLabeledMessage(violationMessage, true);
+ }
+ return detailMessageTemplate.replace("{0}", violationMessage);
+ }
+
+ private String loadStandardMessageTemplate(boolean isDetailMessage)
+ {
+ try
+ {
+ if(isDetailMessage)
+ {
+ return JsfUtils.getDefaultFacesMessageBundle()
+ .getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE_DETAIL);
+ }
+ else
+ {
+ return JsfUtils.getDefaultFacesMessageBundle()
+ .getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE);
+ }
+ }
+ catch (MissingResourceException e)
+ {
+ return null;
+ }
+ }
+}