public T compare(String requestResource,String targetResource,boolean wildcardCompare){
  if (requestResource == null && targetResource == null) {
    return exactMatch;
  }
  if (requestResource == null || targetResource == null) {
    return noMatch;
  }
  if (!caseSensitive) {
    requestResource=requestResource.toLowerCase();
    targetResource=targetResource.toLowerCase();
  }
  requestResource=normalizeRequestResource(requestResource);
  targetResource=normalizeTargetResource(targetResource);
  if (oneLevelWildcardEmbedded && targetResource.indexOf(wildcard) == -1) {
    if (targetResource.indexOf(oneLevelWildcard) != -1 && wildcardCompare) {
      debug.message("PrefixResourceName:compare():invoking one level compare");
      return oneLevelWildcardCompare(requestResource,targetResource,wildcardCompare);
    }
  }
  if (wildcardEmbedded || !(wildcardEmbedded || oneLevelWildcardEmbedded)) {
    if (targetResource.indexOf(oneLevelWildcard) != -1 && wildcardCompare) {
      debug.message("PrefixResourceName:compare():invoking one level compare");
      return oneLevelWildcardCompare(requestResource,targetResource,wildcardCompare);
    }
  }
  int reqBegin=0;
  int reqEnd=0;
  int tarBegin=0;
  int tarEnd=0;
  int reqLen=0;
  int tarLen=0;
  String subString=null;
  reqLen=requestResource.length();
  tarLen=targetResource.length();
  tarEnd=targetResource.indexOf(wildcard,tarBegin);
  if (!wildcardCompare || tarEnd == -1) {
    if (requestResource.equals(targetResource)) {
      return exactMatch;
    }
    if (targetResource.startsWith((requestResource.endsWith(delimiter)) ? requestResource : requestResource + delimiter)) {
      return subResourceMatch;
    }
    if (requestResource.startsWith((targetResource.endsWith(delimiter)) ? targetResource : targetResource + delimiter)) {
      return superResourceMatch;
    }
    return noMatch;
  }
  subString=targetResource.substring(tarBegin,tarEnd);
  if (tarEnd > tarBegin) {
    if (!(requestResource.startsWith(subString))) {
      if (subString.startsWith((requestResource.endsWith(delimiter)) ? requestResource : requestResource + delimiter)) {
        return subResourceMatch;
      }
      return noMatch;
    }
  }
  reqBegin=tarEnd;
  if (tarEnd >= tarLen - 1) {
    return wildcardMatch;
  }
  tarBegin=tarEnd + 1;
  while ((tarEnd=targetResource.indexOf(wildcard,tarBegin)) != -1) {
    subString=targetResource.substring(tarBegin,tarEnd);
    if (tarEnd > tarBegin) {
      if ((reqBegin=requestResource.indexOf(subString,reqBegin)) == -1) {
        return subResourceMatch;
      }
    }
    if (tarEnd >= tarLen - 1) {
      return wildcardMatch;
    }
    reqBegin=reqBegin + (tarEnd - tarBegin);
    tarBegin=tarEnd + 1;
  }
  subString=targetResource.substring(tarBegin,tarLen);
  if ((reqEnd=requestResource.lastIndexOf(subString,reqLen - 1)) == -1) {
    return subResourceMatch;
  }
  if (reqBegin > reqEnd) {
    return subResourceMatch;
  }
  reqBegin=reqEnd;
  if ((reqLen - reqBegin) == (tarLen - tarBegin)) {
    return wildcardMatch;
  }
  reqBegin=reqBegin + (tarLen - tarBegin);
  subString=requestResource.substring(reqBegin,reqBegin + 1);
  if (subString.equals(delimiter)) {
    return superResourceMatch;
  }
  return subResourceMatch;
}

