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:edu.scripps.fl.pubchem.web.session.PCWebSession.java

/**
 * //from w w w  .j av  a  2 s.c  om
 * Returns counts of active, all, inactive, inconclusive and probe
 * substances in the aid.
 * 
 * @param aid
 * @return OutComeCount
 * @throws Exception
 */
public PCOutcomeCounts getSubstanceOutcomeCounts(int aid) throws Exception {
    PCOutcomeCounts oc = null;
    Document doc = getDocument("http://" + SITE + "/assay/assay.cgi?aid=" + aid);
    Node node = doc.selectSingleNode("//div[@id='uptsub']");
    //      Node node = doc.selectSingleNode("//b[. = 'Links:']");
    //Node node = doc.selectSingleNode("//b[. = 'Substances: ']");
    if (node != null) {
        node = node.getParent();
        AppendingVisitorSupport visitor = new AppendingVisitorSupport();
        node.accept(visitor);
        String text = visitor.getText();
        Pattern sectionPattern = Pattern.compile("Tested Substances(.+)", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher matcher = sectionPattern.matcher(text);
        Boolean found = matcher.find();
        if (found) {
            text = matcher.group(1);
            Pattern countPattern;
            if (text.contains("("))
                countPattern = Pattern.compile("([\\w]+)\\((\\d+)\\)");
            else
                countPattern = Pattern.compile("([\\w]+):\\s+(\\d+)");

            matcher = countPattern.matcher(text);
            oc = new PCOutcomeCounts();
            while (matcher.find()) {
                String outcome = matcher.group(1);
                int count = Integer.parseInt(matcher.group(2));
                if ("All".equalsIgnoreCase(outcome))
                    oc.all = count;
                else if (outcome.contains("All"))
                    oc.all = count;
                else if ("Active".equalsIgnoreCase(outcome))
                    oc.active = count;
                else if ("Inactive".equalsIgnoreCase(outcome))
                    oc.inactive = count;
                else if ("Inconclusive".equalsIgnoreCase(outcome))
                    oc.inconclusive = count;
                else if ("Probe".equalsIgnoreCase(outcome))
                    oc.probe = count;
            }
        }
    }
    return oc;
}

From source file:com.icesoft.faces.webapp.parser.JspPageToDocument.java

static String toSingletonTag(String pattern, String input) {
    Pattern tagPattern = Pattern.compile(pattern, Pattern.DOTALL);
    Matcher tagMatcher = tagPattern.matcher(input);
    StringBuffer tagBuf = new StringBuffer();
    while (tagMatcher.find()) {
        String tagName = tagMatcher.group(1);
        String attributes = tagMatcher.group(2);
        tagMatcher.appendReplacement(tagBuf, escapeBackreference("<" + tagName + attributes + "/>"));
    }/*from ww  w  .j av  a2s .com*/
    tagMatcher.appendTail(tagBuf);
    return tagBuf.toString();
}

From source file:de.appsolve.padelcampus.admin.controller.general.AdminGeneralModulesController.java

private void rewriteLinks(Module model) {
    if (model.getId() != null) {
        Module existingModule = moduleDAO.findById(model.getId());
        if (!model.getUrlTitle().equals(existingModule.getUrlTitle())) {
            String oldHref = String.format("href=\"(%s|/page%s)\"", existingModule.getUrl(),
                    existingModule.getUrl());
            String newHref = String.format("href=\"%s\"", model.getUrl());
            Pattern p = Pattern.compile(oldHref, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            for (PageEntry pageEntry : pageEntryDAO.findAll()) {
                String message = pageEntry.getMessage();
                if (!StringUtils.isEmpty(message)) {
                    Matcher m = p.matcher(message);
                    if (m.find()) {
                        LOG.info(String.format("replacing links %s by %s in page entry %s", oldHref, newHref,
                                pageEntry.getId()));
                        pageEntry.setMessage(m.replaceAll(newHref));
                        pageEntryDAO.saveOrUpdate(pageEntry);
                    }/*from   ww  w. j  av  a  2  s  .c o m*/
                }

            }
        }
    }
}

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

public static Map<String, Object> findSubs(String hash, long size, String imdb, String query,
        RendererConfiguration r) throws IOException {
    TreeMap<String, Object> res = new TreeMap<>();
    if (!login()) {
        return res;
    }// www .ja  va2 s  .c om
    String lang = UMSUtils.getLangList(r, true);
    URL url = new URL(OPENSUBS_URL);
    String hashStr = "";
    String imdbStr = "";
    String qStr = "";
    if (!StringUtils.isEmpty(hash)) {
        hashStr = "<member><name>moviehash</name><value><string>" + hash + "</string></value></member>\n"
                + "<member><name>moviebytesize</name><value><double>" + size + "</double></value></member>\n";
    } else if (!StringUtils.isEmpty(imdb)) {
        imdbStr = "<member><name>imdbid</name><value><string>" + imdb + "</string></value></member>\n";
    } else if (!StringUtils.isEmpty(query)) {
        qStr = "<member><name>query</name><value><string>" + query + "</string></value></member>\n";
    } else {
        return res;
    }
    String req = null;
    tokenLock.readLock().lock();
    try {
        req = "<methodCall>\n<methodName>SearchSubtitles</methodName>\n" + "<params>\n<param>\n<value><string>"
                + token + "</string></value>\n</param>\n"
                + "<param>\n<value>\n<array>\n<data>\n<value><struct><member><name>sublanguageid"
                + "</name><value><string>" + lang + "</string></value></member>" + hashStr + imdbStr + qStr
                + "\n" + "</struct></value></data>\n</array>\n</value>\n</param>"
                + "</params>\n</methodCall>\n";
    } finally {
        tokenLock.readLock().unlock();
    }
    Pattern re = Pattern.compile(
            "SubFileName</name>.*?<string>([^<]+)</string>.*?SubLanguageID</name>.*?<string>([^<]+)</string>.*?SubDownloadLink</name>.*?<string>([^<]+)</string>",
            Pattern.DOTALL);
    String page = postPage(url.openConnection(), req);
    Matcher m = re.matcher(page);
    while (m.find()) {
        LOGGER.debug("found subtitle " + m.group(2) + " name " + m.group(1) + " zip " + m.group(3));
        res.put(m.group(2) + ":" + m.group(1), m.group(3));
        if (res.size() > PMS.getConfiguration().liveSubtitlesLimit()) {
            // limit the number of hits somewhat
            break;
        }
    }
    return res;
}

From source file:de.mpg.escidoc.services.syndication.feed.Feed.java

/**
 * Populate parameters with the values taken from the certain <code>uri</code> 
 * and populate <code>paramHash</code> with the parameter/value paars.
 * @param uri// w  w  w . j  a  v  a2  s.  c om
 * @throws SyndicationException
 */
private void populateParamsFromUri(String uri) throws SyndicationException {
    Utils.checkName(uri, "Uri is empty");

    String um = getUriMatcher();

    Utils.checkName(um, "Uri matcher is empty");

    Matcher m = Pattern.compile(um, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(uri);
    if (m.find()) {
        for (int i = 0; i < m.groupCount(); i++)
            paramHash.put((String) paramList.get(i), m.group(i + 1));
    }

    //special handling of Organizational Unit Feed
    //TODO: should be resolved other way!
    if (getUriMatcher().equals("(.+)?/syndication/feed/(.+)?/publications/organization/(.+)?")) {
        TreeMap<String, String> outm = Utils.getOrganizationUnitTree();
        String oid = (String) paramHash.get("${organizationId}");
        for (Map.Entry<String, String> entry : outm.entrySet()) {
            if (entry.getValue().equals(oid)) {
                paramHash.put("${organizationName}", entry.getKey());
            }
        }
    }

    logger.info("parameters: " + paramHash);

}

From source file:com.gs.obevo.db.apps.reveng.AbstractDdlReveng.java

/**
 * TODO move to Sybase subclass.//from w w w.  j av a  2 s .c o m
 */
public String removeQuotesFromProcxmode(String input) {
    Pattern compile = Pattern.compile("sp_procxmode '(?:\")(.*?)(?:\")'", Pattern.DOTALL);

    Matcher matcher = compile.matcher(input);
    if (matcher.find()) {
        return matcher.replaceAll("sp_procxmode '" + matcher.group(1) + "'");
    } else {
        return input;
    }
}

From source file:org.kuali.rice.krms.impl.repository.mock.CriteriaMatcherInMemory.java

private static Pattern compilePattern(final String expr) {
    String regex = quotemeta(expr);
    regex = regex.replace("_", ".").replace("%", ".*?");
    Pattern p = Pattern.compile(regex, Pattern.DOTALL);
    return p;/* ww  w .ja va2s.  co  m*/
}

From source file:org.etudes.util.HtmlHelper.java

/**
 * Remove link and meta tags//from  w w  w .  ja  va2s  . c  o  m
 * 
 * @param data
 *        the html data.
 * @return The cleaned up data.
 */
public static String stripLinks(String data) {
    if (data == null)
        return data;

    // pattern to find link/meta tags
    Pattern p = Pattern.compile("<(link|meta)\\s+.*?(/*>)",
            Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);

    Matcher m = p.matcher(data);
    StringBuffer sb = new StringBuffer();

    while (m.find()) {
        m.appendReplacement(sb, "");
    }

    m.appendTail(sb);

    return sb.toString();
}

From source file:com.evandroid.musica.MainLyricActivity.java

private String getIdUrl(String extra) {
    final Pattern urlPattern = Pattern.compile(
            "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
                    + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);

    Matcher matcher = urlPattern.matcher(extra);
    if (matcher.find())
        return extra.substring(matcher.start(), matcher.end());
    else//from w  ww .j  a v a 2 s. c  o  m
        return null;
}

From source file:net.issarlk.androbunny.inkbunny.API.java

public void scrapeUserPage(User argUser) throws IOException {
    argUser.profile = "Couldn't read user profile";
    String data = "";
    try {//from  ww  w . j  ava2  s .c  om
        data = AndrobunnyAppSingleton.androbunnyapp.readUri(new URI("https://inkbunny.net/" + argUser.name));
    } catch (URISyntaxException e2) {
        Log.e(TAG, e2.toString());
    }
    // Extract profile
    Pattern pattern = Pattern.compile(".*<div class='title'>Profile</div>.*?(<.*)",
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    argUser.profile = extractTree(pattern, data);
    // Extract user icon
    pattern = Pattern.compile(
            "<img [^>]*? src='([^']*)' [^>]*? alt='" + argUser.name + "' title='" + argUser.name + "'[^>]*?/>",
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(data);
    if (matcher.find()) {
        //Found the user icon
        try {
            argUser.icons[0] = new Icon(Icon.LARGE, new URI(matcher.group(1)));
        } catch (URISyntaxException e) {
            Log.e(TAG, e.toString());
        }
    }
}