use of java.util.regex.PatternSyntaxException in project dna by leifeld.
the class ImportOldDNA 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 "";
}
}
use of java.util.regex.PatternSyntaxException in project dna by leifeld.
the class RecodeDialog 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 "";
}
}
use of java.util.regex.PatternSyntaxException in project whole by wholeplatform.
the class GrammarsValidatorVisitor method checkPatterns.
public void checkPatterns(Grammar entity) {
AbstractPatternFilterIterator<RegExp> i = IteratorFactory.<RegExp>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.RegExp);
i.reset(entity);
for (RegExp regex : i) {
try {
Pattern.compile(regex.getValue());
} catch (PatternSyntaxException e) {
getDecorationManager().addError(regex, e.toString(), regex.getValue());
}
}
}
use of java.util.regex.PatternSyntaxException in project pwm by pwm-project.
the class LocalDBLogger method checkEventForParams.
boolean checkEventForParams(final PwmLogEvent event, final LocalDBSearchQuery searchParameters) {
if (event == null) {
return false;
}
boolean eventMatchesParams = true;
if (searchParameters.getMinimumLevel() != null) {
if (event.getLevel().compareTo(searchParameters.getMinimumLevel()) <= -1) {
eventMatchesParams = false;
}
}
Pattern pattern = null;
try {
if (searchParameters.getUsername() != null && searchParameters.getUsername().length() > 0) {
pattern = Pattern.compile(searchParameters.getUsername());
}
} catch (PatternSyntaxException e) {
LOGGER.trace("invalid regex syntax for " + searchParameters.getUsername() + ", reverting to plaintext search");
}
if (pattern != null) {
final Matcher matcher = pattern.matcher(event.getActor() == null ? "" : event.getActor());
if (!matcher.find()) {
eventMatchesParams = false;
}
} else if (eventMatchesParams && (searchParameters.getUsername() != null && searchParameters.getUsername().length() > 1)) {
final String eventUsername = event.getActor();
if (eventUsername == null || !eventUsername.equalsIgnoreCase(searchParameters.getUsername())) {
eventMatchesParams = false;
}
}
if (eventMatchesParams && (searchParameters.getText() != null && searchParameters.getText().length() > 0)) {
final String eventMessage = event.getMessage();
final String textLowercase = searchParameters.getText().toLowerCase();
boolean isAMatch = false;
if (eventMessage != null && eventMessage.length() > 0) {
if (eventMessage.toLowerCase().contains(textLowercase)) {
isAMatch = true;
} else if (event.getTopic() != null && event.getTopic().length() > 0) {
if (event.getTopic().toLowerCase().contains(textLowercase)) {
isAMatch = true;
}
}
if (!isAMatch) {
eventMatchesParams = false;
}
}
}
if (searchParameters.getEventType() != null) {
if (searchParameters.getEventType() == EventType.System) {
if (event.getActor() != null && event.getActor().length() > 0) {
eventMatchesParams = false;
}
} else if (searchParameters.getEventType() == EventType.User) {
if (event.getActor() == null || event.getActor().length() < 1) {
eventMatchesParams = false;
}
}
}
return eventMatchesParams;
}
use of java.util.regex.PatternSyntaxException in project pwm by pwm-project.
the class UrlShortenerService method shortenUrlInText.
public String shortenUrlInText(final String text) throws PwmUnrecoverableException {
final String urlRegex = pwmApplication.getConfig().readAppProperty(AppProperty.URL_SHORTNER_URL_REGEX);
try {
final Pattern p = Pattern.compile(urlRegex);
final Matcher m = p.matcher(text);
final StringBuilder result = new StringBuilder();
Boolean found = m.find();
if (found) {
int start = 0;
int end = m.start();
result.append(text.substring(start, end));
start = end;
end = m.end();
while (found) {
result.append(shortenUrl(text.substring(start, end)));
start = end;
found = m.find();
if (found) {
end = m.start();
result.append(text.substring(start, end));
start = end;
end = m.end();
}
}
result.append(text.substring(end));
return result.toString();
}
} catch (PatternSyntaxException e) {
LOGGER.error("Error compiling pattern: " + e.getMessage());
}
return text;
}
Aggregations