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:com.adguard.filter.rules.UrlFilterRule.java

/**
 * Url regular expression/* ww w .  j a v a  2  s  . com*/
 *
 * @return Regexp
 */
public synchronized Pattern getUrlRegexp() {
    if (invalidRule) {
        return null;
    }

    loadRuleProperties();

    if (urlRegexp == null) {

        int regexOptions = Pattern.DOTALL;
        if (!isOptionEnabled(UrlFilterRuleOption.MATCH_CASE)) {
            regexOptions = regexOptions | Pattern.CASE_INSENSITIVE;
        }
        urlRegexp = Pattern.compile(regex, regexOptions);
        regex = null;
    }

    return urlRegexp;
}

From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java

@Override
protected WakabaReader getWakabaReader(InputStream stream, UrlPageModel urlModel) {
    return new WakabaReader(stream, DATE_FORMAT, canCloudflare()) {
        private final Pattern aHrefPattern = Pattern.compile("<a\\s+href=\"(.*?)\"", Pattern.DOTALL);
        private final Pattern attachmentSizePattern = Pattern.compile("([\\d\\.]+)[KM]B");
        private final Pattern attachmentPxSizePattern = Pattern.compile("(\\d+)x(\\d+)");
        private final char[] dateFilter = "<span class=\"mobile_date dast-date\">".toCharArray();
        private final char[] attachmentFilter = "<span class=\"filesize fs_".toCharArray();
        private ArrayList<AttachmentModel> myAttachments = new ArrayList<>();
        private int curDatePos = 0;
        private int curAttachmentPos = 0;

        @Override//  w w w  . j  a v  a  2s  . co m
        protected void customFilters(int ch) throws IOException {
            if (ch == dateFilter[curDatePos]) {
                ++curDatePos;
                if (curDatePos == dateFilter.length) {
                    parseDate(readUntilSequence("</span>".toCharArray()).trim());
                    curDatePos = 0;
                }
            } else {
                if (curDatePos != 0)
                    curDatePos = ch == dateFilter[0] ? 1 : 0;
            }

            if (ch == attachmentFilter[curAttachmentPos]) {
                ++curAttachmentPos;
                if (curAttachmentPos == attachmentFilter.length) {
                    skipUntilSequence(">".toCharArray());
                    myParseAttachment(readUntilSequence("</span>".toCharArray()));
                    curAttachmentPos = 0;
                }
            } else {
                if (curAttachmentPos != 0)
                    curAttachmentPos = ch == attachmentFilter[0] ? 1 : 0;
            }
        }

        @Override
        protected void parseDate(String date) {
            date = date.substring(date.indexOf(' ') + 1);
            super.parseDate(date);
        }

        private void myParseAttachment(String html) {
            Matcher aHrefMatcher = aHrefPattern.matcher(html);
            if (aHrefMatcher.find()) {
                AttachmentModel attachment = new AttachmentModel();
                attachment.path = aHrefMatcher.group(1);
                attachment.thumbnail = attachment.path.replaceAll("/src/(\\d+)/(?:.*?)\\.(.*?)$",
                        "/thumb/$1s.$2");
                if (attachment.thumbnail.equals(attachment.path)) {
                    attachment.thumbnail = null;
                } else {
                    attachment.thumbnail = attachment.thumbnail.replace(".webm", ".png");
                }

                String ext = attachment.path.substring(attachment.path.lastIndexOf('.') + 1);
                switch (ext) {
                case "jpg":
                case "jpeg":
                case "png":
                    attachment.type = AttachmentModel.TYPE_IMAGE_STATIC;
                    break;
                case "gif":
                    attachment.type = AttachmentModel.TYPE_IMAGE_GIF;
                    break;
                case "svg":
                case "svgz":
                    attachment.type = AttachmentModel.TYPE_IMAGE_SVG;
                    break;
                case "webm":
                case "mp4":
                    attachment.type = AttachmentModel.TYPE_VIDEO;
                    break;
                default:
                    attachment.type = AttachmentModel.TYPE_OTHER_FILE;
                }

                Matcher sizeMatcher = attachmentSizePattern.matcher(html);
                if (sizeMatcher.find()) {
                    try {
                        int mul = sizeMatcher.group(0).endsWith("MB") ? 1024 : 1;
                        attachment.size = Math.round(Float.parseFloat(sizeMatcher.group(1)) * mul);
                    } catch (Exception e) {
                        attachment.size = -1;
                    }
                    try {
                        Matcher pxSizeMatcher = attachmentPxSizePattern.matcher(html);
                        if (!pxSizeMatcher.find(sizeMatcher.end()))
                            throw new Exception();
                        attachment.width = Integer.parseInt(pxSizeMatcher.group(1));
                        attachment.height = Integer.parseInt(pxSizeMatcher.group(2));
                    } catch (Exception e) {
                        attachment.width = -1;
                        attachment.height = -1;
                    }
                } else {
                    attachment.size = -1;
                    attachment.width = -1;
                    attachment.height = -1;
                }

                myAttachments.add(attachment);
            }
        }

        @Override
        protected void postprocessPost(PostModel post) {
            post.attachments = myAttachments.toArray(new AttachmentModel[myAttachments.size()]);
            myAttachments.clear();
        }
    };
}

