Example usage for java.util.regex Pattern DOTALL

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

Introduction

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

Prototype

int DOTALL

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

Click Source Link

Document

Enables dotall mode.

Usage

From source file:org.vanbest.xmltv.TvGids.java

private void fillScraperDetails(String id, Programme result) throws Exception {
    Pattern progInfoPattern = Pattern.compile("prog-info-content.*prog-info-footer", Pattern.DOTALL);
    Pattern infoLinePattern = Pattern.compile("<li><strong>(.*?):</strong>(.*?)</li>");
    Pattern HDPattern = Pattern.compile("HD \\d+[ip]?");
    Pattern kijkwijzerPattern = Pattern
            .compile("<img src=\"http://tvgidsassets.nl/img/kijkwijzer/.*?\" alt=\"(.*?)\" />");

    URL url = HTMLDetailUrl(id);// ww  w  . j a v a 2s .  c o m
    String clob = fetchURL(url);
    Matcher m = progInfoPattern.matcher(clob);
    if (m.find()) {
        String progInfo = m.group();
        Matcher m2 = infoLinePattern.matcher(progInfo);
        while (m2.find()) {
            logger.trace("    infoLine: " + m2.group());
            logger.trace("         key: " + m2.group(1));
            logger.trace("       value: " + m2.group(2));
            String key = m2.group(1).toLowerCase();
            String value = m2.group(2);
            if (key.equals("bijzonderheden")) {
                String[] list = value.split(",");
                for (String item : list) {
                    if (item.toLowerCase().contains("teletekst")) {
                        result.addSubtitle("teletext");
                    } else if (item.toLowerCase().contains("breedbeeld")) {
                        result.setVideoAspect("16:9");
                    } else if (value.toLowerCase().contains("zwart")) {
                        result.setVideoColour(false);
                    } else if (value.toLowerCase().contains("stereo")) {
                        result.setAudioStereo("stereo");
                    } else if (value.toLowerCase().contains("herhaling")) {
                        result.setPreviouslyShown();
                    } else {
                        Matcher m3 = HDPattern.matcher(value);
                        if (m3.find()) {
                            result.setVideoQuality(m3.group());
                        } else {
                            logger.warn("  Unknown value in 'bijzonderheden': " + item);
                        }
                    }
                }
            } else {
                // ignore other keys for now
            }
            Matcher m3 = kijkwijzerPattern.matcher(progInfo);
            List<String> kijkwijzer = new ArrayList<String>();
            while (m3.find()) {
                kijkwijzer.add(m3.group(1));
            }
            if (!kijkwijzer.isEmpty()) {
                // logger.debug("    kijkwijzer: " + kijkwijzer);
            }
        }
    }
}

From source file:com.thoughtworks.go.config.materials.git.GitMaterialUpdaterTest.java

@Test
public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    Matcher matcher = Pattern
            .compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL)
            .matcher(console.output());/*from   ww w . j  av  a  2 s  .  c  o  m*/
    assertThat(matcher.matches(), Matchers.is(true));
}

From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java

private void formatSpoiler() {
    replaceAll("%%", "%%", SpanObjectFactory.SPOILER);
    replaceAll("%%", "%%", SpanObjectFactory.SPOILER);
    replaceAll("^%%\r\n", "\r\n%%$", SpanObjectFactory.SPOILER, Pattern.DOTALL);
}

From source file:ru.runa.common.web.HTMLUtils.java

private static Pattern getPatternForTag(String tagName) {
    final String pattern = "<\\s*%s(\\s+.*>|>)";
    if (!patternForTagCache.containsKey(tagName)) {
        patternForTagCache.put(tagName, Pattern.compile(String.format(pattern, tagName),
                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL));
    }//from   w  ww .ja  va  2 s.  c o  m
    return patternForTagCache.get(tagName);
}

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

