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.asakusafw.dmdl.thundergate.Main.java

/**
 * ??/*from   www  .  j a  v a  2 s  .  c  o m*/
 * @param args ?
 * @return ??
 * @throws IllegalStateException ????
 */
public static Configuration loadConfigurationFromArguments(String[] args) {
    assert args != null;
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(OPTIONS, args);
    } catch (ParseException e) {
        throw new IllegalStateException(e);
    }

    Configuration result = new Configuration();

    String jdbc = getOption(cmd, OPT_JDBC_CONFIG, true);
    try {
        Properties jdbcProps = loadProperties(jdbc);
        result.setJdbcDriver(findProperty(jdbcProps, Constants.K_JDBC_DRIVER));
        result.setJdbcUrl(findProperty(jdbcProps, Constants.K_JDBC_URL));
        result.setJdbcUser(findProperty(jdbcProps, Constants.K_JDBC_USER));
        result.setJdbcPassword(findProperty(jdbcProps, Constants.K_JDBC_PASSWORD));
        result.setDatabaseName(findProperty(jdbcProps, Constants.K_DATABASE_NAME));
        LOG.info("JDBC??????: {}", jdbcProps);
    } catch (IOException e) {
        throw new IllegalStateException(
                MessageFormat.format("JDBC?????????: -{0}={1}",
                        OPT_JDBC_CONFIG.getOpt(), jdbc),
                e);
    }

    String output = getOption(cmd, OPT_OUTPUT, true);
    result.setOutput(new File(output));
    LOG.info("Output: {}", output);

    String includes = getOption(cmd, OPT_INCLUDES, false);
    if (includes != null && includes.isEmpty() == false) {
        try {
            Pattern pattern = Pattern.compile(includes, Pattern.CASE_INSENSITIVE);
            result.setMatcher(new ModelMatcher.Regex(pattern));
            LOG.info("Inclusion: {}", pattern);
        } catch (PatternSyntaxException e) {
            throw new IllegalArgumentException(MessageFormat
                    .format("??????????: {0}", includes), e);
        }
    } else {
        result.setMatcher(ModelMatcher.ALL);
    }

    String excludes = getOption(cmd, OPT_EXCLUDES, false);
    if (excludes != null && excludes.isEmpty() == false) {
        try {
            Pattern pattern = Pattern.compile(excludes, Pattern.CASE_INSENSITIVE);
            result.setMatcher(new ModelMatcher.And(result.getMatcher(),
                    new ModelMatcher.Not(new ModelMatcher.ConstantTable(Constants.SYSTEM_TABLE_NAMES)),
                    new ModelMatcher.Not(new ModelMatcher.Regex(pattern))));
            LOG.info("Exclusion: {}", pattern);
        } catch (PatternSyntaxException e) {
            throw new IllegalArgumentException(MessageFormat
                    .format("??????????: {0}", excludes), e);
        }
    } else {
        result.setMatcher(new ModelMatcher.And(result.getMatcher(),
                new ModelMatcher.Not(new ModelMatcher.ConstantTable(Constants.SYSTEM_TABLE_NAMES))));
    }

    String encoding = getOption(cmd, OPT_ENCODING, false);
    if (encoding != null) {
        try {
            Charset charset = Charset.forName(encoding);
            result.setEncoding(charset);
            LOG.info("Encoding: {}", charset);
        } catch (Exception e) {
            result.setEncoding(Constants.OUTPUT_ENCODING);
        }
    } else {
        result.setEncoding(Constants.OUTPUT_ENCODING);
    }

    checkIf(cmd, OPT_SID_COLUMN, OPT_TIMESTAMP_COLUMN);
    checkIf(cmd, OPT_TIMESTAMP_COLUMN, OPT_SID_COLUMN);

    checkIf(cmd, OPT_SID_COLUMN, OPT_DELETE_FLAG_COLUMN);
    checkIf(cmd, OPT_SID_COLUMN, OPT_DELETE_FLAG_VALUE);
    checkIf(cmd, OPT_DELETE_FLAG_COLUMN, OPT_DELETE_FLAG_VALUE);
    checkIf(cmd, OPT_DELETE_FLAG_VALUE, OPT_DELETE_FLAG_COLUMN);

    String sidColumn = trim(getOption(cmd, OPT_SID_COLUMN, false));
    String timestampColumn = trim(getOption(cmd, OPT_TIMESTAMP_COLUMN, false));
    String deleteFlagColumn = trim(getOption(cmd, OPT_DELETE_FLAG_COLUMN, false));
    String deleteFlagValue = trim(getOption(cmd, OPT_DELETE_FLAG_VALUE, false));
    if (deleteFlagValue != null) {
        // FIXME get "bare" string
        List<String> arguments = Arrays.asList(args);
        int index = arguments.indexOf('-' + OPT_DELETE_FLAG_VALUE.getOpt());
        assert index >= 0;
        assert arguments.size() > index + 1;
        deleteFlagValue = trim(arguments.get(index + 1));
    }

    result.setSidColumn(sidColumn);
    result.setTimestampColumn(timestampColumn);
    result.setDeleteFlagColumn(deleteFlagColumn);
    if (deleteFlagValue != null) {
        try {
            DmdlParser dmdl = new DmdlParser();
            AstLiteral literal = dmdl.parseLiteral(deleteFlagValue);
            result.setDeleteFlagValue(literal);
        } catch (DmdlSyntaxException e) {
            throw new IllegalArgumentException(MessageFormat.format(
                    "???Java???????????: {0}",
                    deleteFlagValue), e);
        }
    }
    String recordLockDdlOutput = getOption(cmd, OPT_RECORD_LOCK_DDL_OUTPUT, false);
    if (recordLockDdlOutput != null) {
        result.setRecordLockDdlOutput(new File(recordLockDdlOutput));
    }
    return result;
}

