[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Galder Zamarreno
galder.zamarreno at jboss.com
Thu Nov 23 11:07:38 EST 2006
User: gzamarreno
Date: 06/11/23 11:07:38
Modified: src/org/jboss/cache/loader FileCacheLoader.java
FileCacheLoaderConfig.java
Log:
[JBCACHE-644] Character portability checks can be disabled now with added flag. Documentation updated. Regex patterns made static final.
Revision Changes Path
1.26 +26 -15 JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- FileCacheLoader.java 20 Nov 2006 19:52:57 -0000 1.25
+++ FileCacheLoader.java 23 Nov 2006 16:07:38 -0000 1.26
@@ -25,7 +25,7 @@
* Simple file-based CacheLoader implementation. Nodes are directories, attributes of a node is a file in the directory
*
* @author Bela Ban
- * @version $Id: FileCacheLoader.java,v 1.25 2006/11/20 19:52:57 bstansberry Exp $
+ * @version $Id: FileCacheLoader.java,v 1.26 2006/11/23 16:07:38 gzamarreno Exp $
*/
public class FileCacheLoader extends AbstractCacheLoader
{
@@ -51,6 +51,16 @@
*/
public static final String DIR_SUFFIX = "fdb";
+ /**
+ * For full path, check '*' '<' '>' '|' '"' '?' Regex: [\*<>|"?]
+ */
+ public static final Pattern PATH_PATTERN = Pattern.compile("[\\*<>|\"?]");
+
+ /**
+ * For fqn, check '*' '<' '>' '|' '"' '?' and also '\' '/' and ':'
+ */
+ public static final Pattern FQN_PATTERN = Pattern.compile("[\\\\\\/:*<>|\"?]");
+
public FileCacheLoader()
{
}
@@ -94,9 +104,12 @@
log.trace("Creating cache loader location " + root);
}
+ if (config.isCheckCharacterPortability())
+ {
/* Before creating the root, check whether the path is character portable. Anything that comes after is part
of the fqn which is inspected later. */
isCharacterPortableLocation(root.getAbsolutePath());
+ }
boolean created = root.mkdirs();
if (!created)
@@ -357,10 +370,13 @@
File child = new File(f, DATA);
if (!child.exists())
{
+ if (config.isCheckCharacterPortability())
+ {
/* Check whether the entire file path (root + fqn + data file name), is lenght portable */
isLengthPortablePath(child.getAbsolutePath());
/* Check whether the fqn tree we're trying to store could contain non portable characters */
isCharacterPortableTree(fqn);
+ }
if (!child.createNewFile())
{
@@ -375,9 +391,7 @@
protected boolean isCharacterPortableLocation(String fileAbsolutePath)
{
- /* For full path, check '*' '<' '>' '|' '"' '?' Regex: [\*<>|"?] */
- Pattern fullPathPattern = Pattern.compile("[\\*<>|\"?]");
- Matcher matcher = fullPathPattern.matcher(fileAbsolutePath);
+ Matcher matcher = PATH_PATTERN.matcher(fileAbsolutePath);
if (matcher.find())
{
log.warn("Cache loader location ( " + fileAbsolutePath + " ) contains one of these characters: '*' '<' '>' '|' '\"' '?'");
@@ -390,15 +404,12 @@
protected boolean isCharacterPortableTree(Fqn fqn)
{
- /* For fqn, check '*' '<' '>' '|' '"' '?' and also '\' '/' and ':' */
- Pattern fqnPattern = Pattern.compile("[\\\\\\/:*<>|\"?]");
-
List elements = fqn.peekElements();
// Don't assume the Fqn is composed of Strings!!
for (Object anElement : elements)
{
// getFullPath converts Object to String via toString(), so we do too
- Matcher matcher = fqnPattern.matcher(anElement.toString());
+ Matcher matcher = FQN_PATTERN.matcher(anElement.toString());
if (matcher.find())
{
log.warn("One of the Fqn ( " + fqn + " ) elements contains one of these characters: '*' '<' '>' '|' '\"' '?' '\\' '/' ':' ");
1.2 +22 -2 JBossCache/src/org/jboss/cache/loader/FileCacheLoaderConfig.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileCacheLoaderConfig.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/FileCacheLoaderConfig.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- FileCacheLoaderConfig.java 26 Oct 2006 19:30:20 -0000 1.1
+++ FileCacheLoaderConfig.java 23 Nov 2006 16:07:38 -0000 1.2
@@ -3,12 +3,15 @@
import java.util.Properties;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.Dynamic;
public class FileCacheLoaderConfig extends IndividualCacheLoaderConfig
{
private static final long serialVersionUID = 4626734068542420865L;
private String location;
+ @Dynamic
+ private boolean checkCharacterPortability = true;
public FileCacheLoaderConfig()
{
@@ -37,10 +40,27 @@
this.location = location;
}
+ public boolean isCheckCharacterPortability()
+ {
+ return checkCharacterPortability;
+ }
+
+ public void setCheckCharacterPortability(boolean checkCharacterPortability)
+ {
+ testImmutability("check.character.portability");
+ this.checkCharacterPortability = checkCharacterPortability;
+ }
+
public void setProperties(Properties props)
{
super.setProperties(props);
- setLocation(props != null ? props.getProperty("location") : null);
+
+ if (props != null)
+ {
+ setLocation(props.getProperty("location"));
+ String prop = props.getProperty("check.character.portability");
+ setCheckCharacterPortability((prop == null || Boolean.valueOf(prop).booleanValue()));
+ }
}
public boolean equals(Object obj)
More information about the jboss-cvs-commits
mailing list