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.ppwcode.vernacular.l10n_III.dojo.DojoDjConfigFilter.java

private String replaceDjConfig(StringBuffer buffer, Locale preferredLocale) {
    StringBuffer result = new StringBuffer(65536);

    // construct regexp
    String regexpFull = "^(.*?<script)"; // up to script tag
    regexpFull += "((\\s+type=\\s*(['\"])text/javascript\\4|"; // type
    regexpFull += "\\s+src=\\s*(['\"])[^'\"]*?dojo[^'\"]*?\\5|"; // src
    regexpFull += "\\s+djConfig=\\s*'[^']*'|";
    regexpFull += "\\s+djConfig=\\s*\"[^\"]*\"){3})"; // djConfig
    regexpFull += "(\\s*>\\s*</script>.*)$"; // closing script tag and afterwards
    LOG.debug("regexp: " + regexpFull);

    Pattern p = Pattern.compile(regexpFull, Pattern.DOTALL);
    Matcher m = p.matcher(buffer);
    // pattern group 1 - before, 2 - djConfig content, 3 - after
    if (m.matches()) {
        LOG.debug("djConfig is: " + m.group(2));
        result.append(m.group(1));/*from w w  w  .  jav a 2  s .  c o m*/
        result.append(replaceDjConfigLocale(m.group(2), preferredLocale));
        LOG.debug("after is: " + m.group(6));
        result.append(m.group(6));
        return result.toString();
    } else {
        LOG.debug("no match");
        return buffer.toString();
    }
}

From source file:com.adrup.saldo.bank.statoil.StatoilManager.java

