Search in sources :

Example 81 with PatternSyntaxException

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;
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) MessageEvent(org.cerberus.engine.entity.MessageEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 82 with PatternSyntaxException

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);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 83 with PatternSyntaxException

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 84 with PatternSyntaxException

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) {
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) VerifyListener(org.eclipse.swt.events.VerifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) Text(org.eclipse.swt.widgets.Text) GridData(org.eclipse.swt.layout.GridData) FocusListener(org.eclipse.swt.events.FocusListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 85 with PatternSyntaxException

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;
}
Also used : com.github.vaerys.objects(com.github.vaerys.objects) java.util(java.util) RequestHandler(com.github.vaerys.handlers.RequestHandler) GuildObject(com.github.vaerys.masterobjects.GuildObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) SAILType(com.github.vaerys.enums.SAILType) GuildHandler(com.github.vaerys.handlers.GuildHandler) StringUtils(org.apache.commons.lang3.StringUtils) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandObject(com.github.vaerys.commands.CommandObject) Logger(org.slf4j.Logger) PatternSyntaxException(java.util.regex.PatternSyntaxException) MalformedURLException(java.net.MalformedURLException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) EmojiManager(com.vdurmont.emoji.EmojiManager) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) Stream(java.util.stream.Stream) StringHandler(com.github.vaerys.handlers.StringHandler) UserObject(com.github.vaerys.masterobjects.UserObject) Command(com.github.vaerys.templates.Command) Emoji(com.vdurmont.emoji.Emoji) Pattern(java.util.regex.Pattern) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) UserObject(com.github.vaerys.masterobjects.UserObject) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

PatternSyntaxException (java.util.regex.PatternSyntaxException)355 Pattern (java.util.regex.Pattern)190 Matcher (java.util.regex.Matcher)115 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)25 List (java.util.List)19 File (java.io.File)14 Map (java.util.Map)12 HashMap (java.util.HashMap)9 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Iterator (java.util.Iterator)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 BufferedReader (java.io.BufferedReader)6 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 InputStreamReader (java.io.InputStreamReader)4 SQLException (java.sql.SQLException)4 LinkedHashMap (java.util.LinkedHashMap)4