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:org.apache.james.transport.mailets.PatternExtractor.java

private int extractOptions(String optionsAsString) {
    int options = 0;
    if (optionsAsString.contains("i")) {
        options |= Pattern.CASE_INSENSITIVE;
    }//  w  ww.j  a v  a2 s .c o m
    if (optionsAsString.contains("m")) {
        options |= Pattern.MULTILINE;
    }
    if (optionsAsString.contains("s")) {
        options |= Pattern.DOTALL;
    }
    return options;
}

From source file:org.openmrs.maven.plugins.distrotools.mojo.ValidateFormsMojo.java

/**
 * Strips comments from the given form XML
 * @param xml the form XML//from  w w w  . j a v a  2  s .c o m
 * @return the form XML with comments stripped
 */
public static String stripComments(String xml) {
    String regex = "<!\\s*--.*?--\\s*>"; // this is the regEx for html comment tag <!-- .* -->
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(xml);
    xml = matcher.replaceAll("");
    return xml;
}

From source file:com.edgenius.wiki.service.impl.TestRenderService.java

@Before
public void setUp() throws Exception {

    singleMacroProvider.compile(FilterRegxConstants.SINGLE_MACRO, Pattern.MULTILINE);
    pluginService.setPluginTemplateEngine(testPluginTemplateEngine);
    securityService.proxyLogin("admin");
}

From source file:com.gs.obevo.db.impl.core.util.MultiLineStringSplitter.java

@Override
public MutableList<String> valueOf(String inputString) {
    inputString += "\n"; // add sentinel to facilitate line split

    MutableList<SqlToken> sqlTokens = this.tokenParser.parseTokens(inputString);
    sqlTokens = this.collapseWhiteSpaceAndTokens(sqlTokens);

    MutableList<String> finalSplitStrings = Lists.mutable.empty();
    String currentSql = "";

    for (SqlToken sqlToken : sqlTokens) {
        if (sqlToken.getTokenType() == SqlTokenType.COMMENT || sqlToken.getTokenType() == SqlTokenType.STRING) {
            currentSql += sqlToken.getText();
        } else {//w  ww . j ava2s.  co m
            String pattern = splitOnWholeLine ? "(?i)^" + this.splitToken + "$" : this.splitToken;
            MutableList<String> splitStrings = Lists.mutable
                    .with(Pattern.compile(pattern, Pattern.MULTILINE).split(sqlToken.getText()));
            if (splitStrings.isEmpty()) {
                // means that we exactly match
                finalSplitStrings.add(currentSql);
                currentSql = "";
            } else if (splitStrings.size() == 1) {
                currentSql += sqlToken.getText();
            } else {
                splitStrings.set(0, currentSql + splitStrings.get(0));

                if (splitOnWholeLine) {
                    if (splitStrings.size() > 1) {
                        splitStrings.set(0, StringUtils.chomp(splitStrings.get(0)));
                        for (int i = 1; i < splitStrings.size(); i++) {
                            String newSql = splitStrings.get(i);
                            if (newSql.startsWith("\n")) {
                                newSql = newSql.replaceFirst("^\n", "");
                            } else if (newSql.startsWith("\r\n")) {
                                newSql = newSql.replaceFirst("^\r\n", "");
                            }

                            // Chomping the end of each sql due to the split of the GO statement
                            if (i < splitStrings.size() - 1) {
                                newSql = StringUtils.chomp(newSql);
                            }
                            splitStrings.set(i, newSql);
                        }
                    }
                }

                finalSplitStrings.addAll(splitStrings.subList(0, splitStrings.size() - 1));
                currentSql = splitStrings.getLast();
            }
        }
    }

    if (!currentSql.isEmpty()) {
        finalSplitStrings.add(currentSql);
    }

    // accounting for the sentinel
    if (finalSplitStrings.getLast().isEmpty()) {
        finalSplitStrings.remove(finalSplitStrings.size() - 1);
    } else {
        finalSplitStrings.set(finalSplitStrings.size() - 1, StringUtils.chomp(finalSplitStrings.getLast()));
    }

    return finalSplitStrings;
}

From source file:com.canoo.webtest.plugins.emailtest.EmailMessageStructureFilter.java

