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:org.sonar.oracleforms.plsql.decorators.DecoratorsFactoryTest.java
/** * Full integration test on all decorators *///ww w . j a va2s .c o m @Test public void decorateModule() { Node module = new Node("form1").setType(Node.Type.FORM_MODULE); Node trigger1 = new Node(module, "trigger1").setType(Node.Type.TRIGGER).setPlsql("content of trigger one"); Node block = new Node(module, "block1").setType(Node.Type.BLOCK); Node trigger2 = new Node(block, "trigger2").setType(Node.Type.TRIGGER).setPlsql("content of trigger two"); String plsql = DecoratorFactory.decorate(module); Pattern p = Pattern.compile(".*Procedure form1_.*content of trigger one.*content of trigger two.*", Pattern.DOTALL); Matcher m = p.matcher(plsql); assertThat(m.matches()).isTrue(); }
From source file:util.StripHTMLTags.java
/** * This method strips all tags from the body except those given in * in the tag array./*from w w w . ja v a 2 s . c om*/ * * @param body The body or text to strip * @param tags The tag array for strip exclusion * @return String Return the body with the stripped tags. */ public String stripTags(String body, String[] tags) { if (null == body) return body; Pattern pattern = Pattern.compile("<.*?>", Pattern.DOTALL); Pattern[] tagPatterns = null; if (tags != null) { tagPatterns = new Pattern[tags.length]; for (int i = 0; i < tags.length; i++) { tagPatterns[i] = Pattern.compile("<(\\s*?)(/??)(\\s*?)" + tags[i] + "((\\s*?>)||(\\s(.*?)>))", Pattern.DOTALL); } } StringBuffer bodyStr = new StringBuffer(body); bodyStr = stripCSS(bodyStr); bodyStr = stripJS(bodyStr); Matcher matcher = pattern.matcher(bodyStr); while (matcher.find()) { logger.debug("Match: " + matcher.group()); boolean matches = false; if ((tags != null) && (tags.length != 0)) { for (int i = 0; i < tags.length && (!matches); i++) { logger.debug("Pattern: " + tagPatterns[i].pattern()); Matcher ematcher = tagPatterns[i].matcher(matcher.group()); matches = matches || ematcher.matches(); } } if (!matches) { logger.debug("Substituting Match"); bodyStr = bodyStr.replace(matcher.start(), matcher.end(), ""); matcher = pattern.matcher(bodyStr); } } return bodyStr.toString(); }
From source file:org.orcid.jaxb.model.notification.permission.MarshallingTest.java
@Test public void testMarshalling() throws JAXBException, IOException, SAXException { NotificationPermission notification = getNotification(); assertNotNull(notification);/*from w w w. ja va 2 s. c o m*/ assertEquals(NotificationType.PERMISSION, notification.getNotificationType()); assertEquals(2, notification.getItems().getItems().size()); assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat()); // Back the other way String expected = IOUtils.toString(getClass().getResourceAsStream(SAMPLE_PATH), "UTF-8"); Pattern pattern = Pattern.compile("<!--.*?-->\\s*", Pattern.DOTALL); expected = pattern.matcher(expected).replaceAll(""); JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.permission"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.orcid.org/ns/notification ../notification-permission-2.0_rc1.xsd"); StringWriter writer = new StringWriter(); marshaller.marshal(notification, writer); XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(expected, writer.toString()); assertTrue(diff.identical()); }
From source file:org.orcid.jaxb.model.notification.addactivities.MarshallingTest.java
@Test public void testMarshalling() throws JAXBException, IOException, SAXException { NotificationAddActivities notification = getNotification(); assertNotNull(notification);//from w w w. j a va 2 s .c om assertEquals(NotificationType.ADD_ACTIVITIES, notification.getNotificationType()); assertEquals(2, notification.getActivities().getActivities().size()); assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat()); // Back the other way String expected = IOUtils.toString(getClass().getResourceAsStream(SAMPLE_PATH), "UTF-8"); Pattern pattern = Pattern.compile("<!--.*?-->\\s*", Pattern.DOTALL); expected = pattern.matcher(expected).replaceAll(""); JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.addactivities"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.orcid.org/ns/notification ../notification-add-activities-2.0_rc1.xsd"); StringWriter writer = new StringWriter(); marshaller.marshal(notification, writer); XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(expected, writer.toString()); assertTrue(diff.identical()); }
From source file:com.liferay.blade.samples.integration.test.utils.BladeCLIUtil.java
public static String execute(File workingDir, String... bladeArgs) throws Exception { String bladeCLIJarPath = getLatestBladeCLIJar(); List<String> command = new ArrayList<>(); command.add("java"); command.add("-jar"); command.add(bladeCLIJarPath);/*w w w . j ava 2s . c o m*/ for (String arg : bladeArgs) { command.add(arg); } Process process = new ProcessBuilder(command.toArray(new String[0])).directory(workingDir).start(); process.waitFor(); InputStream stream = process.getInputStream(); String output = new String(IO.read(stream)); InputStream errorStream = process.getErrorStream(); List<String> errorList = new ArrayList<>(); String stringStream = null; if (errorStream != null) { stringStream = new String(IO.read(errorStream)); errorList.add(stringStream); } List<String> filteredErrorList = new ArrayList<>(); for (String string : errorList) { String exclusion = "(.*setlocale.*)"; Pattern p = Pattern.compile(exclusion, Pattern.DOTALL); Matcher m = p.matcher(string); while (m.find()) { filteredErrorList.add(string); } if (string.contains("Picked up JAVA_TOOL_OPTIONS:")) { filteredErrorList.add(string); } } errorList.removeAll(filteredErrorList); Assert.assertTrue(errorList.toString(), errorList.size() <= 1); if (errorList.size() == 1) { Assert.assertTrue(errorList.get(0), errorList.get(0).isEmpty()); } return output; }
From source file:org.goko.core.rs274ngcv3.parser.GCodeLexer.java
/** * Constructor//from w w w . java2 s. c o m */ public GCodeLexer() { multilineCommentPattern = Pattern.compile(GCodeTokenType.MULTILINE_COMMENT.getPattern(), Pattern.MULTILINE | Pattern.DOTALL); simpleCommentPattern = Pattern.compile(GCodeTokenType.SIMPLE_COMMENT.getPattern()); lineNumberPattern = Pattern.compile(GCodeTokenType.LINE_NUMBER.getPattern()); wordPattern = Pattern.compile(GCodeTokenType.WORD.getPattern()); spacePattern = Pattern.compile("^[ ]+"); }
From source file:org.apache.hadoop.hive.ql.exec.mr.Throttle.java
/** * Fetch http://tracker.om:/gc.jsp?threshold=period. *//*from www . j ava 2s. c o m*/ public static void checkJobTracker(JobConf conf, Log LOG) { try { byte[] buffer = new byte[1024]; int threshold = conf.getInt("mapred.throttle.threshold.percent", DEFAULT_MEMORY_GC_PERCENT); int retry = conf.getInt("mapred.throttle.retry.period", DEFAULT_RETRY_PERIOD); // If the threshold is 100 percent, then there is no throttling if (threshold == 100) { return; } // This is the Job Tracker URL String tracker = JobTrackerURLResolver.getURL(conf) + "/gc.jsp?threshold=" + threshold; while (true) { // read in the first 1K characters from the URL URL url = new URL(tracker); LOG.debug("Throttle: URL " + tracker); InputStream in = null; try { in = url.openStream(); in.read(buffer); in.close(); in = null; } finally { IOUtils.closeStream(in); } String fetchString = new String(buffer); // fetch the xml tag <dogc>xxx</dogc> Pattern dowait = Pattern.compile("<dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); String[] results = dowait.split(fetchString); if (results.length != 2) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } dowait = Pattern.compile("</dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); results = dowait.split(results[1]); if (results.length < 1) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } // if the jobtracker signalled that the threshold is not exceeded, // then we return immediately. if (results[0].trim().compareToIgnoreCase("false") == 0) { return; } // The JobTracker has exceeded its threshold and is doing a GC. // The client has to wait and retry. LOG.warn("Job is being throttled because of resource crunch on the " + "JobTracker. Will retry in " + retry + " seconds.."); Thread.sleep(retry * 1000L); } } catch (Exception e) { LOG.warn("Job is not being throttled. " + e); } }
From source file:com.android.dialer.lookup.whitepages.WhitePagesApi.java
private static ContactInfo[] parseOutputUnitedStates(String output, int maxResults) throws IOException { ArrayList<ContactInfo> people = new ArrayList<ContactInfo>(); Pattern regex = Pattern.compile("<li\\s[^>]+?http:\\/\\/schema\\.org\\/Person", Pattern.DOTALL); Matcher m = regex.matcher(output); while (m.find()) { if (people.size() == maxResults) { break; }//from w ww.j av a2s . c om // Find section of HTML with contact information String section = extractXmlTag(output, m.start(), m.end(), "li"); // Skip entries with no phone number if (section.contains("has-no-phone-icon")) { continue; } String name = LookupUtils.fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"name\">", "span")); if (name == null) { continue; } // Address String addrCountry = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressCountry\">", "span")); String addrState = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressRegion\">", "span")); String addrCity = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressLocality\">", "span")); StringBuilder sb = new StringBuilder(); if (addrCity != null) { sb.append(addrCity); } if (addrState != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addrState); } if (addrCountry != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addrCountry); } // Website Pattern p = Pattern.compile("href=\"(.+?)\""); Matcher m2 = p.matcher(section); String website = null; if (m2.find()) { website = "http://www.whitepages.com" + m2.group(1); } // Phone number is on profile page, so skip if we can't get the // website if (website == null) { continue; } String profile = httpGet(website); String phoneNumber = LookupUtils .fromHtml(extractXmlRegex(profile, "<li[^>]+?class=\"no-overflow tel\">", "li")); String address = parseAddressUnitedStates(profile); if (phoneNumber == null) { Log.e(TAG, "Phone number is null. Either cookie is bad or regex is broken"); continue; } ContactInfo info = new ContactInfo(); info.name = name; info.city = sb.toString(); info.address = address; info.formattedNumber = phoneNumber; info.website = website; people.add(info); } return people.toArray(new ContactInfo[people.size()]); }
From source file:org.apache.accumulo.examples.wikisearch.jexl.Arithmetic.java
/** * This method differs from the parent in that we are not calling String.matches() because it does not match on a newline. Instead we are handling this case. * //from w w w. j av a 2 s.c o m * @param left * first value * @param right * second value * @return test result. */ @Override public boolean matches(Object left, Object right) { if (left == null && right == null) { // if both are null L == R return true; } if (left == null || right == null) { // we know both aren't null, therefore L != R return false; } final String arg = left.toString(); if (right instanceof java.util.regex.Pattern) { return ((java.util.regex.Pattern) right).matcher(arg).matches(); } else { // return arg.matches(right.toString()); Pattern p = Pattern.compile(right.toString(), Pattern.DOTALL); Matcher m = p.matcher(arg); return m.matches(); } }
From source file:org.eclipse.recommenders.tests.jdt.JavaProjectFixture.java
public static List<String> findInnerClassNames(final CharSequence source) { String declaringType = findClassName(source); List<String> names = newArrayList(); Pattern p = Pattern.compile("(class|interface)\\s+(\\w+)", Pattern.DOTALL); Matcher matcher = p.matcher(source); while (matcher.find()) { final String name = matcher.group(2); if (!name.equals(declaringType)) { names.add(declaringType + "$" + name); }/*w ww. ja va 2 s. c o m*/ } return names; }