@Override
public Map<AccountHashKey, RemoteAccount> getAccounts(Map<AccountHashKey, RemoteAccount> accounts)
        throws BankException {
    Log.d(TAG, "-> getAccounts()");
    // HttpClient httpClient = new SaldoHttpClient(mContext);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // Android doesn't like ICA's cert, so we need a forgiving TrustManager
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
    HttpParams params = new BasicHttpParams();
    HttpClient httpClient = new SaldoHttpClient(mContext,
            new ThreadSafeClientConnManager(params, schemeRegistry), null);

    try {//from w  w  w.j  a  va2s  .c  om

        //Do login
        List<NameValuePair> parameters = new ArrayList<NameValuePair>(3);
        parameters.add(new BasicNameValuePair("USERNAME", ("0122" + mBankLogin.getUsername()).toUpperCase()));
        parameters.add(new BasicNameValuePair("referer", "login.jsp"));
        String res = HttpHelper.post(httpClient, LOGIN_URL2, parameters);

        // Do login
        parameters = new ArrayList<NameValuePair>(3);
        parameters.add(new BasicNameValuePair(USER_PARAM, mBankLogin.getUsername()));
        parameters.add(new BasicNameValuePair(PASS_PARAM, mBankLogin.getPassword()));
        parameters.add(new BasicNameValuePair("target", "/nis/stse/main.do"));
        parameters.add(new BasicNameValuePair("prodgroup", "0122"));
        parameters.add(new BasicNameValuePair("USERNAME", ("0122" + mBankLogin.getUsername()).toUpperCase()));
        parameters.add(new BasicNameValuePair("METHOD", "LOGIN"));
        parameters.add(new BasicNameValuePair("CURRENT_METHOD", "PWD"));
        parameters.add(new BasicNameValuePair("choice", "PWD"));
        parameters.add(new BasicNameValuePair("forward", "Logga in"));

        Log.d(TAG, "logging in...");
        res = HttpHelper.post(httpClient, LOGIN_URL3, parameters);

        if (res.contains("errors.header")) {
            //login failed.. bail
            throw new AuthenticationException("auth fail");
        }

        //ACCOUNTS
        Log.d(TAG, "getting account info...");
        res = HttpHelper.get(httpClient, ACCOUNT_URL);
        //Log.d(TAG, "accounts html dump:");
        //Log.d(TAG, res);*

        Pattern pattern = Pattern.compile(ACCOUNTS_REGEX, Pattern.DOTALL);
        Matcher matcher = pattern.matcher(res);

        int ordinal = 1;
        while (matcher.find()) {

            String remoteId = String.valueOf(ordinal);
            ordinal = ordinal++;
            String name = "Statoil Mastercard";
            long balance = Long.parseLong(matcher.group(1).replaceAll("[^0-9\\-]", "")) / 100;
            accounts.put(new AccountHashKey(remoteId, mBankLogin.getId()),
                    new Account(remoteId, mBankLogin.getId(), ordinal, name, balance));
        }

    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
        throw new StatoilException(e.getMessage(), e);
    } catch (HttpException e) {
        Log.e(TAG, e.getMessage(), e);
        throw new StatoilException(e.getMessage(), e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    Log.d(TAG, "<- getAccounts()");

    return accounts;

}

From source file:co.pugo.convert.ConvertServlet.java

/**
 * extract a set of image links/*w w  w . j  a  v  a2s . c  o m*/
 * @param content document content as String
 * @return Set of http links to images
 */
private Set<String> extractImageLinks(String content) {
    final Set<String> imageLinks = new HashSet<>();
    final Scanner scanner = new Scanner(content);
    final Pattern imgPattern = Pattern.compile("<img(.*?)>", Pattern.DOTALL);
    final Pattern srcPattern = Pattern.compile("src=\"(.*?)\"");

    Matcher matchSrc;
    String imgMatch;

    while (scanner.findWithinHorizon(imgPattern, 0) != null) {
        imgMatch = scanner.match().group(1);
        matchSrc = srcPattern.matcher(imgMatch);
        if (matchSrc.find())
            imageLinks.add(matchSrc.group(1));
    }

    scanner.close();
    return imageLinks;
}

From source file:org.clickframes.util.CodeGenerator.java

public boolean modifiedSinceLastGeneration(File file) throws IOException {
    String fileAsString = FileUtils.readFileToString(file);
    // is checksum string present
    Pattern pattern = Pattern.compile(".*clickframes::(version=(\\d+))::clickframes.*", Pattern.DOTALL);
    Matcher m = pattern.matcher(fileAsString);
    if (!m.matches()) {
        // no match found, can't guarentee that it has not changed
        return true;
    }/* www. ja va2  s .  com*/
    long checksumFoundInFile = Long.parseLong(m.group(2));

    // calculate checksum of the remaining file
    String remainingFile = removeCommentForFilename(file.getName(), m.group(1), fileAsString);
    long checksum = checksum(remainingFile);
    return checksum != checksumFoundInFile;
}

From source file:com.surevine.alfresco.repo.impl.FilenameAndContentHTMLIdentifier.java

protected Pattern getHTMLContentRegularExpression() {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Getting HTMLContentRegex");
    }//  w w  w .j av a2  s.  c  o m
    StringBuffer sb = new StringBuffer(_htmlContent.length * 6);
    sb.append(".*(");
    for (int i = 0; i < _htmlContent.length; i++) {
        sb.append("(<\\s*?").append(_htmlContent[i]).append("[\\s>])");
        if (i < _htmlContent.length - 1) {
            sb.append("|");
        }
    }
    sb.append(").*");
    String rVal = sb.toString();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Created RE: " + rVal);
    }
    return Pattern.compile(rVal, Pattern.DOTALL);
}

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

protected String escapeComments(String s) {
    Pattern p = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
    Matcher m = p.matcher(s);//w ww.  j a  va 2s .c o m
    StringBuffer buf = new StringBuffer();
    if (m.find()) {
        String match = m.group(1); // (.*?)
        m.appendReplacement(buf, "<!--" + htmlSpecialChars(match) + "-->");
    }
    m.appendTail(buf);

    return buf.toString();
}

