aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-16 12:10:32 +0300
committerGravatar Vitaly Takmazov2016-11-16 16:21:43 +0300
commitb11a395c46aa92179a4a6019d2ebef15877b3946 (patch)
tree7ab510a4d8a134c17e80795b76b7e153e74b4536
parent96dc5157a2a0979dbe2511366cb3bec6d16c4e7e (diff)
formatMessage moved to core, remove copy-paste from juick-rss
-rw-r--r--juick-core/src/main/java/com/juick/util/MessageUtils.java119
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java3
-rw-r--r--juick-rss/src/main/java/com/juick/rss/Main.java80
-rw-r--r--juick-www/src/main/java/com/juick/www/PM.java3
-rw-r--r--juick-www/src/main/java/com/juick/www/PageTemplates.java5
-rw-r--r--juick-www/src/main/java/com/juick/www/RSS.java3
-rw-r--r--juick-www/src/main/java/com/juick/www/UserThread.java9
-rw-r--r--juick-www/src/main/java/com/juick/www/Utils.java92
-rw-r--r--server-core/src/main/java/com/juick/util/MessageUtils.java24
9 files changed, 137 insertions, 201 deletions
diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java
new file mode 100644
index 00000000..12ae71c1
--- /dev/null
+++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java
@@ -0,0 +1,119 @@
+package com.juick.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created by aalexeev on 11/13/16.
+ */
+public class MessageUtils {
+ private MessageUtils() {
+ throw new IllegalStateException();
+ }
+
+ public static String formatQuote(final String quote) {
+ String result = quote;
+
+ if (quote != null) {
+ if (quote.length() > 50) {
+ result = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n";
+ } else if (!quote.isEmpty()) {
+ result = ">" + quote.replace('\n', ' ') + "\n";
+ }
+ }
+
+ return result;
+ }
+ private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!&gt;))*)([\\]\\}]|&gt;)");
+
+ public static String formatMessageCode(String msg) {
+ msg = msg.replaceAll("&", "&amp;");
+ msg = msg.replaceAll("<", "&lt;");
+ msg = msg.replaceAll(">", "&gt;");
+
+ // http://juick.com/last?page=2
+ // <a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$2</a>");
+
+ // (http://juick.com/last?page=2)
+ // (<a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>)
+ Matcher m = regexLinks2.matcher(msg);
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", "");
+ m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">" + url + "</a>$5");
+ }
+ m.appendTail(sb);
+ msg = sb.toString();
+
+ return "<pre>" + msg + "</pre>";
+ }
+ public static String formatMessage(String msg) {
+ msg = msg.replaceAll("&", "&amp;");
+ msg = msg.replaceAll("<", "&lt;");
+ msg = msg.replaceAll(">", "&gt;");
+
+ // --
+ // &mdash;
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
+
+ // http://juick.com/last?page=2
+ // <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$3</a>");
+
+ // [link text][http://juick.com/last?page=2]
+ // <a href="http://juick.com/last?page=2" rel="nofollow">link text</a>
+ msg = msg.replaceAll("\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]", "<a href=\"$2\" rel=\"nofollow\">$1</a>");
+ msg = msg.replaceAll("\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)", "<a href=\"$2\" rel=\"nofollow\">$1</a>");
+
+ // #12345
+ // <a href="http://juick.com/12345">#12345</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://juick.com/$2\">#$2</a>$3");
+
+ // #12345/65
+ // <a href="http://juick.com/12345#65">#12345/65</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2#$3\">#$2/$3</a>$4");
+
+ // *bold*
+ // <b>bold</b>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<b>$2</b>$3");
+
+ // /italic/
+ // <i>italic</i>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<i>$2</i>$3");
+
+ // _underline_
+ // <span class="u">underline</span>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<span class=\"u\">$2</span>$3");
+
+ // /12
+ // <a href="#12">/12</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"#$2\">/$2</a>$3");
+
+ // @username@jabber.org
+ // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
+
+ // @username
+ // <a href="http://juick.com/username/">@username</a>
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
+
+ // (http://juick.com/last?page=2)
+ // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>)
+ Matcher m = regexLinks2.matcher(msg);
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", "");
+ m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5");
+ }
+ m.appendTail(sb);
+ msg = sb.toString();
+
+ // > citate
+ msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))&gt; *(.*)?(\\n|(?=\\Z))", "<q>$1</q>");
+ msg = msg.replaceAll("</q><q>", "\n");
+
+ msg = msg.replaceAll("\n", "<br/>\n");
+ return msg;
+ }
+}
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index 5b51c65d..21e85c37 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -18,9 +18,7 @@
package com.juick.components;
import com.google.android.gcm.server.*;
-import com.google.android.gcm.server.Message;
import com.juick.json.MessageSerializer;
-import com.juick.util.ThreadHelper;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.apache.commons.lang3.StringEscapeUtils;
@@ -40,7 +38,6 @@ import org.apache.http.util.TextUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.env.Environment;
diff --git a/juick-rss/src/main/java/com/juick/rss/Main.java b/juick-rss/src/main/java/com/juick/rss/Main.java
index bf8348fb..029057e3 100644
--- a/juick-rss/src/main/java/com/juick/rss/Main.java
+++ b/juick-rss/src/main/java/com/juick/rss/Main.java
@@ -20,7 +20,9 @@ package com.juick.rss;
import com.juick.Message;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
+import com.juick.util.MessageUtils;
import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -35,8 +37,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* @author ugnich
@@ -136,14 +136,14 @@ public class Main extends HttpServlet {
}
}
out.println("]]></title>");
- out.println("<description><![CDATA[" + formatMessage(msg.getText()) + "]]></description>");
+ out.println("<description><![CDATA[" + MessageUtils.formatMessage(msg.getText()) + "]]></description>");
out.println("<pubDate>" + sdfRSS.format(msg.getDate()) + "</pubDate>");
out.println("<comments>http://juick.com/" + msg.getUser().getName() + "/" + msg.getMid() + "</comments>");
if (!msg.getTags().isEmpty()) {
for (int n = 0; n < msg.getTags().size(); n++) {
- out.println("<category>" + escapeHtml(msg.getTags().get(n).getName()) + "</category>");
+ out.println("<category>" + StringEscapeUtils.escapeHtml4(msg.getTags().get(n).getName()) + "</category>");
}
}
if (msg.AttachmentType != null) {
@@ -201,14 +201,14 @@ public class Main extends HttpServlet {
reply.pubDate = rs.getTimestamp(6);
reply.attachmentType = rs.getString(7);
return reply;
- }, -hours).stream().forEach(r -> {
+ }, -hours).forEach(r -> {
out.println("<item>");
out.println("<ya:post>http://juick.com/" + r.muname + "/" + r.mid + "</ya:post>");
out.println("<link>http://juick.com/" + r.muname + "/" + r.mid + "#" + r.rid + "</link>");
out.println("<guid>http://juick.com/" + r.muname + "/" + r.mid + "#" + r.rid + "</guid>");
out.println("<author>http://juick.com/" + r.uname + "/</author>");
out.println("<title>@" + r.uname + ":</title>");
- out.println("<description><![CDATA[" + formatMessage(r.description) + "]]></description>");
+ out.println("<description><![CDATA[" + MessageUtils.formatMessage(r.description) + "]]></description>");
out.println("<pubDate>" + sdfRSS.format(r.pubDate) + "</pubDate>");
String attachment = r.attachmentType;
if (attachment != null && !attachment.isEmpty()) {
@@ -230,72 +230,4 @@ public class Main extends HttpServlet {
return sql.queryForList("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())",
Integer.class, -hours);
}
-
- private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!&gt;))*)([\\]\\}]|&gt;)");
-
- public static String escapeHtml(String input) {
- return input.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
- }
-
- public static String formatMessage(String msg) {
- msg = escapeHtml(msg);
-
- // --
- // &mdash;
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
-
- // http://juick.com/last?page=2
- // <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$3</a>");
-
- // #12345
- // <a href="http://juick.com/12345">#12345</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://juick.com/$2\">#$2</a>$3");
-
- // #12345/65
- // <a href="http://juick.com/12345#65">#12345/65</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2#$3\">#$2/$3</a>$4");
-
- // *bold*
- // <b>bold</b>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<b>$2</b>$3");
-
- // /italic/
- // <i>italic</i>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<i>$2</i>$3");
-
- // _underline_
- // <span class="u">underline</span>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<span class=\"u\">$2</span>$3");
-
- // /12
- // <a href="#12">/12</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"#$2\">/$2</a>$3");
-
- // @username@jabber.org
- // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
-
- // @username
- // <a href="http://juick.com/username/">@username</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
-
- // (http://juick.com/last?page=2)
- // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>)
- Matcher m = regexLinks2.matcher(msg);
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", "");
- m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5");
- }
- m.appendTail(sb);
- msg = sb.toString();
-
- // > citate
- msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))&gt; *(.*)?(\\n|(?=\\Z))", "<blockquote>$1</blockquote>");
- msg = msg.replaceAll("</blockquote><blockquote>", "\n");
-
- msg = msg.replaceAll("\n", "<br/>\n");
- return msg;
- }
}
diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java
index 95e2623a..79128e3d 100644
--- a/juick-www/src/main/java/com/juick/www/PM.java
+++ b/juick-www/src/main/java/com/juick/www/PM.java
@@ -20,6 +20,7 @@ package com.juick.www;
import com.juick.server.PMQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import com.juick.util.MessageUtils;
import com.juick.util.UserUtils;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
@@ -50,7 +51,7 @@ public class PM {
String title = "PM: Inbox";
List<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.getUid());
- msgs.forEach(m -> m.setText(Utils.formatMessage(m.getText())));
+ msgs.forEach(m -> m.setText(MessageUtils.formatMessage(m.getText())));
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
PebbleTemplate template = Utils.getEngine().getTemplate("views/pm_inbox.html");
diff --git a/juick-www/src/main/java/com/juick/www/PageTemplates.java b/juick-www/src/main/java/com/juick/www/PageTemplates.java
index 4f7e17b7..f0974e69 100644
--- a/juick-www/src/main/java/com/juick/www/PageTemplates.java
+++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java
@@ -22,6 +22,7 @@ import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -315,9 +316,9 @@ public class PageTemplates {
String txt;
if (msg.getTags().stream().anyMatch(t -> t.getName().equals("code"))) {
- txt = Utils.formatMessageCode(msg.getText());
+ txt = MessageUtils.formatMessageCode(msg.getText());
} else {
- txt = Utils.formatMessage(msg.getText());
+ txt = MessageUtils.formatMessage(msg.getText());
}
out.println("<article data-mid=\"" + msg.getMid() + "\">");
diff --git a/juick-www/src/main/java/com/juick/www/RSS.java b/juick-www/src/main/java/com/juick/www/RSS.java
index f27ea539..5218494d 100644
--- a/juick-www/src/main/java/com/juick/www/RSS.java
+++ b/juick-www/src/main/java/com/juick/www/RSS.java
@@ -19,6 +19,7 @@ package com.juick.www;
import com.juick.Message;
import com.juick.server.MessagesQueries;
+import com.juick.util.MessageUtils;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -49,7 +50,7 @@ public class RSS {
List<Message> msgs = MessagesQueries.getMessages(sql, mids);
- msgs.forEach(m -> Utils.formatMessage(m.getText()));
+ msgs.forEach(m -> MessageUtils.formatMessage(m.getText()));
response.setContentType("application/rss+xml; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
diff --git a/juick-www/src/main/java/com/juick/www/UserThread.java b/juick-www/src/main/java/com/juick/www/UserThread.java
index f12e3c64..394d6712 100644
--- a/juick-www/src/main/java/com/juick/www/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/UserThread.java
@@ -21,6 +21,7 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
+import com.juick.util.MessageUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.IOException;
@@ -106,9 +107,9 @@ public class UserThread {
String txt;
if (msg.getTags().stream().anyMatch(t -> t.getName().equals("code"))) {
- txt = Utils.formatMessageCode(msg.getText());
+ txt = MessageUtils.formatMessageCode(msg.getText());
} else {
- txt = Utils.formatMessage(msg.getText());
+ txt = MessageUtils.formatMessage(msg.getText());
}
if (!tags.isEmpty()) {
@@ -290,7 +291,7 @@ public class UserThread {
out.println(" <div class=\"msg-menu\"><a href=\"#\" class=\"a-thread-links\"></a></div>");
out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMid() + "#" + msg.getRid() + "\" title=\"" + PageTemplates.sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" </div>");
- out.println(" <div class=\"msg-txt\">" + Utils.formatMessage(msg.getText()) + "</div>");
+ out.println(" <div class=\"msg-txt\">" + MessageUtils.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.getMid() + "-" + msg.getRid() + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.getMid() + "-" + msg.getRid() + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
}
@@ -336,7 +337,7 @@ public class UserThread {
out.println(" <div class=\"msg-menu\"><a href=\"#\" class=\"a-thread-links\"></a></div>");
out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMid() + "#" + msg.getRid() + "\" title=\"" + PageTemplates.sdfSQL.format(msg.getDate()) + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.getDate()) + "</a></div>");
out.println(" </div>");
- out.println(" <div class=\"msg-txt\">" + Utils.formatMessage(msg.getText()) + "</div>");
+ out.println(" <div class=\"msg-txt\">" + MessageUtils.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.getMid() + "-" + msg.getRid() + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.getMid() + "-" + msg.getRid() + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
}
diff --git a/juick-www/src/main/java/com/juick/www/Utils.java b/juick-www/src/main/java/com/juick/www/Utils.java
index 988ecb17..611563c7 100644
--- a/juick-www/src/main/java/com/juick/www/Utils.java
+++ b/juick-www/src/main/java/com/juick/www/Utils.java
@@ -208,98 +208,6 @@ public class Utils {
}
}
- private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!&gt;))*)([\\]\\}]|&gt;)");
-
- public static String formatMessageCode(String msg) {
- msg = msg.replaceAll("&", "&amp;");
- msg = msg.replaceAll("<", "&lt;");
- msg = msg.replaceAll(">", "&gt;");
-
- // http://juick.com/last?page=2
- // <a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$2</a>");
-
- // (http://juick.com/last?page=2)
- // (<a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>)
- Matcher m = regexLinks2.matcher(msg);
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", "");
- m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">" + url + "</a>$5");
- }
- m.appendTail(sb);
- msg = sb.toString();
-
- return "<pre>" + msg + "</pre>";
- }
- public static String formatMessage(String msg) {
- msg = msg.replaceAll("&", "&amp;");
- msg = msg.replaceAll("<", "&lt;");
- msg = msg.replaceAll(">", "&gt;");
-
- // --
- // &mdash;
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
-
- // http://juick.com/last?page=2
- // <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$3</a>");
-
- // [link text][http://juick.com/last?page=2]
- // <a href="http://juick.com/last?page=2" rel="nofollow">link text</a>
- msg = msg.replaceAll("\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]", "<a href=\"$2\" rel=\"nofollow\">$1</a>");
- msg = msg.replaceAll("\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)", "<a href=\"$2\" rel=\"nofollow\">$1</a>");
-
- // #12345
- // <a href="http://juick.com/12345">#12345</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)((?=\\s)|(?=\\Z)|(?=\\))|(?=\\.)|(?=\\,))", "$1<a href=\"http://juick.com/$2\">#$2</a>$3");
-
- // #12345/65
- // <a href="http://juick.com/12345#65">#12345/65</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2#$3\">#$2/$3</a>$4");
-
- // *bold*
- // <b>bold</b>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<b>$2</b>$3");
-
- // /italic/
- // <i>italic</i>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<i>$2</i>$3");
-
- // _underline_
- // <span class="u">underline</span>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<span class=\"u\">$2</span>$3");
-
- // /12
- // <a href="#12">/12</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"#$2\">/$2</a>$3");
-
- // @username@jabber.org
- // <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-\\.]+@[\\w\\-\\.]+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
-
- // @username
- // <a href="http://juick.com/username/">@username</a>
- msg = msg.replaceAll("((?<=\\s)|(?<=\\A))@([\\w\\-]{2,16})((?=\\s)|(?=\\Z)|(?=\\p{Punct}))", "$1<a href=\"http://juick.com/$2/\">@$2</a>$3");
-
- // (http://juick.com/last?page=2)
- // (<a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>)
- Matcher m = regexLinks2.matcher(msg);
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", "");
- m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5");
- }
- m.appendTail(sb);
- msg = sb.toString();
-
- // > citate
- msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))&gt; *(.*)?(\\n|(?=\\Z))", "<q>$1</q>");
- msg = msg.replaceAll("</q><q>", "\n");
-
- msg = msg.replaceAll("\n", "<br/>\n");
- return msg;
- }
public static PebbleEngine getEngine() {
return engine;
}
diff --git a/server-core/src/main/java/com/juick/util/MessageUtils.java b/server-core/src/main/java/com/juick/util/MessageUtils.java
deleted file mode 100644
index 1e8165c3..00000000
--- a/server-core/src/main/java/com/juick/util/MessageUtils.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.juick.util;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-public class MessageUtils {
- private MessageUtils() {
- throw new IllegalStateException();
- }
-
- public static String formatQuote(final String quote) {
- String result = quote;
-
- if (quote != null) {
- if (quote.length() > 50) {
- result = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n";
- } else if (!quote.isEmpty()) {
- result = ">" + quote.replace('\n', ' ') + "\n";
- }
- }
-
- return result;
- }
-}