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:edu.stanford.muse.lang.Languages.java
public static void init() { allPatterns.clear();/*from w w w . j av a 2 s . c o m*/ allLanguages.clear(); allScripts.clear(); allLanguages.add("English"); allScripts.add("Roman"); for (String[] lang : script_languages) { String scriptName = lang[0]; String langString = lang[1]; List<String> languages = new ArrayList<String>(); // tokenize langString by , StringTokenizer st = new StringTokenizer(langString, ","); while (st.hasMoreTokens()) { String language = st.nextToken(); language = language.trim(); if (language.length() == 0) continue; languages.add(language); } // build up pattern array or all pattern to languages for (String language : languages) { Pattern p = Pattern.compile(".*\\p{In" + scriptName + "}.*", Pattern.DOTALL); // DOTALL allows matching across lines which is what we want to detect chars in a given script allPatterns.add(new LangInfo(p, language)); allScripts.add(scriptName); allLanguages.add(language); } } log.info(allScripts.size() + " scripts, " + allLanguages.size() + " languages, " + allPatterns.size() + " patterns"); }
From source file:com.adguard.filter.rules.ContentFilterRule.java
/** * Creates an instance of the ContentFilterRule from its text format * * @param ruleText Rule text// w w w. j a va 2 s .co m */ protected ContentFilterRule(String ruleText) { super(ruleText); parentSearchLevel = DEFAULT_PARENT_SEARCH_LEVEL; int contentRuleMarkIndex = StringUtils.indexOf(ruleText, MASK_CONTENT_RULE); int ruleStartIndex = StringUtils.indexOf(ruleText, ATTRIBUTE_START_MARK); // Cutting tag name from string if (ruleStartIndex == -1) { tagName = ruleText.substring(contentRuleMarkIndex + MASK_CONTENT_RULE.length()); } else { tagName = ruleText.substring(contentRuleMarkIndex + MASK_CONTENT_RULE.length(), ruleStartIndex); } // Loading domains (if any)) if (contentRuleMarkIndex > 0) { String domains = ruleText.substring(0, contentRuleMarkIndex); loadDomains(domains); } // Loading attributes filter while (ruleStartIndex != -1) { int equalityIndex = ruleText.indexOf(EQUAL, ruleStartIndex + 1); int quoteStartIndex = ruleText.indexOf(QUOTES, equalityIndex + 1); int quoteEndIndex = getQuoteIndex(ruleText, quoteStartIndex + 1); if (quoteStartIndex == -1 || quoteEndIndex == -1) { break; } int ruleEndIndex = ruleText.indexOf(ATTRIBUTE_END_MARK, quoteEndIndex + 1); String attributeName = ruleText.substring(ruleStartIndex + 1, equalityIndex); String attributeValue = ruleText.substring(quoteStartIndex + 1, quoteEndIndex); attributeValue = StringUtils.replace(attributeValue, "\"\"", "\""); switch (attributeName) { case TAG_CONTENT_MASK: tagContentFilter = attributeValue; break; case WILDCARD_MASK: wildcard = new Wildcard(attributeValue, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); break; case TAG_CONTENT_MAX_LENGTH: maxLength = NumberUtils.toInt(attributeValue); break; case TAG_CONTENT_MIN_LENGTH: minLength = NumberUtils.toInt(attributeValue); break; case PARENT_ELEMENTS: parentElements = Arrays.asList(StringUtils.split(attributeValue, ',')); break; case PARENT_SEARCH_LEVEL: parentSearchLevel = NumberUtils.toInt(attributeValue); break; default: attributesFilter.put(attributeName, attributeValue); break; } if (ruleEndIndex == -1) break; ruleStartIndex = ruleText.indexOf(ATTRIBUTE_START_MARK, ruleEndIndex + 1); } }
From source file:org.opennms.web.rest.AcknowledgmentRestServiceTest.java
@Test @JUnitTemporaryDatabase// w w w . j a v a2 s .c o m public void testAcknowlegeNotification() throws Exception { final Pattern p = Pattern.compile("^.*<answeredBy>(.*?)</answeredBy>.*$", Pattern.DOTALL & Pattern.MULTILINE); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=ack"); String xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200); Matcher m = p.matcher(xml); assertTrue(m.matches()); assertTrue(m.group(1).equals("admin")); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=unack"); xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200); m = p.matcher(xml); assertFalse(m.matches()); }
From source file:org.sleuthkit.autopsy.recentactivity.Util.java
public static String getFileName(String value) { String filename = ""; String filematch = "^([a-zA-Z]\\:)(\\\\[^\\\\/:*?<>\"|]*(?<!\\[ \\]))*(\\.[a-zA-Z]{2,6})$"; Pattern p = Pattern.compile(filematch, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.COMMENTS); Matcher m = p.matcher(value); if (m.find()) { filename = m.group(1);/*from w w w . j a v a2s . com*/ } int lastPos = value.lastIndexOf('\\'); filename = (lastPos < 0) ? value : value.substring(lastPos + 1); return filename.toString(); }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetImagelinkTitles.java
/** * gets the information about a follow-up page from a provided api response. * If there is one, a new request is added to msgs by calling generateRequest. * /*from www . j ava2s . c om*/ * @param s text for parsing */ protected void parseHasMore(final String s) { System.out.println(s); // get the ilcontinue-value Pattern p = Pattern.compile( "<query-continue>.*?" + "<imageusage *iucontinue=\"([^\"]*)\" */>" + ".*?</query-continue>", Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(s); if (m.find()) { nextPageInfo = m.group(1); } }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetTemplateUserTitles.java
/** * gets the information about a follow-up page from a provided api response. * If there is one, a new request is added to msgs by calling generateRequest. * //from w w w. j av a2 s . c o m * @param s text for parsing */ protected void parseHasMore(final String s) { // get the eicontinue-value Pattern p = Pattern.compile( "<query-continue>.*?" + "<embeddedin *eicontinue=\"([^\"]*)\" */>" + ".*?</query-continue>", Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(s); if (m.find()) { nextPageInfo = m.group(1); } }
From source file:org.picketlink.test.trust.tests.JBWSTokenIssuingLoginModuleUnitTestCase.java
private void assertApp(String appUri, String userName, String password, String httpHeader, String httpHeaderValue) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {//from w w w . j a va 2s .co m httpclient.getCredentialsProvider().setCredentials(new AuthScope(getServerAddress(), 8080), // localhost new UsernamePasswordCredentials(userName, password)); HttpGet httpget = new HttpGet(getTargetURL(appUri)); // http://localhost:8080/test-app-1/test if (httpHeader != null) httpget.addHeader(httpHeader, httpHeaderValue); log.debug("executing request" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); assertEquals("Http response has to finish with 'HTTP/1.1 200 OK'", 200, response.getStatusLine().getStatusCode()); HttpEntity entity = response.getEntity(); log.debug("Status line: " + response.getStatusLine()); ByteArrayOutputStream baos = new ByteArrayOutputStream((int) entity.getContentLength()); entity.writeTo(baos); String content = baos.toString(); baos.close(); if (log.isTraceEnabled()) { log.trace(content); } Pattern p = Pattern.compile("[.|\\s]*Credential\\[\\d\\]\\=SamlCredential\\[.*\\]", Pattern.DOTALL); Matcher m = p.matcher(content); boolean samlCredPresentOnSubject = m.find(); assertTrue("SamlCredential on subject is missing for (" + appUri + ")", samlCredPresentOnSubject); EntityUtils.consume(entity); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.android.dialer.lookup.whitepages.WhitePagesApi.java
private static String extractXmlRegex(String str, String regex, String tag) { Pattern p = Pattern.compile(regex, Pattern.DOTALL); Matcher m = p.matcher(str);/* w w w. j ava2s . c o m*/ if (m.find()) { return extractXmlTag(str, m.start(), m.end(), tag); } return null; }
From source file:com.logsniffer.event.publisher.MailPublisherTest.java
@Test public void testMailPublishing() throws PublishException { final Event event = new Event(); event.setId("3"); event.setLogPath("path.log"); event.setLogSourceId(7);/*from www . jav a2s. c o m*/ event.setSnifferId(5); final Map<String, Serializable> data = new HashMap<String, Serializable>(); data.put("key1", "abc"); data.put("key3", "def"); event.putAll(data); final List<LogEntry> entries = new ArrayList<LogEntry>(); final LogEntry e1 = new LogEntry(); e1.setRawContent("e1"); final LogEntry e2 = new LogEntry(); e2.setRawContent("e2"); entries.add(e1); entries.add(e2); event.setEntries(entries); mailPublisher.setSubject("Subject: $event.lf_entries[0].lf_raw"); mailPublisher.setFrom("fromme $event"); mailPublisher.setTo("tome$event,toyou"); final MailPublisher clonePublisher = configManager.createBeanFromJSON(MailPublisher.class, configManager.saveBeanToJSON(mailPublisher)); clonePublisher.publish(event); Mockito.verify(mailSender).send(Mockito.argThat(new BaseMatcher<SimpleMailMessage>() { @Override public boolean matches(final Object arg0) { final SimpleMailMessage mail = (SimpleMailMessage) arg0; if (!mail.getSubject().equals("Subject: " + e1.getRawContent())) { return false; } final Pattern textPattern = Pattern.compile( "[^\n]+/c/sniffers/5/events/#/3\n\n" + "Log entries:\n" + "\\s*e1\n" + "\\s*e2\n\\s*", Pattern.CASE_INSENSITIVE + Pattern.DOTALL + Pattern.MULTILINE); if (!textPattern.matcher(mail.getText()).matches()) { return false; } return mail.getFrom().equals("fromme $event") && mail.getTo().length == 2 && mail.getTo()[0].equals("tome$event") && mail.getTo()[1].equals("toyou"); } @Override public void describeTo(final Description arg0) { } })); }
From source file:org.languagetool.tools.RuleMatchAsXmlSerializerTest.java
@Test public void testRuleMatchesToXML() throws IOException { List<RuleMatch> matches = new ArrayList<>(); String text = "This is an test sentence. Here's another sentence with more text."; FakeRule rule = new FakeRule(); RuleMatch match = new RuleMatch(rule, null, 8, 10, "myMessage"); match.setColumn(99);//from w w w. ja v a 2 s . com match.setEndColumn(100); match.setLine(44); match.setEndLine(45); matches.add(match); String xml = SERIALIZER.ruleMatchesToXml(matches, text, 5, NORMAL_API, LANG, Collections.<String>emptyList()); assertTrue(xml.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")); Pattern matchesPattern = Pattern.compile(".*<matches software=\"LanguageTool\" version=\"" + JLanguageTool.VERSION + "\" buildDate=\".*?\">.*", Pattern.DOTALL); Matcher matcher = matchesPattern.matcher(xml); assertTrue("Did not find expected '<matches>' element ('" + matchesPattern + "'), got:\n" + xml, matcher.matches()); assertTrue(xml.contains(">\n" + "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"FAKE_ID\" msg=\"myMessage\" " + "replacements=\"\" context=\"...s is an test...\" contextoffset=\"8\" offset=\"8\" errorlength=\"2\" " + "category=\"Miscellaneous\" categoryid=\"MISC\" locqualityissuetype=\"misspelling\"/>\n" + "</matches>\n")); }