Author: simonetripodi
Date: Sun Sep 4 13:55:01 2011
New Revision: 1165015
URL: http://svn.apache.org/viewvc?rev=1165015&view=rev
Log:
no reason to reinvent the parser, switched over java tokenizer implementation
fixed path array length
Modified:
commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/ChainResources.java
Modified:
commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/ChainResources.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/ChainResources.java?rev=1165015&r1=1165014&r2=1165015&view=diff
==============================================================================
---
commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/ChainResources.java
(original)
+++
commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/web/ChainResources.java
Sun Sep 4 13:55:01 2011
@@ -20,6 +20,8 @@ package org.apache.commons.chain.web;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.StringTokenizer;
+
import javax.servlet.ServletContext;
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.config.ConfigParser;
@@ -230,26 +232,21 @@ final class ChainResources {
* @since Chain 1.1
*/
static String[] getResourcePaths(String resources) {
- List paths = new ArrayList();
+ if (resources == null || resources.length() == 0) {
+ return new String[0];
+ }
- if (resources != null) {
- String path;
- int comma;
-
- while ((comma = resources.indexOf(',')) >= 0) {
- path = resources.substring(0, comma).trim();
- if (path.length() > 0) {
- paths.add(path);
- }
- resources = resources.substring(comma + 1);
- }
- resources = resources.trim();
- if (resources.length() > 0) {
- paths.add(resources);
+ StringTokenizer resourcesTokenizer = new StringTokenizer(resources,
",");
+ List<String> paths = new
ArrayList<String>(resourcesTokenizer.countTokens());
+
+ while (resourcesTokenizer.hasMoreTokens()) {
+ String path = resourcesTokenizer.nextToken().trim();
+ if (path.length() > 0) {
+ paths.add(path);
}
}
- return (String[]) paths.toArray(new String[0]);
+ return paths.toArray(new String[paths.size()]);
}