public T compare ( String requestResource , String targetResource , boolean wildcardCompare ) { if ( requestResource == null && targetResource == null ) { return exactMatch ; } if ( requestResource == null || targetResource == null ) { return noMatch ; } if ( ! caseSensitive ) { requestResource = requestResource . toLowerCase ( ) ; targetResource = targetResource . toLowerCase ( ) ; } requestResource = normalizeRequestResource ( requestResource ) ; targetResource = normalizeTargetResource ( targetResource ) ; if ( oneLevelWildcardEmbedded && targetResource . indexOf ( wildcard ) == - 1 ) { if ( targetResource . indexOf ( oneLevelWildcard ) != - 1 && wildcardCompare ) { debug . message ( "PrefixResourceName:compare():invoking one level compare" ) ; return oneLevelWildcardCompare ( requestResource , targetResource , wildcardCompare ) ; } } if ( wildcardEmbedded || ! ( wildcardEmbedded || oneLevelWildcardEmbedded ) ) { if ( targetResource . indexOf ( oneLevelWildcard ) != - 1 && wildcardCompare ) { debug . message ( "PrefixResourceName:compare():invoking one level compare" ) ; return oneLevelWildcardCompare ( requestResource , targetResource , wildcardCompare ) ; } } int reqBegin = 0 ; int reqEnd = 0 ; int tarBegin = 0 ; int tarEnd = 0 ; int reqLen = 0 ; int tarLen = 0 ; String subString = null ; reqLen = requestResource . length ( ) ; tarLen = targetResource . length ( ) ; tarEnd = targetResource . indexOf ( wildcard , tarBegin ) ; if ( ! wildcardCompare || tarEnd == - 1 ) { if ( requestResource . equals ( targetResource ) ) { return exactMatch ; } if ( targetResource . startsWith ( ( requestResource . endsWith ( delimiter ) ) ? requestResource : requestResource + delimiter ) ) { return subResourceMatch ; } if ( requestResource . startsWith ( ( targetResource . endsWith ( delimiter ) ) ? targetResource : targetResource + delimiter ) ) { return superResourceMatch ; } return noMatch ; } subString = targetResource . substring ( tarBegin , tarEnd ) ; if ( tarEnd > tarBegin ) { if ( ! ( requestResource . startsWith ( subString ) ) ) { if ( subString . startsWith ( ( requestResource . endsWith ( delimiter ) ) ? requestResource : requestResource + delimiter ) ) { return subResourceMatch ; } return noMatch ; } } reqBegin = tarEnd ; if ( tarEnd >= tarLen - 1 ) { return wildcardMatch ; } tarBegin = tarEnd + 1 ; while ( ( tarEnd = targetResource . indexOf ( wildcard , tarBegin ) ) != - 1 ) { subString = targetResource . substring ( tarBegin , tarEnd ) ; if ( tarEnd > tarBegin ) { if ( ( reqBegin = requestResource . indexOf ( subString , reqBegin ) ) == - 1 ) { return subResourceMatch ; } } if ( tarEnd >= tarLen - 1 ) { return wildcardMatch ; } reqBegin = reqBegin + ( tarEnd - tarBegin ) ; tarBegin = tarEnd + 1 ; } subString = targetResource . substring ( tarBegin , tarLen ) ; if ( ( reqEnd = requestResource . lastIndexOf ( subString , reqLen - 1 ) ) == - 1 ) { return subResourceMatch ; } if ( reqBegin > reqEnd ) { return subResourceMatch ; } reqBegin = reqEnd ; if ( ( reqLen - reqBegin ) == ( tarLen - tarBegin ) ) { return wildcardMatch ; } reqBegin = reqBegin + ( tarLen - tarBegin ) ; subString = requestResource . substring ( reqBegin , reqBegin + 1 ) ; if ( subString . equals ( delimiter ) ) { return superResourceMatch ; } return subResourceMatch ; }
compares two resources . description : the targetresource may contain wildcard or one level wildcard pattern but not both which matches zero or more characters . the wildcard character can show up anywhere within the string . the targetresource can contain any number of one type of wildcard characters . based on the type of wild card in the resource either regular wildcard comparison is done or one level wild card comparison is done . one of the five possible match types is returned based on how the two resource strings are related . the comparison starts from the beginning of the resource 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 .
