1 package org.jahia.services.usermanager; 2 3 11 12 import java.util.Enumeration ; 13 import java.util.Properties ; 14 import java.util.StringTokenizer ; 15 import java.util.Vector ; 16 17 27 28 29 public class GroupRoutingCriteria { 30 private String name; 31 private String description; 32 private Properties conditions; 33 private String destination; 34 private JahiaGroupManagerProvider providerInstance = null; 35 36 public GroupRoutingCriteria (String name, 37 String description, 38 Properties conditions, 39 String destination) { 40 this.name = name; 41 this.description = description; 42 this.conditions = conditions; 43 this.destination = destination; 44 } 45 46 public String getName () { 47 return name; 48 } 49 50 public String getDescription () { 51 return description; 52 } 53 54 public Properties getConditions () { 55 return conditions; 56 } 57 58 public String getDestination () { 59 return destination; 60 } 61 62 63 public boolean matchesValues (Properties values) { 64 65 if (conditions == null) { 67 return false; 68 } 69 if (conditions.size () == 0) { 70 return false; 71 } 72 if (values == null) { 73 return false; 74 } 75 if (values.size () == 0) { 76 return false; 77 } 78 79 Enumeration valueKeys = values.keys (); 81 while (valueKeys.hasMoreElements ()) { 82 Object curKeyObj = valueKeys.nextElement (); 83 if (curKeyObj instanceof String ) { 84 String curKey = (String ) curKeyObj; 85 String curValue = values.getProperty (curKey); 86 String curConditionPattern = conditions.getProperty (curKey); 87 if (curConditionPattern != null) { 88 if (!starMatching (curConditionPattern, curValue)) { 90 return false; 91 } 92 } 93 } 94 } 95 return true; 96 } 97 98 107 private static boolean starMatching (String starPattern, String inputToTest) { 108 StringTokenizer patternTokens = new StringTokenizer (starPattern, "*", false); 111 Vector patternMatchers = new Vector (); 112 113 while (patternTokens.hasMoreTokens ()) { 114 String curToken = patternTokens.nextToken (); 115 patternMatchers.add (curToken); 116 } 117 118 if (patternMatchers.size () == 0) { 119 return false; 120 } 121 122 if (!starPattern.startsWith ("*")) { 123 if (!inputToTest.startsWith ((String ) patternMatchers.elementAt (0))) { 124 return false; 126 } 127 } 128 if (!starPattern.endsWith ("*")) { 129 if (!inputToTest.endsWith ( 130 (String ) patternMatchers.elementAt (patternMatchers.size () - 1))) { 131 return false; 133 } 134 } 135 136 Enumeration patternMatchersEnum = patternMatchers.elements (); 137 int offsetInInput = 0; 138 int matchPos = 0; 139 String curMatcher = null; 140 while (patternMatchersEnum.hasMoreElements ()) { 141 curMatcher = (String ) patternMatchersEnum.nextElement (); 142 matchPos = inputToTest.indexOf (curMatcher, offsetInInput); 143 if (matchPos == -1) { 144 return false; 145 } 146 offsetInInput = matchPos + curMatcher.length (); 147 if (offsetInInput >= inputToTest.length ()) { 148 return false; 151 } 152 } 153 return true; 156 } 157 158 } 159 | Popular Tags |