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:dk.teachus.backend.testdatagenerator.DynamicDataImport.java
private void createVersion() { // Parse the pom file to get the version File file = new File("pom.xml"); if (file.exists()) { try {// ww w .j a v a2 s. c o m String pomContent = FileUtils.readFileToString(file, "UTF-8"); Pattern pattern = Pattern.compile(".*?\\<version\\>([^\\<]+)\\<\\/version>.*", Pattern.MULTILINE | Pattern.DOTALL); Matcher matcher = pattern.matcher(pomContent); if (matcher.matches()) { String version = matcher.group(1); version = version.replace("-SNAPSHOT", ""); Session session = sessionFactory.openSession(); session.beginTransaction(); ApplicationConfigurationEntry entry = new ApplicationConfigurationEntry("VERSION", version); session.save(entry); session.getTransaction().commit(); session.close(); } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:com.ebay.nest.io.sede.RegexSerDe.java
@Override public void initialize(Configuration conf, Properties tbl) throws SerDeException { // We can get the table definition from tbl. // Read the configuration parameters inputRegex = tbl.getProperty("input.regex"); String columnNameProperty = tbl.getProperty(serdeConstants.LIST_COLUMNS); String columnTypeProperty = tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES); boolean inputRegexIgnoreCase = "true".equalsIgnoreCase(tbl.getProperty("input.regex.case.insensitive")); // output format string is not supported anymore, warn user of deprecation if (null != tbl.getProperty("output.format.string")) { LOG.warn("output.format.string has been deprecated"); }/*from ww w . j a v a2s. c om*/ // Parse the configuration parameters if (inputRegex != null) { inputPattern = Pattern.compile(inputRegex, Pattern.DOTALL + (inputRegexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0)); } else { inputPattern = null; throw new SerDeException("This table does not have serde property \"input.regex\"!"); } List<String> columnNames = Arrays.asList(columnNameProperty.split(",")); columnTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty); assert columnNames.size() == columnTypes.size(); numColumns = columnNames.size(); /* Constructing the row ObjectInspector: * The row consists of some set of primitive columns, each column will * be a java object of primitive type. */ List<ObjectInspector> columnOIs = new ArrayList<ObjectInspector>(columnNames.size()); for (int c = 0; c < numColumns; c++) { TypeInfo typeInfo = columnTypes.get(c); String typeName = typeInfo.getTypeName(); if (typeName.equals(serdeConstants.STRING_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector); } else if (typeName.equals(serdeConstants.TINYINT_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaByteObjectInspector); } else if (typeName.equals(serdeConstants.SMALLINT_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaShortObjectInspector); } else if (typeName.equals(serdeConstants.INT_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector); } else if (typeName.equals(serdeConstants.BIGINT_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaLongObjectInspector); } else if (typeName.equals(serdeConstants.FLOAT_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaFloatObjectInspector); } else if (typeName.equals(serdeConstants.DOUBLE_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaDoubleObjectInspector); } else if (typeName.equals(serdeConstants.BOOLEAN_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaBooleanObjectInspector); } else if (typeName.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaTimestampObjectInspector); } else if (typeName.equals(serdeConstants.DATE_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaDateObjectInspector); } else if (typeName.equals(serdeConstants.DECIMAL_TYPE_NAME)) { columnOIs.add(PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector); } else if (typeInfo instanceof PrimitiveTypeInfo && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory() == PrimitiveCategory.VARCHAR) { VarcharTypeParams varcharParams = (VarcharTypeParams) ParameterizedPrimitiveTypeUtils .getTypeParamsFromTypeInfo(typeInfo); columnOIs.add(PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector((PrimitiveTypeInfo) typeInfo)); } else { throw new SerDeException(getClass().getName() + " doesn't allow column [" + c + "] named " + columnNames.get(c) + " with type " + columnTypes.get(c)); } } // StandardStruct uses ArrayList to store the row. rowOI = ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, columnOIs); row = new ArrayList<Object>(numColumns); // Constructing the row object, etc, which will be reused for all rows. for (int c = 0; c < numColumns; c++) { row.add(null); } outputFields = new Object[numColumns]; outputRowText = new Text(); }
From source file:damo.three.ie.util.HtmlUtilities.java
/** * Parses the My3 account usage page to nicer JSON format. * * @param pageContent Page content as HTML. * @return Usage information stripped out and formatted as JSON. * @throws JSONException/*from w ww.j a va2 s .c o m*/ */ public static JSONArray parseUsageAsJSONArray(String pageContent) throws JSONException { // The HTML on prepay is pig-ugly, so we will use JSoup to // clean and parse it. Document doc = Jsoup.parse(pageContent); HtmlUtilities.removeComments(doc); Elements elements = doc.getElementsByTag("table"); JSONArray jsonArray = new JSONArray(); // three don't have a sub label for the 3-to-3 calls, which is not consistent with other items. // .. feck them! boolean three2threeCallsBug = false; for (Element element : elements) { for (Element subelement : element.select("tbody > tr")) { if ((subelement.text().contains("3 to 3 Calls")) && (subelement.text().contains("Valid until"))) { three2threeCallsBug = true; } Elements subsubelements = subelement.select("td"); if (subsubelements.size() == 3) { // skip the "total" entries if (subsubelements.select("td").get(0).text().contains("Total")) { continue; } JSONObject currentItem = new JSONObject(); if (three2threeCallsBug) { currentItem.put("item", "3 to 3 Calls"); } else { // Get rid of that "non-breaking space" character if it exists String titleToClean = subsubelements.select("td").get(0).text().replace("\u00a0", "") .trim(); currentItem.put("item", titleToClean); } /** * Check if date contains "Today", if so, change it to a date. * Otherwise we will never know when usage ends, unless user refreshes, As 'today' * is 'today', tomorrow.. see! */ String value1 = subsubelements.select("td").get(1).text(); if (value1.equals("Today")) { DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yy").withLocale(Locale.UK); DateTime dt = new DateTime(); // current datetime value1 = "Expires " + formatter.print(dt); } currentItem.put("value1", value1); currentItem.put("value2", subsubelements.select("td").get(2).text()); // Out of Bundle charges have an extra property if (currentItem.getString("item").startsWith("Internet")) { Pattern p1 = Pattern.compile(Constants.OUT_OF_BUNDLE_REGEX, Pattern.DOTALL); Matcher m1 = p1.matcher(pageContent); StringBuilder cleanedDate = new StringBuilder(); if (m1.matches()) { cleanedDate.append(m1.group(1)); cleanedDate.append(' '); cleanedDate.append(m1.group(2)); cleanedDate.append(' '); cleanedDate.append(m1.group(3)); currentItem.put("value3", cleanedDate.toString()); } } jsonArray.put(currentItem); } } // reset the 3-to-3 call bug flag for next Element if (three2threeCallsBug) { three2threeCallsBug = false; } } return jsonArray; }
From source file:com.edgenius.wiki.render.filter.MacroFilter.java
/** * Initial macro filter only for special Macro. * /*from w ww . jav a 2s . c o m*/ * At the moment, only {piece} macro need this method - which need get Phase Piece from entire page content... * @param macro */ public void init(Macro macro, boolean immutable) { pairedMacroProvider.compile(FilterRegxConstants.PAIRED_MACRO, Pattern.DOTALL); singleMacroProvider.compile(FilterRegxConstants.SINGLE_MACRO, Pattern.MULTILINE); macroMgr.addMacro(macro, immutable); }
From source file:com.edgenius.wiki.render.filter.ListFilter.java
public void init() { regexProvider.compile(getRegex(), Pattern.MULTILINE | Pattern.DOTALL); }
From source file:de.ist.clonto.webwiki.InfoboxParser.java
private String removeReferences(String text) { text = Pattern.compile("<ref name=\".*?\">.*?</ref>", Pattern.MULTILINE | Pattern.DOTALL).matcher(text) .replaceAll(""); text = Pattern.compile("<ref name=\".*?\"\\s/>", Pattern.MULTILINE | Pattern.DOTALL).matcher(text) .replaceAll(""); return text;/*from ww w. j a va2 s.co m*/ }
From source file:se.rebootit.android.tagbiljetter.DataParser.java
/** * Parse the message and check if it's a valid ticket * @param phonenumber From what number did the sms arrive from? * @param timestamp Timestamp arrived * @param message The message//from w w w . j a v a 2s . c o m */ public TransportCompany parseMessage(String phonenumber, long timestamp, String message) { for (TransportCompany transportCompany : lstCompanies) { if (phonenumber.startsWith(transportCompany.getPhoneNumber())) { String expr = transportCompany.getTicketFormat(); Pattern pattern = Pattern.compile(expr, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); Matcher matcher = pattern.matcher(message); if (matcher.matches()) { return transportCompany; } } } return null; }
From source file:org.openmrs.module.adminui.TestUtils.java
/** * Tests whether the substring is NOT contained in the actual string. Allows for inclusion of * regular expressions in the substring. Ignores white space. Ignores capitalization. *//*from w ww .j a v a2 s . c om*/ public static void assertFuzzyDoesNotContain(String substring, String actual) { if (substring == null) { return; } if (actual == null) { return; } if (Pattern.compile(stripWhitespaceAndConvertToLowerCase(substring), Pattern.DOTALL) .matcher(stripWhitespaceAndConvertToLowerCase(actual)).find()) { Assert.fail(substring + " found in " + actual); } }
From source file:com.thoughtworks.go.matchers.ConsoleOutMatcherJunit5.java
public ConsoleOutMatcherJunit5 matchUsingRegex(final String stringContainingRegex) { final boolean condition = Pattern.compile(stringContainingRegex, Pattern.DOTALL).matcher(actual).find(); if (!condition) { failWithMessage("Expected console to contain [<%s>] but was <%s>.", stringContainingRegex, actual); }// w ww .j av a 2 s. co m return this; }
From source file:org.mule.transport.telnet.TelnetClientWrapper.java
/** * /*from w ww .j a v a2 s . c om*/ * @param regex * @throws IOException * @throws Exception */ protected String readStream(String regex) throws IOException, ResponseTimeoutException { logger.trace("reading stream until matched regex [" + regex + "]"); Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); ByteArrayOutputStream bytebuf = new ByteArrayOutputStream(1024); Matcher matcher = null; try { Thread.sleep(1000); // wait for running command } catch (InterruptedException e) { } this.startTime = System.currentTimeMillis(); try { try { //TODO remove if LINEMODE is enabled. // wait for running command Thread.sleep(1000); } catch (InterruptedException e) { } while (System.currentTimeMillis() - startTime < responseTimeout + 60000) { if (reader.available() > 0) { byte[] tmp = new byte[1024]; int i = reader.read(tmp, 0, 1024); if (i < 0) { break; } bytebuf.write(tmp, 0, i); } bytebuf.flush(); matcher = pattern.matcher(bytebuf.toString(encoding)); if (matcher.find()) break; // timeout processing is disabled if seting responseTimeout to 0. if (responseTimeout > 0 && (System.currentTimeMillis() - startTime) > responseTimeout) { logger.info("timeout : " + responseTimeout + " ms"); throwTimeoutException(); } } if (matcher == null) { logger.debug("no response"); matcher = pattern.matcher(bytebuf.toString(encoding)); } if (!matcher.find()) { matcher = pattern.matcher(bytebuf.toString(encoding)); } if (matcher != null && matcher.find(0) && matcher.groupCount() >= 1) { return (matcher.group(1)); } return null; } catch (ResponseTimeoutException e) { throw e; } catch (IOException e) { throw e; } }