public boolean postTurnSummary(final String message, final String subject) {
    try {/*from  ww w. ja  v  a 2 s  .c om*/
        login();

        // Now we load the post page, and find the hidden fields needed to post
        final GetMethod get = new GetMethod(
                "http://www.axisandallies.org/forums/index.php?action=post;topic=" + m_topicId + ".0");
        int status = m_client.executeMethod(m_hostConfiguration, get, m_httpState);
        String body = get.getResponseBodyAsString();
        if (status == 200) {
            String numReplies;
            String seqNum;
            String sc;
            Matcher m = NUM_REPLIES_PATTERN.matcher(body);
            if (m.matches()) {
                numReplies = m.group(1);
            } else {
                throw new Exception("Hidden field 'num_replies' not found on page");
            }

            m = SEQ_NUM_PATTERN.matcher(body);
            if (m.matches()) {
                seqNum = m.group(1);
            } else {
                throw new Exception("Hidden field 'seqnum' not found on page");
            }

            m = SC_PATTERN.matcher(body);
            if (m.matches()) {
                sc = m.group(1);
            } else {
                throw new Exception("Hidden field 'sc' not found on page");
            }

            // now we have the required hidden fields to reply to
            final PostMethod post = new PostMethod(
                    "http://www.axisandallies.org/forums/index.php?action=post2;start=0;board=40");

            try {
                // Construct the multi part post
                final List<Part> parts = new ArrayList<Part>();

                parts.add(createStringPart("topic", m_topicId));
                parts.add(createStringPart("subject", subject));
                parts.add(createStringPart("icon", "xx"));
                parts.add(createStringPart("message", message));

                // If the user has chosen to receive notifications, ensure this setting is passed on
                parts.add(createStringPart("notify", NOTIFY_PATTERN.matcher(body).matches() ? "1" : "0"));

                if (m_includeSaveGame && m_saveGameFile != null) {
                    final FilePart part = new FilePart("attachment[]", m_saveGameFileName, m_saveGameFile);
                    part.setContentType("application/octet-stream");
                    part.setTransferEncoding(null);
                    part.setCharSet(null);
                    parts.add(part);
                }

                parts.add(createStringPart("post", "Post"));
                parts.add(createStringPart("num_replies", numReplies));
                parts.add(createStringPart("additional_options", "1"));
                parts.add(createStringPart("sc", sc));
                parts.add(createStringPart("seqnum", seqNum));

                final MultipartRequestEntity entity = new MultipartRequestEntity(
                        parts.toArray(new Part[parts.size()]), new HttpMethodParams());
                post.setRequestEntity(entity);

                // add headers
                post.addRequestHeader("Referer",
                        "http://www.axisandallies.org/forums/index.php?action=post;topic=" + m_topicId
                                + ".0;num_replies=" + numReplies);
                post.addRequestHeader("Accept", "*/*");

                try {
                    // the site has spam prevention which means you can't post until 15 seconds after login
                    Thread.sleep(15 * 1000);
                } catch (final InterruptedException ie) {
                    ie.printStackTrace(); // this should never happen
                }

                post.setFollowRedirects(false);
                status = m_client.executeMethod(m_hostConfiguration, post, m_httpState);
                body = post.getResponseBodyAsString();
                if (status == 302) {
                    // site responds with a 302 redirect back to the forum index (board=40)

                    // The syntax for post is ".....topic=xx.yy" where xx is the thread id, and yy is the post number in the given thread
                    // since the site is lenient we can just give a high post_number to go to the last post in the thread
                    m_turnSummaryRef = "http://www.axisandallies.org/forums/index.php?topic=" + m_topicId
                            + ".10000";
                } else {
                    // these two patterns find general errors, where the first pattern checks if the error text appears,
                    // the second pattern extracts the error message. This could be the "The last posting from your IP was less than 15 seconds ago.Please try again later"

                    // this patter finds errors that are marked in red (for instance "You are not allowed to post URLs", or
                    // "Some one else has posted while you vere reading"

                    Matcher matcher = ERROR_LIST_PATTERN.matcher(body);
                    if (matcher.matches()) {
                        throw new Exception("The site gave an error: '" + matcher.group(1) + "'");
                    }

                    matcher = AN_ERROR_OCCURRED_PATTERN.matcher(body);
                    if (matcher.matches()) {
                        matcher = ERROR_TEXT_PATTERN.matcher(body);
                        if (matcher.matches()) {
                            throw new Exception("The site gave an error: '" + matcher.group(1) + "'");
                        }
                    }

                    final Header refreshHeader = post.getResponseHeader("Refresh");
                    if (refreshHeader != null) {
                        // sometimes the message will be flagged as spam, and a refresh url is given
                        final String value = refreshHeader.getValue(); // refresh: 0; URL=http://...topic=26114.new%3bspam=true#new
                        final Pattern p = Pattern.compile("[^;]*;\\s*url=.*spam=true.*",
                                Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
                        m = p.matcher(value);
                        if (m.matches()) {
                            throw new Exception("The summary was posted but was flagged as spam");
                        }
                    }
                    throw new Exception(
                            "Unknown error, please contact the forum owner and also post a bug to the tripleA development team");
                }
            } finally {
                post.releaseConnection();
                // Commented out log out call since it was causing all of a user's sessions to be logged out and doesn't appear to be needed
                // final GetMethod logout = new GetMethod("http://www.axisandallies.org/forums/index.php?action=logout;sesc=" + sc);
                // try
                // {
                // status = m_client.executeMethod(m_hostConfiguration, logout, m_httpState);
                // // site responds with a 200 + Refresh header to redirect to index.php
                // if (status != 200)
                // {
                // // nothing we can do if this fails
                // }
                // } finally
                // {
                // logout.releaseConnection();
                // }
            }
        } else {
            throw new Exception("Unable to load forum post " + m_topicId);
        }

    } catch (final Exception e) {
        m_turnSummaryRef = e.getMessage();
        return false;
    }

    return true;
}

From source file:com.alkacon.opencms.formgenerator.dialog.CmsFormEditDialog.java

/**
 * Checks if the given String value is needed a textarea or a normal input field.<p>
 * //w  ww  . j av  a2  s .c om
 * @param value the value to check if a textarea widget needed
 * 
 * @return <code>true</code>if a textarea widget is needed otherwise <code>false</code>
 */
private boolean isTextareaWidget(String value) {

    boolean result = false;

    if (value != null) {

        String escape = CmsStringUtil.escapeHtml(value);
        boolean length = (value.length() > STRING_TRIM_SIZE);
        length &= escape.matches(".*(<.{1,5}>|[ \\t\\n\\x0B\\f\\r]).*");

        Pattern pat = Pattern.compile(".*(<.{1,5}>|[\\t\\n\\x0B\\f\\r]).*", Pattern.DOTALL);
        Matcher match = pat.matcher(escape);
        result = (length || match.matches());
    }
    return result;
}

From source file:org.apache.falcon.regression.ui.search.MirrorWizardPage.java

private static String getBetween(String text, String first, String second) {
    Pattern pattern = Pattern.compile(".*" + first + "(.+)" + second + ".*", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(text);
    if (matcher.find()) {
        return matcher.group(1).trim();
    } else {/*  w w  w. j  av a2 s  .  c o  m*/
        return null;
    }
}

From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java

/**
 * Logs response details to debug and logs error message as error if found
 * @param filePost//from  w ww  . j  a  v  a  2 s .  c om
 * @throws IOException
 */
private void logResponseDetails(HttpMethodBase filePost) throws IOException {
    InputStream stream = filePost.getResponseBodyAsStream();
    if (stream == null) {
        throw new IOException("Null response stream");
    }

    String responseBody = IOUtils.toString(stream);
    getLog().debug("Response body: " + responseBody);

    String errorPattern = "(?<=<span class=\"error_line\">)(.+)(?=</span>)";
    Pattern regex = Pattern.compile(errorPattern,
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
    Matcher matcher = regex.matcher(responseBody);

    StringBuilder errorMessage = new StringBuilder();

    while (matcher.find()) {
        errorMessage.append(matcher.group() + " ");
    }

    if (!StringUtils.isEmpty(errorMessage.toString())) {
        getLog().error(errorMessage.toString());
    }
}

From source file:com.gewara.util.XSSFilter.java

protected String validateEntities(String s) {
    // validate entities throughout the string
    Pattern p = Pattern.compile("&([^&;]*)(?=(;|&|$))");
    Matcher m = p.matcher(s);/*from www . j  a  v  a2 s. co  m*/
    if (m.find()) {
        String one = m.group(1); // ([^&;]*)
        String two = m.group(2); // (?=(;|&|$))
        s = checkEntity(one, two);
    }

    // validate quotes outside of tags
    p = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
    m = p.matcher(s);
    StringBuffer buf = new StringBuffer();
    if (m.find()) {
        String one = m.group(1); // (>|^)
        String two = m.group(2); // ([^<]+?)
        String three = m.group(3); // (<|$)
        m.appendReplacement(buf, one + two.replaceAll("\"", "&quot;") + three);
    }
    m.appendTail(buf);

    return s;
}