private static void appendUuencodedAttachments(final StringBuffer buf, final String content) {
    // iterate over string looking for ^begin ddd$
    final String lineStr = "(^.*$)";
    final String startUuencodeStr = "begin \\d\\d\\d .*";
    final Pattern linePattern = Pattern.compile(lineStr, Pattern.MULTILINE);
    final Matcher matcher = linePattern.matcher(content);
    while (matcher.find()) {
        final String line = matcher.group(0);
        if (line.matches(startUuencodeStr)) {
            final int lastSpace = line.lastIndexOf(" ");
            final String filename = line.substring(lastSpace + 1);
            buf.append("    <part type=\"uuencoded\" filename=\"");
            buf.append(filename).append("\"/>").append(LS);
        }//from   ww w  .j a  v  a 2 s. c o m
    }
}

From source file:org.j2free.util.HtmlFilter.java

/**
 *
 * @param text//ww  w.  java 2s.c om
 * @return
 */
public String filterForEmail(String text) {
    Pattern links = Pattern.compile(LINK_PATTERN, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

    Matcher matcher = links.matcher(text);
    text = matcher.replaceAll("$2 [link: $1]");

    // First replace <tr> and <br> with \n
    text = text.replaceAll(EMAIL_LINE_BREAKS, "\n");

    text = strictFilter(text);

    text = text.replaceAll(NOBR_SPACE_PATTERN, " ") // make all &nbsp; into plain text spaces
            .replaceAll("\t", " ") // make all tabs spaces
            .replaceAll(" {2,}", " ") // make all multiple space sections a single space
            .replaceAll("^\\s", "") // remove any leaving space
            .replaceAll("\n{2,}", "\n\n"); // make sure there aren't too many line breaks in a row

    // Get the text as lines
    String[] lines = text.split("\n");
    String[] words;

    StringBuilder body = new StringBuilder();

    int lineLength = 0;
    String lastWord;
    for (String line : lines) {
        words = line.split("\\s");
        lineLength = 0;

        lastWord = "";
        for (String word : words) {
            if (lineLength > 0 && lineLength + word.length() >= PLAINTEXT_LINE_LENGTH
                    && !lastWord.equals("[link:")) {
                body.append("\n" + word);
                lineLength = word.length();
            } else {
                body.append((lineLength > 0 ? " " : "") + word);
                lineLength += word.length();
            }
            lastWord = word;
        }
        body.append("\n");
    }
    return body.toString().replaceAll("\n{3,}", "\n\n");
}

From source file:org.eurekastreams.commons.search.explanation.FieldMatchDeterminer.java

/**
 * Parse the input Explanation string to find which of the input search keywords matched with the input Analyzer.
 *
 * @param inExplanationText/*from  ww w  .  ja  va  2 s.  co m*/
 *            the Explanation text returned from the search
 * @param searchText
 *            the search string the user typed
 * @return A Map with the keys representing the fields to analyze and the values as a list of keywords that the user
 *         typed as search parameters that matched the corresponding keyword.
 */
public FieldMatch determineFieldMatches(final String inExplanationText, final String searchText) {
    String explanationText = inExplanationText;

    FieldMatch matchedKeywords = new FieldMatch();
    if (fieldsToAnalyze.size() == 0) {
        return matchedKeywords;
    }

    log.debug("Explanation:" + explanationText);

    // Remove the boost values, makes things easier...
    Pattern boostPattern = Pattern.compile("\\^[0-9]+.[0-9]+");
    Matcher boostPatternMatcher = boostPattern.matcher(explanationText);
    explanationText = boostPatternMatcher.replaceAll("");

    // convert the keywords to the analyzed form, then store them in a hashtable of <tokenizedForm, originalKeyword>
    Map<String, String> tokenizedKeywords = tokenizeKeywords(searchText);

    // We now have a Map with the tokenized keyword as the key, the original search word as the value.
    // Start looking through the explanation for the values
    for (String fieldName : fieldsToAnalyze) {
        Pattern weightPattern = Pattern.compile("\\sweight\\(" + fieldName + ":(\\w+)\\s",
                java.util.regex.Pattern.CASE_INSENSITIVE | java.util.regex.Pattern.MULTILINE);
        Matcher m = weightPattern.matcher(explanationText);
        boolean result = m.find();
        while (result) {
            matchedKeywords.addMatch(fieldName, tokenizedKeywords.get(m.group(1)));
            result = m.find();
        }
    }
    return matchedKeywords;
}

From source file:org.jetbrains.jet.grammar.GrammarGenerator.java

private static StringBuilder markDeclarations(CharSequence allRules) {
    StringBuilder output = new StringBuilder();

    Pattern symbolReference = Pattern.compile("^\\w+$", Pattern.MULTILINE);
    Matcher matcher = symbolReference.matcher(allRules);
    int copiedUntil = 0;
    while (matcher.find()) {
        int start = matcher.start();
        output.append(allRules.subSequence(copiedUntil, start));

        String group = matcher.group();
        output.append("&").append(group);
        copiedUntil = matcher.end();//from w  ww.  j av  a2  s  . com
    }
    output.append(allRules.subSequence(copiedUntil, allRules.length()));
    return output;
}

From source file:org.eclim.installer.ant.CleanupTask.java

/**
 * Executes this task.// w  ww  . ja v a 2  s  .  c  om
 */
public void execute() throws BuildException {
    Command command = null;
    try {
        Project project = Installer.getProject();

        String url = project.getProperty("eclim.feature.location");
        command = new UninstallCommand(null, url, "org.eclim.installer", "org.eclipse.equinox.p2.director");
        command.start();
        command.join();
        if (command.getReturnCode() != 0) {
            logger.warn("error: " + command.getErrorMessage() + " out: " + command.getResult());
        }

        // remove installer plugin jar + artifacts.xml entry which the p2
        // director does not.
        new File(project.replaceProperties("${eclipse.local}/plugins/org.eclim.installer_${eclim.version}.jar"))
                .delete();

        FileInputStream fin = new FileInputStream(project.replaceProperties("${eclipse.local}/artifacts.xml"));
        FileWriter fout = null;
        try {
            String artifacts = IOUtils.toString(fin);
            fin.close();
            Pattern pattern = Pattern.compile(
                    "\n\\s*<artifact classifier='osgi.bundle' " + "id='org\\.eclim\\.installer.*?</artifact>",
                    Pattern.DOTALL);
            artifacts = pattern.matcher(artifacts).replaceFirst("");
            fout = new FileWriter(project.replaceProperties("${eclipse.local}/artifacts.xml"));
            fout.write(artifacts);
        } finally {
            IOUtils.closeQuietly(fout);
            IOUtils.closeQuietly(fin);
        }

        // remove references to the temp formic update site.
        String settingsDir = "p2/org.eclipse.equinox.p2.engine/.settings/";
        String profileSettingsDir = "p2/org.eclipse.equinox.p2.engine/profileRegistry/"
                + "SDKProfile.profile/.data/.settings/";
        String[] files = new String[] { settingsDir + "org.eclipse.equinox.p2.artifact.repository.prefs",
                settingsDir + "org.eclipse.equinox.p2.metadata.repository.prefs",
                profileSettingsDir + "org.eclipse.equinox.p2.artifact.repository.prefs",
                profileSettingsDir + "org.eclipse.equinox.p2.metadata.repository.prefs", };
        Pattern pattern = Pattern.compile("^.*formic.*$\n", Pattern.MULTILINE);
        for (int ii = 0; ii < files.length; ii++) {
            File file = new File(project.replaceProperties("${eclipse.local}/" + files[ii]));
            if (file.exists()) {
                try {
                    fin = new FileInputStream(file);
                    String contents = IOUtils.toString(fin);
                    contents = pattern.matcher(contents).replaceAll("");
                    fin.close();

                    fout = new FileWriter(file);
                    fout.write(contents);
                } catch (Exception e) {
                    logger.warn("Error removing formic update site references.", e);
                    e.printStackTrace();
                } finally {
                    IOUtils.closeQuietly(fout);
                    IOUtils.closeQuietly(fin);
                }
            }
        }
    } catch (Exception e) {
        throw new BuildException(e);
    } finally {
        if (command != null) {
            command.destroy();
        }
    }
}

From source file:org.webcat.notifications.googlevoice.GoogleVoice.java

/**
 * Logs in to the Google Voice service./*from w ww. j a v a  2s .  co m*/
 */
public void login() {
    HttpUriRequest request = buildRequest(CLIENT_LOGIN_URL, true, "accountType", "GOOGLE", "Email", username,
            "Passwd", password, "service", "grandcentral", "source", source);

    new AsyncURLConnection(request, new SimpleURLConnectionDelegate() {
        public void didFinishLoading() {
            if (statusCode() == HttpStatus.SC_OK) {
                Pattern pattern = Pattern.compile("^auth=(.*)$", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
                Matcher matcher = pattern.matcher(responseString());

                if (matcher.find()) {
                    authToken = matcher.group(1);
                }

                if (authToken != null) {
                    getRnrSeToken();
                } else {
                    delegate.loginFailed(GoogleVoice.this, new IOException("No authorization token received."));
                }
            } else {
                delegate.loginFailed(GoogleVoice.this,
                        new IOException("Google Voice login failed with status code " + statusCode()));
            }
        }

        public void didFailWithException(IOException e) {
            delegate.loginFailed(GoogleVoice.this, e);
        }
    });
}