use of java.util.regex.PatternSyntaxException in project DiscordSailv2 by Vaerys-Dawn.
the class TagRegex method execute.
@Override
public String execute(String from, CommandObject command, String args, List<ReplaceObject> toReplace) {
List<String> splitArgs = getSplit(from);
String test = "Testing.";
try {
test.replaceAll(splitArgs.get(0), test);
} catch (PatternSyntaxException e) {
from = replaceFirstTag(from, error);
return from;
}
from = removeFirstTag(from);
toReplace.add(new ReplaceObject(splitArgs.get(0), splitArgs.get(1)));
return from;
}
use of java.util.regex.PatternSyntaxException in project application by collectionspace.
the class GenericSearch method escapeUnescapedChars.
/**
* Escapes unescaped characters within the text of a services advanced search string.
*
* For the match patterns and replacement algorithm, see;
* http://stackoverflow.com/a/5937852 and
* http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#quoteReplacement%28java.lang.String%29
*
* @param value the original text of the search string.
* @param matchPattern a regex pattern to be matched. This pattern MUST contain exactly
* one matching group; text will be found and replaced within that group.
* @param findText some text to find within the matching group of the search string.
* @param replaceText the replacement text for the text found, if any, in that group.
* @return the text of the search string, with any character escaping performed.
*/
private static String escapeUnescapedChars(String value, String matchPattern, String findText, String replaceText) {
if (value == null || value.isEmpty()) {
return value;
}
StringBuffer sb = new StringBuffer("");
try {
final Pattern pattern = Pattern.compile(UNESCAPED_PREVIOUS_CHAR_PATTERN + matchPattern);
final Matcher matcher = pattern.matcher(value);
int groupCount = matcher.groupCount();
if (groupCount != 1) {
log.warn("Match pattern must contain exactly one matching group. Pattern " + matchPattern + " contains " + groupCount + " matching groups.");
return value;
}
while (matcher.find()) {
if (matcher.groupCount() >= 1) {
matcher.appendReplacement(sb, matcher.group(1).replace(findText, Matcher.quoteReplacement(replaceText)));
}
}
matcher.appendTail(sb);
} catch (PatternSyntaxException pse) {
log.warn("Invalid regular expression pattern " + matchPattern + ": " + pse.getMessage());
}
return sb.toString();
}
use of java.util.regex.PatternSyntaxException in project OpenOLAT by OpenOLAT.
the class UserModule method init.
@Override
public void init() {
int count = 0;
for (String regexp : loginBlacklist) {
try {
Pattern.compile(regexp);
loginBlacklistChecked.add(regexp);
} catch (PatternSyntaxException pse) {
log.error("Invalid pattern syntax in blacklist. Pattern: " + regexp + ". Removing from this entry from list ");
}
count++;
}
log.info("Successfully added " + count + " entries to login blacklist.");
String userEmailOptionalValue = getStringPropertyValue(USER_EMAIL_MANDATORY, false);
if (StringHelper.containsNonWhitespace(userEmailOptionalValue)) {
isEmailMandatory = "true".equalsIgnoreCase(userEmailOptionalValue);
}
String userEmailUniquenessOptionalValue = getStringPropertyValue(USER_EMAIL_UNIQUE, false);
if (StringHelper.containsNonWhitespace(userEmailUniquenessOptionalValue)) {
isEmailUnique = "true".equalsIgnoreCase(userEmailUniquenessOptionalValue);
}
// Check if user manager is configured properly and has user property
// handlers for the mandatory user properties used in OLAT
checkMandatoryUserProperty(UserConstants.FIRSTNAME);
checkMandatoryUserProperty(UserConstants.LASTNAME);
if (isEmailMandatory()) {
checkMandatoryUserProperty(UserConstants.EMAIL);
}
// Add controller factory extension point to launch user profile controller
NewControllerFactory.getInstance().addContextEntryControllerCreator(Identity.class.getSimpleName(), new IdentityContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator("HomeSite", new IdentityContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator("HomePage", new HomePageContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator(User.class.getSimpleName(), new UserAdminContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator(UserAdminSite.class.getSimpleName(), new UserAdminContextEntryControllerCreator());
}
use of java.util.regex.PatternSyntaxException in project opencast by opencast.
the class SakaiUserProviderInstance method verifySakaiUser.
/*
** Verify that the user exists
** Query with /direct/user/:ID:/exists
*/
private boolean verifySakaiUser(String userId) {
logger.debug("verifySakaiUser({})", userId);
try {
if ((userPattern != null) && !userId.matches(userPattern)) {
logger.debug("verify user {} failed regexp {}", userId, userPattern);
return false;
}
} catch (PatternSyntaxException e) {
logger.warn("Invalid regular expression for user pattern {} - disabling checks", userPattern);
userPattern = null;
}
int code;
try {
// This webservice does not require authentication
URL url = new URL(sakaiUrl + "/direct/user/" + userId + "/exists");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", OC_USERAGENT);
connection.connect();
code = connection.getResponseCode();
} catch (Exception e) {
logger.warn("Exception verifying Sakai user " + userId + " at " + sakaiUrl + ": " + e.getMessage());
return false;
}
// HTTP OK 200 for site exists, return false for everything else (typically 404 not found)
return (code == 200);
}
use of java.util.regex.PatternSyntaxException in project dna by leifeld.
the class TextFileImporter method patternToString.
public String patternToString(String text, String pattern) {
Pattern p;
try {
p = Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
return ("");
}
Matcher m = p.matcher(text);
if (m.find()) {
try {
String string = m.group(0);
return string;
} catch (IndexOutOfBoundsException e) {
return ("");
}
} else {
return "";
}
}
Aggregations