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:de.undercouch.bson4jackson.BsonGenerator.java

/**
 * Converts a a Java flags word into a BSON options pattern
 *
 * @param flags the Java flags//from w w w. j  a  va  2s . c  o  m
 * @return the regex options string
 */
protected String flagsToRegexOptions(int flags) {
    StringBuilder options = new StringBuilder();
    if ((flags & Pattern.CASE_INSENSITIVE) != 0) {
        options.append("i");
    }
    if ((flags & Pattern.MULTILINE) != 0) {
        options.append("m");
    }
    if ((flags & Pattern.DOTALL) != 0) {
        options.append("s");
    }
    if ((flags & Pattern.UNICODE_CASE) != 0) {
        options.append("u");
    }
    return options.toString();
}

From source file:info.icefilms.icestream.browse.Location.java

protected static String CleanString(String string) {
    // Remove any html tags
    string = Pattern.compile("<.*?>", Pattern.DOTALL).matcher(string).replaceAll("");

    // Replace any special HTML characters
    string = StringEscapeUtils.unescapeHtml4(string);

    return string;
}

From source file:com.hexidec.ekit.component.HTMLUtilities.java

private static String addColgroups(String html, List<String> colgroups) {
    StringBuffer sb = new StringBuffer();

    Pattern p = Pattern.compile("<table\\b[^>]*>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);

    Matcher m = p.matcher(html);//from www. ja va2s . c  om

    if (!m.find()) {
        return html;
    }

    int i = 0;
    do {
        String colgroup = colgroups.get(i++);
        m.appendReplacement(sb, Matcher.quoteReplacement(m.group() + colgroup));
    } while (m.find());

    m.appendTail(sb);

    return sb.toString();
}

From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java

@Test
public void shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_FullConfigSave()
        throws Exception {
    assertThat(configWatchList.getCurrentConfigRepos().size()).isEqualTo(1);
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo,
            latestModification);// www  .ja v a2 s . c  o m
    assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1"))).isTrue();

    final PipelineConfig dupPipelineConfig = PipelineMother
            .twoBuildPlansWithResourcesAndSvnMaterialsAtUrl("pipe1", "ut", "www.spring.com");
    try {
        goConfigDao.updateConfig(new UpdateConfigCommand() {
            @Override
            public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
                cruiseConfig.getGroups().first().add(dupPipelineConfig);
                return cruiseConfig;
            }
        });
        fail("Should have thrown");
    } catch (RuntimeException ex) {
        String errorMessage = ex.getMessage();
        assertThat(errorMessage).contains(
                "You have defined multiple pipelines named 'pipe1'. Pipeline names must be unique. Source(s):");
        Matcher matcher = Pattern.compile("^.*\\[(.*),\\s(.*)\\].*$", Pattern.DOTALL | Pattern.MULTILINE)
                .matcher(errorMessage);
        assertThat(matcher.matches()).isTrue();
        assertThat(matcher.groupCount()).isEqualTo(2);
        PipelineConfig pipe1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("pipe1"));
        List<String> expectedSources = asList(dupPipelineConfig.getOriginDisplayName(),
                pipe1.getOriginDisplayName());
        List<String> actualSources = new ArrayList<>();
        for (int i = 1; i <= matcher.groupCount(); i++) {
            actualSources.add(matcher.group(i));
        }
        assertThat(actualSources.size()).isEqualTo(expectedSources.size());
        assertThat(actualSources.containsAll(expectedSources)).isTrue();
    }
}

From source file:org.tinymediamanager.core.tvshow.connector.TvShowEpisodeToXbmcNfoConnector.java