From source file:com.akop.bach.parser.PsnParser.java

protected ArrayList<HashMap<String, String>> parsePairsInSimpleXml(String document, String nodeName) {
    Pattern outerNode = Pattern.compile("<" + nodeName + "(?:\\s+[^>]*)?>(.*?)</" + nodeName + ">",
            Pattern.DOTALL);
    Pattern innerNode = Pattern.compile("<(\\w+)[^>]*>([^<]*)</\\1>");

    ArrayList<HashMap<String, String>> kvpList = new ArrayList<HashMap<String, String>>();

    Matcher nodeMatcher = outerNode.matcher(document);
    while (nodeMatcher.find()) {
        String content = nodeMatcher.group(1);

        Matcher m = innerNode.matcher(content);
        HashMap<String, String> items = new HashMap<String, String>();

        while (m.find()) {
            String innerNodeName = m.group(1);
            if (items.containsKey(innerNodeName))
                continue;

            items.put(innerNodeName, m.group(2));
        }/*from  w ww. ja  v  a2s.  co m*/

        if (items.size() > 0)
            kvpList.add(items);
    }

    return kvpList;
}

From source file:org.opencastproject.userdirectory.JpaGroupRoleProvider.java

private boolean like(final String str, final String expr) {
    if (str == null)
        return false;
    String regex = expr.replace("_", ".").replace("%", ".*?");
    Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    return p.matcher(str).matches();
}

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

private void formatCode() {
    replaceAll("``", "``", SpanObjectFactory.CODE_BLOCK);
    replaceAll("`", "`", SpanObjectFactory.CODE_BLOCK);
    replaceAll("^``\r\n", "\r\n``$", SpanObjectFactory.CODE_BLOCK, Pattern.DOTALL);
}

From source file:hudson.plugins.android_emulator.SdkInstaller.java

