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.aliyun.datahub.flume.sink.serializer.OdpsRegexEventSerializer.java

@Override
public void configure(Context context) {
    String regex = context.getString(REGEX_CONFIG, REGEX_DEFAULT);
    regexIgnoreCase = context.getBoolean(IGNORE_CASE_CONFIG, INGORE_CASE_DEFAULT);
    inputPattern = Pattern.compile(regex, Pattern.DOTALL + (regexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
    charset = Charset.forName(context.getString(CHARSET_CONFIG, CHARSET_DEFAULT));

    String colNameStr = context.getString(FIELD_NAMES, FIELD_NAME_DEFAULT);
    inputColNames = colNameStr.split(",");
}

From source file:net.sf.jabref.groups.structure.KeywordGroup.java

private void compilePattern() throws IllegalArgumentException {
    pattern = caseSensitive ? Pattern.compile("\\b" + searchExpression + "\\b")
            : Pattern.compile("\\b" + searchExpression + "\\b", Pattern.CASE_INSENSITIVE);
}

From source file:team.curise.dao.BaseDao.java

/**
 * orderby??//from ww  w.j  av  a  2  s .co  m
 * @param hql
 * @return
 */
public static String removeOrders(String hql) {
    Assert.hasText(hql);
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(hql);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:net.solarnetwork.node.backup.FileBackupResourceProvider.java

@Override
public Iterable<BackupResource> getBackupResources() {
    if (resourceDirectories == null || resourceDirectories.length < 1) {
        return Collections.emptyList();
    }// w  w  w  .  j  a v  a2s .  c o  m
    final Pattern pat = (fileNamePattern == null ? null
            : Pattern.compile(fileNamePattern, Pattern.CASE_INSENSITIVE));
    List<BackupResource> fileList = new ArrayList<BackupResource>(20);
    for (String path : resourceDirectories) {
        File rootDir = (rootPath != null && rootPath.length() > 0 ? new File(rootPath, path) : new File(path));
        if (!rootDir.isDirectory()) {
            log.info("Skipping path {} because does not exist or is not a directory",
                    rootDir.getAbsolutePath());
            continue;
        }
        File[] files = rootDir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return pat.matcher(name).find();
            }
        });
        if (files == null || files.length < 1) {
            continue;
        }
        for (File f : files) {
            // make sure backup path is relative
            final String backupPath = path + '/' + f.getName();
            String digest = null;
            InputStream in = null;
            try {
                in = new BufferedInputStream(new FileInputStream(f));
                digest = DigestUtils.sha256Hex(in);
            } catch (IOException e) {
                log.warn("Error calculating SHA-256 digest of {}: {}", f, e.getMessage());
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        // ignore
                    }
                }
            }

            fileList.add(new ResourceBackupResource(new FileSystemResource(f), backupPath, getKey(), digest));
        }
    }
    return fileList;
}

From source file:com.cloudant.tests.UnicodeTest.java

/**
 * Returns the charset of a plain-text entity.
 *///  ww w  .j  a va 2 s.  c om
private static Charset getPlainTextEntityCharset(HttpConnection connection) {
    // For plain text, use the charset that is mentioned in the response
    // header field 'Content-Type'.
    // See http://stackoverflow.com/questions/3216730/with-httpclient-is-there-a-way-to-get
    // -the-character-set-of-the-page-with-a-head

    String contentType = connection.getConnection().getContentType();
    if (contentType == null) {
        contentType = "text/plain";
    }

    //look for any charset information in the Content-Type
    String charsetName = null;
    Matcher m = Pattern.compile(".*;\\s*charset=(^;)+.*", Pattern.CASE_INSENSITIVE).matcher(contentType);
    if (m.matches() && m.groupCount() >= 1) {
        charsetName = m.group(1);
    }

    Charset charset;
    if (charsetName == null) {
        // In the HTTP protocol, the default charset is ISO-8859-1.
        // But not for the Cloudant server:
        // - When we retrieve a document without specifying an 'Accept' header,
        //   it replies with a UTF-8 encoded JSON string and a header
        //   "Content-Type: text/plain;charset=utf-8".
        // - When we do the same thing with a "Accept: application/json" header,
        //   it replies with the same UTF-8 encoded JSON string and a header
        //   "Content-Type: application/json". So here the UTF-8 encoding must
        //   be implicitly understood.
        if ("application/json".equalsIgnoreCase(contentType)) {
            charset = Charset.forName("UTF-8");
        } else {
            charset = Charset.forName("ISO-8859-1");
        }
    } else {
        charset = Charset.forName(charsetName);
    }
    return charset;
}

From source file:com.norconex.importer.handler.transformer.impl.StripAfterTransformer.java

@Override
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata,
        boolean parsed, boolean partialContent) {
    if (stripAfterRegex == null) {
        LOG.error("No regular expression provided.");
        return;//from   w w w.  java2 s  . com
    }
    int flags = Pattern.DOTALL | Pattern.UNICODE_CASE;
    if (!caseSensitive) {
        flags = flags | Pattern.CASE_INSENSITIVE;
    }
    Pattern pattern = Pattern.compile(stripAfterRegex, flags);
    Matcher match = pattern.matcher(content);
    if (match.find()) {
        if (inclusive) {
            content.delete(match.start(), content.length());
        } else {
            content.delete(match.end(), content.length());
        }
    }
}

From source file:com.eyem.bean.PostBean.java

