Default validator configuration should not override user specified
configuration
---------------------------------------------------------------------------------
Key: SHALE-489
URL: https://issues.apache.org/struts/browse/SHALE-489
Project: Shale
Issue Type: Improvement
Components: Validator
Affects Versions: 1.0.4
Environment: Any
Reporter: Jeff Tsay
Priority: Minor
It seems strange the way that configuration rules are loaded. If the
default configuration file is not found, the validator lifecycle
listener will add the default configuration file to the end of a url
list. However, since the list is processed in forward order, that means
if you leave out the default configuration file, any settings you have
in your own file will be overwritten by the default. That means you need
to explicitly put the default configuration file in your
org.apache.shale.validator.VALIDATOR_RULES list before your own files.
Since I think it makes more sense to have your specified configuration
files override the default settings, I propose the following change in
ValidatorLifeCycleListener:
private ValidatorResources validatorResources(ServletContext context)
throws IOException, SAXException {
// Process the explicitly configured resources (if any)
// jtsay
// Since we want to add to the beginning later, use a linked list
// ArrayList urls = new ArrayList()
LinkedList urls = new LinkedList();
...
// Process the default configuration resources (if not already
loaded)
if (!didDefault) {
try {
url = context.getResource(Globals.DEFAULT_VALIDATOR_RULES);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("MalformedURLException:"
+ " The URL '" + Globals.DEFAULT_VALIDATOR_RULES
+ "' specified as a validator rules resource is
malformed.");
}
if (url == null) {
url =
ValidatorLifecycleListener.class.getResource(Globals.DEFAULT_VALIDATOR_RULES);
}
if (url == null) {
throw new
IllegalArgumentException(Globals.DEFAULT_VALIDATOR_RULES);
}
// jtsay
// Add to beginning of list so that explicit resources override
// default, not the other way around.
urls.addFirst(url);
}
Also below, there is some code to iterate over all elements in the list. Since
the list is now a LinkedList it is not efficient to iterate using an array
index. So the replaced code should like this:
int i = 0;
for (Iterator it = urls.iterator(); it.hasNext(); i++) {
array[i] = ((URL) it.next()).toExternalForm();
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.