Example usage for java.util.regex Pattern MULTILINE

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

Introduction

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

Prototype

int MULTILINE

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

Click Source Link

Document

Enables multiline mode.

Usage

From source file:com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck.java

/**
 * Instantiates an new RegexpCheck.
 */
public RegexpCheck() {
    // the empty language
    super("$^", Pattern.MULTILINE);
}

From source file:org.squale.welcom.outils.TrimStringBuffer.java

/**
 * Renvoi le string buffer optmi si necessaire
 * /*w  w  w .ja  v a2 s  .c  om*/
 * @return le string buffer optmi si necessaire
 */
public String toString() {
    if (optimize) {
        final String value = sb.toString();

        try {
            final Pattern reg = Pattern.compile("<\\s*(textarea|pre)[^>]*>([^<]*)<\\/\\s*\\1\\s*>",
                    Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
            final StringBuffer sbtmp = new StringBuffer();

            final Matcher match = reg.matcher(value);

            int start = 0;
            int end = 0;

            while (match.find()) {
                final String chaineANePasRempacer = match.group();
                end = match.start();

                final String chaineARemplacer = value.substring(start, end);
                final String chainePurge = removeSpaces(chaineARemplacer);
                sbtmp.append(chainePurge);
                sbtmp.append(chaineANePasRempacer);
                start = match.end();
            }

            sbtmp.append(removeSpaces(value.substring(start, value.length())));

            return sbtmp.toString();
        } catch (final Exception ex) {
            log.error(ex, ex);

            return sb.toString();
        }
    } else {
        return sb.toString();
    }
}

From source file:wuit.common.crawler.WebSit.CrawlerAPIBaiDu.java

/**
 * HTTP POST?HTML/*ww w . j  ava2  s . c  om*/
 *
 * @param url
 *            URL?
 * @param params
 *            ?,?null
 * @param charset
 *            
 * @param pretty
 *            ?
 * @return ?HTML
 */
/*public static String doPost(String url, Map<String, String> params,
    String charset, boolean pretty) {
StringBuffer response = new StringBuffer();
HttpClient client = new HttpClient();
HttpMethod method = new PostMethod(url);
// Http Post?
if (params != null) {
    HttpMethodParams p = new HttpMethodParams();
    for (Map.Entry<String, String> entry : params.entrySet()) {
        p.setParameter(entry.getKey(), entry.getValue());
    }
    method.setParams(p);
}
try {
    client.executeMethod(method);
    if (method.getStatusCode() == HttpStatus.SC_OK) {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(method.getResponseBodyAsStream(),
                        charset));
        String line;
        while ((line = reader.readLine()) != null) {
            if (pretty)
                response.append(line).append(
                        System.getProperty("line.separator"));
            else
                response.append(line);
        }
        reader.close();
    }
} catch (IOException e) {
    log.error("HTTP Post" + url + "??", e);
} finally {
    method.releaseConnection();
}
return response.toString();
}*/

public static void matchValues(String content, String filter, List<KeyValue> list) {
    if (list == null)
        list = new ArrayList<KeyValue>();
    try {
        Matcher m = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(content);
        while (m.find()) {
            if (m.group().isEmpty())
                continue;
            KeyValue value = new KeyValue();
            value.value = m.group();
            value.start = m.start();
            value.end = m.end();
            list.add(value);
        }
    } catch (Exception e) {
        System.out.println("Crawler Utitles  matchValues :" + e.getMessage());
    }
}

From source file:apps.ParsedPost.java

private static String replace(String src, String pat, String repl, boolean bIgnoreCase) {
    Pattern p = bIgnoreCase// w  w w.ja  va2  s . c  o  m
            ? Pattern.compile(pat, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL)
            : Pattern.compile(pat, Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = p.matcher(src);

    return m.replaceAll(repl);
}

From source file:Main.java

/**
 * Converts the string flags to their pattern constants
 * @param flags/*from  w  w  w . j a  va2  s .co  m*/
 * @return
 */
public static int convertFlagsToConstants(ArrayList<String> flags) {
    int ret = 0;
    for (String s : flags) {
        if (s.equals("i")) {
            ret |= Pattern.CASE_INSENSITIVE;
        } else if (s.equals("m")) {
            ret |= Pattern.MULTILINE;
        } else {
            ret |= Pattern.DOTALL;
        }
    }
    return ret;
}

From source file:com.norconex.importer.parser.AbstractParserTest.java

private void assertDefaults(ImporterDocument doc, String testType, String resourcePath, String contentType,
        String contentRegex, String extension, String family) throws IOException {
    Pattern p = Pattern.compile(contentRegex, Pattern.DOTALL | Pattern.MULTILINE);

    Assert.assertNotNull("Document is null", doc);

    String content = IOUtils.toString(doc.getContent());
    Assert.assertEquals(testType + " content-type detection failed for \"" + resourcePath + "\".",
            ContentType.valueOf(contentType), doc.getContentType());

    Assert.assertTrue(/*from w w  w .  j  av a 2 s.  co  m*/
            testType + " content extraction failed for \"" + resourcePath + "\". Content:\n" + content,
            p.matcher(content).find());

    String ext = doc.getContentType().getExtension();
    Assert.assertEquals(testType + " extension detection failed for \"" + resourcePath + "\".", extension, ext);

    String familyEnglish = doc.getContentType().getContentFamily().getDisplayName(Locale.ENGLISH);
    //        System.out.println("FAMILY: " + familyEnglish);
    Assert.assertEquals(testType + " family detection failed for \"" + resourcePath + "\".", family,
            familyEnglish);

}

From source file:org.limy.eclipse.qalab.mark.CheckCreator.java

private InputStream supportEncoding(LimyQalabEnvironment env, File configFile) throws IOException {
    String lines = FileUtils.readFileToString(configFile, "UTF-8");

    Matcher matcherTree = Pattern
            .compile(".*<module name=\"TreeWalker\">(.*)", Pattern.MULTILINE | Pattern.DOTALL).matcher(lines);
    if (matcherTree.matches()) {
        int pos = matcherTree.start(1);
        StringBuilder buff = new StringBuilder(lines);
        try {//from   w  w w.  j  av a 2s . c om
            buff.insert(pos,
                    "<property name=\"charset\" value=\"" + env.getProject().getDefaultCharset() + "\"/>");
            lines = buff.toString();
        } catch (CoreException e) {
            LimyEclipsePluginUtils.log(e);
        }
    }

    return new StringInputStream(lines);
}

From source file:dk.teachus.backend.testdatagenerator.DynamicDataImport.java

private void createVersion() {
    // Parse the pom file to get the version
    File file = new File("pom.xml");

    if (file.exists()) {
        try {/*from w  w w . j  a  va  2s.  co m*/
            String pomContent = FileUtils.readFileToString(file, "UTF-8");

            Pattern pattern = Pattern.compile(".*?\\<version\\>([^\\<]+)\\<\\/version>.*",
                    Pattern.MULTILINE | Pattern.DOTALL);
            Matcher matcher = pattern.matcher(pomContent);
            if (matcher.matches()) {
                String version = matcher.group(1);
                version = version.replace("-SNAPSHOT", "");

                Session session = sessionFactory.openSession();
                session.beginTransaction();

                ApplicationConfigurationEntry entry = new ApplicationConfigurationEntry("VERSION", version);
                session.save(entry);

                session.getTransaction().commit();
                session.close();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.intel.hadoop.graphbuilder.demoapps.wikipedia.linkgraph.LinkGraphTokenizer.java

/** This function is taken and modified from wikixmlj WikiTextParser */
private void parseLinks(String text) {
    links.clear();/*from  www  .j a v  a 2  s  .  c  o m*/
    Pattern catPattern = Pattern.compile("\\[\\[(.*?)\\]\\]", Pattern.MULTILINE);
    Matcher matcher = catPattern.matcher(text);
    while (matcher.find()) {
        String[] temp = matcher.group(1).split("\\|");
        if (temp == null || temp.length == 0)
            continue;
        String link = temp[0];
        if (!link.replaceAll("\\s", "").isEmpty() && !link.contains(":")) {
            links.add(link.replaceAll("\\s", "_"));
        }
    }
}

From source file:org.ng200.openolympus.cerberus.compilers.FPCCompiler.java

@Override
public void compile(final List<Path> inputFiles, final Path outputFile,
        final Map<String, Object> additionalParameters) throws CompilationException {
    FPCCompiler.logger.debug("Compiling {} to {} using FPC", inputFiles, outputFile);

    final CommandLine commandLine = new CommandLine("ppcx64");
    commandLine.setSubstitutionMap(additionalParameters);

    this.arguments.forEach((arg) -> commandLine.addArgument(arg));

    commandLine.addArgument("-o" + outputFile.toAbsolutePath().toString()); // Set
    // outuput/*from  www  . ja v a  2 s  .com*/
    // file
    commandLine.addArgument("-l-");
    commandLine.addArgument("-v0");
    inputFiles.forEach((file) -> commandLine
            .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add
    // input
    // files

    FPCCompiler.logger.debug("Running FPC with arguments: {}", commandLine.toString());

    final DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValues(new int[] { 0, 1 });

    final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(errorStream, null, null));

    executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to
    // compile
    int result;
    try {
        result = executor.execute(commandLine);
    } catch (final IOException e) {
        FPCCompiler.logger.error("Could not execute FPC: {}", e);
        throw new CompilationException("Could not execute FPC", e);
    }
    switch (result) {
    case 0:
        return;
    case 1:
        try {
            final String errorString = errorStream.toString("UTF-8");

            final Pattern pattern = Pattern.compile(
                    "^(" + inputFiles.stream().map(file -> Pattern.quote(file.getFileName().toString()))
                            .collect(Collectors.joining("|")) + ")",
                    Pattern.MULTILINE);

            FPCCompiler.logger.debug("Compilation error: {}", errorString);

            throw new CompilerError("fpc.wrote.stdout", errorString);
        } catch (final UnsupportedEncodingException e) {
            throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e);
        }
    }
}