From source file:dk.dma.msinm.common.time.TimeTranslator.java

/**
 * Translate the time description/*w  w w .j a  va  2  s. com*/
 * @param time the time description to translate
 * @param translateRules the translation rules to apply
 * @return the result
 */
public String translate(String time, Map<String, String> translateRules) throws TimeException {

    BufferedReader reader = new BufferedReader(new StringReader(time));
    String line;
    StringBuilder result = new StringBuilder();
    try {
        while ((line = reader.readLine()) != null) {
            //line = line.trim().toLowerCase();

            // Replace according to replace rules
            for (String key : translateRules.keySet()) {
                String value = translateRules.get(key);

                Matcher m = Pattern.compile(key, Pattern.CASE_INSENSITIVE).matcher(line);
                StringBuffer sb = new StringBuffer();
                while (m.find()) {
                    String text = m.group();
                    m.appendReplacement(sb, value);
                }
                m.appendTail(sb);
                line = sb.toString();
            }

            // Capitalize, unless the line starts with something like "a) xxx"
            if (!line.matches("\\w\\) .*")) {
                line = StringUtils.capitalize(line);
            }

            result.append(line + "\n");
        }
    } catch (Exception e) {
        throw new TimeException("Failed translating time description", e);
    }

    return result.toString().trim();
}

From source file:eu.nerdz.api.impl.fastreverse.messages.FastReverseConversationHandler.java

/**
 * Replaces a single tag.//  w  w w .  ja  v a 2 s  .  c om
 * @param regex A regex
 * @param message A message to be parsed
 * @return A string in which all occurrences of regex have been substituted with the contents matched
 */
private static String replaceSingle(String regex, String message) {

    Matcher matcher = Pattern.compile(regex, Pattern.DOTALL | Pattern.CASE_INSENSITIVE).matcher(message);
    StringBuffer result = new StringBuffer();

    while (matcher.find()) {
        matcher.appendReplacement(result, matcher.group(1).replace("$", "\\$"));
    }

    matcher.appendTail(result);

    return result.toString();
}

From source file:org.opencron.common.utils.StringUtils.java

/**
 * script/*from  www . j a v a 2s.  co m*/
 *
 * @param htmlStr
 * @return writer:<a href="mailto:benjobs@qq.com">benjobs</a> 2012.2.1
 */
public static String replaceScript(String htmlStr) {
    if (htmlStr == null || "".equals(htmlStr)) {
        return "";
    }
    String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // script?
    Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
    Matcher m_script = p_script.matcher(htmlStr);
    htmlStr = m_script.replaceAll(""); // script
    return htmlStr.trim(); // 
}

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

/**
 * Logs into axisandallies.org/*  ww w.  ja  v  a  2s  .  com*/
 * nb: Username and password are posted in clear text
 * 
 * @throws Exception
 *             if login fails
 */
