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.pentaho.di.trans.steps.autodoc.KettleFileTableModel.java

public static String getVariables(ReportSubjectLocation filename) throws KettleException {
    log.logError("call me!");
    ArrayList<String> variables = new ArrayList<String>();
    if (filename.isTransformation()) {
        TransMeta transMeta = TransformationInformation.getInstance().getTransMeta(filename);
        Pattern pattern = Pattern.compile("\\$\\{([^\\}]*)\\}", Pattern.DOTALL);
        Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeXml(transMeta.getXML()));
        while (matcher.find()) {
            if (!variables.contains(matcher.group(1))) {
                variables.add(matcher.group(1));
            }//from   ww  w . j a  v a  2  s .  c om
        }
    } else {
        JobMeta jobMeta = JobInformation.getInstance().getJobMeta(filename);
        Pattern pattern = Pattern.compile("\\$\\{([^\\}]*)\\}", Pattern.DOTALL);
        Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeXml(jobMeta.getXML()));
        while (matcher.find()) {
            if (!variables.contains(matcher.group(1))) {
                variables.add(matcher.group(1));
            }
        }
    }
    Object[] sorted_variables = (Object[]) variables.toArray();
    Arrays.sort(sorted_variables);
    return Joiner.on(", ").join(sorted_variables);
}

From source file:hivemall.docs.FuncsListGenerator.java

private void generate(@Nonnull File outputFile, @Nonnull String preface,
        @Nonnull Map<String, List<String>> headers) throws MojoExecutionException {
    Reflections reflections = new Reflections("hivemall");
    Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(Description.class);

    StringBuilder sb = new StringBuilder();
    Map<String, Set<String>> packages = new HashMap<>();

    Pattern func = Pattern.compile("_FUNC_(\\(.*?\\))(.*)", Pattern.DOTALL);

    for (Class<?> annotatedClass : annotatedClasses) {
        Deprecated deprecated = annotatedClass.getAnnotation(Deprecated.class);
        if (deprecated != null) {
            continue;
        }/*from  w  w w.  j a  va2 s  .  c  om*/

        Description description = annotatedClass.getAnnotation(Description.class);

        String value = description.value().replaceAll("\n", " ");
        Matcher matcher = func.matcher(value);
        if (matcher.find()) {
            value = asInlineCode(description.name() + matcher.group(1)) + escapeHtml(matcher.group(2));
        }
        sb.append(asListElement(value));

        StringBuilder sbExtended = new StringBuilder();
        if (!description.extended().isEmpty()) {
            sbExtended.append(description.extended());
            sb.append("\n");
        }

        String extended = sbExtended.toString();
        if (extended.isEmpty()) {
            sb.append("\n");
        } else {
            if (extended.toLowerCase().contains("select")) { // extended description contains SQL statements
                sb.append(indent(asCodeBlock(extended, "sql")));
            } else {
                sb.append(indent(asCodeBlock(extended)));
            }
        }

        String packageName = annotatedClass.getPackage().getName();
        if (!packages.containsKey(packageName)) {
            Set<String> set = new TreeSet<>();
            packages.put(packageName, set);
        }
        Set<String> List = packages.get(packageName);
        List.add(sb.toString());

        StringUtils.clear(sb);
    }

    try (PrintWriter writer = new PrintWriter(outputFile)) {
        // license header
        writer.println("<!--");
        try {
            File licenseFile = new File(basedir, "resources/license-header.txt");
            FileReader fileReader = new FileReader(licenseFile);

            try (BufferedReader bufferedReader = new BufferedReader(fileReader)) {
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    writer.println(indent(line));
                }
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to read license file");
        }
        writer.println("-->\n");

        writer.println(preface);

        writer.println("\n<!-- toc -->\n");

        for (Map.Entry<String, List<String>> e : headers.entrySet()) {
            writer.println(e.getKey() + "\n");
            List<String> packageNames = e.getValue();
            for (String packageName : packageNames) {
                for (String desc : packages.get(packageName)) {
                    writer.println(desc);
                }
            }
        }

        writer.flush();
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Output file is not found");
    }
}

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

