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.picketlink.test.trust.tests.Gateway2ServiceHttpUnitTestCase.java
private boolean samlCredentialPresense(String content) { Pattern p = Pattern.compile("[.|\\s]*Credential\\[\\d\\]\\=SamlCredential\\[.*\\]", Pattern.DOTALL); Matcher m = p.matcher(content); return m.find(); }
From source file:org.sonar.dotnet.tools.commons.visualstudio.ModelFactory.java
private static List<String> getBuildConfigurations(String solutionContent) { // A pattern to extract the build configurations from a visual studio solution String confExtractExp = "(\tGlobalSection\\(SolutionConfigurationPlatforms\\).*?^\tEndGlobalSection$)"; Pattern confExtractPattern = Pattern.compile(confExtractExp, Pattern.MULTILINE + Pattern.DOTALL); List<String> buildConfigurations = new ArrayList<String>(); // Extracts all the projects from the solution Matcher blockMatcher = confExtractPattern.matcher(solutionContent); if (blockMatcher.find()) { String buildConfigurationBlock = blockMatcher.group(1); String buildConfExtractExp = " = (.*)\\|"; Pattern buildConfExtractPattern = Pattern.compile(buildConfExtractExp); Matcher buildConfMatcher = buildConfExtractPattern.matcher(buildConfigurationBlock); while (buildConfMatcher.find()) { String buildConfiguration = buildConfMatcher.group(1); buildConfigurations.add(buildConfiguration); }// w w w . ja v a 2 s . c o m } return buildConfigurations; }
From source file:org.sleuthkit.autopsy.recentactivity.Util.java
public static String getPath(String txt) { String path = ""; //String drive ="([a-z]:\\\\(?:[-\\w\\.\\d]+\\\\)*(?:[-\\w\\.\\d]+)?)"; // Windows drive String drive = "([a-z]:\\\\\\S.+)"; Pattern p = Pattern.compile(drive, Pattern.CASE_INSENSITIVE | Pattern.COMMENTS); Matcher m = p.matcher(txt);// w ww . ja v a 2s .co m if (m.find()) { path = m.group(1); } else { String network = "(\\\\(?:\\\\[^:\\s?*\"<>|]+)+)"; // Windows network Pattern p2 = Pattern.compile(network, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m2 = p2.matcher(txt); if (m2.find()) { path = m2.group(1); } } return path; }
From source file:com.github.rwitzel.streamflyer.regex.RegexModifierTest.java
@Test public void testExampleFromHomepage_advancedExample_firstImprovement() throws Exception { // select the modifier Modifier myModifier = new RegexModifier("edit stream", 0, "modify stream"); // test: does not support other whitespace characters assertNotEquals("modify\tstream", modify("edit\tstream", myModifier)); // test: does not support new line characters assertNotEquals("modify\nstream", modify("edit\nstream", myModifier)); // first improvement Modifier myModifier1 = new RegexModifier("edit\\sstream", Pattern.DOTALL, "modify stream"); // test: supports other whitespace characters assertEquals("modify stream", modify("edit\tstream", myModifier1)); // test: supports new line characters assertEquals("modify stream", modify("edit\nstream", myModifier1)); }
From source file:org.opennms.web.rest.v1.AcknowledgmentRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w w w. ja va 2 s .c om public void testAcknowlegeAlarm() throws Exception { final Pattern p = Pattern.compile("^.*<ackTime>(.*?)</ackTime>.*$", Pattern.DOTALL & Pattern.MULTILINE); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=ack", 200); // Try to fetch a non-existent ack, get 404 Not Found String xml = sendRequest(GET, "/acks/999999", 404); xml = sendRequest(GET, "/acks/count", 200); // {@link DatabasePopulator} adds one ack so we have 2 total assertEquals("2", xml); Integer newAckId = null; for (OnmsAcknowledgment ack : getXmlObject(JaxbUtils.getContextFor(OnmsAcknowledgmentCollection.class), "/acks", 200, OnmsAcknowledgmentCollection.class).getObjects()) { if (AckType.UNSPECIFIED.equals(ack.getAckType())) { // Ack from DatabasePopulator assertEquals(AckAction.UNSPECIFIED, ack.getAckAction()); assertEquals("admin", ack.getAckUser()); } else if (AckType.ALARM.equals(ack.getAckType())) { // Ack that we just created assertEquals(new Integer(1), ack.getRefId()); assertEquals(AckAction.ACKNOWLEDGE, ack.getAckAction()); newAckId = ack.getId(); } else { fail("Unrecognized alarm type: " + ack.getAckType().toString()); } } if (newAckId == null) { fail("Couldn't determine ID of new ack"); } xml = sendRequest(GET, "/acks/" + newAckId, 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); Matcher m = p.matcher(xml); assertTrue(m.matches()); assertTrue(m.group(1).length() > 0); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=unack", 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); m = p.matcher(xml); assertFalse(m.matches()); // POST with no argument, this will ack by default sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1", 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); m = p.matcher(xml); assertTrue(m.matches()); }
From source file:org.clickframes.util.CodeGenerator.java
/** * use case: the user formats the white-space of existing file. the * generated file is defined to be the same as the existing file if the only * changes made to the existing file is white space and formatting related, * such that our checksum algorithm computes the same checksum * * @param generatedFileWithoutChecksum/*from www.j a v a2 s.com*/ * @param existingUnmodifiedFileWithChecksum * @return * * @author Vineet Manohar * @throws IOException */ private boolean generatedFileLogicallySameAsExistingFile(File generatedFileWithoutChecksum, File existingUnmodifiedFileWithChecksum) throws IOException { // existing file with checksum String existingFileWithChecksumAsString = FileUtils.readFileToString(existingUnmodifiedFileWithChecksum); // is checksum string present Pattern pattern = Pattern.compile(".*clickframes::(version=(\\d+))::clickframes.*", Pattern.DOTALL); Matcher m = pattern.matcher(existingFileWithChecksumAsString); if (!m.matches()) { throw new IllegalArgumentException( "File does not have checksum stored: " + existingUnmodifiedFileWithChecksum); } long checksumFoundInFile = Long.parseLong(m.group(2)); // generated file without checksum String generatedContentWithoutChecksum = FileUtils.readFileToString(generatedFileWithoutChecksum); long checksumOfGeneratedContent = checksum(generatedContentWithoutChecksum); return checksumFoundInFile == checksumOfGeneratedContent; }
From source file:de.micromata.genome.gwiki.tools.PatchVersion.java
public void patch(Pair<String, String> p) { String f = readFile(p.getFirst()); Pattern pattern = Pattern.compile(p.getSecond(), Pattern.MULTILINE | Pattern.DOTALL); Matcher m = pattern.matcher(f); if (m.matches() == false) { System.out.println("Does not match: " + p.getFirst() + "; Pattern: " + p.getSecond()); return;/* ww w. j av a 2 s. c o m*/ } String g1 = m.group(1); String g2 = m.group(2); String g3 = m.group(3); if (StringUtils.isNotEmpty(expected) == true) { if (expected.equals(g2) == false) { System.out.println("Do not patch " + p.getFirst() + ". Expect: " + expected + "; got: " + g2); return; } } String ret = g1 + version + g3; System.out.println("Patched " + p.getFirst() + " from " + g2 + " to " + version); if (testOnly == true) { return; } writeFile(p.getFirst(), ret); }
From source file:de.innovationgate.wgpublisher.RTFEncodingFormatter.java
public String format(Object obj) throws FormattingException { try {//from w w w . j a v a 2 s .c om String text = (String) obj; _generateDataURL = (Boolean) _scriptletEngineParameters .get(RhinoExpressionEngine.SCRIPTLETOPTION_IMAGEURL_AS_DATAURL); if (_generateDataURL == null) { _generateDataURL = Boolean.FALSE; } // Step one: Resolve scriptlets RhinoExpressionEngine engine = ExpressionEngineFactory.getTMLScriptEngine(); text = engine.resolveScriptlets(text, _context, _scriptletEngineParameters); // Step two: Filter out all old relative links and replace them with dynamic URLs // We can ONLY do this in pure display mode. If field gets rendered for RTF editor we must prevent this because // it would lead to the storage of those dynamic URLs if (!_editMode) { // replace qualified and unqualified attachment links text = WGUtils.strReplace(text, "=\"../", this, true); // replace content links text = replaceContentLinks(text); } if (_editMode && WGUtils.stringToBoolean(System.getProperty(SYSPROP_FORCE_HTML_CLEANUP, "false"))) { // remove RTF-Editor declarations if contained in item value (possible due to copy&paste operations in the CM) Pattern rtfEditorDeclarationPatter = Pattern.compile("(<span[^>]*class=\"WGA-Item[^\"]*[^>]*>)", Pattern.DOTALL); Matcher matcher = rtfEditorDeclarationPatter.matcher(text); while (matcher.find()) { String spanTag = matcher.group(); if (spanTag.contains("display:none")) { text = matcher.replaceFirst("<span style=\"display:none\">"); } else { text = matcher.replaceFirst("<span>"); } matcher.reset(text); } while (!removeNoOpSpanTags(text).equals(text)) { text = removeNoOpSpanTags(text); } } return text; } catch (WGException e) { throw new FormattingException("Exception on RTF-Encoding", e); } }
From source file:org.ppwcode.vernacular.l10n_III.I18nExceptionHelpers.java
/** * Evaluate the given pattern inside the given context, with the given locale and add the object to the list. * *//*from w w w. j ava 2s . c om*/ protected static String processPattern(String pattern, Object context, Locale locale, List<Object> list) throws I18nException { // first process all elements found inside the pattern and replace the pattern // find deepest "${}" pattern first String regexp = "^(.*)\\$\\{([^\\{\\}]*)\\}(.*)$"; Pattern regexpPattern = Pattern.compile(regexp, Pattern.DOTALL); String workPattern = pattern; Matcher regexpMatcher = regexpPattern.matcher(workPattern); while (regexpMatcher.matches()) { String before = regexpMatcher.group(1); String middle = regexpMatcher.group(2); String after = regexpMatcher.group(3); workPattern = before + processElementString(middle, context, locale) + after; regexpMatcher = regexpPattern.matcher(workPattern); } // evaluate pattern Object value = processElementObject(workPattern, context, locale); int position = list.size(); list.add(value); return Integer.toString(position); }
From source file:de.micromata.genome.gwiki.plugin.vfolder_1_0.GWikiVFolderNode.java
public Pattern getExtractHtmlBodyRePatternCompiled() { if (extractHtmlBodyRePatternCompiled != null) { return extractHtmlBodyRePatternCompiled; }//from w ww . j a v a2 s . c om if (StringUtils.isNotBlank(extractHtmlBodyRePattern) == true) { extractHtmlBodyRePatternCompiled = Pattern.compile(extractHtmlBodyRePattern, Pattern.DOTALL); } return extractHtmlBodyRePatternCompiled; }