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.qmetry.qaf.automation.util.LocatorUtil.java

private static String parseParameters(String str) {

    try {//from  w w w  .ja v a  2  s  .  co m
        Pattern p = Pattern.compile("\\$\\{([^}]+)\\}", Pattern.MULTILINE);
        Matcher m = p.matcher(str);

        while (m.find()) {
            String param = m.group(1);
            if (ConfigurationManager.getBundle().containsKey(param)) {
                str = str.replaceAll("\\$\\{" + param + "\\}",
                        ConfigurationManager.getBundle().getString(param));
            }
        }
    } catch (Exception e) {
        System.err.println("Unable to parse: " + str);
        e.printStackTrace();
    }

    return str;

}

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

@Override
public void compile(final List<Path> inputFiles, final Path outputFile,
        final Map<String, Object> additionalParameters) throws CompilationException, IOException {

    FileAccess.createDirectories(outputFile);

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

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

    commandLine.addArgument("-d");
    commandLine.addArgument(outputFile.toAbsolutePath().toString());

    commandLine.addArgument("-nowarn"); // Prohibit warnings because they
    // screw//from   w  w w.jav a2  s .  co  m
    // up error detection

    inputFiles.forEach((file) -> commandLine
            .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add
    // input
    // files

    JavaCompiler.logger.info("Running javac with arguments: {}", Arrays.asList(commandLine.getArguments()));

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

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

    executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to
    // compile
    int result;
    try {
        result = executor.execute(commandLine);
    } catch (final IOException e) {
        JavaCompiler.logger.error("Could not execute javac: {}", e);
        throw new CompilationException("Could not execute javac", e);
    }

    switch (result) {
    case 0:
        return;
    case 1:
        try {
            String errorString = errorStream.toString("UTF-8");
            final Pattern pattern = Pattern.compile(
                    "^(" + inputFiles.stream().map(file -> Pattern.quote(file.toAbsolutePath().toString()))
                            .collect(Collectors.joining("|")) + "):",
                    Pattern.MULTILINE);
            errorString = pattern.matcher(errorString).replaceAll("");

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

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

From source file:com.edgenius.wiki.render.filter.ListFilter.java

public void init() {
    regexProvider.compile(getRegex(), Pattern.MULTILINE | Pattern.DOTALL);
}

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

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

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

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

    commandLine.addArgument("-w"); // Prohibit warnings because they screw
    // up error detection

    commandLine.addArgument("-o");
    commandLine.addArgument(MessageFormat.format("\"{0}\"", outputFile.toAbsolutePath().toString())); // Set outuput file

    inputFiles.forEach((file) -> commandLine
            .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add
    // input/*from   www.j a v  a  2 s. c  om*/
    // files

    GNUCompiler.logger.debug("Running GCC with arguments: {}", Arrays.asList(commandLine.getArguments()));

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

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

    executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to
    // compile
    int result;
    try {
        result = executor.execute(commandLine);
    } catch (final IOException e) {
        GNUCompiler.logger.error("Could not execute GCC: {}", e);
        throw new CompilationException("Could not execute GCC", e);
    }

    switch (result) {
    case 0:
        return;
    case 1:
        try {
            String errorString = errorStream.toString(StandardCharsets.UTF_8.name());

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

            GNUCompiler.logger.debug("Compilation error: {}", errorString);
            throw new CompilerError("gcc.wrote.stderr", errorString);
        } catch (final UnsupportedEncodingException e) {
            throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e);
        }
    }
}

From source file:de.ist.clonto.webwiki.InfoboxParser.java

private String removeReferences(String text) {
    text = Pattern.compile("<ref name=\".*?\">.*?</ref>", Pattern.MULTILINE | Pattern.DOTALL).matcher(text)
            .replaceAll("");
    text = Pattern.compile("<ref name=\".*?\"\\s/>", Pattern.MULTILINE | Pattern.DOTALL).matcher(text)
            .replaceAll("");

    return text;/*w  ww  .  j a v  a  2  s . c o  m*/
}

From source file:Normalization.TextNormalization.java

public String removeSpacesFromString(String content) {

    String utf8tweet = "";
    try {//from   w ww. jav a 2 s. co  m
        byte[] utf8Bytes = content.getBytes("UTF-8");

        utf8tweet = new String(utf8Bytes, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    }

    final String regex = "\\s{2,}";
    final Pattern unicodeOutliers = Pattern.compile(regex,
            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);

    Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet);
    utf8tweet = unicodeOutlierMatcher.replaceAll(" ");
    return utf8tweet;
}

From source file:se.rebootit.android.tagbiljetter.DataParser.java

/**
 * Parse the message and check if it's a valid ticket
 * @param phonenumber   From what number did the sms arrive from?
 * @param timestamp      Timestamp arrived
 * @param message      The message//w w w  .  j  a v  a 2  s.  co  m
 */
public TransportCompany parseMessage(String phonenumber, long timestamp, String message) {
    for (TransportCompany transportCompany : lstCompanies) {
        if (phonenumber.startsWith(transportCompany.getPhoneNumber())) {
            String expr = transportCompany.getTicketFormat();

            Pattern pattern = Pattern.compile(expr,
                    Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
            Matcher matcher = pattern.matcher(message);

            if (matcher.matches()) {
                return transportCompany;
            }
        }
    }

    return null;
}

From source file:com.edgenius.wiki.render.filter.MacroFilter.java

/**
 * Initial macro filter only for special Macro. 
 * /*from   ww w  .  jav  a2 s.c  o  m*/
 * At the moment, only {piece} macro need this method - which need get Phase Piece from entire page content...
 * @param macro
 */
public void init(Macro macro, boolean immutable) {
    pairedMacroProvider.compile(FilterRegxConstants.PAIRED_MACRO, Pattern.DOTALL);
    singleMacroProvider.compile(FilterRegxConstants.SINGLE_MACRO, Pattern.MULTILINE);

    macroMgr.addMacro(macro, immutable);

}

From source file:org.projectforge.scripting.GroovyEngine.java

private String replaceIncludes(final String template) {
    if (template == null) {
        return null;
    }//from w  w w  .j a v a2 s  .  c o  m
    final Pattern p = Pattern.compile("#INCLUDE\\{([0-9\\.a-zA-Z/]*)\\}", Pattern.MULTILINE);
    final StringBuffer buf = new StringBuffer();
    final Matcher m = p.matcher(template);
    while (m.find()) {
        if (m.group(1) != null) {
            final String filename = m.group(1);
            final Object[] res = ConfigXml.getInstance().getContent(filename);
            String content = (String) res[0];
            if (content != null) {
                content = replaceIncludes(content).replaceAll("\\$", "#HURZ#");
                m.appendReplacement(buf, content); // Doesn't work with $ in content
            } else {
                m.appendReplacement(buf, "*** " + filename + " not found! ***");
            }
        }
    }
    m.appendTail(buf);
    return buf.toString();
}

From source file:com.qualinsight.plugins.sonarqube.smell.plugin.extension.SmellMeasurer.java

private void measureSmellDebt(final InputFile inputFile, final String fileContent) {
    final Pattern pattern = Pattern.compile(SMELL_ANNOTATION_DEBT_DETECTION_REGULAR_EXPRESSION,
            Pattern.MULTILINE);
    final Matcher matcher = pattern.matcher(fileContent);
    Long debt = 0L;// www  .ja  v a 2  s  .  c o  m
    while (matcher.find()) {
        debt += Integer.valueOf(matcher.group(2));
    }
    this.context.newMeasure().forMetric(SmellMetrics.metricFor("SMELL_DEBT")).on(inputFile).withValue(debt)
            .save();
    LOGGER.debug("Smell debt: {} ", debt);
}