use of java.util.regex.PatternSyntaxException in project cerberus-source by cerberustesting.
the class ControlService method VerifyTextNotInPage.
private MessageEvent VerifyTextNotInPage(TestCaseExecution tCExecution, String regex) {
LOG.debug("Control : VerifyTextNotInPage on : " + regex);
MessageEvent mes;
if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getApplicationObj().getType()) || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getApplicationObj().getType()) || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getApplicationObj().getType())) {
String pageSource;
try {
pageSource = this.webdriverService.getPageSource(tCExecution.getSession());
if (LOG.isDebugEnabled()) {
LOG.debug(pageSource);
}
try {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(pageSource);
if (!(matcher.find())) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINPAGE);
mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE);
mes.setDescription(mes.getDescription().replace("%STRING1%", Pattern.quote(regex)));
return mes;
}
} catch (PatternSyntaxException e) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE_INVALIDPATERN);
mes.setDescription(mes.getDescription().replace("%PATERN%", Pattern.quote(regex)));
mes.setDescription(mes.getDescription().replace("%ERROR%", e.getMessage()));
return mes;
}
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyTextNotInPage"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
}
use of java.util.regex.PatternSyntaxException in project jmeter-plugins by undera.
the class PageDataExtractorOverTimeGui method processPageLabel.
private void processPageLabel(String pageBody, String label, String regExpValue, boolean isDelta, long time) {
Pattern patternValue = patterns.get(regExpValue);
if (patternValue == null) {
try {
patternValue = Pattern.compile(regExpValue);
patterns.put(regExpValue, patternValue);
} catch (PatternSyntaxException ex) {
log.error("Error compiling pattern: " + regExpValue);
}
}
if (patternValue != null) {
Matcher mValue = patternValue.matcher(pageBody);
int counter = 0;
while (mValue.find()) {
counter++;
String key;
if (counter > 1) {
key = label + " (" + counter + ")";
} else {
key = label;
}
String sValue = mValue.group(1);
try {
double value = Double.parseDouble(sValue);
if (isDelta) {
if (oldValues.containsKey(key)) {
double delta = value - oldValues.get(key);
addRecord(key, time, delta);
}
oldValues.put(key, value);
} else {
addRecord(key, time, value);
}
} catch (NumberFormatException ex) {
log.error("Value extracted is not a number: " + sValue);
}
}
if (counter == 0) {
log.warn("No data found for regExpValue: " + regExpValue);
}
}
}
use of java.util.regex.PatternSyntaxException in project wigle-wifi-wardriving by wiglenet.
the class FilterMatcher method getSsidFilterMatcher.
public static Matcher getSsidFilterMatcher(final SharedPreferences prefs, final String prefix) {
final String regex = prefs.getString(prefix + ListFragment.PREF_MAPF_REGEX, "");
Matcher matcher = null;
if (isSsidFilterOn(prefs, prefix) && regex != null && !"".equals(regex)) {
try {
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher("");
} catch (PatternSyntaxException ex) {
MainActivity.error("regex pattern exception: " + ex);
}
}
return matcher;
}
use of java.util.regex.PatternSyntaxException in project usbdm-eclipse-plugins by podonoghue.
the class DeviceSelectorPanel method createControl.
/**
* Create control composite
*
* @param parent
*/
private void createControl(Composite parent) {
setLayout(new GridLayout(3, false));
Label label = new Label(this, SWT.NONE);
label.setText("Search Filter: ");
fDeviceText = new Text(this, SWT.BORDER);
fDeviceText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
fDeviceText.setToolTipText("Filter/name of device");
fDeviceText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
}
@Override
public void focusGained(FocusEvent e) {
fDeviceText.selectAll();
}
});
fDeviceText.setText(NO_DEVICE_STRING);
fDeviceText.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
e.text = e.text.toUpperCase();
if (!e.text.matches("[A-Z|0-9|_\\-]*")) {
e.doit = false;
}
}
});
fDeviceText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
fMatchErrorMsg = null;
try {
filter = new NameFilter(fDeviceText.getText());
} catch (PatternSyntaxException e) {
fMatchErrorMsg = "Illegal filter";
filter = Filter.NullNameFilter;
}
filterNodes();
}
});
fButton = new Button(this, SWT.NONE);
fButton.setText("X");
fButton.setToolTipText("Clear filter");
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
gd.widthHint = 40;
fButton.setLayoutData(gd);
fButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
fDeviceText.setText(NO_DEVICE_STRING);
fDeviceText.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
fViewer = new TreeViewer(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
fViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
fViewer.getTree().setToolTipText("Available devices");
fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// System.err.println("selectionChanged() "+event);
if (!((TreeViewer) event.getSource()).getControl().isFocusControl()) {
// Filter selection events due to re-population of tree i.e. when tree doesn't have focus
return;
}
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
Object domain = iterator.next();
if (domain instanceof DeviceModel) {
DeviceModel deviceModel = (DeviceModel) domain;
fDeviceName = deviceModel.getName();
fDeviceText.setText(fDeviceName);
}
}
}
});
fViewer.setContentProvider(new ViewContentProvider());
fViewer.setInput(fModel);
fViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object item) {
if (item instanceof BaseModel) {
boolean rv = ((BaseModel) item).isAvailable();
return rv;
}
return true;
}
});
fViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
if (fMatchingNodesCount <= EXPAND_THRESHOLD) {
return;
}
Object domain = event.getElement();
if (domain instanceof CategoryModel) {
CategoryModel deviceModel = (CategoryModel) domain;
BaseModel parent = deviceModel.getParent();
for (BaseModel sibling : parent.getChildren()) {
if (sibling == domain) {
continue;
}
fViewer.collapseToLevel(sibling, AbstractTreeViewer.ALL_LEVELS);
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent arg0) {
}
});
}
use of java.util.regex.PatternSyntaxException in project DiscordSailv2 by Vaerys-Dawn.
the class Utility method getUser.
public static UserObject getUser(CommandObject command, String args, boolean doContains, boolean hasProfile) {
if (args != null && !args.isEmpty()) {
IUser user = null;
IUser conUser = null;
String toTest;
if (args.split(" ").length != 1) {
toTest = escapeRegex(args);
} else {
toTest = escapeRegex(args).replace("_", "[_| ]");
}
List<IUser> guildUsers = command.guild.getUsers();
guildUsers.sort(Comparator.comparing(o -> o.getRolesForGuild(command.guild.get()).size()));
Collections.reverse(guildUsers);
for (IUser u : guildUsers) {
if (user != null) {
break;
}
try {
UserObject object = new UserObject(u, command.guild, true);
if (hasProfile) {
ProfileObject profile = object.getProfile(command.guild);
if (profile == null || profile.isEmpty())
continue;
}
if ((u.getName() + "#" + u.getDiscriminator()).matches("(?i)" + toTest)) {
user = u;
}
if (u.getName().matches("(?i)" + toTest) && user == null) {
user = u;
}
String displayName = u.getDisplayName(command.guild.get());
if (displayName.matches("(?i)" + toTest) && user == null) {
user = u;
}
if (doContains && conUser == null) {
if (u.getName().matches("(?i).*" + toTest + ".*")) {
conUser = u;
}
if (displayName.matches("(?i).*" + toTest + ".*") && conUser == null) {
conUser = u;
}
}
} catch (PatternSyntaxException e) {
// continue.
}
}
UserObject userObject = null;
try {
long uID = Long.parseLong(args);
return new UserObject(uID, command.guild);
} catch (NumberFormatException e) {
if (command.message.get().getMentions().size() > 0) {
user = command.message.get().getMentions().get(0);
}
}
if (user == null && doContains) {
user = conUser;
}
if (user != null) {
userObject = new UserObject(user, command.guild);
}
return userObject;
}
return null;
}
Aggregations