private static boolean isPlatformInstalled(PrintStream logger, Launcher launcher, AndroidSdk sdk,
        String platform, String abi) throws IOException, InterruptedException {
    ByteArrayOutputStream targetList = new ByteArrayOutputStream();
    // Preferably we'd use the "--compact" flag here, but it wasn't added until r12,
    // nor does it give any information about which system images are installed...
    Utils.runAndroidTool(launcher, targetList, logger, sdk, Tool.ANDROID, "list target", null);
    boolean platformInstalled = targetList.toString().contains('"' + platform + '"');
    if (!platformInstalled) {
        return false;
    }/*from w w w  . j a  v  a 2s. c o  m*/

    if (abi != null) {
        // Check whether the desired ABI is included in the output
        Pattern regex = Pattern.compile(String.format("\"%s\".+?%s", platform, abi), Pattern.DOTALL);
        Matcher matcher = regex.matcher(targetList.toString());
        if (!matcher.find() || matcher.group(0).contains("---")) {
            // We did not find the desired ABI within the section for the given platform
            return false;
        }
    }

    // Everything we wanted is installed
    return true;
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.css.FerramentaCSSPanel.java

/**
 * Implementando//from   ww w  .  j a v  a2  s  .c o  m
 * @param codHtml
 * @return lista de links de css
 */
@SuppressWarnings("unused")
private List<String> getCssUrlList(String codHtml) {
    ArrayList<String> urls = new ArrayList<String>();
    Pattern pat = Pattern.compile("<link\\s.*?>", Pattern.DOTALL);
    Matcher mat = pat.matcher(codHtml);
    RegrasHardCodedEmag regra = new RegrasHardCodedEmag();
    while (mat.find()) {
        String tag = mat.group();
        String tipo = regra.getAtributo(tag, "type");
        String href = regra.getAtributo(tag, "href");
        if (tipo.equals("text/css") || href.toLowerCase().endsWith(".css")) {
            urls.add(href);
        }
    }
    return urls;
}

From source file:org.apache.ode.test.BPELTestAbstract.java

protected Invocation addInvoke(String id, QName target, String operation, String request,
        String responsePattern, Invocation synchronizeWith) throws Exception {

    Invocation inv = new Invocation(id, synchronizeWith);
    inv.target = target;/* ww w.  jav  a  2 s .  c  o m*/
    inv.operation = operation;
    inv.request = DOMUtils.stringToDOM(request);
    inv.expectedStatus = null;
    if (responsePattern != null) {
        inv.expectedFinalStatus = MessageExchange.Status.RESPONSE;
        inv.expectedResponsePattern = Pattern.compile(responsePattern, Pattern.DOTALL);
    }

    _invocations.add(inv);
    return inv;
}

From source file:de.mpg.escidoc.services.reporting.ReportFHI.java

public static String replaceAllTotal(String what, String expr, String replacement) {
    return Pattern.compile(expr, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(what)
            .replaceAll(replacement);/*from  w  w w . j a  v  a 2  s . c  o  m*/
}

From source file:com.wavemaker.studio.StudioService.java

@ExposeToClient
public Hashtable<String, Object> getLogUpdate(String filename, String lastStamp) throws IOException {
    java.io.File logFolder = new java.io.File(System.getProperty("catalina.home") + "/logs/ProjectLogs",
            this.projectManager.getCurrentProject().getProjectName());
    java.io.File logFile = new java.io.File(logFolder, filename);
    if (!logFile.exists()) {
        Hashtable<String, Object> PEmpty = new Hashtable<String, Object>();
        PEmpty.put(LOG_UPDATE_LOGS, "");
        PEmpty.put(LOG_UPDATE_LAST_STAMP, 0);
        return PEmpty;
    }/*from w w w  .j  ava2 s . com*/
    InputStream inputStream = new FileInputStream(logFile);
    try {
        String logFileContent = IOUtils.toString(inputStream);
        if (lastStamp.length() > 0) {
            // remove everything up to START_WM_LOG_LINE lastStamp
            Pattern pattern = Pattern.compile("^.*START_WM_LOG_LINE\\s+" + lastStamp + "\\s+", Pattern.DOTALL);
            Matcher matcher = pattern.matcher(logFileContent);
            logFileContent = matcher.replaceFirst("");
            // Replace everything from the start of whats left of this line to END_WM_LOG_LINE
            logFileContent = logFileContent.replaceFirst("^.*?END_WM_LOG_LINE", "");
        }

        Pattern htmlTagPattern = Pattern
                .compile("(START_WM_LOG_LINE\\s+\\d+\\:\\d+\\:\\d+,\\d+\\s+)(\\S+) (\\(.*\\))");
        Matcher htmlTagMatcher = htmlTagPattern.matcher(logFileContent);
        logFileContent = htmlTagMatcher
                .replaceAll("$1<span class='LogType$2'>$2</span> <span class='LogLocation'>$3</span>");

        Pattern p = Pattern.compile("START_WM_LOG_LINE\\s+\\d+\\:\\d+\\:\\d+,\\d+");
        Matcher m = p.matcher(logFileContent);
        String timestamp = "";
        while (m.find()) {
            timestamp = m.group();
            timestamp = timestamp.replaceFirst("START_WM_LOG_LINE\\s+.*?", "");
        }
        Hashtable<String, Object> logUpdate = new Hashtable<String, Object>();
        logFileContent = m.replaceAll(""); // remove all START_WM_LOG_LINE xxx:xxx:xxx,xxx
        logFileContent = logFileContent.replaceAll(" END_WM_LOG_LINE", "");
        if (logFileContent.matches("^\\s+$")) {
            logFileContent = "";
        }
        logFileContent = logFileContent.replaceAll("(\\S+)(\\n\\r|\\r\\n|\\n|\\r)", "$1<br/>");
        Pattern trimPattern = Pattern.compile("^\\s*", Pattern.MULTILINE);
        Matcher trimMatcher = trimPattern.matcher(logFileContent);
        logFileContent = trimMatcher.replaceAll("");
        logUpdate.put(LOG_UPDATE_LOGS, logFileContent);
        logUpdate.put(LOG_UPDATE_LAST_STAMP, timestamp);
        return logUpdate;
    } finally {
        inputStream.close();
    }
}