/**
 * Remove any text that match the "comments damaged from IE and Tiny" from the data.
 * //from w  ww .  ja  va2s. c o m
 * @param data
 *        the html data.
 * @return The cleaned up data.
 */
public static String stripDamagedComments(String data) {
    if (data == null)
        return data;

    // quick check for any hint of the pattern
    if (data.indexOf("<! [endif] >") == -1)
        return data;

    // Notes: DOTALL so the "." matches line terminators too, "*?" Reluctant quantifier so text between two different comments is not lost
    Pattern p = Pattern.compile("<!--\\[if.*?<! \\[endif\\] >",
            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);

    // now remove the bad comment end
    String rv = sb.toString().replace("<-->", "");
    return rv;
}

From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java

private String resolveJs(final String userAgent, final String pluginName, final String url,
        final String resultString) throws IOException {
    log.debug("Resolving JavaScript for URL " + url);
    final StringBuilder outString = new StringBuilder();
    int currPos = 0;
    final Pattern linkPattern = Pattern.compile(
            "<script>?[^>]*src=[\"\\']([^>\"\\']*)[\"\\']([^>]*/>|[^>]*>[ \r\n]*</script>)",
            Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    final Matcher matcher = linkPattern.matcher(resultString);
    while (matcher.find(currPos)) {
        final int start = matcher.start();
        final int end = matcher.end();
        outString.append(resultString.substring(currPos, start));
        final String cssUrl = matcher.group(1);
        final String jsText = retrieveJs(userAgent, pluginName, url, cssUrl);
        outString.append(jsText);//  w ww .  j  a  v  a2 s.c  om
        currPos = end;
    }

    outString.append(resultString.substring(currPos));
    log.debug(outString.length() + " JavaScript chars included for URL " + url);
    return outString.toString();
}

From source file:org.kuali.rice.testtools.common.JiraAwareFailureUtils.java

protected static String findMatchedJiraRegex(String contents) {
    if (regexJiraMatches == null || regexJiraMatches.keySet() == null) {
        System.out.println(//from   w  w w.  j  a v  a  2  s.co m
                "WARNING JiraAwareFailureUtils Regex properties empty, findMatchesJiraRegex not available.");
        return "";
    }
    String key = null;
    Pattern pattern = null;
    Matcher matcher = null;

    Iterator iter = regexJiraMatches.keySet().iterator();

    while (iter.hasNext()) {
        key = (String) iter.next();
        pattern = Pattern.compile(key, Pattern.DOTALL); // match across line terminators
        matcher = pattern.matcher(contents);

        if (matcher.find()) {
            return ("\n" + JIRA_BROWSE_URL + regexJiraMatches.get(key) + "\n\n" + contents);
        }
    }

    return "";
}

From source file:com.clustercontrol.custom.factory.RunCustomString.java

/**
 * ????<br/>/*from   ww  w  .  j  a  va2  s .  c  o m*/
 * 
 * @throws HinemosUnknown
 *             ??????
 * @throws MonitorNotFound
 *             ??????
 * @throws CustomInvalid
 *             ??????
 */
@Override
public void monitor() throws HinemosUnknown, MonitorNotFound, CustomInvalid {
    // Local Variables
    MonitorInfo monitor = null;

    int priority = PriorityConstant.TYPE_UNKNOWN;
    String facilityPath = "";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(HinemosTime.getTimeZone());
    String msg = "";
    String msgOrig = "";

    boolean isMonitorJob = result.getRunInstructionInfo() != null;

    // MAIN
    try {
        monitor = new MonitorSettingControllerBean().getMonitor(result.getMonitorId());

        String executeDate = dateFormat.format(result.getExecuteDate());
        String exitDate = dateFormat.format(result.getExitDate());
        String collectDate = dateFormat.format(result.getCollectDate());

        facilityPath = new RepositoryControllerBean().getFacilityPath(result.getFacilityId(), null);
        if (result.getTimeout() || result.getStdout() == null || result.getStdout().isEmpty()
                || result.getResults() == null) {
            if (m_log.isDebugEnabled()) {
                m_log.debug("command monitoring : timeout or no stdout [" + result + "]");
            }
            // if command execution failed (timeout or no stdout)
            if (isMonitorJob || monitor.getMonitorFlg()) {
                msg = "FAILURE : command execution failed (timeout, no stdout or not unexecutable command)...";

                msgOrig = "FAILURE : command execution failed (timeout, no stdout or unexecutable command)...\n\n"
                        + "COMMAND : " + result.getCommand() + "\n" + "COLLECTION DATE : " + collectDate + "\n"
                        + "executed at " + executeDate + "\n" + "exited (or timeout) at " + exitDate + "\n"
                        + "EXIT CODE : " + (result.getExitCode() != null ? result.getExitCode() : "timeout")
                        + "\n\n" + "[STDOUT]\n" + result.getStdout() + "\n" + "[STDERR]\n" + result.getStderr()
                        + "\n";

                // 
                if (!isMonitorJob) {
                    notify(PriorityConstant.TYPE_UNKNOWN, monitor, result.getFacilityId(), facilityPath, null,
                            msg, msgOrig, HinemosModuleConstant.MONITOR_CUSTOM_S);
                } else {
                    // 
                    this.monitorJobEndNodeList.add(new MonitorJobEndNode(result.getRunInstructionInfo(),
                            HinemosModuleConstant.MONITOR_CUSTOM_S, makeJobOrgMessage(monitor, msgOrig), "",
                            RunStatusConstant.END, MonitorJobWorker.getReturnValue(
                                    result.getRunInstructionInfo(), PriorityConstant.TYPE_UNKNOWN)));
                }
            }
        } else {
            // if command stdout was returned Monitor
            msg = result.getStdout();
            // Stdout???
            Pattern patternMsg = Pattern.compile("\r\n$|\n$");
            Matcher matcherMsg = patternMsg.matcher(msg);
            msg = matcherMsg.replaceAll("");

            if (m_log.isDebugEnabled()) {
                m_log.debug("command monitoring : values [" + msg + "]");
            }

            // ?
            if (monitor.getCollectorFlg()) { // collector each value
                List<StringSample> sampleList = new ArrayList<StringSample>();
                StringSample sample = new StringSample(new Date(HinemosTime.currentTimeMillis()),
                        monitor.getMonitorId());
                // 
                sample.set(result.getFacilityId(), "custom", msg);

                sampleList.add(sample);
                if (!sampleList.isEmpty()) {
                    CollectStringDataUtil.store(sampleList);
                }
            }

            // 
            int orderNo = 0;
            if (isMonitorJob || monitor.getMonitorFlg()) { // monitor each value
                for (MonitorStringValueInfo stringValueInfo : monitor.getStringValueInfo()) {
                    ++orderNo;
                    if (m_log.isDebugEnabled()) {
                        m_log.info(String.format(
                                "monitoring (monitorId = %s, orderNo = %d, patten = %s, enabled = %s, casesensitive = %s)",
                                monitor.getMonitorId(), orderNo, stringValueInfo.getPattern(),
                                stringValueInfo.getValidFlg(), stringValueInfo.getCaseSensitivityFlg()));
                    }
                    if (!stringValueInfo.getValidFlg()) {
                        // ?????
                        continue;
                    }
                    // ?
                    if (m_log.isDebugEnabled()) {
                        m_log.debug(String.format("filtering customtrap (regex = %s, Msg = %s",
                                stringValueInfo.getPattern(), msg));
                    }
                    try {
                        Pattern pattern = null;
                        if (stringValueInfo.getCaseSensitivityFlg()) {
                            // ?????
                            pattern = Pattern.compile(stringValueInfo.getPattern(),
                                    Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
                        } else {
                            // ???
                            pattern = Pattern.compile(stringValueInfo.getPattern(), Pattern.DOTALL);
                        }
                        Matcher matcher = pattern.matcher(msg);
                        if (matcher.matches()) {
                            if (stringValueInfo.getProcessType()) {
                                msgOrig = MessageConstant.LOGFILE_PATTERN.getMessage() + "="
                                        + stringValueInfo.getPattern() + "\n"
                                        + MessageConstant.LOGFILE_LINE.getMessage() + "=" + msg + "\n\n"
                                        + "COMMAND : " + result.getCommand() + "\n" + "COLLECTION DATE : "
                                        + collectDate + "\n" + "executed at " + executeDate + "\n"
                                        + "exited (or timeout) at " + exitDate + "\n" + "EXIT CODE : "
                                        + (result.getExitCode() != null ? result.getExitCode() : "timeout")
                                        + "\n\n" + "[STDOUT]\n" + result.getStdout() + "\n\n" + "[STDERR]\n"
                                        + result.getStderr() + "\n";

                                msg = makeMsg(stringValueInfo, msg);

                                priority = stringValueInfo.getPriority();
                                if (!isMonitorJob) {
                                    // 
                                    notify(priority, monitor, result.getFacilityId(), facilityPath,
                                            stringValueInfo.getPattern(), msg, msgOrig,
                                            HinemosModuleConstant.MONITOR_CUSTOM_S);
                                } else {
                                    // 
                                    this.monitorJobEndNodeList
                                            .add(new MonitorJobEndNode(result.getRunInstructionInfo(),
                                                    HinemosModuleConstant.MONITOR_CUSTOM_S,
                                                    makeJobOrgMessage(monitor, msgOrig), "",
                                                    RunStatusConstant.END, MonitorJobWorker.getReturnValue(
                                                            result.getRunInstructionInfo(), priority)));
                                }
                            } else {
                                m_log.debug(String.format("not ProcessType (regex = %s, Msg = %s",
                                        stringValueInfo.getPattern(), result.getStdout()));
                            }
                            break;// Syslog??????
                        }
                    } catch (RuntimeException e) {
                        m_log.warn("filtering failure. (regex = " + stringValueInfo.getPattern() + ") . "
                                + e.getMessage(), e);
                    }
                }
            }
        }
    } catch (MonitorNotFound | CustomInvalid | HinemosUnknown e) {
        m_log.warn("unexpected internal failure occurred. [" + result + "]");
        throw e;
    } catch (Exception e) {
        m_log.warn("unexpected internal failure occurred. [" + result + "]", e);
        throw new HinemosUnknown("unexpected internal failure occurred. [" + result + "]", e);
    }
}

From source file:com.amazonaws.eclipse.sdk.ui.wizard.NewAwsJavaProjectWizard.java

private static String updateSampleContentWithConfiguredProfile(String sampleContent,
        final AccountInfo selectedAccount) {
    final String credFileLocation = AwsToolkitCore.getDefault().getPreferenceStore()
            .getString(PreferenceConstants.P_CREDENTIAL_PROFILE_FILE_LOCATION);

    String paramString;//from ww  w .  j  av  a 2s  . c o  m
    if (AwsToolkitCore.getDefault().getPreferenceStore()
            .isDefault(PreferenceConstants.P_CREDENTIAL_PROFILE_FILE_LOCATION)) {
        // Don't need to specify the file location
        paramString = String.format("\"%s\"", selectedAccount.getAccountName());

    } else {
        paramString = String.format("\"%s\", \"%s\"", credFileLocation, selectedAccount.getAccountName());
    }

    // Change the parameter of the ProfileCredentialsProvider
    sampleContent = sampleContent.replace("new ProfileCredentialsProvider().getCredentials();", String
            .format("new ProfileCredentialsProvider(%s).getCredentials();", escapeBackSlashes(paramString)));

    // Remove the block of comment between "Before running the code" and "WARNING"
    String COMMNET_TO_REMOVE_REGEX = "(Before running the code:.*?)?Fill in your AWS access credentials.*?(?=WANRNING:)";
    sampleContent = Pattern.compile(COMMNET_TO_REMOVE_REGEX, Pattern.DOTALL) // dot should match newline
            .matcher(sampleContent).replaceAll("");

    // [default] ==> [selected-profile-name]
    sampleContent = sampleContent.replace("[default]", String.format("[%s]", selectedAccount.getAccountName()));

    // (~/.aws/credentials) ==> (user-specified preference store value)
    sampleContent = sampleContent.replace("(~/.aws/credentials)",
            String.format("(%s)", escapeBackSlashes(credFileLocation)));

    return sampleContent;
}

From source file:org.apache.pdfbox.pdfparser.PDFParser.java

/**
 * Skip to the start of the next object.  This is used to recover
 * from a corrupt object. This should handle all cases that parseObject
 * supports. This assumes that the next object will
 * start on its own line.//from w w  w .  j  av a 2 s.  c  o  m
 *
 * @throws IOException
 */
private void skipToNextObj() throws IOException {
    byte[] b = new byte[16];
    Pattern p = Pattern.compile("\\d+\\s+\\d+\\s+obj.*", Pattern.DOTALL);
    /* Read a buffer of data each time to see if it starts with a
     * known keyword. This is not the most efficient design, but we should
     * rarely be needing this function. We could update this to use the
     * circular buffer, like in readUntilEndStream().
     */
    while (!pdfSource.isEOF()) {
        int l = pdfSource.read(b);
        if (l < 1) {
            break;
        }
        String s = new String(b, "US-ASCII");
        if (s.startsWith("trailer") || s.startsWith("xref") || s.startsWith("startxref")
                || s.startsWith("stream") || p.matcher(s).matches()) {
            pdfSource.unread(b);
            break;
        } else {
            pdfSource.unread(b, 1, l - 1);
        }
    }
}

From source file:me.vertretungsplan.parser.UntisMonitorParser.java

static void findSubDocs(List<Document> docs, String html, Document doc) {
    // Some schools concatenate multiple HTML files for multiple days
    Pattern pattern = Pattern.compile("(<html>.*?</html>)", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(html);
    List<String> subHtmls = new ArrayList<>();
    while (matcher.find()) {
        subHtmls.add(matcher.group());//from  w  w  w. ja va2 s  .com
    }

    if (subHtmls.size() > 1) {
        for (String subHtml : subHtmls) {
            docs.add(Jsoup.parse(subHtml));
        }
    } else {
        docs.add(doc);
    }
}

From source file:password.pwm.util.queue.SmsQueueManager.java

private static void determineIfResultSuccessful(final Configuration config, final int resultCode,
        final String resultBody) throws PwmOperationalException {
    final List<String> resultCodeTests = config.readSettingAsStringArray(PwmSetting.SMS_SUCCESS_RESULT_CODE);
    if (resultCodeTests != null && !resultCodeTests.isEmpty()) {
        final String resultCodeStr = String.valueOf(resultCode);
        if (!resultCodeTests.contains(resultCodeStr)) {
            throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_SMS_SEND_ERROR,
                    "response result code " + resultCode + " is not a configured successful result code"));
        }/*from w w w  . j  av a  2s.co  m*/
    }

    final List<String> regexBodyTests = config.readSettingAsStringArray(PwmSetting.SMS_RESPONSE_OK_REGEX);
    if (regexBodyTests == null || regexBodyTests.isEmpty()) {
        return;

    }

    if (resultBody == null || resultBody.isEmpty()) {
        throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_SMS_SEND_ERROR,
                "result has no body but there are configured regex response matches, so send not considered successful"));
    }

    for (final String regex : regexBodyTests) {
        final Pattern p = Pattern.compile(regex, Pattern.DOTALL);
        final Matcher m = p.matcher(resultBody);
        if (m.matches()) {
            LOGGER.trace("result body matched configured regex match setting: " + regex);
            return;
        }
    }

    throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_SMS_SEND_ERROR,
            "result body did not matching any configured regex match settings"));
}