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:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.LoadAnnotationListener.java
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub this.pathToFile = this.loadAnnotationUI.getPathToFile(); this.platformId = this.loadAnnotationUI.getPlatformId(); this.annotationDate = this.loadAnnotationUI.getAnnotationDate(); this.annotationRelease = this.loadAnnotationUI.getAnnotationRelease(); this.annotationTitle = this.loadAnnotationUI.getAnnotationTitle(); this.loadAnnotationUI.openLoadingShell(); Thread thread = new Thread() { public void run() { try { //initiate kettle environment KettleEnvironment.init(false); //find the kettle job to initiate the loading URL jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation.kjb"); jobUrl = FileLocator.toFileURL(jobUrl); String jobPath = jobUrl.getPath(); //create a new job from the kettle file JobMeta jobMeta = new JobMeta(jobPath, null); Job job = new Job(null, jobMeta); //find the other files needed for this job and put them in the cache jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_AFFY_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_GEO_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation_to_lt.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/run_i2b2_load_annotation_deapp.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation_to_de_gpl_info.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); job.getJobMeta().setParameterValue("DATA_LOCATION", pathToFile); File sort = new File( StudySelectionController.getWorkspace().getAbsoluteFile() + File.separator + ".sort"); if (!sort.exists()) { FileUtils.forceMkdir(sort); }/*from w ww . ja va 2s . c o m*/ job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath()); job.getJobMeta().setParameterValue("DATA_SOURCE", "A"); //check if gpl id is not empty if (platformId == null) { loadAnnotationUI.setMessage("Please provide the platform identifier"); loadAnnotationUI.setIsLoading(false); return; } job.getJobMeta().setParameterValue("GPL_ID", platformId); job.getJobMeta().setParameterValue("SKIP_ROWS", "1"); job.getJobMeta().setParameterValue("GENE_ID", "4"); job.getJobMeta().setParameterValue("GENE_SYMBOL_COL", "3"); job.getJobMeta().setParameterValue("ORGANISM_COL", "5"); job.getJobMeta().setParameterValue("PROBE_COL", "2"); if (annotationDate != null) { job.getJobMeta().setParameterValue("ANNOTATION_DATE", annotationDate); } if (annotationRelease != null) { job.getJobMeta().setParameterValue("ANNOTATION_RELEASE", annotationRelease); } //check if annotation title is not empty if (annotationTitle == null) { loadAnnotationUI.setMessage("Please provide the annotation title"); loadAnnotationUI.setIsLoading(false); return; } job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle); job.getJobMeta().setParameterValue("LOAD_TYPE", "I"); job.getJobMeta().setParameterValue("TM_CZ_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("TM_CZ_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("TM_CZ_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("TM_CZ_DB_USER", PreferencesHandler.getTm_czUser()); job.getJobMeta().setParameterValue("TM_CZ_DB_PWD", PreferencesHandler.getTm_czPwd()); job.getJobMeta().setParameterValue("TM_LZ_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("TM_LZ_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("TM_LZ_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("TM_LZ_DB_USER", PreferencesHandler.getTm_lzUser()); job.getJobMeta().setParameterValue("TM_LZ_DB_PWD", PreferencesHandler.getTm_lzPwd()); job.getJobMeta().setParameterValue("DEAPP_DB_SERVER", PreferencesHandler.getDbServer()); job.getJobMeta().setParameterValue("DEAPP_DB_NAME", PreferencesHandler.getDbName()); job.getJobMeta().setParameterValue("DEAPP_DB_PORT", PreferencesHandler.getDbPort()); job.getJobMeta().setParameterValue("DEAPP_DB_USER", PreferencesHandler.getDeappUser()); job.getJobMeta().setParameterValue("DEAPP_DB_PWD", PreferencesHandler.getDeappPwd()); job.start(); job.waitUntilFinished(3000000); job.interrupt(); //job.waitUntilFinished(5000000); @SuppressWarnings("unused") Result result = job.getResult(); Log4jBufferAppender appender = CentralLogStore.getAppender(); String logText = appender.getBuffer(job.getLogChannelId(), false).toString(); Pattern pattern = Pattern.compile( ".*run_i2b2_load_annotation_deapp - Dispatching started for transformation \\[run_i2b2_load_annotation_deapp\\].*", Pattern.DOTALL); Matcher matcher = pattern.matcher(logText); if (matcher.matches()) { String connectionString = "jdbc:oracle:thin:@" + PreferencesHandler.getDbServer() + ":" + PreferencesHandler.getDbPort() + ":" + PreferencesHandler.getDbName(); Connection con = DriverManager.getConnection(connectionString, PreferencesHandler.getTm_czUser(), PreferencesHandler.getTm_czPwd()); Statement stmt = con.createStatement(); //remove rows for this study before adding new ones ResultSet rs = stmt.executeQuery( "select max(JOB_ID) from CZ_JOB_AUDIT where STEP_DESC='Starting i2b2_load_annotation_deapp'"); int jobId; if (rs.next()) { jobId = rs.getInt("max(JOB_ID)"); } else { con.close(); loadAnnotationUI.setIsLoading(false); return; } logText += "\nOracle job id:\n" + String.valueOf(jobId); rs = stmt.executeQuery( "select job_status from cz_job_master where job_id=" + String.valueOf(jobId)); if (rs.next()) { if (rs.getString("job_status").compareTo("Running") == 0) { loadAnnotationUI.setMessage( "Kettle job time out because the stored procedure is not over. Please check in a while if loading has succeed"); loadAnnotationUI.setIsLoading(false); return; } } rs = stmt.executeQuery( "select ERROR_MESSAGE from CZ_JOB_ERROR where JOB_ID=" + String.valueOf(jobId)); String procedureErrors = ""; if (rs.next()) { procedureErrors = rs.getString("ERROR_MESSAGE"); } con.close(); if (procedureErrors.compareTo("") == 0) { loadAnnotationUI.setMessage("Platform annotation has been loaded"); } else { loadAnnotationUI.setMessage("Error during procedure: " + procedureErrors); } } else { loadAnnotationUI.setMessage("Error in Kettle job: see log file"); } writeLog(logText); CentralLogStore.discardLines(job.getLogChannelId(), false); // loadAnnotationUI.setIsLoading(false); } catch (Exception e1) { loadAnnotationUI.setMessage("Error: " + e1.getLocalizedMessage()); loadAnnotationUI.setIsLoading(false); //this.write(e1.getMessage()); e1.printStackTrace(); } loadAnnotationUI.setIsLoading(false); } }; thread.start(); this.loadAnnotationUI.waitForThread(); WorkPart.updateSteps(); WorkPart.updateFiles(); }
From source file:org.etudes.util.HtmlHelper.java
/** * Remove any text that match the "comments from Word font definitions encoded into html by Tiny" from the data. * /* w ww . ja v a2 s .c om*/ * @param data * the html data. * @return The cleaned up data. */ public static String stripEncodedFontDefinitionComments(String data) { if (data == null) return data; // quick check for any hint of the pattern if (data.indexOf("<!-- /* Font Definitions */") == -1) return data; // Notes: DOTALL so the "." matches line terminators too, "*?" Reluctant quantifier so text between two different comments is not lost Pattern p = Pattern.compile("<!-- /\\* Font Definitions \\*/.*?-->", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); Matcher m = p.matcher(data); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); }
From source file:com.frostwire.search.youtube.jd.Request.java
public String getHtmlCode() throws CharacterCodingException { final String ct = this.httpConnection.getContentType(); /* check for image content type */ if (ct != null && Pattern.compile("images?/\\w*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(ct) .matches()) {//from ww w . ja v a2 s .c o m throw new IllegalStateException("Content-Type: " + ct); } if (this.htmlCode == null && this.byteArray != null) { /* use custom charset or charset from httpconnection */ String useCS = this.customCharset == null ? this.httpConnection.getCharset() : this.customCharset; if (useCS == null) { useCS = this.getCharsetFromMetaTags(); } try { try { try { if (useCS != null) { /* try to use wanted charset */ this.htmlCode = new String(this.byteArray, useCS.toUpperCase()); return this.htmlCode; } } catch (final Exception e) { } this.htmlCode = new String(this.byteArray, "ISO-8859-1"); return this.htmlCode; } catch (final Exception e) { //System.out.println("could neither charset: " + useCS + " nor default charset"); /* fallback to default charset in error case */ this.htmlCode = new String(this.byteArray); return this.htmlCode; } } catch (final Exception e) { /* in case of error we do not reset byteArray */ } } return this.htmlCode; }
From source file:de.stkl.gbgvertretungsplan.sync.SyncAdapter.java
private Map<String, String> parseGeneralData(Element root, int dataType) { Map<String, String> generalData = new HashMap<String, String>(); // last update time and day Element updateTime = root.select("table.mon_head td:eq(2) p").first(); if (updateTime != null) { Pattern pat = Pattern.compile("(Stand: [\\.:0-9 ]+)", Pattern.DOTALL); Matcher matcher = pat.matcher(updateTime.text()); if (matcher.find()) generalData.put(Sync.GENERAL_DATA_UPDATETIME, matcher.group(1)); }/* ww w. j a va2 s. co m*/ // date the substitution table belongs to Element belongingDate = root.select("div.mon_title").first(); if (belongingDate != null) generalData.put(Sync.GENERAL_DATA_DATE, belongingDate.text()); // daily information Elements dailyInfos = root.select("table.info tr"); int i = 0; for (Element info : dailyInfos) { Elements e = info.select("td"); if (e.size() == 0) continue; String title = "", description = ""; for (TextNode node : e.first().textNodes()) title += node.text() + '\n'; title = title.trim(); // description only if available if (e.size() > 1) { for (TextNode node : e.get(1).textNodes()) description += node.text() + '\n'; description = title.trim(); } String keyTitle = "", keyDescription = ""; switch (i) { case 0: keyTitle = Sync.GENERAL_DATA_DAILYINFO_1_TITLE; keyDescription = Sync.GENERAL_DATA_DAILYINFO_1_DESCRIPTION; break; case 1: keyTitle = Sync.GENERAL_DATA_DAILYINFO_2_TITLE; keyDescription = Sync.GENERAL_DATA_DAILYINFO_2_DESCRIPTION; break; case 2: keyTitle = Sync.GENERAL_DATA_DAILYINFO_3_TITLE; keyDescription = Sync.GENERAL_DATA_DAILYINFO_3_DESCRIPTION; break; default: break; } if (!keyTitle.equals("")) { generalData.put(keyTitle, title); generalData.put(keyDescription, description); } i++; } generalData.put(Sync.GENERAL_DATA_DATATYPE, String.valueOf(dataType)); return generalData; }
From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFRegExpInstr.java
@Override public Object evaluate(DeferredObject[] arguments) throws HiveException { IntWritable intWritable = new IntWritable(0); int position = 1; int occurrence = 1; int return_option = 0; String match_parameter = "c"; if (arguments[0].get() == null || arguments[1].get() == null) { return null; }// www. j av a2 s . c om str = (String) converters[0].convert(arguments[0].get()); substr = (String) converters[1].convert(arguments[1].get()); String strFromPosition = str; if (arguments.length > 2) { position = ((IntObjectInspector) argumentOIs[2]).get(arguments[2].get()); if (position > str.length() || position < 1) { LOG.warn("illegal start position"); return intWritable; } if (arguments.length > 3) { occurrence = ((IntObjectInspector) argumentOIs[3]).get(arguments[3].get()); if (occurrence > str.length() || occurrence < 0) { LOG.warn("illegal occurrence"); return intWritable; } } if (arguments.length > 4) { return_option = ((IntObjectInspector) argumentOIs[4]).get(arguments[4].get()); if ((return_option != 0) && (return_option != 1)) { LOG.warn("illegal occurrence"); return intWritable; } } if (arguments.length > 5) { match_parameter = ((StringObjectInspector) argumentOIs[5]) .getPrimitiveJavaObject(arguments[5].get()); match_parameter = match_parameter.toLowerCase(); char[] tmp_char = match_parameter.toCharArray(); String tmp_str = "icnmx"; for (int i = 0; i < match_parameter.length(); i++) { if (!tmp_str.contains(String.valueOf(tmp_char[i]))) { LOG.warn("illegal match_parameter"); return intWritable; } } match_parameter = String.valueOf(tmp_char[match_parameter.length() - 1]); } } try { if (match_parameter.compareToIgnoreCase("i") == 0) { p = Pattern.compile(substr.toString(), Pattern.CASE_INSENSITIVE); } else if (match_parameter.compareToIgnoreCase("c") == 0) { p = Pattern.compile(substr.toString()); } else if (match_parameter.compareToIgnoreCase("n") == 0) { p = Pattern.compile(substr.toString(), Pattern.DOTALL); } else if (match_parameter.compareToIgnoreCase("m") == 0) { p = Pattern.compile(substr.toString(), Pattern.MULTILINE); } else if (match_parameter.compareToIgnoreCase("x") == 0) { p = Pattern.compile(substr.toString(), Pattern.COMMENTS); } else { p = Pattern.compile(substr.toString()); } if (position > 1) { strFromPosition = str.substring(position - 1); } Matcher m = p.matcher(strFromPosition.toString()); for (int i = 0; i < occurrence; i++) { if (m.find()) { if (return_option == 0) { intWritable.set(m.start() + position); } else { intWritable.set(m.end() + position); } } else { LOG.info("m.find() = " + m.find()); intWritable.set(0); break; } } return intWritable; } catch (PatternSyntaxException e) { LOG.info("PatternSyntaxException"); return intWritable; } }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2lookReveng.java
public static AbstractDdlReveng.LineParseOutput substituteTablespace(String input) { Pattern compile = Pattern.compile("(\\s+IN\\s+)\"(\\w+)\"(\\s*)", Pattern.DOTALL); StringBuffer sb = new StringBuffer(input.length()); String addedToken = null;//from ww w . j av a2 s .c o m String addedValue = null; Matcher matcher = compile.matcher(input); if (matcher.find()) { addedToken = matcher.group(2) + "_token"; addedValue = matcher.group(2); matcher.appendReplacement(sb, matcher.group(1) + "\"\\${" + addedToken + "}\"" + matcher.group(3)); } matcher.appendTail(sb); return new AbstractDdlReveng.LineParseOutput(sb.toString()).withToken(addedToken, addedValue); }
From source file:org.squale.welcom.struts.webServer.WebEngine.java
/** * Suppresion des commentaires ///*from w w w . j av a 2 s . c o m*/ * * @param s chaine nettoyer * @return chaine nettoye */ private String smartReplaceAll(final String s) { Pattern pattern = Pattern.compile("(.)(//[^\\n\\\\]*)\\n", Pattern.DOTALL | Pattern.MULTILINE); Matcher matcher = pattern.matcher(s); StringBuffer sb = new StringBuffer(); boolean result = matcher.find(); while (result) { if (Util.isEquals(matcher.group(1), "\\")) { matcher.appendReplacement(sb, "\\" + matcher.group()); } else if (Util.isEquals(matcher.group(1), ":")) { matcher.appendReplacement(sb, matcher.group()); } else { matcher.appendReplacement(sb, matcher.group(1)); } result = matcher.find(); } matcher.appendTail(sb); // Recherche le ligne qui ont chapp au filtre et qui sont des commentaires pattern = Pattern.compile("^//[^\\n]*\\n", Pattern.DOTALL | Pattern.MULTILINE); matcher = pattern.matcher(sb.toString()); sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); } matcher.appendTail(sb); return sb.toString(); }
From source file:org.eclipse.che.selenium.editor.autocomplete.AutocompleteProposalJavaDocTest.java
private void verifyJavaDoc(String javaDocHtml, String regex) { assertTrue(Pattern.compile(regex, Pattern.DOTALL).matcher(javaDocHtml).matches(), String.format("Actual Java Doc HTML was '%s'.", javaDocHtml)); }
From source file:com.github.thorqin.webapi.mail.MailService.java
public static Mail createHtmlMailFromTemplate(String templatePath, Map<String, String> replaced) { Mail mail = new Mail(); try (InputStream in = MailService.class.getClassLoader().getResourceAsStream(templatePath)) { 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 w ww. j a v a2s.com*/ 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); } } catch (IOException ex) { logger.log(Level.SEVERE, "Create mail from template error: {0}, {1}", new Object[] { templatePath, ex }); } return mail; }
From source file:org.transdroid.search.hdbitsorg.HdBitsOrgAdapter.java
protected List<SearchResult> parseHtml(String html, int maxResults) throws Exception { Log.d(LOG_TAG, "Parsing search results."); List<SearchResult> results = new ArrayList<SearchResult>(); int matchCount = 0; int errorCount = 0; Pattern regex = Pattern.compile(SEARCH_REGEX, Pattern.DOTALL); Matcher match = regex.matcher(html); while (match.find() && matchCount < maxResults) { matchCount++;/*from ww w . j a v a 2 s. com*/ if (match.groupCount() != 11) { errorCount++; continue; } String detailsUrl = URL_PREFIX + match.group(1); String title = match.group(2); String torrentUrl = URL_PREFIX + match.group(3); String size = match.group(8) + match.group(9); // size + unit int seeders = Integer.parseInt(match.group(10)); int leechers = Integer.parseInt(match.group(11)); int time1 = Integer.parseInt(match.group(4)); String timeUnit1 = match.group(5); int time2 = Integer.parseInt(match.group(6)); String timeUnit2 = match.group(7); // hdbits.org lists "added date" in a relative format (i.e. 8 months 7 days ago) // we roughly calculate the number of MS elapsed then subtract that from "now" // could be a day or two off depending on month lengths, it's just imprecise data long elapsedTime = 0; if (timeUnit1.startsWith("month")) elapsedTime += time1 * 1000L * 60L * 60L * 24L * 30L; if (timeUnit1.startsWith("day")) elapsedTime += time1 * 1000L * 60L * 60L * 24L; if (timeUnit2.startsWith("day")) elapsedTime += time2 * 1000L * 60L * 60L * 24L; if (timeUnit2.startsWith("hour")) elapsedTime += time2 * 1000L * 60L * 60L; Date addedDate = new Date(); addedDate.setTime(addedDate.getTime() - elapsedTime); // build our search result SearchResult torrent = new SearchResult(title, torrentUrl, detailsUrl, size, addedDate, seeders, leechers); results.add(torrent); } Log.d(LOG_TAG, "Found " + matchCount + " matches and successfully parsed " + (matchCount - errorCount) + " of those matches."); return results; }