From: rjung Date: Tue, 3 Aug 2010 19:39:38 +0000 (+0000) Subject: - clean up Javadoc of new class X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5bbb5e13ab1828df8721f96cffda009b38103fc4;p=tomcat7.0 - clean up Javadoc of new class - localize log messages - remove unused imports and members git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@982013 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/file/Constants.java b/java/org/apache/tomcat/util/file/Constants.java new file mode 100644 index 000000000..a056e6c60 --- /dev/null +++ b/java/org/apache/tomcat/util/file/Constants.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.util.file; + +/** + * String constants for the file package. + */ +public final class Constants { + + public static final String Package = "org.apache.tomcat.util.file"; + +} diff --git a/java/org/apache/tomcat/util/file/LocalStrings.properties b/java/org/apache/tomcat/util/file/LocalStrings.properties new file mode 100644 index 000000000..eff025109 --- /dev/null +++ b/java/org/apache/tomcat/util/file/LocalStrings.properties @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +matcher.tokenize=Tokenizing path [{0}] diff --git a/java/org/apache/tomcat/util/file/Matcher.java b/java/org/apache/tomcat/util/file/Matcher.java index dae013368..aa416be3f 100644 --- a/java/org/apache/tomcat/util/file/Matcher.java +++ b/java/org/apache/tomcat/util/file/Matcher.java @@ -21,16 +21,17 @@ package org.apache.tomcat.util.file; import java.io.File; import java.util.Locale; import java.util.Set; -import java.util.StringTokenizer; -import java.util.Vector; + +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.res.StringManager; /** - *

This is a utility class used by selectors and DirectoryScanner. The - * functionality more properly belongs just to selectors, but unfortunately - * DirectoryScanner exposed these as protected methods. Thus we have to - * support any subclasses of DirectoryScanner that may access these methods. + *

This is a utility class to match file globs. + * The class has been derived from + * org.apache.tools.ant.types.selectors.SelectorUtils. *

- *

This is a Singleton.

+ *

All methods are static.

*/ public final class Matcher { @@ -39,7 +40,6 @@ public final class Matcher { */ public static final String DEEP_TREE_MATCH = "**"; - private static final Matcher instance = new Matcher(); private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); private static final String PATH_SEP = @@ -48,26 +48,20 @@ public final class Matcher { private static final boolean ON_DOS = isDos(); /** - * Private Constructor + * The string resources for this package. */ - private Matcher() { - } + private static final StringManager sm = + StringManager.getManager(Constants.Package); - /** - * Retrieves the instance of the Singleton. - * @return singleton instance - */ - public static Matcher getInstance() { - return instance; - } + private static final Log log = LogFactory.getLog(Matcher.class); /** * Tests whether or not a given path matches any pattern in the given set. * * If you need to call this method multiple times with the same - * pattern you should rather use TokenizedPath + * pattern you should rather pre parse the pattern using tokenizePathAsArray. * - * @see TokenizedPath + * @see #tokenizePathAsArray * * @param patternSet The pattern set to match against. Must not be * null. @@ -91,9 +85,9 @@ public final class Matcher { * Tests whether or not a given path matches a given pattern. * * If you need to call this method multiple times with the same - * pattern you should rather use TokenizedPath + * pattern you should rather pre parse the pattern using tokenizePathAsArray. * - * @see TokenizedPath + * @see #tokenizePathAsArray * * @param pattern The pattern to match against. Must not be * null. @@ -112,9 +106,9 @@ public final class Matcher { * Tests whether or not a given path matches a given pattern. * * If you need to call this method multiple times with the same - * pattern you should rather use TokenizedPattern + * pattern you should rather pre parse the pattern using tokenizePathAsArray. * - * @see TokenizedPattern + * @see #tokenizePathAsArray * * @param pattern The pattern to match against. Must not be * null. @@ -133,10 +127,9 @@ public final class Matcher { } /** - * Core implementation of matchPath. It is isolated so that it - * can be called from TokenizedPattern. + * Core implementation of matchPath using an already tokenized pattern. */ - static boolean matchPath(String[] tokenizedPattern, String[] strDirs, + public static boolean matchPath(String[] tokenizedPattern, String[] strDirs, boolean isCaseSensitive) { int patIdxStart = 0; int patIdxEnd = tokenizedPattern.length - 1; @@ -420,7 +413,7 @@ public final class Matcher { } /** - * Breaks a path up into a Vector of path elements, tokenizing on + * Breaks a path up into a array of path elements, tokenizing on * File.separator. * * @param path Path to tokenize. Must not be null. @@ -428,6 +421,9 @@ public final class Matcher { * @return a String array of path elements from the tokenized path */ public static String[] tokenizePathAsArray(String path) { + if (log.isTraceEnabled()) { + log.trace(sm.getString("matcher.tokenize", path)); + } String root = null; if (isAbsolutePath(path)) { String[] s = dissect(path); diff --git a/java/org/apache/tomcat/util/file/package.html b/java/org/apache/tomcat/util/file/package.html new file mode 100644 index 000000000..39f77a9af --- /dev/null +++ b/java/org/apache/tomcat/util/file/package.html @@ -0,0 +1,29 @@ + + + + + + + +

+This package contains utility classes for file handling. +

+ + diff --git a/java/org/apache/tomcat/util/scan/LocalStrings.properties b/java/org/apache/tomcat/util/scan/LocalStrings.properties index 27b59ddf1..ee7e22dca 100644 --- a/java/org/apache/tomcat/util/scan/LocalStrings.properties +++ b/java/org/apache/tomcat/util/scan/LocalStrings.properties @@ -15,6 +15,10 @@ jarScan.classloaderFail=Failed to scan [{0}] from classloader hierarchy jarScan.classloaderStart=Scanning for JARs in classloader hierarchy +jarScan.classloaderJarScan=Scanning JAR [{0}] from classpath +jarScan.classloaderJarNoScan=Not scanning JAR [{0}] from classpath jarScan.jarUrlStart=Scanning JAR at URL [{0}] jarScan.webinflibFail=Failed to scan JAR [{0}] from WEB-INF/lib jarScan.webinflibStart=Scanning WEB-INF/lib for JARs +jarScan.webinflibJarScan=Scanning JAR [{0}] from WEB-INF/lib +jarScan.webinflibJarNoScan=Not scanning JAR [{0}] from WEB-INF/lib diff --git a/java/org/apache/tomcat/util/scan/StandardJarScanner.java b/java/org/apache/tomcat/util/scan/StandardJarScanner.java index 52c8553b7..05ec3051c 100644 --- a/java/org/apache/tomcat/util/scan/StandardJarScanner.java +++ b/java/org/apache/tomcat/util/scan/StandardJarScanner.java @@ -137,9 +137,6 @@ public class StandardJarScanner implements JarScanner { } Set ignoredJarsTokens = new HashSet(); for (String pattern: ignoredJars) { - if (log.isDebugEnabled()) { - log.debug("Tokenizing " + pattern); - } ignoredJarsTokens.add(Matcher.tokenizePathAsArray(pattern)); } @@ -149,15 +146,12 @@ public class StandardJarScanner implements JarScanner { Iterator it = dirList.iterator(); while (it.hasNext()) { String path = it.next(); - if (log.isDebugEnabled()) { - log.debug("Matching path '" + path + "'"); - } if (path.endsWith(Constants.JAR_EXT) && - !Matcher.matchPath(ignoredJarsTokens, - path.substring(path.lastIndexOf('/')+1))) { + !Matcher.matchPath(ignoredJarsTokens, + path.substring(path.lastIndexOf('/')+1))) { // Need to scan this JAR if (log.isDebugEnabled()) { - log.debug("Scanning jar " + path); + log.debug(sm.getString("jarScan.webinflibJarScan", path)); } URL url = null; try { @@ -167,8 +161,8 @@ public class StandardJarScanner implements JarScanner { log.warn(sm.getString("jarScan.webinflibFail", url), e); } } else { - if (log.isDebugEnabled()) { - log.debug("Didn't scan jar " + path); + if (log.isTraceEnabled()) { + log.trace(sm.getString("jarScan.webinflibJarNoScan", path)); } } } @@ -192,15 +186,12 @@ public class StandardJarScanner implements JarScanner { // Skip JARs with known not to be interesting and JARs // in WEB-INF/lib we have already scanned - if (log.isDebugEnabled()) { - log.debug("Matching jar '" + jarName + "'"); - } if (jarName != null && !(Matcher.matchPath(ignoredJarsTokens, jarName) || urls[i].toString().contains( Constants.WEB_INF_LIB + jarName))) { if (log.isDebugEnabled()) { - log.debug("Scanning jar " + jarName); + log.debug(sm.getString("jarScan.classloaderJarScan", jarName)); } try { process(callback, urls[i]); @@ -209,8 +200,8 @@ public class StandardJarScanner implements JarScanner { "jarScan.classloaderFail",urls[i]), ioe); } } else { - if (log.isDebugEnabled()) { - log.debug("Didn't scan jar " + jarName); + if (log.isTraceEnabled()) { + log.trace(sm.getString("jarScan.classloaderJarNoScan", jarName)); } } }