From source file:org.eclipse.skalli.services.search.SearchQuery.java

public void setPattern(String pattern, boolean ignoreCase) throws QueryParseException {
    if (StringUtils.isNotBlank(pattern)) {
        try {//from   w  ww . j  a  v a  2  s  .  c  om
            int flags = Pattern.DOTALL;
            if (ignoreCase) {
                flags = flags | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE;
            }
            setPattern(Pattern.compile(pattern, flags));
        } catch (PatternSyntaxException e) {
            throw new QueryParseException("Pattern has a syntax error", e);
        }
    }
}

From source file:net.pms.util.OpenSubtitle.java

public static String fetchImdbId(String hash) throws IOException {
    LOGGER.debug("fetch imdbid for hash " + hash);
    Pattern re = Pattern.compile("MovieImdbID.*?<string>([^<]+)</string>", Pattern.DOTALL);
    String info = checkMovieHash(hash);
    LOGGER.debug("info is " + info);
    Matcher m = re.matcher(info);
    if (m.find()) {
        return m.group(1);
    }/*from  w  w w  .  j  a v  a2s  .co m*/
    return "";
}

From source file:net.fizzl.redditengine.impl.UserApi.java

public void setPermissions(String user, String subreddit, String permissions, String type)
        throws RedditEngineException {
    // POST [/r/subreddit]/api/setpermissions
    // hard to test, gives 403
    StringBuilder path = new StringBuilder();
    path.append(UrlUtils.BASE_URL);
    if (subreddit != null && !subreddit.isEmpty()) {
        path.append("/r/");
        path.append(subreddit);/*from   w  ww.j  a  v a  2 s. c o  m*/
    }
    path.append("/api/setpermissions");
    String url = path.toString();

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("api_type", "json"));
    params.add(new BasicNameValuePair("name", user));
    params.add(new BasicNameValuePair("permissions", permissions));
    params.add(new BasicNameValuePair("type", type));

    try {
        SimpleHttpClient client = SimpleHttpClient.getInstance();
        InputStream is = client.post(url, params);
        // if a 403 occurs the response is HTML
        StringWriter writer = new StringWriter();
        IOUtils.copy(is, writer, "UTF-8");
        is.close();
        String response = writer.toString();
        Pattern pattern = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL);
        boolean containsHTML = pattern.matcher(response).find();
        if (containsHTML == false) {
            // create POJO here
            Log.d(getClass().getName(), response);
        } else {
            Log.e(getClass().getName(), "response was HTML: " + response.substring(0, 64) + "...");
        }
    } catch (ClientProtocolException e) {
        throw new RedditEngineException(e);
    } catch (IOException e) {
        throw new RedditEngineException(e);
    } catch (UnexpectedHttpResponseException e) {
        throw new RedditEngineException(e);
    }
}

From source file:de.mpg.mpdl.inge.exportmanager.Export.java

public String explainFormatsXML() throws ExportManagerException {

    // TODO: Revision with ValueObjects

    String citStyles;/*w  w  w  .  j  a va 2  s  .com*/
    try {
        citStyles = getCitationStyleHandler().explainStyles();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get citation styles explain", e);
    }

    String structured;
    try {
        structured = getStructuredExportHandler().explainFormats();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get structured exports explain", e);
    }

    String result;
    // get export-format elements
    String regexp = "<export-formats.*?>(.*?)</export-formats>";
    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(citStyles);
    m.find();
    result = m.group(1);
    m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(structured);
    m.find();
    result += m.group(1);

    m = Pattern.compile("<export-format\\s+.*</export-format>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(structured);
    m.find();
    result = m.replaceAll(result);

    // replace comments
    // m = Pattern
    // .compile(
    // "<!--.*?-->"
    // , Pattern.CASE_INSENSITIVE | Pattern.DOTALL
    // )
    // .matcher(result);
    // m.find();
    // result = m.replaceAll("");

    return result;
}