private static List<TvShowEpisodeToXbmcNfoConnector> parseNfo(File nfoFile) {
    List<TvShowEpisodeToXbmcNfoConnector> xbmcConnectors = new ArrayList<>(1);

    // tv show episode NFO is a bit weird. There can be stored multiple
    // episodes inside one XML (in a non valid manner); so we have
    // to read the NFO, split it into some smaller NFOs and parse them
    if (nfoFile.exists()) {
        String completeNFO;//from   w w  w  . j  av a 2  s. c  om
        try {
            completeNFO = FileUtils.readFileToString(nfoFile, "UTF-8");
            Pattern pattern = Pattern.compile("<\\?xml.*\\?>");
            Matcher matcher = pattern.matcher(completeNFO);
            String xmlHeader = "";
            if (matcher.find()) {
                xmlHeader = matcher.group();
            }

            pattern = Pattern.compile("<episodedetails>.+?<\\/episodedetails>", Pattern.DOTALL);
            matcher = pattern.matcher(completeNFO);
            while (matcher.find()) {
                StringBuilder sb = new StringBuilder(xmlHeader);
                sb.append(matcher.group());

                // read out each episode
                try {
                    TvShowEpisodeToXbmcNfoConnector xbmc = parseNfoPart(sb.toString());
                    xbmcConnectors.add(xbmc);
                } catch (Exception e) {
                    LOGGER.error("failed to parse " + nfoFile.getAbsolutePath(), e);
                }
            }
        } catch (IOException e) {
            // MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, nfoFile.getPath(), "message.nfo.readerror"));
        }
    }

    return xbmcConnectors;
}

From source file:com.hexidec.ekit.component.HTMLUtilities.java

private static String corrigeBR(String html) {
    Pattern p = Pattern.compile("<br\\b.*?>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    return p.matcher(html).replaceAll("<br/>");
}

From source file:com.hexidec.ekit.component.HTMLUtilities.java

public static boolean terminaComTabela(String html) {
    Pattern p = Pattern.compile(".*</table\\b[^>]*>\\s*(</p\\b[^>]*>)?\\s*$",
            Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    return p.matcher(html).matches();
}

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

/**
 * @param fromPattern// w  w w  .  j  a v  a2 s .com
 *            ???pattern
 * @param toFormat
 *            ??pattern
 * @param replaceText
 *            ??
 */
String replacer(String fromPattern, String toFormat, String replaceText) {
    String errorRtn = replaceText.toString();
    try {
        int patternFlag = 0;

        // 
        if (multiLineCheckBox.isSelected()) {
            patternFlag = Pattern.DOTALL | Pattern.MULTILINE;
        }

        Pattern pattern = Pattern.compile(fromPattern, patternFlag);
        Matcher matcher = pattern.matcher(replaceText);

        StringBuffer sb = new StringBuffer();
        String tempStr = null;

        TradeOffConfig config = this.getTradeOffConfig();

        {
            int startPos = 0;
            for (; matcher.find();) {
                tempStr = toFormat.toString();
                sb.append(replaceText.substring(startPos, matcher.start()));

                // ----------------------------------------------
                if (StringUtils.isBlank(config.fremarkerKey)) {
                    // regex
                    for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                        System.out.println(ii + " -- " + matcher.group(ii));
                        tempStr = tempStr.replaceAll("#" + ii + "#",
                                Matcher.quoteReplacement(matcher.group(ii)));
                    }
                } else if (StringUtils.isNotBlank(config.fremarkerKey)) {
                    // freemarker
                    Map<String, Object> root = new HashMap<String, Object>();
                    TreeMap<Integer, Object> lstMap = new TreeMap<Integer, Object>();
                    for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                        lstMap.put(ii, matcher.group(ii));
                    }
                    root.put(StringUtils.trimToEmpty(config.fremarkerKey), lstMap.values());
                    System.out.println("template Map : " + root);
                    tempStr = FreeMarkerSimpleUtil.replace(tempStr, root);
                }
                // ----------------------------------------------

                sb.append(tempStr);
                startPos = matcher.end();
            }
            sb.append(replaceText.substring(startPos));
        }

        return sb.toString();
    } catch (Exception ex) {
        JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(), getTitle());
        return errorRtn;
    }
}