public void crearPost(String email, String tipo) {

    Post p = new Post();
    Usuario u = usuarioService.buscarPorEmail(email);
    p.setContenido(contenido);/*from  ww  w. ja v a  2s . c  om*/
    String pattern = "https?:\\/\\/(?:[0-9A-Z-]+\\.)?(?:youtu\\.be\\/|youtube\\.com\\S*[^\\w\\-\\s])([\\w\\-]{11})(?=[^\\w\\-]|$)(?![?=&+%\\w]*(?:['\"][^<>]*>|<\\/a>))[?=&+%\\w]*";
    List<String> mostraporvacio = new ArrayList<>();

    Pattern compiledPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    if (uploadedFile != null && uploadedFile.getSize() < 20000 && uploadedFile.getSize() > 10000) {
        System.out.println(uploadedFile.getName());
        try {
            long uniqueName = System.currentTimeMillis();
            uploadedFile.write(uniqueName + ".jpg");

            p.setImagen("resources/uploads/" + uniqueName + ".jpg");
            imagen = null;
        } catch (IOException ex) {
            Logger.getLogger(PostBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    Matcher matcher = compiledPattern.matcher(imagen);
    while (matcher.find()) {
        System.out.println(matcher.group());
        video = matcher.group();
        imagen = null;
        if (video.contains("/embed/")) {
            p.setVideo(video);
        }
    }

    if (null != imagen && !imagen.isEmpty()) {
        try {
            java.net.URL url = new java.net.URL(imagen);
            Logger.getLogger(PostBean.class.getName()).log(Level.INFO, null,
                    url.toString() + " subido por " + u.getEmail());
            p.setImagen(imagen);
        } catch (MalformedURLException ex) {
            Logger.getLogger(PostBean.class.getName()).log(Level.SEVERE, null,
                    ex + " causado por " + u.getEmail());
            p.setImagen(null);
        }
    }
    p.setIdPost(System.currentTimeMillis());
    p.setTipo(tipo);
    p.setCreador(u);
    p.setMostradoPor(mostraporvacio);

    postService.crearPost(p);
    contenido = null;
    imagen = null;
    uploadedFile = null;

}

From source file:edu.harvard.hms.dbmi.bd2k.i2b2proxy.filter.SessionFilter.java

private String validateAuthorizationHeader(HttpServletRequest req) {
    String authorizationHeader = ((HttpServletRequest) req).getHeader("Authorization");
    if (authorizationHeader != null) {
        try {/*from  w  w  w.  j  av  a2s . c  om*/

            String[] parts = authorizationHeader.split(" ");
            if (parts.length != 2) {
                return null;
            }

            String scheme = parts[0];
            String credentials = parts[1];
            String token = "";

            Pattern pattern = Pattern.compile("^Bearer$", Pattern.CASE_INSENSITIVE);
            if (pattern.matcher(scheme).matches()) {
                token = credentials;
            }

            byte[] secret = Base64.decodeBase64(this.clientSecret);
            Map<String, Object> decodedPayload = new JWTVerifier(secret, this.clientId).verify(token);

            return (String) decodedPayload.get(this.userField);

        } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | SignatureException
                | IOException | JWTVerifyException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:org.freaknet.gtrends.api.GoogleTrendsClient.java

/**
 * Execute the request./*w w  w .  jav  a 2 s  . c om*/
 *
 * @param request
 * @return content The content of the response
 * @throws GoogleTrendsClientException
 */
public String execute(GoogleTrendsRequest request) throws GoogleTrendsClientException {
    String html = null;
    try {
        if (!authenticator.isLoggedIn()) {
            authenticator.authenticate();
        }
        Logger.getLogger(GoogleConfigurator.getLoggerPrefix()).log(Level.FINE, "Query: {0}",
                request.build().toString());

        HttpRequestBase httpRequest = request.build();
        HttpResponse response = client.execute(httpRequest);
        html = GoogleUtils.toString(response.getEntity().getContent());
        httpRequest.releaseConnection();

        Pattern p = Pattern.compile(
                GoogleConfigurator.getConfiguration().getString("google.trends.client.reError"),
                Pattern.CASE_INSENSITIVE);
        Matcher matcher = p.matcher(html);
        if (matcher.find()) {
            throw new GoogleTrendsClientException(
                    "*** You are running too fast man! Looks like you reached your quota limit. Wait a while and slow it down with the '-S' option! *** ");
        }
    } catch (GoogleAuthenticatorException ex) {
        throw new GoogleTrendsClientException(ex);
    } catch (ClientProtocolException ex) {
        throw new GoogleTrendsClientException(ex);
    } catch (IOException ex) {
        throw new GoogleTrendsClientException(ex);
    } catch (ConfigurationException ex) {
        throw new GoogleTrendsClientException(ex);
    } catch (GoogleTrendsRequestException ex) {
        throw new GoogleTrendsClientException(ex);
    }

    return html;
}

From source file:com.norconex.importer.handler.transformer.impl.StripBeforeTransformer.java

@Override
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata,
        boolean parsed, boolean partialContent) {
    if (stripBeforeRegex == null) {
        LOG.error("No regular expression provided.");
        return;//from  w  w  w  .j ava 2s .co  m
    }
    int flags = Pattern.DOTALL | Pattern.UNICODE_CASE;
    if (!caseSensitive) {
        flags = flags | Pattern.CASE_INSENSITIVE;
    }
    Pattern pattern = Pattern.compile(stripBeforeRegex, flags);
    Matcher match = pattern.matcher(content);
    if (match.find()) {
        if (inclusive) {
            content.delete(0, match.end());
        } else {
            content.delete(0, match.start());
        }
    }
}