public ResourceMatch compare(String requestResource,String targetResource,boolean wildcardCompare){
  int beginIndex1=0;
  int endIndex1=0;
  int beginIndex2=0;
  int endIndex2=0;
  int strlen1=0;
  int strlen2=0;
  String substr=null;
  if ((requestResource == null) && (targetResource == null)) {
    return (ResourceMatch.EXACT_MATCH);
  }
  if (((requestResource == null) || (targetResource == null))) {
    return (ResourceMatch.NO_MATCH);
  }
  if (!caseSensitive) {
    requestResource=requestResource.toLowerCase();
    targetResource=targetResource.toLowerCase();
  }
  requestResource=reverseString(requestResource);
  targetResource=reverseString(targetResource);
  while (requestResource.endsWith(delimiter)) {
    int len=requestResource.length();
    requestResource=requestResource.substring(0,len - 1);
  }
  while (targetResource.endsWith(delimiter)) {
    int len=targetResource.length();
    targetResource=targetResource.substring(0,len - 1);
  }
  strlen1=requestResource.length();
  strlen2=targetResource.length();
  endIndex2=targetResource.indexOf(wildcard,beginIndex2);
  if ((!wildcardCompare) || (endIndex2 == -1)) {
    if (requestResource.equals(targetResource)) {
      return (ResourceMatch.EXACT_MATCH);
    }
    if (targetResource.startsWith(requestResource + delimiter)) {
      return (ResourceMatch.SUB_RESOURCE_MATCH);
    }
    if (requestResource.startsWith(targetResource + delimiter)) {
      return (ResourceMatch.SUPER_RESOURCE_MATCH);
    }
    return (ResourceMatch.NO_MATCH);
  }
  substr=targetResource.substring(beginIndex2,endIndex2);
  if (endIndex2 > beginIndex2) {
    if (!(requestResource.startsWith(substr))) {
      if (substr.startsWith(requestResource + delimiter)) {
        return (ResourceMatch.SUB_RESOURCE_MATCH);
      }
      return (ResourceMatch.NO_MATCH);
    }
  }
  beginIndex1=beginIndex1 + (endIndex2 - beginIndex2);
  if (endIndex2 >= strlen2 - 1) {
    return (ResourceMatch.WILDCARD_MATCH);
  }
  beginIndex2=endIndex2 + 1;
  while ((endIndex2=targetResource.indexOf(wildcard,beginIndex2)) != -1) {
    substr=targetResource.substring(beginIndex2,endIndex2);
    if (endIndex2 > beginIndex2) {
      if ((beginIndex1=requestResource.indexOf(substr,beginIndex1)) == -1) {
        return (ResourceMatch.SUB_RESOURCE_MATCH);
      }
    }
    beginIndex1=beginIndex1 + (endIndex2 - beginIndex2);
    if (endIndex2 >= strlen2 - 1) {
      return (ResourceMatch.WILDCARD_MATCH);
    }
    beginIndex2=endIndex2 + 1;
  }
  substr=targetResource.substring(beginIndex2,strlen2);
  if ((endIndex1=requestResource.lastIndexOf(substr,strlen1 - 1)) == -1) {
    return (ResourceMatch.SUB_RESOURCE_MATCH);
  }
  if (beginIndex1 > endIndex1) {
    return (ResourceMatch.SUB_RESOURCE_MATCH);
  }
  beginIndex1=endIndex1;
  if ((strlen1 - beginIndex1) == (strlen2 - beginIndex2)) {
    return (ResourceMatch.WILDCARD_MATCH);
  }
  beginIndex1=beginIndex1 + (strlen2 - beginIndex2);
  substr=requestResource.substring(beginIndex1,beginIndex1 + 1);
  if (substr.equals(delimiter)) {
    return (ResourceMatch.SUPER_RESOURCE_MATCH);
  }
  return (ResourceMatch.SUB_RESOURCE_MATCH);
}

