List of usage examples for java.util.regex Pattern DOTALL
int DOTALL
To view the source code for java.util.regex Pattern DOTALL.
Click Source Link
From source file:com.edgenius.wiki.render.RenderUtil.java
/** * @param input//w w w . j a v a 2 s . c om * @param key * @param regions * @param newlineKey * @return */ public static CharSequence createRegion(CharSequence input, String key, Collection<Region> regions, String newlineKey) { if (regions == null || regions.size() == 0) return input; //first, web split whole text by special border tag string some think like "key_regionKey_S|E" input = createRegionBorder(input, key, regions, newlineKey); //then we split them one by one. The split is dependent on the RegionComparator(), which ensure the split //from end to start, and from inside to outside. And this makes easier on below replacement process. Set<Region> sortRegions = new TreeSet<Region>(new RegionComparator()); sortRegions.addAll(regions); StringBuilder buf = new StringBuilder(input); StringBuilder regKey = new StringBuilder(key); int ks = key.length(); for (Region region : sortRegions) { //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 Pattern pat = Pattern.compile(new StringBuilder(key).append(region.getKey()).append("S(.*?)") .append(key).append(region.getKey()).append("E").toString(), Pattern.DOTALL); try { Matcher matcher = pat.matcher(buf); if (matcher.find()) { region.setBody(matcher.group(1)); buf.delete(matcher.start(), matcher.end()); regKey.delete(ks, regKey.length()); buf.insert(matcher.start(), regKey.append(region.getKey()).append(Region.REGION_SUFFIX)); } } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]", e); } } return buf; }
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
public static String removeSmallFont(String htmlContent) { if (htmlContent != null && HTML_CONTENT_RX.matcher(htmlContent).find()) { htmlContent = htmlContent.replaceAll("(<span )(style=\"font-size:8pt\">)", "$1qc$2"); htmlContent = htmlContent.replaceAll("\r\n", "\n"); // ALM uses <div> while swing <p> to make lines htmlContent = Pattern.compile("<div([ >].*?</)div>", Pattern.DOTALL).matcher(htmlContent) .replaceAll("<p style=\"margin-top: 0\"$1p>"); }/*from ww w . j a v a2 s . c o m*/ return htmlContent; }
From source file:edu.temple.cis3238.wiki.utils.StringUtils.java
/** * Removes all html tags from string/*from w w w . j a va 2 s .c om*/ * * @param val * @return */ public static String removeHtmlMarkups(String val) { String clean = ""; try { Pattern pattern = Pattern.compile(REGEX_HTML_MARKUP_CHARS, Pattern.DOTALL | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher matcher = pattern.matcher(val); try { clean = matcher.replaceAll(""); } catch (IllegalArgumentException ex) { } catch (IndexOutOfBoundsException ex) { } } catch (PatternSyntaxException ex) { } // return toS(clean); }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2lookReveng.java
public static String removeQuotes(String input) { Pattern compile = Pattern.compile("\"([A-Z_0-9]+)\"", Pattern.DOTALL); StringBuffer sb = new StringBuffer(input.length()); Matcher matcher = compile.matcher(input); while (matcher.find()) { matcher.appendReplacement(sb, matcher.group(1)); }/* ww w .ja v a 2 s . c o m*/ matcher.appendTail(sb); return sb.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); }/*from w ww .j ava 2 s . co m*/ return ""; }
From source file:org.executequery.gui.editor.QueryEditorTextPanel.java
/** * Moves the caret to the beginning of the specified query. * * @param query - the query to move the cursor to *//*from w w w . j a v a 2s . c o m*/ public void caretToQuery(String query) { // replace any regex control chars for (int i = 0; i < REGEX_CHARS.length; i++) { query = query.replaceAll(REGEX_CHARS[i], REGEX_SUBS[i]); } Matcher matcher = Pattern.compile(query, Pattern.DOTALL).matcher(queryPane.getText()); if (matcher.find()) { int index = matcher.start(); if (index != -1) { queryPane.setCaretPosition(index); } } matcher = null; GUIUtils.requestFocusInWindow(queryPane); }
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 www .j a va2 s. 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); } return mail; }
From source file:uis.cipsi.rdd.opentsdb.TSDBInputFormat.java
/** * Sets the configuration. This is used to set the details for the table to * be scanned.//from ww w. j ava 2 s . c om * * @param configuration * The configuration to set. * @see org.apache.hadoop.conf.Configurable#setConf(org.apache.hadoop.conf.Configuration) */ @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION", justification = "Intentional") public void setConf(Configuration configuration) { this.conf = configuration; Scan scan = null; if (conf.get(SCAN) != null) { try { scan = convertStringToScan(conf.get(SCAN)); } catch (IOException e) { LOG.error("An error occurred.", e); } } else { try { scan = new Scan(); // Configuration for extracting the UIDs for the user specified // metric and tag names. if (conf.get(TSDB_UIDS) != null) { // We get all uids for all specified column quantifiers // (metrics|tagk|tagv) String filter = String.format("^%s$", conf.get(TSDB_UIDS)); RegexStringComparator keyRegEx = new RegexStringComparator(filter); RowFilter rowFilter = new RowFilter(CompareOp.EQUAL, keyRegEx); scan.setFilter(rowFilter); } else { // Configuration for extracting & filtering the required // rows // from tsdb table. String metrics = ""; String tags = ""; if (conf.get(METRICS) != null) { String filter = null; metrics = conf.get(METRICS); if (conf.get(TAGKV) != null) // If we have to extract based on a metric and its group of tags "^%s.{4}.*%s.*$" { filter = String.format("^%s.*%s.*$", conf.get(METRICS), conf.get(TAGKV)); tags = conf.get(TAGKV); } else { // If we have to extract based on just the metric filter = String.format("^%s.+$", conf.get(METRICS)); } RegexStringComparator keyRegEx = new RegexStringComparator(filter, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); // keyRegEx.setCharset(Charset.forName("ISO-8859-1")); RowFilter rowFilter = new RowFilter(CompareOp.EQUAL, keyRegEx); scan.setFilter(rowFilter); } // Extracts data based on the supplied timerange. If // timerange // is not provided then all data are extracted if (conf.get(TSDB_TIMERANGE_START) != null && conf.get(TSDB_TIMERANGE_END) != null) { // System.out.println(hexStringToByteArray(metrics + conf.get(TSDB_TIMERANGE_START) + tags) ); // System.out.println(hexStringToByteArray(metrics + conf.get(TSDB_TIMERANGE_END) + tags)); scan.setStartRow(hexStringToByteArray(metrics + conf.get(TSDB_TIMERANGE_START) + tags)); scan.setStopRow(hexStringToByteArray(metrics + conf.get(TSDB_TIMERANGE_END) + tags)); } } // false by default, full table scans generate too much BC churn scan.setCacheBlocks((conf.getBoolean(SCAN_CACHEBLOCKS, false))); } catch (Exception e) { LOG.error(StringUtils.stringifyException(e)); } } setScan(scan); }
From source file:org.apache.ode.jbi.JbiTestBase.java
protected void matchResponse(String expectedResponse, String result, boolean succeeded) { if (succeeded) { assertTrue("Response doesn't match expected regex.\nExpected: " + expectedResponse + "\nReceived: " + result, Pattern.compile(expectedResponse, Pattern.DOTALL).matcher(result).matches()); } else {/*from w w w. j av a2s. c o m*/ assertTrue("Expected success, but got fault", expectedResponse.equals("FAULT")); } }
From source file:com.liferay.ide.project.core.tests.UpgradeLiferayProjectsOpTests.java
private String getNewDoctTypeSetting(String doctypeSetting, String regrex) { Pattern p = Pattern.compile(regrex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(doctypeSetting); if (m.find()) { return m.group(m.groupCount()); }/*from w ww . j a v a2 s . c o m*/ return null; }