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:net.inbox.InboxMessage.java
/** * Starts GPG message work./*from w w w . ja v a 2 s . c o m*/ **/ private void gpg_crypto_start() { // Starting decryption and verification intent Intent gpg = new Intent(this, InboxGPG.class); Bundle b = new Bundle(); int request_code; if (msg_encrypted) { request_code = 92; // Extracting the encrypted part attachments = db.get_all_attachments_of_msg(current.get_id()); boolean pgp_content = false; for (Attachment a : attachments) { if (a.get_mime_type().toLowerCase().contains("pgp-encrypted")) { pgp_content = true; } else if (pgp_content) { msg_contents = current.get_contents_crypto(); if (msg_contents == null) { Pager.log += getString(R.string.err_missing_crypto_mime) + "\n\n"; Dialogs.toaster(false, getString(R.string.err_missing_crypto_mime), this); return; } int start_index = -1; int end_index = -1; Pattern p = Pattern.compile(".*(-----BEGIN PGP MESSAGE-----.*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(msg_contents); if (m.matches()) start_index = m.start(1); p = Pattern.compile(".*-----END PGP MESSAGE-----(.*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); m = p.matcher(msg_contents); if (m.matches()) end_index = m.start(1); if ((start_index > -1 && end_index > -1) && start_index < end_index) { msg_contents = msg_contents.substring(start_index, end_index); } else { Pager.log += getString(R.string.err_missing_crypto_mime) + "\n\n"; Dialogs.toaster(false, getString(R.string.err_missing_crypto_mime), this); return; } break; } } } else if (msg_signed) { request_code = 93; // Extracting the signed part String[] ct_bonds = Utils.content_type_boundary(current.get_content_type()); msg_contents = current.get_contents_crypto(); int split_index = msg_contents.indexOf(ct_bonds[1]); if (split_index != -1) { msg_contents = msg_contents.substring(split_index + ct_bonds[1].length()); // Twice to remove \r\n if (msg_contents.charAt(0) == '\r' || msg_contents.charAt(0) == '\n') { msg_contents = msg_contents.substring(1); } if (msg_contents.charAt(0) == '\r' || msg_contents.charAt(0) == '\n') { msg_contents = msg_contents.substring(1); } } split_index = msg_contents.indexOf(ct_bonds[1]); if (split_index != -1) { msg_contents = msg_contents.substring(0, split_index - 1).trim() + "\r\n"; } msg_signature = Utils.mime_part_section(current.get_contents_crypto(), "2", ct_bonds[1]); b.putString("signature", msg_signature);//get from pgp-mime part } else return; b.putString("message-data", msg_contents); b.putInt("request-code", request_code); gpg = gpg.putExtras(b); startActivityForResult(gpg, request_code, null); overridePendingTransition(R.anim.left_in, R.anim.left_out); }
From source file:net.inbox.InboxMessage.java
/** * MIME to message conversion after decryption. **///from www . j av a2s .c o m private void gpg_mime_parsing() { String c_type; if (msg_contents.length() > 500) { c_type = msg_contents.substring(0, 500); } else { c_type = msg_contents; } // Decrypted inner MIME Content-type & boundary String[] ct_bound = Utils.content_type_boundary(c_type); try { Pattern p = Pattern.compile(".*(" + ct_bound[1] + "(.*)" + ct_bound[1] + "--).*", Pattern.DOTALL); Matcher m = p.matcher(msg_contents); if (m.matches()) { msg_contents = m.group(1); current.set_contents_crypto(msg_contents); String m_type = ct_bound[0].trim(); // Structural parsing ArrayList<String[]> msg_structure = Utils.mime_bodystructure(msg_contents, ct_bound[1], m_type); ArrayList<String[]> msg_texts = new ArrayList<>(); Utils.mime_parse_full_msg_into_texts(current.get_contents_crypto(), msg_structure, msg_texts, current); msg_contents = ""; set_btn_texts(); // Inner attachments assignment attachments = new ArrayList<>(); if (msg_structure != null && msg_structure.size() > 0) { for (int ii = 0; ii < msg_structure.size(); ++ii) { // Mime part, i.e. - BODY[1], BODY[1.1], ... Attachment att = new Attachment(); att.set_pop_indx(msg_structure.get(ii)[0]); att.set_mime_type(msg_structure.get(ii)[1]); att.set_boundary(msg_structure.get(ii)[2]); att.set_name(msg_structure.get(ii)[3]); att.set_transfer_encoding(msg_structure.get(ii)[4]); att.set_size(-1); attachments.add(att); } } else { tv_page_attachments.setVisibility(View.GONE); } } else { Pager.log += getString(R.string.err_missing_crypto_mime) + "\n\n"; Dialogs.dialog_error_line(getString(R.string.err_missing_crypto_mime), this); } } catch (Exception e) { Pager.log += e.getMessage() + "\n\n"; Dialogs.dialog_exception(e, this); } }
From source file:org.wso2.connector.integration.test.base.ConnectorIntegrationTestBase.java
/** * This method de-serialize XML object graph. In addition if there are parameterized strings such as * <code>%s(accessToken)</code> in the XML file, those will be parsed and and replace with the values * specified in the Connection Properties resource file or the parameter map passed in to this method. <br> * <br>/* www. j a v a 2s . c om*/ * <b>Example XML file.</b><br> * * <pre> * {@code * <?xml version="1.0" encoding="UTF-8"?> * <java class="java.beans.XMLDecoder"> * <object class="test.base.Person"> * <void property="address"> * <object class="test.base.Address"> * <void property="city"> * <string>Test City</string> * </void> * <void property="country"> * <string>Test Country</string> * </void> * <void property="street"> * <string>Test street</string> * </void> * </object> * </void> * <void property="age"> * <int>20</int> * </void> * <void property="name"> * <string>Test Person Name</string> * </void> * </object> * </java> * } * </pre> * * @param filePath file name including path to the XML serialized file. * @param paramMap map containing key value pairs where key being the parameter specified in the XML file * if parameter in XML is <code>%s(accessToken)</code>, the key should be just * <code>accessToken</code>. * @return the de-serialized object, user can cast this to the object type specified in the XML. * @throws IOException if file path is null or empty as well as if there's any exception while reading the * XML file. */ protected Object loadObjectFromFile(String fileName, Map<String, String> paramMap) throws IOException { String filePath = pathToRequestsDirectory + fileName; if (filePath == null || filePath.isEmpty()) { throw new IOException("File path cannot be null or empty."); } Object retObj = null; BufferedInputStream bi = null; XMLDecoder decoder = null; try { bi = new BufferedInputStream(new FileInputStream(filePath)); byte[] buf = new byte[bi.available()]; bi.read(buf); String content = new String(buf); if (connectorProperties != null) { // We don't need to change the original connection properties in case same key is sent with // different value. Properties prop = (Properties) connectorProperties.clone(); if (paramMap != null) { prop.putAll(paramMap); } Matcher matcher = Pattern.compile("%s\\(([A-Za-z0-9]*)\\)", Pattern.DOTALL).matcher(content); while (matcher.find()) { String key = matcher.group(1); content = content.replaceAll("%s\\(" + key + "\\)", Matcher.quoteReplacement(prop.getProperty(key))); } } ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(Charset.defaultCharset())); decoder = new XMLDecoder(in); retObj = decoder.readObject(); } finally { if (bi != null) { bi.close(); } if (decoder != null) { decoder.close(); } } return retObj; }
From source file:org.mind.prebot.robot.PreBot.java
@Override public void onMessage(String channel, String sender, String login, String hostname, String message) { if (!this.getIgnoredList().contains(sender)) { String years_str = "", months_str = "", days_str = "", hours_str = "", minutes_str = "", seconds_str = ""; String[] tab = this.decryptData(message, true).trim().split(" "); if (tab.length > 0) { if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!pre") || tab[0].equalsIgnoreCase("!p"))) { if (tab.length > 1) { String names = ""; for (Integer i = 1; i < tab.length; i++) names += tab[i] + " "; Release release = this.getMySQLManager().pre(names.trim()); if (release.getResults().equals(0)) this.sendMessage(channel, this.encryptData("Nothing found for your search: " + names.trim())); else { if (release.getResults() > 1) this.sendMessage(channel, this.encryptData(Colors.TEAL + "[ " + Colors.RED + release.getResults() + " results found! " + Colors.TEAL + "]")); else this.sendMessage(channel, this.encryptData(Colors.TEAL + "[ " + Colors.RED + release.getResults() + " result found! " + Colors.TEAL + "]")); Integer years = release.getDiffDate() / 31536000; Integer yearsMod = release.getDiffDate() % 31536000; if (years == 1) years_str = years + " year "; else if (years > 1) years_str = years + " years "; Integer months = yearsMod / 2592000; Integer monthsMod = yearsMod % 2592000; if (months == 1) months_str = months + " month "; else if (months > 1) months_str = months + " months "; Integer days = monthsMod / 86400; Integer daysMod = monthsMod % 86400; if (days == 1) days_str = days + " day "; else if (days > 1) days_str = days + " days "; Integer hours = daysMod / 3600; Integer hoursMod = daysMod % 3600; if (hours == 1) hours_str = hours + " hour "; else if (hours > 1) hours_str = hours + " hours "; Integer minutes = hoursMod / 60; if (minutes == 1) minutes_str = minutes + " minute "; else if (minutes > 1) minutes_str = minutes + " minutes "; Integer seconds = hoursMod % 60; if (seconds == 1) seconds_str = seconds + " second "; else seconds_str = seconds + " seconds "; if (release.getChecked().equals("1") || release.getNuked().equals("0")) this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.YELLOW + " PRED " + Colors.TEAL + "][ " + Utils.getCategoryCode(release.getCategory()) + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]" + (release.getChecked().equals("1") ? "" : "[ " + Colors.RED + "UNCHECKED" + Colors.TEAL + " ]"))); else this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL + "][ " + Utils.getCategoryCode(release.getCategory()) + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ " + Colors.RED + release.getReason() + Colors.TEAL + " ][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]")); }/* www .j av a2s . c o m*/ } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!dupenuke") || tab[0].equalsIgnoreCase("!dnu"))) { String names = ""; String limit = "10"; for (Integer i = 1; i < tab.length; i++) { if (tab[i].contains("limit")) limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length()); else names += tab[i] + " "; } LinkedList<Release> releases = null; if (tab.length > 1) releases = this.getMySQLManager().dupenuke(names.trim(), limit); else releases = this.getMySQLManager().dupenuke("", limit); if (releases.isEmpty()) this.sendMessage(channel, this.encryptData( "Nothing found for your search: " + (tab.length > 1 ? names.trim() : ""))); else { if (releases.get(0).getResults() > 1) this.sendMessage(channel, this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.RED + " nuked " + Colors.LIGHT_GRAY + "results.")); else this.sendMessage(channel, this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.RED + " nuked " + Colors.LIGHT_GRAY + "results")); for (Release release : releases) { Integer years = release.getDiffDate() / 31536000; Integer yearsMod = release.getDiffDate() % 31536000; if (years == 1) years_str = years + " year "; else if (years > 1) years_str = years + " years "; Integer months = yearsMod / 2592000; Integer monthsMod = yearsMod % 2592000; if (months == 1) months_str = months + " month "; else if (months > 1) months_str = months + " months "; Integer days = monthsMod / 86400; Integer daysMod = monthsMod % 86400; if (days == 1) days_str = days + " day "; else if (days > 1) days_str = days + " days "; Integer hours = daysMod / 3600; Integer hoursMod = daysMod % 3600; if (hours == 1) hours_str = hours + " hour "; else if (hours > 1) hours_str = hours + " hours "; Integer minutes = hoursMod / 60; if (minutes == 1) minutes_str = minutes + " minute "; else if (minutes > 1) minutes_str = minutes + " minutes "; Integer seconds = hoursMod % 60; if (seconds == 1) seconds_str = seconds + " second "; else seconds_str = seconds + " seconds "; this.sendMessage(sender, this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL + "][ " + Utils.getCategoryCode(release.getCategory()) + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ " + Colors.RED + release.getReason() + Colors.TEAL + " ][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]")); } } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!dupe") || tab[0].equalsIgnoreCase("!d"))) { String names = ""; String limit = "10"; for (Integer i = 1; i < tab.length; i++) { if (tab[i].contains("limit")) limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length()); else names += tab[i] + " "; } LinkedList<Release> releases = null; if (tab.length > 1) releases = this.getMySQLManager().dupe(names.trim(), limit); else releases = this.getMySQLManager().dupe("", limit); if (releases.isEmpty()) this.sendMessage(channel, this.encryptData( "Nothing found for your search: " + (tab.length > 1 ? names.trim() : ""))); else { if (releases.get(0).getResults() > 1) this.sendMessage(channel, this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.LIGHT_GRAY + " results.")); else this.sendMessage(channel, this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.LIGHT_GRAY + " result.")); for (Release release : releases) { Integer years = release.getDiffDate() / 31536000; Integer yearsMod = release.getDiffDate() % 31536000; if (years == 1) years_str = years + " year "; else if (years > 1) years_str = years + " years "; Integer months = yearsMod / 2592000; Integer monthsMod = yearsMod % 2592000; if (months == 1) months_str = months + " month "; else if (months > 1) months_str = months + " months "; Integer days = monthsMod / 86400; Integer daysMod = monthsMod % 86400; if (days == 1) days_str = days + " day "; else if (days > 1) days_str = days + " days "; Integer hours = daysMod / 3600; Integer hoursMod = daysMod % 3600; if (hours == 1) hours_str = hours + " hour "; else if (hours > 1) hours_str = hours + " hours "; Integer minutes = hoursMod / 60; if (minutes == 1) minutes_str = minutes + " minute "; else if (minutes > 1) minutes_str = minutes + " minutes "; Integer seconds = hoursMod % 60; if (seconds == 1) seconds_str = seconds + " second "; else seconds_str = seconds + " seconds "; if (release.getChecked().equals("1") || release.getNuked().equals("0")) this.sendMessage(sender, this.encryptData(Colors.TEAL + "[" + Colors.YELLOW + " PRED " + Colors.TEAL + "][ " + Utils.getCategoryCode(release.getCategory()) + release.getCategory() + Colors.TEAL + "][ " + Colors.LIGHT_GRAY + release.getName() + Colors.TEAL + "][ " + Colors.LIGHT_GRAY + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]" + (release.getChecked().equals("1") ? "" : "[ " + Colors.RED + "UNCHECKED" + Colors.TEAL + " ]"))); else this.sendMessage(sender, this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL + "][ " + Utils.getCategoryCode(release.getCategory()) + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ " + Colors.RED + release.getReason() + Colors.TEAL + " ][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]")); } } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!nuke") || tab[0].equalsIgnoreCase("!nk"))) { if (this.getNukerList().contains(sender)) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; if (tab.length > 2) { Integer ret = this.getMySQLManager().nuke(tab[1], names.trim()); if (ret > 0) this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has been successfully " + Colors.RED + "nuked" + Colors.LIGHT_GRAY + "!")); else this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has not been successfully " + Colors.RED + "nuked" + Colors.LIGHT_GRAY + "!")); } } else this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this.")); } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!unnuke") || tab[0].equalsIgnoreCase("!un"))) { if (this.getNukerList().contains(sender)) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; if (tab.length > 2) { Integer ret = this.getMySQLManager().unnuke(tab[1], names.trim()); if (ret > 0) this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has been successfully " + Colors.DARK_GREEN + "unnuked" + Colors.LIGHT_GRAY + "!")); else this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has not been successfully " + Colors.DARK_GREEN + "unnuked" + Colors.LIGHT_GRAY + "!")); } } else this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this.")); } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!addpre") || tab[0].equalsIgnoreCase("!ap"))) { if (this.getNukerList().contains(sender)) { String names = ""; for (Integer i = 3; i < tab.length; i++) names += tab[i] + " "; if (tab.length > 3) { Integer ret = this.getMySQLManager().addpre(tab[1], tab[2], names.trim()); if (ret > 0) this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has been successfully " + Colors.DARK_GREEN + "addpred" + Colors.LIGHT_GRAY + "!")); else this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has not been successfully " + Colors.DARK_GREEN + "addpred" + Colors.LIGHT_GRAY + "!")); } } else this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this.")); } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!delpre") || tab[0].equalsIgnoreCase("!dp"))) { if (this.getNukerList().contains(sender)) { if (tab.length > 1) { Integer ret = this.getMySQLManager().delpre(tab[1]); if (ret > 0) this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has been successfully " + Colors.DARK_GREEN + "delpred" + Colors.LIGHT_GRAY + "!")); else this.sendMessage(channel, this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY + " has not been successfully " + Colors.DARK_GREEN + "delpred" + Colors.LIGHT_GRAY + "!")); } } else this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this.")); } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel()) && tab[0].equalsIgnoreCase("!vdm")) { List<String> vdms = Utils.getMatcher(Utils.VDMRegex, Utils.getCode(Utils.VDMFeed), Pattern.MULTILINE); if (!vdms.isEmpty()) { String vdm = vdms.get(new Random().nextInt(vdms.size())); vdm = StringEscapeUtils.unescapeHtml4(vdm); vdm = vdm.substring(30).replaceAll("[\r\n]+", "").replaceAll(" {2,}", " ").trim(); this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.BROWN + " VDM " + Colors.TEAL + "] :: [ " + Colors.DARK_GREEN + vdm + Colors.TEAL + " ]")); } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel()) && tab[0].equalsIgnoreCase("!cnf")) { List<String> cnfs = Utils.getMatcher(Utils.CNFRegex, Utils.getCode(Utils.CNFPage), Pattern.MULTILINE); if (!cnfs.isEmpty()) { String cnf = cnfs.get(new Random().nextInt(cnfs.size())); cnf = StringEscapeUtils.unescapeHtml4(cnf); cnf = cnf.substring(cnf.indexOf(">") + 1, cnf.indexOf("</div>")).replaceAll("[\r\n]+", "") .replaceAll(" {2,}", " ").trim(); this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.RED + " CNF " + Colors.TEAL + "] :: [ " + Colors.DARK_GREEN + cnf + Colors.TEAL + " ]")); } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel()) && (tab[0].equalsIgnoreCase("!slap") || tab[0].equalsIgnoreCase("!s"))) { if (this.getSlaps() < this.getSlapsRandom()) this.setSlaps(this.getSlaps() + 1); else { this.kick(channel, sender, this.encryptData("Sorry, you loose this time ^^")); this.setSlaps(0); this.setSlapsRandom(new Random().nextInt(26)); } } else if (tab[0].equalsIgnoreCase("!kick") || tab[0].equalsIgnoreCase("!k")) { if (sender.equals("BaYbEE")) { if (tab.length > 2) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; this.kick(channel, tab[1], this.encryptData(names.trim())); } else this.kick(channel, tab[1]); } } else if (tab[0].equalsIgnoreCase("!ban") || tab[0].equalsIgnoreCase("!b")) { if (sender.equals("BaYbEE")) { if (tab.length > 1) this.ban(channel, tab[1]); } } else if (tab[0].equalsIgnoreCase("!mode") || tab[0].equalsIgnoreCase("!m")) { if (sender.equals("BaYbEE")) { if (tab.length > 2) this.setMode(channel, tab[1] + " " + tab[2]); } } else if (tab[0].equalsIgnoreCase("!message") || tab[0].equalsIgnoreCase("!msg")) { if (sender.equals("BaYbEE")) { if (tab.length > 2) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; this.sendMessage(tab[1], this.encryptData(names.trim())); } } } else if (tab[0].equalsIgnoreCase("!action") || tab[0].equalsIgnoreCase("!a")) { if (sender.equals("BaYbEE")) { if (tab.length > 2) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; this.sendAction(tab[1], this.encryptData(names.trim())); } } } else if (tab[0].equalsIgnoreCase("!notice") || tab[0].equalsIgnoreCase("!n")) { if (sender.equals("BaYbEE")) { if (tab.length > 2) { String names = ""; for (Integer i = 2; i < tab.length; i++) names += tab[i] + " "; this.sendNotice(tab[1], this.encryptData(names.trim())); } } } else if (tab[0].equalsIgnoreCase("!ignore") || tab[0].equalsIgnoreCase("!i")) { if (sender.equals("BaYbEE")) { if (tab.length > 1) { if (!this.getIgnoredList().contains(tab[1])) this.getIgnoredList().add(tab[1]); } } } else if (tab[0].equalsIgnoreCase("!unignore") || tab[0].equalsIgnoreCase("!ui")) { if (sender.equals("BaYbEE")) { if (tab.length > 1) { if (this.getIgnoredList().contains(tab[1])) this.getIgnoredList().remove(tab[1]); } } } else if (tab[0].equalsIgnoreCase("!addnuker") || tab[0].equalsIgnoreCase("!an")) { if (sender.equals("BaYbEE")) { if (tab.length > 1) { if (!this.getNukerList().contains(tab[1])) this.getNukerList().add(tab[1]); } } } else if (tab[0].equalsIgnoreCase("!delnuker") || tab[0].equalsIgnoreCase("!dn")) { if (sender.equals("BaYbEE")) { if (tab.length > 1) { if (this.getNukerList().contains(tab[1])) this.getNukerList().remove(tab[1]); } } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!showrequest") || tab[0].equalsIgnoreCase("!sr"))) { if (tab.length > 1) { String names = ""; for (Integer i = 1; i < tab.length; i++) names += tab[i] + " "; Request request = this.getMySQLManager().showrequest(names.trim()); if (request.getResults().equals(0)) this.sendMessage(channel, this.encryptData("Nothing found for your search: " + names.trim())); else { if (request.getResults() > 1) this.sendMessage(channel, this.encryptData( "\00310[\00304 " + request.getResults() + " results found! \00310]")); else this.sendMessage(channel, this.encryptData( "\00310[\00304 " + request.getResults() + " result found! \00310]")); Integer years = request.getDiffDate() / 31536000; Integer yearsMod = request.getDiffDate() % 31536000; if (years == 1) years_str = years + " year "; else if (years > 1) years_str = years + " years "; Integer months = yearsMod / 2592000; Integer monthsMod = yearsMod % 2592000; if (months == 1) months_str = months + " month "; else if (months > 1) months_str = months + " months "; Integer days = monthsMod / 86400; Integer daysMod = monthsMod % 86400; if (days == 1) days_str = days + " day "; else if (days > 1) days_str = days + " days "; Integer hours = daysMod / 3600; Integer hoursMod = daysMod % 3600; if (hours == 1) hours_str = hours + " hour "; else if (hours > 1) hours_str = hours + " hours "; Integer minutes = hoursMod / 60; if (minutes == 1) minutes_str = minutes + " minute "; else if (minutes > 1) minutes_str = minutes + " minutes "; Integer seconds = hoursMod % 60; if (seconds == 1) seconds_str = seconds + " second "; else seconds_str = seconds + " seconds "; if (request.getFilled()) this.sendMessage(channel, this.encryptData("\00310[\00308 REQ \00310] [\00315 " + request.getRequest() + " \00310] [\00315 " + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + (request.getRequestDate()) + ") \00310] [ \00307Requested by: \00315" + request.getRequestBy() + " \00310] [ \00307Filled by: \00315" + request.getFilledBy() + " \00310]")); else this.sendMessage(channel, this.encryptData("\00310[\00308 REQ \00310] [\00315 " + request.getRequest() + " \00310] [\00315 " + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315" + request.getRequestBy() + " \00310]")); } } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!addrequest") || tab[0].equalsIgnoreCase("!ar"))) { String names = ""; for (Integer i = 1; i < tab.length; i++) names += tab[i] + " "; if (tab.length > 1) { Request request = new Request(); request.setRequest(names.trim()); request.setRequestBy(sender); request.setRequestDate(null); request.setFilled(false); request.setFilledBy(""); Integer ret = this.getMySQLManager().addrequest(request); if (ret > 0) this.sendMessage(channel, this.encryptData("\00307" + names.trim() + "\00315 has been successfully \00304requested\00315!")); else this.sendMessage(channel, this.encryptData("\00307" + names.trim() + "\00315 has not been successfully \00304requested\00315!")); } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!fillrequest") || tab[0].equalsIgnoreCase("!fr"))) { String names = ""; for (Integer i = 1; i < tab.length; i++) names += tab[i] + " "; if (tab.length > 1) { Integer ret = this.getMySQLManager().fillrequest(names.trim(), sender); if (ret > 0) this.sendMessage(channel, this.encryptData( "\00307" + names.trim() + "\00315 has been successfully \00304filled\00315!")); else this.sendMessage(channel, this.encryptData("\00307" + names.trim() + "\00315 has not been successfully \0030filled\00315!")); } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!duperequest") || tab[0].equalsIgnoreCase("!dr"))) { String names = ""; String limit = "10"; for (Integer i = 1; i < tab.length; i++) { if (tab[i].contains("limit")) limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length()); else names += tab[i] + " "; } LinkedList<Request> requests = null; if (tab.length > 1) requests = this.getMySQLManager().duperequest(names.trim(), limit); else requests = this.getMySQLManager().duperequest("", limit); if (requests.isEmpty()) this.sendMessage(channel, this.encryptData( "Nothing found for your search: " + (tab.length > 1 ? names.trim() : ""))); else { if (requests.get(0).getResults() > 1) this.sendMessage(channel, this.encryptData("Sending \00307" + sender + "\00315 last \00307" + requests.get(0).getResults() + "\00315 results.")); else this.sendMessage(channel, this.encryptData("Sending \00307" + sender + "\00315 last \00307" + requests.get(0).getResults() + "\00315 result.")); for (Request request : requests) { Integer years = request.getDiffDate() / 31536000; Integer yearsMod = request.getDiffDate() % 31536000; if (years == 1) years_str = years + " year "; else if (years > 1) years_str = years + " years "; Integer months = yearsMod / 2592000; Integer monthsMod = yearsMod % 2592000; if (months == 1) months_str = months + " month "; else if (months > 1) months_str = months + " months "; Integer days = monthsMod / 86400; Integer daysMod = monthsMod % 86400; if (days == 1) days_str = days + " day "; else if (days > 1) days_str = days + " days "; Integer hours = daysMod / 3600; Integer hoursMod = daysMod % 3600; if (hours == 1) hours_str = hours + " hour "; else if (hours > 1) hours_str = hours + " hours "; Integer minutes = hoursMod / 60; if (minutes == 1) minutes_str = minutes + " minute "; else if (minutes > 1) minutes_str = minutes + " minutes "; Integer seconds = hoursMod % 60; if (seconds == 1) seconds_str = seconds + " second "; else seconds_str = seconds + " seconds "; if (request.getFilled()) this.sendMessage(sender, this.encryptData("\00310[\00308 REQ \00310] [\00315 " + request.getRequest() + " \00310] [\00315 " + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315" + request.getRequestBy() + " \00310] [ \00307Filled by: \00315" + request.getFilledBy() + " \00310]")); else this.sendMessage(sender, this.encryptData("\00310[\00308 REQ \00310] [\00315 " + request.getRequest() + " \00310] [\00315 " + years_str + months_str + days_str + hours_str + minutes_str + seconds_str + "ago (" + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315" + request.getRequestBy() + " \00310]")); } } } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel()) && (tab[0].equalsIgnoreCase("!group") || tab[0].equalsIgnoreCase("!g"))) { Group group = this.getMySQLManager().group(); this.sendMessage(channel, this.encryptData(Colors.DARK_GRAY + "Total Releases: " + Colors.GREEN + group.getTotalReleases() + Colors.DARK_GRAY + " Total Nuked: " + Colors.RED + group.getTotalNukes() + Colors.DARK_GRAY + " Total Unuked: " + Colors.OLIVE + group.getTotalUnnukes())); this.sendMessage(channel, this.encryptData(Colors.DARK_GRAY + "First Pre: " + Colors.LIGHT_GRAY + "[" + Utils.getCategoryCode(group.getCategoryFirstPre()) + group.getCategoryFirstPre() + Colors.LIGHT_GRAY + "] " + group.getFirstPre() + " [" + group.getDateFirstPre() + "]")); this.sendMessage(channel, this.encryptData(Colors.DARK_GRAY + "Last Pre: " + Colors.LIGHT_GRAY + "[" + Utils.getCategoryCode(group.getCategoryLastPre()) + group.getCategoryLastPre() + Colors.LIGHT_GRAY + "] " + group.getLastPre() + " [" + group.getDateLastPre() + "]")); } else { for (String t : tab) { if (!Utils.getMatcher(Utils.URLRegex, t, Pattern.DOTALL).isEmpty()) { String title = Utils.getTitleMatcher(Utils.getCode(t)); if (title != null) { title = StringEscapeUtils.unescapeHtml4(title); title = title.substring(7, title.length() - 8).replaceAll("[\r\n]+", "") .replaceAll(" {2,}", " ").trim(); this.sendMessage(channel, this.encryptData("\00310[\00303 Title:\00307 " + title + " \00310]")); } } } } } } }
From source file:com.amazonaws.a2s.AmazonA2SClient.java
/** * Checks for presense of the Errors in the response * If errors found, constructs and throws AmazonA2SException * with information from the Errors//w ww . ja va2s . c o m * */ private void throwIfErrors(String responseString, int status) throws AmazonA2SException { Pattern errorPattern = Pattern.compile( ".*\\<RequestId>(.*)\\</RequestId>.*" + "(\\<Error>\\<Code>(.*)\\</Code>\\<Message>(.*)\\</Message>\\</Error>).*(\\<Error>)?.*", Pattern.MULTILINE | Pattern.DOTALL); Matcher errorMatcher = errorPattern.matcher(responseString); if (errorMatcher.matches()) { String requestId = errorMatcher.group(1); String xml = errorMatcher.group(2); String code = errorMatcher.group(3); String message = errorMatcher.group(4); AmazonA2SException exception = new AmazonA2SException(message, status, code, requestId, xml); log.debug("Error found in the response: " + "Error code: " + code + "; " + "Error message: " + message + "; " + "Response XML: " + xml + "; " + "Request ID : " + requestId + "; "); throw exception; } }
From source file:com.liferay.blade.cli.CreateCommandTest.java
private void contains(String content, String pattern) throws Exception { assertTrue(Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL).matcher(content).matches()); }
From source file:com.liferay.blade.cli.CreateCommandTest.java
private void lacks(File file, String pattern) throws Exception { String content = new String(IO.read(file)); assertFalse(Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL).matcher(content).matches()); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Processes /me command in group chats. * * @param chatMessage the chat message//from ww w. j a va 2 s .c o m * @return the newly processed message string */ public String processMeCommand(ChatMessage chatMessage) { String contentType = chatMessage.getContentType(); String message = chatMessage.getMessage(); if (message.length() <= 4 || !message.startsWith("/me ")) { return ""; } String msgID = ChatHtmlUtils.MESSAGE_TEXT_ID + chatMessage.getMessageUID(); String chatString = "<DIV ID='" + msgID + "'><B><I>"; String endHeaderTag = "</I></B></DIV>"; chatString += GuiUtils.escapeHTMLChars("*** " + chatMessage.getContactName() + " " + message.substring(4)) + endHeaderTag; Map<String, ReplacementService> listSources = GuiActivator.getReplacementSources(); for (ReplacementService source : listSources.values()) { boolean isSmiley = source instanceof SmiliesReplacementService; if (!isSmiley) { continue; } String sourcePattern = source.getPattern(); Pattern p = Pattern.compile(sourcePattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(chatString); chatString = m.replaceAll(ChatHtmlUtils.HTML_CONTENT_TYPE.equalsIgnoreCase(contentType) ? "$0" : StringEscapeUtils.escapeHtml4("$0")); } return chatString; }
From source file:com.liferay.blade.cli.command.CreateCommandTest.java
private void _contains(String content, String regex) throws Exception { Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL); Matcher matcher = pattern.matcher(content); Assert.assertTrue(matcher.matches()); }
From source file:com.liferay.blade.cli.command.CreateCommandTest.java
private void _lacks(File file, String regex) throws Exception { String content = FileUtil.read(file); Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL); Matcher matcher = pattern.matcher(content); Assert.assertFalse(matcher.matches()); }