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.clustercontrol.agent.util.MonitorStringUtil.java

/**
 * ???????//from   ww  w  .  ja  va 2 s.  c o  m
 * @param line 
 * @param generationDate ?
 * @param monitorInfo 
 */
public static void patternMatch(String line, MonitorInfo monitorInfo, RunInstructionInfo runInstructionInfo,
        Date generationDate, String filename) {
    if (runInstructionInfo == null && monitorInfo.getCalendar() != null
            && !CalendarWSUtil.isRun(monitorInfo.getCalendar())) {
        m_log.debug("patternMatch is skipped because of calendar");
        return;
    }

    boolean processed = false;
    if (runInstructionInfo != null || monitorInfo.isMonitorFlg()) {
        int order_no = 0;
        for (MonitorStringValueInfo stringInfo : monitorInfo.getStringValueInfo()) {
            ++order_no;
            if (m_log.isDebugEnabled()) {
                m_log.debug("patternMatch() line = " + line + ", monitorId = " + stringInfo.getMonitorId()
                        + ", orderNo = " + order_no + ", pattern = " + stringInfo.getPattern());
            }
            if (!stringInfo.isValidFlg()) {
                continue;
            }
            String patternText = stringInfo.getPattern();
            String message = line;
            m_log.trace("patternMatch check " + message);

            Pattern pattern = null;
            // ?????
            if (stringInfo.isCaseSensitivityFlg()) {
                pattern = Pattern.compile(patternText, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
            }
            // ???
            else {
                pattern = Pattern.compile(patternText, Pattern.DOTALL);
            }
            Matcher matcher = pattern.matcher(line);

            if (matcher.matches()) {
                m_log.debug("patternMatch match " + message);

                // ???
                if (stringInfo.isProcessType()) {
                    MessageInfo logmsg = new MessageInfo();
                    logmsg.setMessage(line);

                    if (generationDate != null) {
                        m_log.debug("patternMatch set generation date : " + generationDate);
                        logmsg.setGenerationDate(generationDate.getTime());
                    } else {
                        logmsg.setGenerationDate(HinemosTime.getDateInstance().getTime());
                    }
                    logmsg.setHostName(Agent.getAgentInfo().getHostname());

                    MonitorInfo monitorInfo2 = new MonitorInfo();
                    if (filename != null) {
                        monitorInfo2.setApplication(monitorInfo.getApplication());
                        monitorInfo2.setCalendar(monitorInfo.getCalendar());
                        monitorInfo2.setCalendarId(monitorInfo.getCalendarId());
                        monitorInfo2.setCollectorFlg(monitorInfo.isCollectorFlg());
                        monitorInfo2.setCustomCheckInfo(monitorInfo.getCustomCheckInfo());
                        monitorInfo2.setCustomTrapCheckInfo(monitorInfo.getCustomTrapCheckInfo());
                        monitorInfo2.setDelayTime(monitorInfo.getDelayTime());
                        monitorInfo2.setDescription(monitorInfo.getDescription());
                        monitorInfo2.setFacilityId(monitorInfo.getFacilityId());
                        monitorInfo2.setFailurePriority(monitorInfo.getFailurePriority());
                        monitorInfo2.setHttpCheckInfo(monitorInfo.getHttpCheckInfo());
                        monitorInfo2.setHttpScenarioCheckInfo(monitorInfo.getHttpScenarioCheckInfo());
                        monitorInfo2.setItemName(monitorInfo.getItemName());
                        monitorInfo2.setJmxCheckInfo(monitorInfo.getJmxCheckInfo());

                        // ???????LogfileCheckInfo???????
                        LogfileCheckInfo logFileCheckInfo = new LogfileCheckInfo();
                        logFileCheckInfo.setDirectory(monitorInfo.getLogfileCheckInfo().getDirectory());
                        logFileCheckInfo.setFileEncoding(monitorInfo.getLogfileCheckInfo().getFileEncoding());
                        logFileCheckInfo.setFileName(monitorInfo.getLogfileCheckInfo().getFileName());
                        logFileCheckInfo
                                .setFileReturnCode(monitorInfo.getLogfileCheckInfo().getFileReturnCode());
                        logFileCheckInfo.setLogfile(monitorInfo.getLogfileCheckInfo().getLogfile());
                        logFileCheckInfo.setMaxBytes(monitorInfo.getLogfileCheckInfo().getMaxBytes());
                        logFileCheckInfo.setMonitorId(monitorInfo.getLogfileCheckInfo().getMonitorId());
                        logFileCheckInfo.setMonitorTypeId(monitorInfo.getLogfileCheckInfo().getMonitorTypeId());
                        logFileCheckInfo.setPatternHead(monitorInfo.getLogfileCheckInfo().getPatternHead());
                        logFileCheckInfo.setPatternTail(monitorInfo.getLogfileCheckInfo().getPatternTail());

                        monitorInfo2.setLogfileCheckInfo(logFileCheckInfo);// 
                        monitorInfo2.setLogFormatId(monitorInfo.getLogFormatId());
                        monitorInfo2.setMeasure(monitorInfo.getMeasure());
                        monitorInfo2.setMonitorFlg(monitorInfo.isMonitorFlg());
                        monitorInfo2.setMonitorId(monitorInfo.getMonitorId());
                        monitorInfo2.setMonitorType(monitorInfo.getMonitorType());
                        monitorInfo2.setMonitorTypeId(monitorInfo.getMonitorTypeId());
                        monitorInfo2.setNotifyGroupId(monitorInfo.getNotifyGroupId());
                        monitorInfo2.setOwnerRoleId(monitorInfo.getOwnerRoleId());
                        monitorInfo2.setPerfCheckInfo(monitorInfo.getPerfCheckInfo());
                        monitorInfo2.setPingCheckInfo(monitorInfo.getPingCheckInfo());
                        monitorInfo2.setPluginCheckInfo(monitorInfo.getPluginCheckInfo());
                        monitorInfo2.setPortCheckInfo(monitorInfo.getPortCheckInfo());
                        monitorInfo2.setProcessCheckInfo(monitorInfo.getProcessCheckInfo());
                        monitorInfo2.setRegDate(monitorInfo.getRegDate());
                        monitorInfo2.setRegUser(monitorInfo.getRegUser());
                        monitorInfo2.setRunInterval(monitorInfo.getRunInterval());
                        monitorInfo2.setScope(monitorInfo.getScope());
                        monitorInfo2.setSnmpCheckInfo(monitorInfo.getSnmpCheckInfo());
                        monitorInfo2.setSqlCheckInfo(monitorInfo.getSqlCheckInfo());
                        monitorInfo2.setTrapCheckInfo(monitorInfo.getTrapCheckInfo());
                        monitorInfo2.setTriggerType(monitorInfo.getTriggerType());
                        monitorInfo2.setUpdateDate(monitorInfo.getUpdateDate());
                        monitorInfo2.setUpdateUser(monitorInfo.getUpdateUser());
                        monitorInfo2.setWinEventCheckInfo(monitorInfo.getWinEventCheckInfo());
                        monitorInfo2.setWinServiceCheckInfo(monitorInfo.getWinServiceCheckInfo());

                        monitorInfo2.getLogfileCheckInfo().setLogfile(filename);
                    }

                    if (HinemosModuleConstant.MONITOR_LOGFILE.equals(monitorInfo.getMonitorTypeId())) {
                        if (filename != null) {
                            LogfileResultForwarder.getInstance().add(message, logmsg, monitorInfo2, stringInfo,
                                    runInstructionInfo);
                        } else {
                            LogfileResultForwarder.getInstance().add(message, logmsg, monitorInfo, stringInfo,
                                    runInstructionInfo);
                        }
                    } else if (HinemosModuleConstant.MONITOR_WINEVENT.equals(monitorInfo.getMonitorTypeId())) {
                        WinEventResultForwarder.getInstance().add(message, logmsg, monitorInfo, stringInfo,
                                runInstructionInfo);
                    }

                    processed = true;

                    m_log.debug("patternMatch send message : " + message);
                    m_log.debug("patternMatch send logmsg message : " + logmsg.getMessage());
                    m_log.debug("patternMatch send logmsg generation date : "
                            + new Date(logmsg.getGenerationDate()));
                    m_log.debug("patternMatch send logmsg hostname : " + logmsg.getHostName());
                }
                break;
            }
        }
    } else {
        m_log.debug("patternMatch is skipped because of monitor flg");
    }

    if (!processed && monitorInfo.isCollectorFlg()) {
        MessageInfo logmsg = new MessageInfo();
        logmsg.setMessage(line);
        if (generationDate != null) {
            m_log.debug("patternMatch set generation date : " + generationDate);
            logmsg.setGenerationDate(generationDate.getTime());
        } else {
            logmsg.setGenerationDate(HinemosTime.getDateInstance().getTime());
        }
        logmsg.setHostName(Agent.getAgentInfo().getHostname());

        if (filename != null) {
            monitorInfo.getLogfileCheckInfo().setLogfile(filename);
        }

        if (HinemosModuleConstant.MONITOR_LOGFILE.equals(monitorInfo.getMonitorTypeId())) {
            LogfileResultForwarder.getInstance().add(line, logmsg, monitorInfo, null, runInstructionInfo);
        } else if (HinemosModuleConstant.MONITOR_WINEVENT.equals(monitorInfo.getMonitorTypeId())) {
            WinEventResultForwarder.getInstance().add(line, logmsg, monitorInfo, null, runInstructionInfo);
        }
    } else {
        if (!processed)
            m_log.debug("collected no data.");
    }
}

From source file:tvbrowser.core.search.regexsearch.RegexSearcher.java

/**
 * Creates a pattern for a regular expression.
 *
 * @param regex The regular expression//from   w w  w.j  a  v a2s  .c  o m
 * @param caseSensitive Should the search be case sensitive?
 * @return The pattern
 * @throws TvBrowserException If there is a syntax error in the regular expression.
 */
public static Pattern createSearchPattern(String regex, boolean caseSensitive) throws TvBrowserException {
    // Get the flags for the regex
    int flags = Pattern.DOTALL;
    if (!caseSensitive) {
        flags |= Pattern.CASE_INSENSITIVE;
        flags |= Pattern.UNICODE_CASE;
    }

    // Compile the regular expression
    Pattern pattern;
    try {
        pattern = Pattern.compile(regex, flags);
    } catch (PatternSyntaxException exc) {
        throw new TvBrowserException(RegexSearcher.class, "error.1",
                "Syntax error in the regular expression of the search pattern!", exc);
    }

    return pattern;
}

From source file:com.gs.obevo.db.impl.platforms.oracle.OracleReveng.java

private static ImmutableList<RevengPattern> getRevengPatterns() {
    final String schemaNameSubPattern = getSchemaObjectPattern(QUOTE, QUOTE);
    String schemaSysNamePattern = getSchemaObjectWithPrefixPattern(QUOTE, QUOTE, "SYS_");
    NamePatternType namePatternType = NamePatternType.TWO;

    // need this function to split the package and package body lines, as the Oracle reveng function combines them together
    Function<String, LineParseOutput> prependBodyLineToPackageBody = new Function<String, LineParseOutput>() {
        private final Pattern packageBodyPattern = Pattern
                .compile("(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)package\\s+body\\s+"
                        + schemaNameSubPattern, Pattern.DOTALL);

        @Override// ww w.ja v  a 2  s  . c o m
        public LineParseOutput valueOf(String object) {
            Matcher matcher = packageBodyPattern.matcher(object);
            if (matcher.find()) {
                String output = object.substring(0, matcher.start()) + "\n//// BODY\n"
                        + object.substring(matcher.start());
                return new LineParseOutput(output);
            }
            return new LineParseOutput(object);
        }
    };
    return Lists.immutable.with(
            new AbstractDdlReveng.RevengPattern(ChangeType.SEQUENCE_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)?sequence\\s+" + schemaNameSubPattern)
                            .withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new AbstractDdlReveng.RevengPattern(ChangeType.TABLE_STR, namePatternType,
                    "(?i)create\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE)
                            .withPostProcessSql(REMOVE_QUOTES),
            new AbstractDdlReveng.RevengPattern(ChangeType.TABLE_STR, namePatternType,
                    "(?i)alter\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REMOVE_QUOTES),
            new AbstractDdlReveng.RevengPattern(ChangeType.TABLE_STR, namePatternType,
                    "(?i)create\\s+unique\\s+index\\s+" + schemaSysNamePattern + "\\s+on\\s+"
                            + schemaNameSubPattern,
                    2, 1,
                    "excludeEnvs=\"%\" comment=\"this_is_potentially_a_redundant_primaryKey_index_please_double_check\"")
                            .withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new AbstractDdlReveng.RevengPattern(ChangeType.TABLE_STR, namePatternType,
                    "(?i)create\\s+(?:unique\\s+)index\\s+" + schemaNameSubPattern + "\\s+on\\s+"
                            + schemaNameSubPattern,
                    2, 1, "INDEX").withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new AbstractDdlReveng.RevengPattern(ChangeType.FUNCTION_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?function\\s+"
                            + schemaNameSubPattern),
            new AbstractDdlReveng.RevengPattern(ChangeType.VIEW_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?view\\s+"
                            + schemaNameSubPattern),
            new AbstractDdlReveng.RevengPattern(ChangeType.SP_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)procedure\\s+"
                            + schemaNameSubPattern),
            new AbstractDdlReveng.RevengPattern(ChangeType.PACKAGE_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)package\\s+" + schemaNameSubPattern)
                            .withPostProcessSql(prependBodyLineToPackageBody),
            new AbstractDdlReveng.RevengPattern(ChangeType.SYNONYM_STR, namePatternType,
                    "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)synonym\\s+" + schemaNameSubPattern),
            new AbstractDdlReveng.RevengPattern(ChangeType.TRIGGER_STR, namePatternType,
                    "(?i)create\\s+or\\s+replace\\s+trigger\\s+" + schemaNameSubPattern));
}

From source file:org.eclipse.recommenders.tests.jdt.JavaProjectFixture.java

public static List<String> findAnonymousClassNames(final CharSequence source) {
    String declaringType = findClassName(source);
    int num = 1;//from   w  w w. j  a  v  a2s  .c o m
    List<String> names = newArrayList();

    // new <name> ( ... ) {
    Pattern p = Pattern.compile("new\\s*?(\\w+)\\s*?\\([^)]*?\\)\\s*?\\{", Pattern.DOTALL);
    Matcher matcher = p.matcher(source);
    while (matcher.find()) {
        final String name = matcher.group(1);
        if (!name.equals(declaringType)) {
            names.add(declaringType + "$" + num++);
        }
    }
    return names;
}

From source file:com.aliyun.datahub.flume.sink.serializer.OdpsRegexEventSerializer.java

@Override
public void configure(Context context) {
    String regex = context.getString(REGEX_CONFIG, REGEX_DEFAULT);
    regexIgnoreCase = context.getBoolean(IGNORE_CASE_CONFIG, INGORE_CASE_DEFAULT);
    inputPattern = Pattern.compile(regex, Pattern.DOTALL + (regexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
    charset = Charset.forName(context.getString(CHARSET_CONFIG, CHARSET_DEFAULT));

    String colNameStr = context.getString(FIELD_NAMES, FIELD_NAME_DEFAULT);
    inputColNames = colNameStr.split(",");
}

From source file:org.eclim.installer.ant.CleanupTask.java

/**
 * Executes this task./*from  ww  w  .  j  a  va2  s.c  om*/
 */
public void execute() throws BuildException {
    Command command = null;
    try {
        Project project = Installer.getProject();

        String url = project.getProperty("eclim.feature.location");
        command = new UninstallCommand(null, url, "org.eclim.installer", "org.eclipse.equinox.p2.director");
        command.start();
        command.join();
        if (command.getReturnCode() != 0) {
            logger.warn("error: " + command.getErrorMessage() + " out: " + command.getResult());
        }

        // remove installer plugin jar + artifacts.xml entry which the p2
        // director does not.
        new File(project.replaceProperties("${eclipse.local}/plugins/org.eclim.installer_${eclim.version}.jar"))
                .delete();

        FileInputStream fin = new FileInputStream(project.replaceProperties("${eclipse.local}/artifacts.xml"));
        FileWriter fout = null;
        try {
            String artifacts = IOUtils.toString(fin);
            fin.close();
            Pattern pattern = Pattern.compile(
                    "\n\\s*<artifact classifier='osgi.bundle' " + "id='org\\.eclim\\.installer.*?</artifact>",
                    Pattern.DOTALL);
            artifacts = pattern.matcher(artifacts).replaceFirst("");
            fout = new FileWriter(project.replaceProperties("${eclipse.local}/artifacts.xml"));
            fout.write(artifacts);
        } finally {
            IOUtils.closeQuietly(fout);
            IOUtils.closeQuietly(fin);
        }

        // remove references to the temp formic update site.
        String settingsDir = "p2/org.eclipse.equinox.p2.engine/.settings/";
        String profileSettingsDir = "p2/org.eclipse.equinox.p2.engine/profileRegistry/"
                + "SDKProfile.profile/.data/.settings/";
        String[] files = new String[] { settingsDir + "org.eclipse.equinox.p2.artifact.repository.prefs",
                settingsDir + "org.eclipse.equinox.p2.metadata.repository.prefs",
                profileSettingsDir + "org.eclipse.equinox.p2.artifact.repository.prefs",
                profileSettingsDir + "org.eclipse.equinox.p2.metadata.repository.prefs", };
        Pattern pattern = Pattern.compile("^.*formic.*$\n", Pattern.MULTILINE);
        for (int ii = 0; ii < files.length; ii++) {
            File file = new File(project.replaceProperties("${eclipse.local}/" + files[ii]));
            if (file.exists()) {
                try {
                    fin = new FileInputStream(file);
                    String contents = IOUtils.toString(fin);
                    contents = pattern.matcher(contents).replaceAll("");
                    fin.close();

                    fout = new FileWriter(file);
                    fout.write(contents);
                } catch (Exception e) {
                    logger.warn("Error removing formic update site references.", e);
                    e.printStackTrace();
                } finally {
                    IOUtils.closeQuietly(fout);
                    IOUtils.closeQuietly(fin);
                }
            }
        }
    } catch (Exception e) {
        throw new BuildException(e);
    } finally {
        if (command != null) {
            command.destroy();
        }
    }
}

From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalQuerySimpleSqlParser.java

private String runRegExExpression(String sqlString, String regEx) {
    Pattern p = Pattern.compile(regEx, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(sqlString);
    if (m.find() && m.groupCount() > 0)
        return m.group(1).trim();
    else//from  w w  w.j  a v a  2 s.c  om
        return null;
}

From source file:nl.nn.adapterframework.webcontrol.ParamWrapperFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    final String toCompile;
    final String initParameter = filterConfig.getInitParameter(INIT_PARAM_NAME);
    if (initParameter != null && initParameter.trim().length() > 0) {
        toCompile = initParameter;/*from   w  w  w  .ja  v  a 2  s. c  om*/
    } else {
        toCompile = DEFAULT_BLACKLIST_PATTERN;
    }

    iaflog.info("INFO Message: Struts1 'do'-Filter active");
    this.pattern = Pattern.compile(toCompile, Pattern.DOTALL);
}

From source file:com.norconex.importer.handler.transformer.impl.StripAfterTransformer.java

@Override
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata,
        boolean parsed, boolean partialContent) {
    if (stripAfterRegex == null) {
        LOG.error("No regular expression provided.");
        return;//from ww w. j a  v  a 2  s  .  co  m
    }
    int flags = Pattern.DOTALL | Pattern.UNICODE_CASE;
    if (!caseSensitive) {
        flags = flags | Pattern.CASE_INSENSITIVE;
    }
    Pattern pattern = Pattern.compile(stripAfterRegex, flags);
    Matcher match = pattern.matcher(content);
    if (match.find()) {
        if (inclusive) {
            content.delete(match.start(), content.length());
        } else {
            content.delete(match.end(), content.length());
        }
    }
}

From source file:com.norconex.importer.handler.transformer.impl.StripBeforeTransformer.java

@Override
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata,
        boolean parsed, boolean partialContent) {
    if (stripBeforeRegex == null) {
        LOG.error("No regular expression provided.");
        return;/*from  w  ww. j av  a 2  s  .  c o m*/
    }
    int flags = Pattern.DOTALL | Pattern.UNICODE_CASE;
    if (!caseSensitive) {
        flags = flags | Pattern.CASE_INSENSITIVE;
    }
    Pattern pattern = Pattern.compile(stripBeforeRegex, flags);
    Matcher match = pattern.matcher(content);
    if (match.find()) {
        if (inclusive) {
            content.delete(0, match.end());
        } else {
            content.delete(0, match.start());
        }
    }
}