private void login() throws Exception {
    // creates and configures a new http client
    m_client = new HttpClient();
    m_client.getParams().setParameter("http.protocol.single-cookie-header", true);
    m_client.getParams().setParameter("http.useragent",
            "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
    m_httpState = new HttpState();
    m_hostConfiguration = new HostConfiguration();
    // add the proxy
    GameRunner2.addProxy(m_hostConfiguration);
    m_hostConfiguration.setHost("www.axisandallies.org");

    final PostMethod post = new PostMethod("http://www.axisandallies.org/forums/index.php?action=login2");
    try {
        post.addRequestHeader("Accept", "*/*");
        post.addRequestHeader("Accept-Language", "en-us");
        post.addRequestHeader("Cache-Control", "no-cache");
        post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        final List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new NameValuePair("user", getUsername()));
        parameters.add(new NameValuePair("passwrd", getPassword()));
        post.setRequestBody(parameters.toArray(new NameValuePair[parameters.size()]));

        int status = m_client.executeMethod(m_hostConfiguration, post, m_httpState);
        if (status == 200) {
            final String body = post.getResponseBodyAsString();
            if (body.toLowerCase().contains("password incorrect")) {
                throw new Exception("Incorrect Password");
            }
            // site responds with 200, and a refresh header
            final Header refreshHeader = post.getResponseHeader("Refresh");
            if (refreshHeader == null) {
                throw new Exception("Missing refresh header after login");
            }

            final String value = refreshHeader.getValue(); // refresh: 0; URL=http://...
            final Pattern p = Pattern.compile("[^;]*;\\s*url=(.*)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
            final Matcher m = p.matcher(value);
            if (m.matches()) {
                final String url = m.group(1);
                final GetMethod getRefreshPage = new GetMethod(url);

                try {
                    status = m_client.executeMethod(m_hostConfiguration, getRefreshPage, m_httpState);
                    if (status != 200) {
                        // something is probably wrong, but there is not much we can do about it, we handle errors when we post
                    }
                } finally {
                    getRefreshPage.releaseConnection();
                }
            } else {
                throw new Exception("The refresh header didn't contain a URL");
            }
        } else {
            throw new Exception("Failed to login to forum, server responded with status code: " + status);
        }
    } finally {
        post.releaseConnection();
    }
}

From source file:de.mpg.escidoc.services.exportmanager.Export.java

public String explainFormatsXML() throws ExportManagerException {

    //TODO: Revision with ValueObjects

    String citStyles;/*w  w w .  ja  v  a2  s. c  o m*/
    try {
        citStyles = getCitationStyleHandler().explainStyles();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get citation styles explain", e);
    }

    String structured;
    try {
        structured = getStructuredExportHandler().explainFormats();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get structured exports explain", e);
    }

    String result;
    // get export-format elements
    String regexp = "<export-formats.*?>(.*?)</export-formats>";
    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(citStyles);
    m.find();
    result = m.group(1);
    m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(structured);
    m.find();
    result += m.group(1);

    m = Pattern.compile("<export-format\\s+.*</export-format>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(structured);
    m.find();
    result = m.replaceAll(result);

    // replace comments
    // m = Pattern
    // .compile(
    // "<!--.*?-->"
    // , Pattern.CASE_INSENSITIVE | Pattern.DOTALL
    // )
    // .matcher(result);
    // m.find();
    // result = m.replaceAll("");

    return result;
}

From source file:com.qq.tars.maven.gensrc.TarsBuildMojo.java

protected boolean includedScope(final String scope) {
    if (pattern == null) {
        pattern = Pattern.compile(includedScope, Pattern.CASE_INSENSITIVE);
    }//from  ww  w  . jav  a2 s.  c  o m
    return scope != null ? pattern.matcher(scope).matches() : Boolean.TRUE;
}

From source file:net.sf.zekr.engine.search.tanzil.ZeroHighlighter.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private List filterBucket(List intermediateResult, String pattern, boolean exclude, boolean firstTime,
        PatternEnricher enricher) throws SearchException {
    try {/*from  w w w .  j  av  a  2s. c  o  m*/
        List res = new ArrayList();
        Pattern regex = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
        for (int i = 0; i < intermediateResult.size(); i++) {
            Matcher matcher;
            String line;
            IQuranLocation loc;
            if (firstTime) {
                loc = (IQuranLocation) intermediateResult.get(i);
                line = ' ' + quranText.get(loc) + ' ';
            } else {
                SearchResultItem sri = (SearchResultItem) intermediateResult.get(i);
                loc = sri.location;
                line = sri.text;
            }
            // matcher = regex.matcher(enricher.enrich(line));
            matcher = regex.matcher(line);
            if (matcher.find() ^ exclude) {
                if (firstTime) {
                    res.add(new SearchResultItem(line, loc));
                } else {
                    res.add(intermediateResult.get(i));
                }
            }
        }
        return res;
    } catch (PatternSyntaxException pse) {
        logger.implicitLog(pse);
        throw new SearchException(pse.getMessage());
    }
}

From source file:com.myhexin.filter.FileMultipartFilter.java

public boolean isIllegalFileSuffix(MultipartHttpServletRequest mRequest) {

    Map<String, MultipartFile> fileMap = mRequest.getFileMap();

    for (Iterator<Map.Entry<String, MultipartFile>> it = fileMap.entrySet().iterator(); it.hasNext();) {

        Map.Entry<String, MultipartFile> entry = it.next();
        MultipartFile mFile = entry.getValue();

        String origFileName = mFile.getOriginalFilename();
        String name = mFile.getName();
        int a = origFileName.indexOf(".", -1);
        Pattern pattern = Pattern.compile(FILE_FILTER_REGX, Pattern.CASE_INSENSITIVE);
        if (a != -1) {
            String suffix = origFileName.substring(a + 1);
            if (pattern.matcher(suffix).matches()) {
                recordXssRequestInfo(mRequest, origFileName);
                return true;
            } else {
                return false;
            }//  ww w .  j  av  a 2 s  .c  o m

        } else {
            return false;
        }
    }
    return false;
}

From source file:gov.nih.nci.cabig.caaers.web.filters.BadInputFilter.java

/**
 * Construct a new instance of this class with default property values.
 *///  w ww .j a va  2  s  .  c om
public BadInputFilter() {

    // Populate the regex escape maps.

    //commented follwing 2 lines to fix  -
    // CAAERS-6005 - Apostrophe (') in course description is being rendered html character codes in it
    quotesLinkedHashMap.put(Pattern.compile("\""), "&quot;");
    quotesLinkedHashMap.put(Pattern.compile("\'"), "&#39;");
    quotesLinkedHashMap.put(Pattern.compile("`"), "&#96;");

    angleBracketsLinkedHashMap.put(Pattern.compile("<"), "&lt;");
    angleBracketsLinkedHashMap.put(Pattern.compile(">"), "&gt;");

    String[] formTags = "form,textarea,input,button,select,optgroup,label,fieldset".split(",");
    for (String tag : formTags) {
        htmlLinkedHashMap.put(Pattern.compile("<" + tag + "(\\s*)", Pattern.CASE_INSENSITIVE), tag + "$1");
    }

    javaScriptLinkedHashMap.put(Pattern.compile("<(\\s*)(/\\s*)?script(\\s*)>"), "<$2script-disabled>");
    javaScriptLinkedHashMap.put(Pattern.compile("%3Cscript%3E"), "%3Cscript-disabled%3E");
    javaScriptLinkedHashMap.put(Pattern.compile("<(\\s*)(/\\s*)?iframe(\\s*)>"), "<$2iframe-disabled>");
    javaScriptLinkedHashMap.put(Pattern.compile("%3Ciframe%3E"), "%3Ciframe-disabled%3E");
    javaScriptLinkedHashMap.put(Pattern.compile("alert(\\s*)\\("), "alert[");
    javaScriptLinkedHashMap.put(Pattern.compile("alert%28"), "alert%5B");
    javaScriptLinkedHashMap.put(Pattern.compile("document(.*)\\.(.*)cookie"), "document cookie");
    javaScriptLinkedHashMap.put(Pattern.compile("eval(\\s*)\\("), "eval[");
    javaScriptLinkedHashMap.put(Pattern.compile("setTimeout(\\s*)\\("), "setTimeout$1[");
    javaScriptLinkedHashMap.put(Pattern.compile("setInterval(\\s*)\\("), "setInterval$1[");
    javaScriptLinkedHashMap.put(Pattern.compile("execScript(\\s*)\\("), "execScript$1[");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)javascript(?-i):"), "javascript ");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onclick(?-i)"), "oncl1ck");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)ondblclick(?-i)"), "ondblcl1ck");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onmouseover(?-i)"), "onm0useover");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onmousedown(?-i)"), "onm0usedown");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onmouseup(?-i)"), "onm0useup");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onmousemove(?-i)"), "onm0usemove");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onmouseout(?-i)"), "onm0useout");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onchange(?-i)"), "onchahge");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onfocus(?-i)"), "onf0cus");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)autofocus(?-i)"), "aut0f0cus");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onblur(?-i)"), "onb1ur");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onkeypress(?-i)"), "onkeyqress");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onkeyup(?-i)"), "onkeyuq");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onkeydown(?-i)"), "onkeyd0wn");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onload(?-i)"), "onl0ad");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onreset(?-i)"), "onrezet");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onselect(?-i)"), "onzelect");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onsubmit(?-i)"), "onsubm1t");
    javaScriptLinkedHashMap.put(Pattern.compile("(?i)onunload(?-i)"), "onunl0ad");
    javaScriptLinkedHashMap.put(Pattern.compile("&#x61;&#x6C;&#x65;&#x72;&#x74;"), "a1ert");

    newlinesLinkedHashMap.put(Pattern.compile("\r"), " ");
    newlinesLinkedHashMap.put(Pattern.compile("\n"), "<br/>");
}