From fc53fd7d63c703b2664e5cb0cbd6360e4b3f7bd5 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sat, 5 Jan 2013 03:59:25 +0700
Subject: Tag *code
---
src/java/com/juick/http/www/PageTemplates.java | 34 ++++++++++++++++++++++++--
src/java/com/juick/http/www/UserThread.java | 9 ++++++-
2 files changed, 40 insertions(+), 3 deletions(-)
(limited to 'src/java/com/juick')
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index 80b5a22e..11d20f32 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -52,7 +52,7 @@ public class PageTemplates {
out.println("");
out.println("
");
out.println(" " + title + "");
- out.println(" ");
+ out.println(" ");
out.println(" ");
out.println(" ");
out.println(" ");
@@ -261,6 +261,29 @@ public class PageTemplates {
}
private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?", ">");
+
+ // http://juick.com/last?page=2
+ // http://juick.com/last?page=2
+ msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1$2");
+
+ // (http://juick.com/last?page=2)
+ // (http://juick.com/last?page=2)
+ 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" + url + "$5");
+ }
+ m.appendTail(sb);
+ msg = sb.toString();
+
+ return "" + msg + "
";
+ }
+
public static String formatMessage(String msg) {
msg = msg.replaceAll("&", "&");
msg = msg.replaceAll("<", "<");
@@ -360,6 +383,13 @@ public class PageTemplates {
break;
}
+ String txt;
+ if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) {
+ txt = formatMessageCode(msg.Text);
+ } else {
+ txt = formatMessage(msg.Text);
+ }
+
out.println(" ");
out.println(" ");
out.println(" ");
@@ -367,7 +397,7 @@ public class PageTemplates {
if (msg.Place != null) {
out.println(" ");
}
- out.println(" " + formatMessage(msg.Text) + "
");
+ out.print(" " + txt + "
");
if (msg.AttachmentType != null) {
if (msg.AttachmentType.equals("jpg")) {
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index 9001bd17..3b315be2 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -114,6 +114,13 @@ public class UserThread {
break;
}
+ String txt;
+ if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) {
+ txt = PageTemplates.formatMessageCode(msg.Text);
+ } else {
+ txt = PageTemplates.formatMessage(msg.Text);
+ }
+
out.println("