📄 routingcriteria.java
字号:
package org.jahia.services.usermanager;import java.util.*;import java.lang.reflect.*;/** * <p>Title: a routing criteria is a set of pattern matching rules that * define a criteria to route method calls to a specific object</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: Jahia Inc.</p> * * @author Serge Huber * @version 3.0 */class RoutingCriteria { private String name; private String description; private Properties conditions; private String destination; private JahiaUserManagerProvider providerInstance = null; public RoutingCriteria(String name, String description, Properties conditions, String destination) { this.name = name; this.description = description; this.conditions = conditions; this.destination = destination; } public String getName() { return name; } public String getDescription() { return description; } public Properties getConditions() { return conditions; } public String getDestination() { return destination; } public boolean matchesValues(Properties values) { // let's first test all the stupid stuff... if (conditions == null) { return false; } if (conditions.size() == 0) { return false; } if (values == null) { return false; } if (values.size() == 0) { return false; } // now let's do some real work guys... Enumeration valueKeys = values.keys(); while (valueKeys.hasMoreElements()) { Object curKeyObj = valueKeys.nextElement(); if (curKeyObj instanceof String) { String curKey = (String) curKeyObj; String curValue = values.getProperty(curKey); String curConditionPattern = conditions.getProperty(curKey); if (curConditionPattern != null) { // we found a matching condition for this property key if (!starMatching(curConditionPattern, curValue)) { return false; } } } } return true; } /** * Case sensitive star pattern matching. eg t*t matches "test", but not * "true" * @param starPattern * @param inputToTest * @return true if the inputToTest string matches the starPattern pattern */ private static boolean starMatching(String starPattern, String inputToTest) { // we try to make every effort to determine a match as quickly as possible, // but we must at least parse the pattern :( StringTokenizer patternTokens = new StringTokenizer(starPattern, "*", false); Vector patternMatchers = new Vector(); while (patternTokens.hasMoreTokens()) { String curToken = patternTokens.nextToken(); patternMatchers.add(curToken); } if (patternMatchers.size() == 0) { return false; } if (!starPattern.startsWith("*")) { if (!inputToTest.startsWith((String)patternMatchers.elementAt(0))) { // beginning doesn't match... return false; } } if (!starPattern.endsWith("*")) { if (!inputToTest.endsWith((String)patternMatchers.elementAt(patternMatchers.size() - 1))) { // beginning doesn't match... return false; } } Enumeration patternMatchersEnum = patternMatchers.elements(); int offsetInInput = 0; int matchPos = 0; String curMatcher = null; while (patternMatchersEnum.hasMoreElements()) { curMatcher = (String) patternMatchersEnum.nextElement(); matchPos = inputToTest.indexOf(curMatcher, offsetInInput); if (matchPos == -1) { return false; } offsetInInput = matchPos + curMatcher.length(); if (offsetInInput >= inputToTest.length()) { // we still have pattern to match but we got to the end of // the string too early. return false; } } // if we got here it means we've matched all the pattern matchers in // the input string. return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -