You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/02/15 04:43:01 UTC
svn commit: r153886 -
jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java
Author: skitching
Date: Mon Feb 14 19:43:01 2005
New Revision: 153886
URL: http://svn.apache.org/viewcvs?view=rev&rev=153886
Log:
New class containing code formerly in (deleted) class SupplementaryRuleManager.
Original author: Oliver Zeigermann
Added:
jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java (with props)
Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java?view=auto&rev=153886
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java (added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java Mon Feb 14 19:43:01 2005
@@ -0,0 +1,60 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.commons.digester2;
+
+/**
+ * A collection of static utility methods for matching patterns against
+ * xml element paths using simple matching functionality.
+ */
+
+public class SimpleMatchUtils {
+
+ /**
+ * Returns true if the pathToMatch is an absolute path that matches
+ * the input path, or if it is a relative path that matches the last
+ * part of the specified path.
+ */
+ public static boolean matches(String path, String pathToMatch) {
+ if (pathToMatch.charAt(0) == '/') {
+ // absolute
+ return path.equals(pathToMatch);
+ } else {
+ // relative
+ // XXX looks wrong but protects a match of
+ // "a/b" against a path of "/gotcha/b", but
+ // still allows
+ // "a/b" to match against "/a/b"
+ return path.endsWith("/" + pathToMatch);
+ }
+ }
+
+ /**
+ * Checks if this path matches any of the paths given. This means we
+ * iterate through <code>pathsToMatch</code> and match every entry to
+ * this path.
+ */
+ public static boolean matchsAny(String path, String[] pathsToMatch) {
+ for (int i = 0; i < pathsToMatch.length; i++) {
+ if (matches(path, pathsToMatch[i]))
+ return true;
+ }
+ return false;
+ }
+}
+
Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SimpleMatchUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org