From: <jbo...@li...> - 2006-05-27 19:55:36
|
Author: adamw Date: 2006-05-27 15:55:33 -0400 (Sat, 27 May 2006) New Revision: 4454 Modified: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessConfiguration.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-84 Modified: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessConfiguration.java =================================================================== --- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessConfiguration.java 2006-05-27 19:24:57 UTC (rev 4453) +++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessConfiguration.java 2006-05-27 19:55:33 UTC (rev 4454) @@ -16,11 +16,20 @@ private List<FileAccessMonitor> monitors; private List<Pattern> allowedPatterns; + private String[] getTokensFromProperty(Properties props, String propName) { + String prop = props.getProperty(propName); + if ((prop == null) || ("".equals(prop))) { + return new String[0]; + } + + return prop.split("[,]"); + } + public FileAccessConfiguration(Properties props) { monitors = new ArrayList<FileAccessMonitor>(); // Reading monitor classes. - String[] monitorsTokens = props.getProperty("monitor.stack", "").split("[,]"); + String[] monitorsTokens = getTokensFromProperty(props, "monitor.stack"); for (String monitorToken : monitorsTokens) { try { monitors.add((FileAccessMonitor) Class.forName(monitorToken).newInstance()); @@ -33,7 +42,7 @@ allowedPatterns = new ArrayList<Pattern>(); // 1. Allowed paths which contain a given string. - String[] containingTokens = props.getProperty("allowed.paths.containing", "").split("[,]"); + String[] containingTokens = getTokensFromProperty(props, "allowed.paths.containing"); for (String containingToken : containingTokens) { allowedPatterns.add(Pattern.compile(".*" + Pattern.quote(containingToken) + ".*")); } @@ -47,7 +56,7 @@ if (path.indexOf("..") != -1) { return false; } - + for (Pattern p : allowedPatterns) { if (p.matcher(path).matches()) { return true; |