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.entando.entando.aps.system.services.guifragment.GuiFragmentManager.java

@Override
public List getGuiFragmentUtilizers(String guiFragmentCode) throws ApsSystemException {
    List<GuiFragment> utilizers = new ArrayList<GuiFragment>();
    try {/*from w  w  w  . j  a v  a  2 s  .c  om*/
        String strToSearch = "code=\"" + guiFragmentCode + "\"";
        Set<String> results = new HashSet<String>();
        results.addAll(this.searchFragments(strToSearch, "gui"));
        results.addAll(this.searchFragments(strToSearch, "defaultgui"));
        if (!results.isEmpty()) {
            Pattern pattern = Pattern.compile("<@wp\\.fragment.*code=\"" + guiFragmentCode + "\".*/>",
                    Pattern.MULTILINE);
            Iterator<String> it = results.iterator();
            while (it.hasNext()) {
                String fcode = it.next();
                GuiFragment fragment = this.getGuiFragment(fcode);
                if (this.scanTemplate(pattern, fragment.getGui())
                        || this.scanTemplate(pattern, fragment.getDefaultGui())) {
                    utilizers.add(fragment);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting utilizers", t);
        throw new ApsSystemException("Error extracting utilizers", t);
    }
    return utilizers;
}

From source file:nya.miku.wishmaster.chans.arhivach.ArhivachBoardReader.java

protected void parseTags(String s) throws IOException {
    Matcher matcher = Pattern.compile("<a[^>]*>([^<]*)</a>", Pattern.MULTILINE).matcher(s);
    String tags = "";
    while (matcher.find()) {
        tags += "[" + matcher.group(1) + "]";
    }//ww w .ja  va 2  s.c o  m
    currentPost.name = tags;
}

From source file:com.github.thorqin.toolkit.mail.MailService.java

public static Mail createMailByTemplateStream(InputStream in, Map<String, String> replaced) throws IOException {
    Mail mail = new Mail();
    InputStreamReader reader = new InputStreamReader(in, "utf-8");
    char[] buffer = new char[1024];
    StringBuilder builder = new StringBuilder();
    while (reader.read(buffer) != -1)
        builder.append(buffer);/*from  w  w w  . j av a2 s. c  o m*/
    String mailBody = builder.toString();
    builder.setLength(0);
    Pattern pattern = Pattern.compile("<%\\s*(.+?)\\s*%>", Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(mailBody);
    int scanPos = 0;
    while (matcher.find()) {
        builder.append(mailBody.substring(scanPos, matcher.start()));
        scanPos = matcher.end();
        String key = matcher.group(1);
        if (replaced != null) {
            String value = replaced.get(key);
            if (value != null) {
                builder.append(value);
            }
        }
    }
    builder.append(mailBody.substring(scanPos, mailBody.length()));
    mail.htmlBody = builder.toString();
    pattern = Pattern.compile("<title>(.*)</title>",
            Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(mail.htmlBody);
    if (matcher.find()) {
        mail.subject = matcher.group(1);
    }
    return mail;
}

From source file:org.squale.welcom.struts.webServer.WebEngine.java

/**
 * Suppression des commentaires /*/*from w  w  w .  j a v a 2 s  . c om*/
 * 
 * @param s chaine  nettoyer
 * @return chaine nettoye
 */
private String removeComments(final String s) {

    final StringBuffer sb = new StringBuffer();

    final Pattern patternDebut = Pattern.compile("/\\*", Pattern.MULTILINE);
    final Pattern patternFin = Pattern.compile("\\*/", Pattern.MULTILINE);
    final Matcher matcherDebut = patternDebut.matcher(s);
    final Matcher matcherFin = patternFin.matcher(s);

    int posStart = 0;
    int posEnd = 0;
    while (matcherDebut.find(posStart) && matcherFin.find(posStart)) {

        while (matcherFin.end() < matcherDebut.start()) {
            matcherFin.find(matcherDebut.start());
        }

        posEnd = matcherDebut.start();
        sb.append(s.substring(posStart, posEnd));

        posStart = matcherFin.end();
    }
    sb.append(s.substring(posStart, s.length()));

    return sb.toString();
}

From source file:com.sonymobile.tools.gerrit.gerritevents.mock.SshdServerMock.java

/**
 * Gets the number of commands that match the given regular expression from the command history.
 *
 * @param commandSearch the regular expression to match.
 * @return number of found commands./*from   w  ww.  j ava 2  s.com*/
 */
public synchronized int getNrCommandsHistory(String commandSearch) {
    int matches = 0;
    if (commandHistory != null) {
        Pattern p = Pattern.compile(commandSearch, Pattern.MULTILINE);
        for (CommandMock command : commandHistory) {
            Matcher matcher = p.matcher(command.getCommand());
            if (matcher.find()) {
                matches++;
            }
        }
    }
    return matches;
}

From source file:com.github.thorqin.webapi.mail.MailService.java

public static Mail createHtmlMailFromTemplate(String templatePath, Map<String, String> replaced) {
    Mail mail = new Mail();
    try (InputStream in = MailService.class.getClassLoader().getResourceAsStream(templatePath)) {
        InputStreamReader reader = new InputStreamReader(in, "utf-8");
        char[] buffer = new char[1024];
        StringBuilder builder = new StringBuilder();
        while (reader.read(buffer) != -1)
            builder.append(buffer);/*from  ww w.  j a va  2s  . co m*/
        String mailBody = builder.toString();
        builder.setLength(0);
        Pattern pattern = Pattern.compile("<%\\s*(.+?)\\s*%>", Pattern.MULTILINE);
        Matcher matcher = pattern.matcher(mailBody);
        int scanPos = 0;
        while (matcher.find()) {
            builder.append(mailBody.substring(scanPos, matcher.start()));
            scanPos = matcher.end();
            String key = matcher.group(1);
            if (replaced != null) {
                String value = replaced.get(key);
                if (value != null) {
                    builder.append(value);
                }
            }
        }
        builder.append(mailBody.substring(scanPos, mailBody.length()));
        mail.htmlBody = builder.toString();
        pattern = Pattern.compile("<title>(.*)</title>",
                Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(mail.htmlBody);
        if (matcher.find()) {
            mail.subject = matcher.group(1);
        }
    } catch (IOException ex) {
        logger.log(Level.SEVERE, "Create mail from template error: {0}, {1}",
                new Object[] { templatePath, ex });
    }
    return mail;
}

From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java

/**
 * pure le corps d'une page//w w w. j  a  va  2 s.com
 * 
 * @param corps chaine contenant le flux  modifier
 * @return le flux modifi
 */
public static String getSuperLightBody(final String corps) {
    final StringBuffer buf = new StringBuffer();
    // Cherche les chechbox
    final Pattern reg = Pattern.compile("(<\\s*input[^>]*>)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    final Matcher mat = reg.matcher(corps);

    // RE reg=new RE("(<\\s*input[^>]*>)",RE.MATCH_CASEINDEPENDENT);
    int pos = 0;

    while (mat.find(pos)) {
        final Hashtable parameters = searchParameter(mat.group(0));

        if (Util.isEqualsIgnoreCase(Util.removeQuotes((String) parameters.get("type")), "checkbox")
                && parameters.containsKey("checked")) {

            buf.append(convertInputToLightInput(mat.group(0)));
        }

        pos = mat.end(0);
    }

    return buf.toString();
}

From source file:org.opennms.web.rest.AlarmStatsRestServiceTest.java

private String getXml(final String tag, final String xml) {
    final Pattern p = Pattern.compile("(<" + tag + ">.*?</" + tag + ">)",
            Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Matcher m = p.matcher(xml);
    if (m.find()) {
        return m.group(1);
    }/*www .  j ava  2s .com*/
    return "";
}

From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.TrafficController.java

/**
 * Function to check if the interface in use has already been fully
 * bootstrapped with the required tc configuration
 *
 * @return boolean indicating the result of the check
 *//* w  ww. ja v  a  2  s  .  c o  m*/
private boolean checkIfAlreadyBootstrapped(String state) throws ResourceHandlerException {
    List<String> regexes = new ArrayList<>();

    //root qdisc
    regexes.add(String.format("^qdisc htb %d: root(.)*$", ROOT_QDISC_HANDLE));
    //cgroup filter
    regexes.add(String.format("^filter parent %d: protocol ip " + "(.)*cgroup(.)*$", ROOT_QDISC_HANDLE));
    //root, default and yarn classes
    regexes.add(String.format("^class htb %d:%d root(.)*$", ROOT_QDISC_HANDLE, ROOT_CLASS_ID));
    regexes.add(String.format("^class htb %d:%d parent %d:%d(.)*$", ROOT_QDISC_HANDLE, DEFAULT_CLASS_ID,
            ROOT_QDISC_HANDLE, ROOT_CLASS_ID));
    regexes.add(String.format("^class htb %d:%d parent %d:%d(.)*$", ROOT_QDISC_HANDLE, YARN_ROOT_CLASS_ID,
            ROOT_QDISC_HANDLE, ROOT_CLASS_ID));

    for (String regex : regexes) {
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);

        if (pattern.matcher(state).find()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Matched regex: " + regex);
            }
        } else {
            String logLine = new StringBuffer("Failed to match regex: ").append(regex)
                    .append(" Current state: ").append(state).toString();
            LOG.warn(logLine);
            return false;
        }
    }

    LOG.info("Bootstrap check succeeded");

    return true;
}

From source file:gtu._work.ui.SqlCreaterUI.java

private void executeBtnPreformed() {
    try {//w w  w .  jav  a 2s  .  c  o m
        logArea.setText("");
        File srcFile = JCommonUtil.filePathCheck(excelFilePathText.getText(), "?", false);
        if (srcFile == null) {
            return;
        }
        if (!srcFile.getName().endsWith(".xlsx")) {
            JCommonUtil._jOptionPane_showMessageDialog_error("excel");
            return;
        }
        if (StringUtils.isBlank(sqlArea.getText())) {
            return;
        }
        File saveFile = JCommonUtil._jFileChooser_selectFileOnly_saveFile();
        if (saveFile == null) {
            JCommonUtil._jOptionPane_showMessageDialog_error("?");
            return;
        }

        String sqlText = sqlArea.getText();

        StringBuffer sb = new StringBuffer();
        Map<Integer, String> refMap = new HashMap<Integer, String>();
        Pattern sqlPattern = Pattern.compile("\\$\\{(\\w+)\\}", Pattern.MULTILINE);
        Matcher matcher = sqlPattern.matcher(sqlText);
        while (matcher.find()) {
            String val = StringUtils.trim(matcher.group(1)).toUpperCase();
            refMap.put(ExcelUtil.cellEnglishToPos(val), val);
            matcher.appendReplacement(sb, "\\$\\{" + val + "\\}");
        }
        matcher.appendTail(sb);
        appendLog(refMap.toString());

        sqlText = sb.toString();
        sqlArea.setText(sqlText);

        Configuration cfg = new Configuration();
        StringTemplateLoader stringTemplatge = new StringTemplateLoader();
        stringTemplatge.putTemplate("aaa", sqlText);
        cfg.setTemplateLoader(stringTemplatge);
        cfg.setObjectWrapper(new DefaultObjectWrapper());
        Template temp = cfg.getTemplate("aaa");

        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(saveFile), "utf8"));

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(bis);
        Sheet sheet = xssfWorkbook.getSheetAt(0);
        for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) {
            Row row = sheet.getRow(j);
            if (row == null) {
                continue;
            }
            Map<String, Object> root = new HashMap<String, Object>();
            for (int index : refMap.keySet()) {
                root.put(refMap.get(index), formatCellType(row.getCell(index)));
            }
            appendLog(root.toString());

            StringWriter out = new StringWriter();
            temp.process(root, out);
            out.flush();
            String writeStr = out.getBuffer().toString();
            appendLog(writeStr);

            writer.write(writeStr);
            writer.newLine();
        }
        bis.close();

        writer.flush();
        writer.close();

        JCommonUtil._jOptionPane_showMessageDialog_info("? : \n" + saveFile);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}