All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.forge.camel.maven.EndpointHelper Maven / Gradle / Ivy

/**
 *  Copyright 2005-2015 Red Hat, Inc.
 *
 *  Red Hat 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 io.fabric8.forge.camel.maven;

import java.util.regex.PatternSyntaxException;

public final class EndpointHelper {

    /**
     * Matches the name with the given pattern.
     * 

* The match rules are applied in this order: *

    *
  • exact match, returns true
  • *
  • wildcard match (pattern ends with a * and the name starts with the pattern), returns true
  • *
  • regular expression match, returns true
  • *
  • otherwise returns false
  • *
* * @param name the name * @param pattern a pattern to match * @return true if match, false otherwise. */ public static boolean matchPattern(String name, String pattern) { if (name == null || pattern == null) { return false; } if (name.equals(pattern)) { // exact match return true; } if (matchWildcard(name, pattern)) { return true; } if (matchRegex(name, pattern)) { return true; } // no match return false; } /** * Matches the name with the given pattern. *

* The match rules are applied in this order: *

    *
  • wildcard match (pattern ends with a * and the name starts with the pattern), returns true
  • *
  • otherwise returns false
  • *
* * @param name the name * @param pattern a pattern to match * @return true if match, false otherwise. */ private static boolean matchWildcard(String name, String pattern) { // we have wildcard support in that hence you can match with: file* to match any file endpoints if (pattern.endsWith("*") && name.startsWith(pattern.substring(0, pattern.length() - 1))) { return true; } return false; } /** * Matches the name with the given pattern. *

* The match rules are applied in this order: *

    *
  • regular expression match, returns true
  • *
  • otherwise returns false
  • *
* * @param name the name * @param pattern a pattern to match * @return true if match, false otherwise. */ private static boolean matchRegex(String name, String pattern) { // match by regular expression try { if (name.matches(pattern)) { return true; } } catch (PatternSyntaxException e) { // ignore } return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy