1 package org.jahia.services.usermanager; 2 3 import java.util.Enumeration ; 4 import java.util.Properties ; 5 import java.util.StringTokenizer ; 6 import java.util.Vector ; 7 8 18 19 class RoutingCriteria { 20 21 private String name; 22 private String description; 23 private Properties conditions; 24 private String destination; 25 private JahiaUserManagerProvider providerInstance = null; 26 27 public RoutingCriteria (String name, 28 String description, 29 Properties conditions, 30 String destination) { 31 this.name = name; 32 this.description = description; 33 this.conditions = conditions; 34 this.destination = destination; 35 } 36 37 public String getName () { 38 return name; 39 } 40 41 public String getDescription () { 42 return description; 43 } 44 45 public Properties getConditions () { 46 return conditions; 47 } 48 49 public String getDestination () { 50 return destination; 51 } 52 53 54 public boolean matchesValues (Properties values) { 55 56 if (conditions == null) { 58 return false; 59 } 60 if (conditions.size () == 0) { 61 return false; 62 } 63 if (values == null) { 64 return false; 65 } 66 if (values.size () == 0) { 67 return false; 68 } 69 70 Enumeration valueKeys = values.keys (); 72 while (valueKeys.hasMoreElements ()) { 73 Object curKeyObj = valueKeys.nextElement (); 74 if (curKeyObj instanceof String ) { 75 String curKey = (String ) curKeyObj; 76 String curValue = values.getProperty (curKey); 77 String curConditionPattern = conditions.getProperty (curKey); 78 if (curConditionPattern != null) { 79 if (!starMatching (curConditionPattern, curValue)) { 81 return false; 82 } 83 } 84 } 85 } 86 return true; 87 } 88 89 98 private static boolean starMatching (String starPattern, String inputToTest) { 99 StringTokenizer patternTokens = new StringTokenizer (starPattern, "*", false); 102 Vector patternMatchers = new Vector (); 103 104 while (patternTokens.hasMoreTokens ()) { 105 String curToken = patternTokens.nextToken (); 106 patternMatchers.add (curToken); 107 } 108 109 if (patternMatchers.size () == 0) { 110 return false; 111 } 112 113 if (!starPattern.startsWith ("*")) { 114 if (!inputToTest.startsWith ((String ) patternMatchers.elementAt (0))) { 115 return false; 117 } 118 } 119 if (!starPattern.endsWith ("*")) { 120 if (!inputToTest.endsWith ( 121 (String ) patternMatchers.elementAt (patternMatchers.size () - 1))) { 122 return false; 124 } 125 } 126 127 Enumeration patternMatchersEnum = patternMatchers.elements (); 128 int offsetInInput = 0; 129 int matchPos = 0; 130 String curMatcher = null; 131 while (patternMatchersEnum.hasMoreElements ()) { 132 curMatcher = (String ) patternMatchersEnum.nextElement (); 133 matchPos = inputToTest.indexOf (curMatcher, offsetInInput); 134 if (matchPos == -1) { 135 return false; 136 } 137 offsetInInput = matchPos + curMatcher.length (); 138 if (offsetInInput >= inputToTest.length ()) { 139 return false; 142 } 143 } 144 return true; 147 } 148 149 } | Popular Tags |