public ResourceMatch compare ( String requestResource , String targetResource , boolean wildcardCompare ) { int beginIndex1 = 0 ; int endIndex1 = 0 ; int beginIndex2 = 0 ; int endIndex2 = 0 ; int strlen1 = 0 ; int strlen2 = 0 ; String substr = null ; if ( ( requestResource == null ) && ( targetResource == null ) ) { return ( ResourceMatch . EXACT_MATCH ) ; } if ( ( ( requestResource == null ) || ( targetResource == null ) ) ) { return ( ResourceMatch . NO_MATCH ) ; } if ( ! caseSensitive ) { requestResource = requestResource . toLowerCase ( ) ; targetResource = targetResource . toLowerCase ( ) ; } requestResource = reverseString ( requestResource ) ; targetResource = reverseString ( targetResource ) ; while ( requestResource . endsWith ( delimiter ) ) { int len = requestResource . length ( ) ; requestResource = requestResource . substring ( 0 , len - 1 ) ; } while ( targetResource . endsWith ( delimiter ) ) { int len = targetResource . length ( ) ; targetResource = targetResource . substring ( 0 , len - 1 ) ; } strlen1 = requestResource . length ( ) ; strlen2 = targetResource . length ( ) ; endIndex2 = targetResource . indexOf ( wildcard , beginIndex2 ) ; if ( ( ! wildcardCompare ) || ( endIndex2 == - 1 ) ) { if ( requestResource . equals ( targetResource ) ) { return ( ResourceMatch . EXACT_MATCH ) ; } if ( targetResource . startsWith ( requestResource + delimiter ) ) { return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; } if ( requestResource . startsWith ( targetResource + delimiter ) ) { return ( ResourceMatch . SUPER_RESOURCE_MATCH ) ; } return ( ResourceMatch . NO_MATCH ) ; } substr = targetResource . substring ( beginIndex2 , endIndex2 ) ; if ( endIndex2 > beginIndex2 ) { if ( ! ( requestResource . startsWith ( substr ) ) ) { if ( substr . startsWith ( requestResource + delimiter ) ) { return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; } return ( ResourceMatch . NO_MATCH ) ; } } beginIndex1 = beginIndex1 + ( endIndex2 - beginIndex2 ) ; if ( endIndex2 >= strlen2 - 1 ) { return ( ResourceMatch . WILDCARD_MATCH ) ; } beginIndex2 = endIndex2 + 1 ; while ( ( endIndex2 = targetResource . indexOf ( wildcard , beginIndex2 ) ) != - 1 ) { substr = targetResource . substring ( beginIndex2 , endIndex2 ) ; if ( endIndex2 > beginIndex2 ) { if ( ( beginIndex1 = requestResource . indexOf ( substr , beginIndex1 ) ) == - 1 ) { return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; } } beginIndex1 = beginIndex1 + ( endIndex2 - beginIndex2 ) ; if ( endIndex2 >= strlen2 - 1 ) { return ( ResourceMatch . WILDCARD_MATCH ) ; } beginIndex2 = endIndex2 + 1 ; } substr = targetResource . substring ( beginIndex2 , strlen2 ) ; if ( ( endIndex1 = requestResource . lastIndexOf ( substr , strlen1 - 1 ) ) == - 1 ) { return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; } if ( beginIndex1 > endIndex1 ) { return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; } beginIndex1 = endIndex1 ; if ( ( strlen1 - beginIndex1 ) == ( strlen2 - beginIndex2 ) ) { return ( ResourceMatch . WILDCARD_MATCH ) ; } beginIndex1 = beginIndex1 + ( strlen2 - beginIndex2 ) ; substr = requestResource . substring ( beginIndex1 , beginIndex1 + 1 ) ; if ( substr . equals ( delimiter ) ) { return ( ResourceMatch . SUPER_RESOURCE_MATCH ) ; } return ( ResourceMatch . SUB_RESOURCE_MATCH ) ; }
compares two resources . description : the targetresource may contain wildcard ' * ' which matches zero or more characters . the wildcard character can show up anywhere within the string . the targetresource can contain any number of wildcard characters . one of the five possible match types is returned based on how the two resource strings are related . the comparison starts from the end of the reource strings . resourcematch . no_match means two resources don ' t match . resourcematch . exact_match means two resources match . resourcematch . sub_resource_match means targetresource is the sub resource of the requestresource . resourcematch . super_resource_match means targetresource is the super resource of the requestresource . resourcematch . wildcard_match means two resources match with respect to the wildcard .
