final String strContainKey = new String(
tempBuffer.delete(0, SPConstants.CONTAINS.length()));
RE re;
try {
re = new RE(strContainKey); // with case
final REMatch reMatch = re.getMatch(strValue);
if (reMatch != null) {
return true;
}
return false;
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
}
// handle regexp
// if pattern starts with "regexp:", then check for regex match with
// case
if (pattern.startsWith(SPConstants.REGEXP)) {
final StringBuffer tempBuffer = new StringBuffer(pattern);
final String strRegexPattrn = new String(
tempBuffer.delete(0, SPConstants.REGEXP.length()));
RE re;
try {
re = new RE(strRegexPattrn);
final REMatch reMatch = re.getMatch(strValue);
if (reMatch != null) {
return true;
}
return false;
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
}
// handle regexpCase
// if pattern starts with "regexpCase:", then check for regex match with
// case
if (pattern.startsWith(SPConstants.REGEXP_CASE)) {
final StringBuffer tempBuffer = new StringBuffer(pattern);
final String strRegexCasePattrn = new String(
tempBuffer.delete(0, SPConstants.REGEXP_CASE.length()));
RE re;
try {
re = new RE(strRegexCasePattrn);
final REMatch reMatch = re.getMatch(strValue);
if (reMatch != null) {
return true;
}
return false;
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
}
// handle regexpIgnoreCase
// if pattern starts with "regexpIgnoreCase:", then check for regex
// match without case
if (pattern.startsWith(SPConstants.REGEXP_IGNORE_CASE)) {
final StringBuffer tempBuffer = new StringBuffer(pattern);
final String strRegexIgnoreCasePattrn = new String(
tempBuffer.delete(0, SPConstants.REGEXP_IGNORE_CASE.length()));
RE re;
try {
re = new RE(strRegexIgnoreCasePattrn, RE.REG_ICASE); // ignore
// case
final REMatch reMatch = re.getMatch(strValue);
if (reMatch != null) {
return true;
}
return false;
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
}
// handle "^" and "$"
if (pattern.startsWith(SPConstants.CARET)
|| pattern.endsWith(SPConstants.DOLLAR)) {
StringBuffer tempBuffer = new StringBuffer(pattern);
boolean bDollar = false;
String strValueModified = strValue;
if (pattern.startsWith(SPConstants.CARET)) {
URL urlValue;
try {
urlValue = new URL(strValue);
int port = urlValue.getPort();
if (port == -1) {
port = urlValue.getDefaultPort();
strValueModified = urlValue.getProtocol() + SPConstants.URL_SEP
+ urlValue.getHost() + SPConstants.COLON + port
+ urlValue.getFile();
}
} catch (final MalformedURLException e1) {
LOGGER.log(Level.FINE, e1.getMessage());
return false;
}
tempBuffer = new StringBuffer(pattern);
final int indexOfStar = tempBuffer.indexOf("*");
if (indexOfStar != -1) {
tempBuffer.replace(indexOfStar, indexOfStar + "*".length(), "[0-9].*");
} else {
tempBuffer.delete(0, "^".length());
if (pattern.endsWith(SPConstants.DOLLAR)) {
bDollar = true;
tempBuffer.delete(tempBuffer.length() - SPConstants.DOLLAR.length(), tempBuffer.length());
}
try {
final URL urlPatt = new URL(tempBuffer.toString());
final int port = urlPatt.getPort();
final String strHost = urlPatt.getHost().toString();
if ((port == -1) && (strHost != null) && (strHost.length() != 0)) {
tempBuffer = new StringBuffer("^" + urlPatt.getProtocol()
+ SPConstants.URL_SEP + urlPatt.getHost() + ":[0-9].*"
+ urlPatt.getPath());
}
if (bDollar) {
tempBuffer.append(SPConstants.DOLLAR);
}
} catch (final MalformedURLException e) {
LOGGER.log(Level.FINE, e.getMessage());
tempBuffer = new StringBuffer(pattern);
}
}
}
RE re;
try {
re = new RE(tempBuffer);
final REMatch reMatch = re.getMatch(strValueModified);
if (reMatch != null) {
return true;
}
return false;
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
}
// url decode the pattern
String patternDecoded = pattern;
try {
patternDecoded = URLDecoder.decode(pattern, "UTF-8");
} catch (final Exception e) {
LOGGER.log(Level.FINE, e.getMessage());
patternDecoded = pattern;
}
if (patternDecoded == null) {
return false;
}
boolean containProtocol = false;
try {
final RE re = new RE(SPConstants.URL_SEP);
final REMatch reMatch = re.getMatch(patternDecoded);
if (reMatch != null) {
containProtocol = true; // protocol is present
}
} catch (final REException e) {
containProtocol = false;
}
if (containProtocol) {
// split the test URL into two parts
String urlValue1stPart = null;
String urlValue2ndPart = null;
URL urlValue;
try {
urlValue = new URL(strValue);
int port = urlValue.getPort();
if (port == -1) {
port = urlValue.getDefaultPort();
}
urlValue1stPart = urlValue.getProtocol() + SPConstants.URL_SEP
+ urlValue.getHost() + SPConstants.COLON + port;
urlValue2ndPart = urlValue.getFile();
if (urlValue2ndPart != null) {
if (!urlValue2ndPart.startsWith(SPConstants.SLASH)) {
urlValue2ndPart = SPConstants.SLASH + urlValue2ndPart;
}
}
} catch (final MalformedURLException e1) {
LOGGER.log(Level.FINE, e1.getMessage());
return false;
}
// split the pattern into two parts
String urlPatt1stPart = null;
String urlPatt2ndPart = null;
boolean bPortStar = false;
try {
final URL urlPatt = new URL(patternDecoded);
final int port = urlPatt.getPort();
String strPort = "";
if (port == -1) {
strPort = "[0-9].*";
} else {
strPort = port + "";
}
urlPatt1stPart = "^" + urlPatt.getProtocol() + SPConstants.URL_SEP
+ urlPatt.getHost() + SPConstants.COLON + strPort;
if (!(urlPatt.getFile()).startsWith(SPConstants.SLASH)) { // The
// pattern
// must
// have
// "/"
// at
// after
// the
// port
return false;
}
urlPatt2ndPart = "^" + urlPatt.getFile();
} catch (final MalformedURLException e) {
LOGGER.log(Level.FINE, e.getMessage());
bPortStar = true;
}
if (bPortStar) {
final int indexOfStar = patternDecoded.indexOf("*");
if (indexOfStar != -1) {
urlPatt1stPart = "^" + patternDecoded.substring(0, indexOfStar)
+ "[0-9].*";
if (!(patternDecoded.substring(indexOfStar + 1)).startsWith(SPConstants.SLASH)) {
return false;
}
urlPatt2ndPart = "^" + patternDecoded.substring(indexOfStar + 1);
}
}
// check 1st part of both with ignorecase
RE re;
try {
re = new RE(urlPatt1stPart, RE.REG_ICASE); // ignore case for
// 1st part
REMatch reMatch = re.getMatch(urlValue1stPart);
if (reMatch != null) {
// check 2nd part of both with case
re = new RE(urlPatt2ndPart);
reMatch = re.getMatch(urlValue2ndPart);
if (reMatch != null) {
return true;
}
}
} catch (final REException e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
} catch (final Exception e) {
LOGGER.log(Level.FINE, e.getMessage());
return false;
}
} else {
String pat1 = null;
String pat2 = null;
// split the pattern into two parts
if (patternDecoded.indexOf(SPConstants.SLASH) != -1) {
if (patternDecoded.indexOf(SPConstants.COLON) == -1) {
pat1 = patternDecoded.substring(0, patternDecoded.indexOf(SPConstants.SLASH))
+ ":[0-9].*";
} else {
pat1 = patternDecoded.substring(0, patternDecoded.indexOf(SPConstants.SLASH));
}
pat2 = patternDecoded.substring(patternDecoded.indexOf(SPConstants.SLASH));
} else {
// The pattern must have "/" at after the port
return false;
}
pat1 = "^.*://.*" + pat1;
pat2 = "^" + pat2;
URL urlValue;
try {
urlValue = new URL(strValue);
int port = urlValue.getPort();
if (port == -1) {
port = urlValue.getDefaultPort();
}
final String urlValue1stPart = urlValue.getProtocol()
+ SPConstants.URL_SEP + urlValue.getHost() + SPConstants.COLON
+ port;
String urlValue2ndPart = urlValue.getFile();
if (urlValue2ndPart != null) {
if (!urlValue2ndPart.startsWith(SPConstants.SLASH)) {
urlValue2ndPart = SPConstants.SLASH + urlValue2ndPart;
}
}
RE re;
try {
re = new RE(pat1, RE.REG_ICASE); // ignore case for 1st part
REMatch reMatch = re.getMatch(urlValue1stPart);
if (reMatch != null) {
re = new RE(pat2); // with case for 2nd part
reMatch = re.getMatch(urlValue2ndPart);
if (reMatch != null) {
return true;