Author: rich
Date: Tue Sep 21 23:20:37 2004
New Revision: 47030
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowActionFormBean.java
- copied, changed from rev 47025,
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowFormBeanConfig.java
Removed:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowFormBeanConfig.java
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/FormBeanModel.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidatableField.java
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidationModel.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
Log:
This is a contribution from Carlin Rogers, who's been looking at our
declarative validation (ValidatorPlugIn) support. Here's his comment:
"- changes to make sure the pageflow compiler won't overload a
formset rule explicitly defined for a specific locale with
a rule for all-locales of the same name.
- order the <formset> elements to the validator rules so that
the most specific locales are first.
- renamed the PageFlowFormBeanConfig class to
PageFlowActionFormBean based on its parent class."
DRT: netui (linux)
BB: self (WinXP)
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
Tue Sep 21 23:20:37 2004
@@ -374,7 +374,9 @@
throws FileNotFoundException, XmlException, IOException
{
String outputFile = _strutsApp.getWebappRoot() +
_strutsApp.getOutputFileURI( STRUTS_VALIDATION_PREFIX );
- writeXml( new PrintStream( new FileOutputStream( outputFile ) ),
_mergeFile );
+ PrintStream printStream = new PrintStream( new FileOutputStream(
outputFile ) );
+ writeXml( printStream, _mergeFile );
+ printStream.close();
}
public String getOutputFileURI()
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/FormBeanModel.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/FormBeanModel.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/FormBeanModel.java
Tue Sep 21 23:20:37 2004
@@ -88,7 +88,7 @@
}
- private static final String JPF_FORM_BEAN_CONFIG_CLASSNAME =
PAGEFLOW_PACKAGE + ".config.PageFlowFormBeanConfig";
+ private static final String JPF_ACTION_FORM_BEAN_CLASSNAME =
PAGEFLOW_PACKAGE + ".config.PageFlowActionFormBean";
private String _id = ""; // NOI18N
private String _className = null;
@@ -126,7 +126,7 @@
SetProperty prop = xb.addNewSetProperty();
prop.setProperty( "actualType" );
prop.setValue( _actualType );
- xb.setClassName( JPF_FORM_BEAN_CONFIG_CLASSNAME );
+ xb.setClassName( JPF_ACTION_FORM_BEAN_CLASSNAME );
}
if ( xb.getClassName() == null &&_className != null )
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidatableField.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidatableField.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidatableField.java
Tue Sep 21 23:20:37 2004
@@ -48,6 +48,19 @@
return _propertyName;
}
+ protected boolean hasRule( ValidatorRule rule )
+ {
+ String name = rule.getRuleName();
+ for ( int i = 0; i < _rules.size(); i++ )
+ {
+ if ( ( ( ValidatorRule ) _rules.get( i ) ).getRuleName().equals(
name ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void addRule( ValidatorRule rule )
{
_rules.add( rule );
Modified:
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidationModel.java
==============================================================================
---
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidationModel.java
(original)
+++
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/model/validation/ValidationModel.java
Tue Sep 21 23:20:37 2004
@@ -116,6 +116,19 @@
addFieldRule( ruleInfo, rule, localeSet );
}
+ private boolean hasFieldRule( RuleInfo ruleInfo, ValidatorRule rule,
LocaleSet localeSet )
+ {
+ String entityName = ruleInfo.getEntityName();
+ ValidatableEntity entity = localeSet.getEntity( entityName );
+ if ( entity == null ) { return false ; }
+
+ String fieldName = ruleInfo.getFieldName();
+ ValidatableField field = entity.getField( fieldName );
+ if ( field == null ) { return false; }
+
+ return field.hasRule( rule );
+ }
+
private void addFieldRule( RuleInfo ruleInfo, ValidatorRule rule,
LocaleSet localeSet )
{
String entityName = ruleInfo.getEntityName();
@@ -139,6 +152,9 @@
{
//
// First, if we haven't written the all-locale rules to each locale,
do so now.
+ // However, before we add a rule, check that it does not already
exist. We don't
+ // want to overload a rule explicitly defined for a specific locale
with
+ // an all-locale rule of the same name.
//
if ( _rulesToAddForAllLocales != null )
{
@@ -148,10 +164,15 @@
for ( Iterator j = _localeSets.values().iterator();
j.hasNext(); )
{
- addFieldRule( ruleAdd.ruleInfo, ruleAdd.rule, ( LocaleSet
) j.next() );
+ LocaleSet localeSet = ( LocaleSet ) j.next();
+ if ( !hasFieldRule( ruleAdd.ruleInfo, ruleAdd.rule,
localeSet ) ) {
+ addFieldRule( ruleAdd.ruleInfo, ruleAdd.rule,
localeSet );
+ }
+ }
+
+ if ( !hasFieldRule( ruleAdd.ruleInfo, ruleAdd.rule,
_defaultLocaleSet ) ) {
+ addFieldRule( ruleAdd.ruleInfo, ruleAdd.rule,
_defaultLocaleSet );
}
-
- addFieldRule( ruleAdd.ruleInfo, ruleAdd.rule,
_defaultLocaleSet );
}
_rulesToAddForAllLocales = null;
@@ -209,13 +230,9 @@
//
// Now write out all the LocaleSets, which contain the
forms/fields/rules.
//
+ writeLocaleSets( formValidationElement );
writeLocaleSet( _defaultLocaleSet, formValidationElement );
- for ( Iterator i = _localeSets.values().iterator(); i.hasNext(); )
- {
- writeLocaleSet( ( LocaleSet ) i.next(), formValidationElement );
- }
-
//
// Write the file.
//
@@ -229,6 +246,63 @@
return null;
}
+ private void writeLocaleSets( FormValidationDocument.FormValidation
formValidationElement )
+ {
+ //
+ // Commons Validator behavior is to build a key from the locale of a
FormSet
+ // or uses the default Locale (Locale.getDefault() - the system
locale) to
+ // track different <formset> elements. This implies that the <formset>
+ // without language or country attributes could be mapped to "en_US"
+ // if that's the default locale.
+ // See org.apache.commons.validator.ValidatorResources.buildKey()
+ //
+ // Therefor, to ensure the validator uses <formset> rules for of a
specific
+ // locale before the FormSet with no language or country attributes
(even
+ // if it is the locale of the system), write the most specific locales
first.
+ //
+ List allLocales = new ArrayList( _localeSets.keySet() );
+ List langCountryVariant = new ArrayList();
+ List langCountry = new ArrayList();
+ List langVariant = new ArrayList();
+ List lang = new ArrayList();
+ List orderedLocales = new ArrayList( allLocales.size() );
+
+ for ( Iterator i = allLocales.iterator(); i.hasNext(); )
+ {
+ Locale locale = ( Locale ) i.next();
+ if ( locale.getCountry() != null && locale.getCountry().length() >
0 )
+ {
+ if ( locale.getVariant() != null &&
locale.getVariant().length() > 0 )
+ {
+ langCountryVariant.add( locale );
+ }
+ else
+ {
+ langCountry.add( locale );
+ }
+ }
+ else if ( locale.getVariant() != null &&
locale.getVariant().length() > 0 )
+ {
+ langVariant.add( locale );
+ }
+ else
+ {
+ lang.add( locale );
+ }
+ }
+
+ orderedLocales.addAll( langCountryVariant );
+ orderedLocales.addAll( langCountry );
+ orderedLocales.addAll( langVariant );
+ orderedLocales.addAll( lang );
+
+ for ( Iterator i = orderedLocales.iterator(); i.hasNext(); )
+ {
+ LocaleSet localeSet = ( LocaleSet ) _localeSets.get( i.next() );
+ writeLocaleSet( localeSet, formValidationElement );
+ }
+ }
+
private void writeLocaleSet( LocaleSet localeSet,
FormValidationDocument.FormValidation formValidationElement )
{
FormsetDocument.Formset[] existingFormSetElements =
formValidationElement.getFormsetArray();
@@ -244,7 +318,7 @@
formSetElementToUse = existingFormSetElement;
break;
}
- else if ( locale.getLanguage().equals(
existingFormSetElement.getLanguage() ) )
+ else if ( locale != null && locale.getLanguage().equals(
existingFormSetElement.getLanguage() ) )
{
if ( ( locale.getCountry() == null &&
existingFormSetElement.getCountry() == null )
|| locale.getCountry().equals(
existingFormSetElement.getCountry() ) )
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
Tue Sep 21 23:20:37 2004
@@ -17,7 +17,7 @@
*/
package org.apache.beehive.netui.pageflow;
-import org.apache.beehive.netui.pageflow.config.PageFlowFormBeanConfig;
+import org.apache.beehive.netui.pageflow.config.PageFlowActionFormBean;
import org.apache.beehive.netui.pageflow.internal.ActionResultImpl;
import org.apache.beehive.netui.pageflow.internal.InternalUtils;
import org.apache.beehive.netui.pageflow.scoping.ScopedRequest;
@@ -417,9 +417,9 @@
for ( int j = 0; j < formBeans.length; ++j )
{
assert formBeans[j] != null;
- if ( formBeans[j] instanceof PageFlowFormBeanConfig )
+ if ( formBeans[j] instanceof PageFlowActionFormBean )
{
- formNameMap.put( ( ( PageFlowFormBeanConfig ) formBeans[j]
).getActualType(),
+ formNameMap.put( ( ( PageFlowActionFormBean ) formBeans[j]
).getActualType(),
formBeans[j].getName() );
}
else
Copied:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowActionFormBean.java
(from rev 47025,
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowFormBeanConfig.java)
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowFormBeanConfig.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowActionFormBean.java
Tue Sep 21 23:20:37 2004
@@ -24,7 +24,7 @@
/**
* Class to handle our extensions to the Struts <form-bean> tag.
*/
-public class PageFlowFormBeanConfig extends ActionFormBean
+public class PageFlowActionFormBean extends ActionFormBean
{
private String _actualType; // applicable for non-ActionForm-derived form
types