Example usage for java.util.regex Pattern CASE_INSENSITIVE

List of usage examples for java.util.regex Pattern CASE_INSENSITIVE

Introduction

In this page you can find the example usage for java.util.regex Pattern CASE_INSENSITIVE.

Prototype

int CASE_INSENSITIVE

To view the source code for java.util.regex Pattern CASE_INSENSITIVE.

Click Source Link

Document

Enables case-insensitive matching.

Usage

From source file:com.github.zhanhb.ckfinder.connector.handlers.command.FileUploadCommand.java

private boolean isProtectedName(String nameWithoutExtension) {
    return Pattern.compile("^(AUX|COM\\d|CLOCK\\$|CON|NUL|PRN|LPT\\d)$", Pattern.CASE_INSENSITIVE)
            .matcher(nameWithoutExtension).matches();
}

From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java

private static boolean isNight(String text) {
    String patternStr = "night|tonight";
    Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(text);
    boolean matchFound = matcher.find();

    return matchFound;
}

From source file:games.strategy.triplea.pbem.AxisAndAlliesForumPoster.java

public boolean postTurnSummary(final String message, final String subject) {
    try {/* w  w  w. j av a  2 s.c  om*/
        login();

        // Now we load the post page, and find the hidden fields needed to post
        final GetMethod get = new GetMethod(
                "http://www.axisandallies.org/forums/index.php?action=post;topic=" + m_topicId + ".0");
        int status = m_client.executeMethod(m_hostConfiguration, get, m_httpState);
        String body = get.getResponseBodyAsString();
        if (status == 200) {
            String numReplies;
            String seqNum;
            String sc;
            Matcher m = NUM_REPLIES_PATTERN.matcher(body);
            if (m.matches()) {
                numReplies = m.group(1);
            } else {
                throw new Exception("Hidden field 'num_replies' not found on page");
            }

            m = SEQ_NUM_PATTERN.matcher(body);
            if (m.matches()) {
                seqNum = m.group(1);
            } else {
                throw new Exception("Hidden field 'seqnum' not found on page");
            }

            m = SC_PATTERN.matcher(body);
            if (m.matches()) {
                sc = m.group(1);
            } else {
                throw new Exception("Hidden field 'sc' not found on page");
            }

            // now we have the required hidden fields to reply to
            final PostMethod post = new PostMethod(
                    "http://www.axisandallies.org/forums/index.php?action=post2;start=0;board=40");

            try {
                // Construct the multi part post
                final List<Part> parts = new ArrayList<Part>();

                parts.add(createStringPart("topic", m_topicId));
                parts.add(createStringPart("subject", subject));
                parts.add(createStringPart("icon", "xx"));
                parts.add(createStringPart("message", message));

                // If the user has chosen to receive notifications, ensure this setting is passed on
                parts.add(createStringPart("notify", NOTIFY_PATTERN.matcher(body).matches() ? "1" : "0"));

                if (m_includeSaveGame && m_saveGameFile != null) {
                    final FilePart part = new FilePart("attachment[]", m_saveGameFileName, m_saveGameFile);
                    part.setContentType("application/octet-stream");
                    part.setTransferEncoding(null);
                    part.setCharSet(null);
                    parts.add(part);
                }

                parts.add(createStringPart("post", "Post"));
                parts.add(createStringPart("num_replies", numReplies));
                parts.add(createStringPart("additional_options", "1"));
                parts.add(createStringPart("sc", sc));
                parts.add(createStringPart("seqnum", seqNum));

                final MultipartRequestEntity entity = new MultipartRequestEntity(
                        parts.toArray(new Part[parts.size()]), new HttpMethodParams());
                post.setRequestEntity(entity);

                // add headers
                post.addRequestHeader("Referer",
                        "http://www.axisandallies.org/forums/index.php?action=post;topic=" + m_topicId
                                + ".0;num_replies=" + numReplies);
                post.addRequestHeader("Accept", "*/*");

                try {
                    // the site has spam prevention which means you can't post until 15 seconds after login
                    Thread.sleep(15 * 1000);
                } catch (final InterruptedException ie) {
                    ie.printStackTrace(); // this should never happen
                }

                post.setFollowRedirects(false);
                status = m_client.executeMethod(m_hostConfiguration, post, m_httpState);
                body = post.getResponseBodyAsString();
                if (status == 302) {
                    // site responds with a 302 redirect back to the forum index (board=40)

                    // The syntax for post is ".....topic=xx.yy" where xx is the thread id, and yy is the post number in the given thread
                    // since the site is lenient we can just give a high post_number to go to the last post in the thread
                    m_turnSummaryRef = "http://www.axisandallies.org/forums/index.php?topic=" + m_topicId
                            + ".10000";
                } else {
                    // these two patterns find general errors, where the first pattern checks if the error text appears,
                    // the second pattern extracts the error message. This could be the "The last posting from your IP was less than 15 seconds ago.Please try again later"

                    // this patter finds errors that are marked in red (for instance "You are not allowed to post URLs", or
                    // "Some one else has posted while you vere reading"

                    Matcher matcher = ERROR_LIST_PATTERN.matcher(body);
                    if (matcher.matches()) {
                        throw new Exception("The site gave an error: '" + matcher.group(1) + "'");
                    }

                    matcher = AN_ERROR_OCCURRED_PATTERN.matcher(body);
                    if (matcher.matches()) {
                        matcher = ERROR_TEXT_PATTERN.matcher(body);
                        if (matcher.matches()) {
                            throw new Exception("The site gave an error: '" + matcher.group(1) + "'");
                        }
                    }

                    final Header refreshHeader = post.getResponseHeader("Refresh");
                    if (refreshHeader != null) {
                        // sometimes the message will be flagged as spam, and a refresh url is given
                        final String value = refreshHeader.getValue(); // refresh: 0; URL=http://...topic=26114.new%3bspam=true#new
                        final Pattern p = Pattern.compile("[^;]*;\\s*url=.*spam=true.*",
                                Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
                        m = p.matcher(value);
                        if (m.matches()) {
                            throw new Exception("The summary was posted but was flagged as spam");
                        }
                    }
                    throw new Exception(
                            "Unknown error, please contact the forum owner and also post a bug to the tripleA development team");
                }
            } finally {
                post.releaseConnection();
                // Commented out log out call since it was causing all of a user's sessions to be logged out and doesn't appear to be needed
                // final GetMethod logout = new GetMethod("http://www.axisandallies.org/forums/index.php?action=logout;sesc=" + sc);
                // try
                // {
                // status = m_client.executeMethod(m_hostConfiguration, logout, m_httpState);
                // // site responds with a 200 + Refresh header to redirect to index.php
                // if (status != 200)
                // {
                // // nothing we can do if this fails
                // }
                // } finally
                // {
                // logout.releaseConnection();
                // }
            }
        } else {
            throw new Exception("Unable to load forum post " + m_topicId);
        }

    } catch (final Exception e) {
        m_turnSummaryRef = e.getMessage();
        return false;
    }

    return true;
}

From source file:esg.node.components.monitoring.MonitorDAO.java

private void loadMemInfoResource() {
    memInfoResource = new InfoResources("/proc/meminfo",
            Integer.parseInt(props.getProperty("monitor.buffer.meminfo", "-1")));
    memInfoPattern_memTotal = Pattern.compile("(?:MemTotal)\\s*:\\s*(\\d*)\\s*kB.*", Pattern.CASE_INSENSITIVE);
    memInfoPattern_memFree = Pattern.compile("(?:MemFree)\\s*:\\s*(\\d*)\\s*kB.*", Pattern.CASE_INSENSITIVE);
    memInfoPattern_swapTotal = Pattern.compile("(?:SwapTotal)\\s*:\\s*(\\d*)\\s*kB.*",
            Pattern.CASE_INSENSITIVE);
    memInfoPattern_swapFree = Pattern.compile("(?:SwapFree)\\s*:\\s*(\\d*)\\s*kB.*", Pattern.CASE_INSENSITIVE);
}

From source file:com.afis.jx.ckfinder.connector.handlers.command.FileUploadCommand.java

/**
 * if file exists this method adds (number) to file.
 *
 * @param path folder/* w  w w .ja  va 2  s  .  c o  m*/
 * @param name file name
 * @return new file name.
 */
private String getFinalFileName(final String path, final String name) {
    File file = new File(path, name);
    int number = 0;

    String nameWithoutExtension = FileUtils.getFileNameWithoutExtension(name, false);
    Pattern p = Pattern.compile("^(AUX|COM\\d|CLOCK\\$|CON|NUL|PRN|LPT\\d)$", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(nameWithoutExtension);
    boolean protectedName = m.find();

    while (true) {
        if (file.exists() || protectedName) {
            number++;
            StringBuilder sb = new StringBuilder();
            sb.append(FileUtils.getFileNameWithoutExtension(name, false));
            sb.append("(").append(number).append(").");
            sb.append(FileUtils.getFileExtension(name, false));
            this.newFileName = sb.toString();
            file = new File(path, this.newFileName);
            this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
            protectedName = false;
        } else {
            return this.newFileName;
        }
    }
}

From source file:com.careerly.utils.TextUtils.java

/**
 * ????html//from  w ww  . jav  a2  s .c  o  m
 *
 * @param inputString
 * @return
 */
public static boolean validateStructureHtml(String inputString) {
    Pattern pattern = Pattern.compile("<[a-zA-Z]+[1-9]?[^><]*>|</[a-zA-Z]+[1-9]?>|\\&[a-zA-Z]{1,10};",
            Pattern.CASE_INSENSITIVE);
    return pattern.matcher(inputString).find();
}

From source file:com.ibuildapp.romanblack.TableReservationPlugin.TableReservationEMailSignUpActivity.java

/**
 * Validate input data and signs up new user on iBuildApp.
 *///from w w  w  .  j  a v a 2s  .  c o  m
private void registration() {
    if (signUpActive) {
        handler.sendEmptyMessage(SHOW_PROGRESS_DIALOG);

        new Thread(new Runnable() {
            public void run() {

                HttpParams params = new BasicHttpParams();
                params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
                HttpClient httpClient = new DefaultHttpClient(params);

                try {
                    HttpPost httpPost = new HttpPost(TableReservationHTTP.SIGNUP_URL);

                    String firstNameString = firstNameEditText.getText().toString();
                    String lastNameString = lastNameEditText.getText().toString();
                    String emailString = emailEditText.getText().toString();
                    String passwordString = passwordEditText.getText().toString();
                    String rePasswordString = rePasswordEditText.getText().toString();

                    MultipartEntity multipartEntity = new MultipartEntity();
                    multipartEntity.addPart("firstname",
                            new StringBody(firstNameString, Charset.forName("UTF-8")));
                    multipartEntity.addPart("lastname",
                            new StringBody(lastNameString, Charset.forName("UTF-8")));
                    multipartEntity.addPart("email", new StringBody(emailString, Charset.forName("UTF-8")));
                    multipartEntity.addPart("password",
                            new StringBody(passwordString, Charset.forName("UTF-8")));
                    multipartEntity.addPart("password_confirm",
                            new StringBody(rePasswordString, Charset.forName("UTF-8")));

                    // add security part
                    multipartEntity.addPart("app_id", new StringBody(Statics.appId, Charset.forName("UTF-8")));
                    multipartEntity.addPart("token",
                            new StringBody(Statics.appToken, Charset.forName("UTF-8")));

                    httpPost.setEntity(multipartEntity);

                    String resp = httpClient.execute(httpPost, new BasicResponseHandler());

                    fwUser = JSONParser.parseLoginRequestString(resp);

                    if (fwUser == null) {
                        handler.sendEmptyMessage(EMEIL_IN_USE);
                        handler.sendEmptyMessage(HIDE_PROGRESS_DIALOG);
                        return;
                    }

                    handler.sendEmptyMessage(HIDE_PROGRESS_DIALOG);

                    handler.sendEmptyMessage(CLOSE_ACTIVITY_OK);

                } catch (Exception e) {
                    handler.sendEmptyMessage(CLOSE_ACTIVITY_BAD);
                }

            }
        }).start();
    } else {
        if (firstNameEditText.getText().toString().length() == 0
                || lastNameEditText.getText().toString().length() == 0
                || emailEditText.getText().toString().length() == 0
                || passwordEditText.getText().toString().length() == 0
                || rePasswordEditText.getText().toString().length() == 0) {
            Toast.makeText(this, R.string.alert_registration_fillin_fields, Toast.LENGTH_LONG).show();
            return;
        }

        if (firstNameEditText.getText().toString().equals(lastNameEditText.getText().toString())) {
            Toast.makeText(this, R.string.alert_registration_spam, Toast.LENGTH_LONG).show();
            return;
        }

        if (firstNameEditText.getText().toString().length() <= 2
                || lastNameEditText.getText().toString().length() <= 2) {
            Toast.makeText(this, R.string.alert_registration_two_symbols_name, Toast.LENGTH_LONG).show();
            return;
        }

        String regExpn = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
                + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
                + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                + "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";

        Pattern pattern = Pattern.compile(regExpn, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(emailEditText.getText().toString());

        if (matcher.matches()) {
        } else {
            Toast.makeText(this, R.string.alert_registration_correct_email, Toast.LENGTH_LONG).show();
            return;
        }

        if (passwordEditText.getText().toString().length() < 4) {
            Toast.makeText(this, R.string.alert_registration_two_symbols_password, Toast.LENGTH_LONG).show();
            return;
        }

        if (!passwordEditText.getText().toString().equals(rePasswordEditText.getText().toString())) {
            Toast.makeText(this, "Passwords don't match.", Toast.LENGTH_LONG).show();
            return;
        }
    }
}

From source file:com.dgtlrepublic.anitomyj.ParserNumber.java

/**
 * Match fractional episodes. e.g. "07.5".
 *
 * @param word  the word//from   w w  w  .ja va2  s .com
 * @param token the token
 * @return true if the token matched
 */
public boolean matchFractionalEpisodePattern(String word, Token token) {
    if (StringUtils.isEmpty(word))
        word = "";
    String regexPattern = "\\d+\\.5";
    Pattern pattern = Pattern.compile(regexPattern, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(word);
    if (matcher.matches()) {
        if (setEpisodeNumber(word, token, true))
            return true;
    }

    return false;
}

From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java

/**
 * Logs response details to debug and logs error message as error if found
 * @param filePost//from  w  w  w  .j  a  va  2s . co m
 * @throws IOException
 */
private void logResponseDetails(HttpMethodBase filePost) throws IOException {
    InputStream stream = filePost.getResponseBodyAsStream();
    if (stream == null) {
        throw new IOException("Null response stream");
    }

    String responseBody = IOUtils.toString(stream);
    getLog().debug("Response body: " + responseBody);

    String errorPattern = "(?<=<span class=\"error_line\">)(.+)(?=</span>)";
    Pattern regex = Pattern.compile(errorPattern,
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
    Matcher matcher = regex.matcher(responseBody);

    StringBuilder errorMessage = new StringBuilder();

    while (matcher.find()) {
        errorMessage.append(matcher.group() + " ");
    }

    if (!StringUtils.isEmpty(errorMessage.toString())) {
        getLog().error(errorMessage.toString());
    }
}

From source file:com.vmware.identity.samlservice.SamlServiceTest.java

@Test
public void testBuildPostResponseForm() throws UnmarshallingException {
    Response response = service.createSamlResponse("42", acsUrl, OasisNames.REQUESTER,
            OasisNames.REQUEST_UNSUPPORTED, RESPONSE_MESSAGE, null);
    String relayState = "{\"dest\":\"d2d25106-44ee-4e36-877e-1d7aa1335dcd\",\"idpId\":53}";
    String formHtml = service.buildPostResponseForm(response, relayState, acsUrl);
    assertNotNull(formHtml);//w  ww. jav  a2 s.c o m

    // find input attribute for RelayState in html post form, validate the expected RelayState is embedded in the form
    Pattern inputPattern = Pattern.compile("<input(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Pattern attributePattern = Pattern.compile("(\\w+)=\"(.*?)\"");
    Matcher inputPatternMatcher = inputPattern.matcher(formHtml);
    boolean relayStateFound = false;
    while (inputPatternMatcher.find()) {
        String attributesStr = inputPatternMatcher.group(1);
        Matcher attributePatternMatcher = attributePattern.matcher(attributesStr);
        while (attributePatternMatcher.find()) {
            if (attributePatternMatcher.group(1).equals("name")) {
                String key = attributePatternMatcher.group(2).trim();
                if (key.equals("RelayState")) {
                    attributePatternMatcher.find();
                    if (attributePatternMatcher.group(1).equals("value")) {
                        String value = StringEscapeUtils.unescapeHtml(attributePatternMatcher.group(2).trim());
                        assertEquals(relayState, value);
                        relayStateFound = true;
                        break;
                    }
                }
            }
        }
    }
    assertTrue(relayStateFound);
}