From source file:edu.umass.cs.utils.Util.java

public static void writeProperty(String key, String value, String filename, String prefix) throws IOException {
    String props = readFileAsString(filename);
    String modified = "";
    String comment = "\n# automatically modified property\n";
    // append if no prefix
    if (prefix == null || prefix.equals("") || !Pattern
            .compile(".*\n[\\s]*" + prefix + "[^\n]*=[^\n]*\n.*", Pattern.DOTALL).matcher(props).matches())
        modified = props + comment + key + "=" + value;
    // replace if property exists
    else if (Pattern.compile(".*\n[\\s]*" + key + "[^\n]*=[^\n]*\n.*", Pattern.DOTALL).matcher(props)
            .matches()) {/*from  w  w w . j  a v  a2s  . c  o m*/
        if (value != null) // replace
            modified = props.replaceAll("\n[\\s]*" + key + "[^\n]*=[^\n]*\n",
                    comment + key + "=" + value + "\n");
        else
            // comment out
            modified = props.replaceAll("\n[\\s]*" + key + "[^\n]*=[^\n]*\n",
                    comment + "#" + key + "=" + value + "\n");
    }
    // add as new property after last prefix match
    else {
        String[] tokens = props.split("\n");
        boolean oneTime = false;
        for (int i = tokens.length - 1; i > 0; i--)
            modified = tokens[i] + "\n"
                    + (tokens[i].trim().startsWith(prefix) && (!oneTime && (oneTime = true))
                            ? comment + key + "=" + value + "\n"
                            : "")
                    + modified;
    }
    Files.write(Paths.get(filename), modified.getBytes());
}

From source file:com.jsmartframework.web.manager.FilterControl.java

private void versionResources(FilterConfig config) {
    try {// w ww. j  a va 2  s  . c o m
        if (CONFIG.getContent().getFileVersions() == null) {
            LOGGER.log(Level.INFO, "Not using files version control.");
            return;
        }

        String automaticVersion = getAutomaticResourceVersion(config);
        if (automaticVersion != null) {
            LOGGER.log(Level.INFO, "Automatic versioning detected as " + automaticVersion);
        }

        ServletContext context = config.getServletContext();
        File rootFile = new File(context.getRealPath(ROOT_PATH));
        Dir content = Vfs.fromURL(rootFile.toURI().toURL());

        Map<String, StringBuilder> patternBuilders = new HashMap<>();
        Iterator<Vfs.File> files = content.getFiles().iterator();

        while (files.hasNext()) {
            Vfs.File file = files.next();
            String relativePath = file.getRelativePath();

            FileVersion fileVersion = CONFIG.getContent().getFileVersion(relativePath);
            if (fileVersion != null && !fileVersion.isOnExcludeFolders(relativePath)) {
                if (!fileVersion.isIncludeMinified() && fileVersion.isMinifiedFile(relativePath)) {
                    continue;
                }

                String patternVersion = automaticVersion;
                if (!fileVersion.isAuto()) {
                    patternVersion = fileVersion.getVersion();
                }
                if (patternVersion == null) {
                    continue;
                }

                StringBuilder patternBuilder = patternBuilders.get(patternVersion);
                if (patternBuilder == null) {
                    patternBuilder = new StringBuilder("(");
                    patternBuilders.put(patternVersion, patternBuilder);
                }
                if (patternBuilder.length() > 1) {
                    patternBuilder.append("|");
                }
                patternBuilder.append(relativePath.replace(".", "\\."));
            }
        }

        for (String version : patternBuilders.keySet()) {
            StringBuilder patternBuilder = patternBuilders.get(version).append(")");
            versionFilePatterns.put(version, Pattern.compile(patternBuilder.toString(), Pattern.DOTALL));
        }
    } catch (Exception ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage());
    }
}