aboutsummaryrefslogtreecommitdiff
path: root/juick-www
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www')
-rw-r--r--juick-www/src/main/java/com/juick/www/NewMessage.java17
-rw-r--r--juick-www/src/main/java/com/juick/www/PageTemplates.java14
-rw-r--r--juick-www/src/main/java/com/juick/www/User.java19
-rw-r--r--juick-www/src/main/java/com/juick/www/UserThread.java10
4 files changed, 31 insertions, 29 deletions
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
index c066c5b3..ca783779 100644
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/NewMessage.java
@@ -19,6 +19,7 @@ package com.juick.www;
import com.juick.Tag;
import com.juick.server.*;
+import com.juick.server.helpers.TagStats;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.math.NumberUtils;
@@ -100,16 +101,16 @@ public class NewMessage {
}
void printUserTags(JdbcTemplate sql, PrintWriter out, com.juick.User visitor) {
- List<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.getUid());
+ List<TagStats> tags = TagQueries.getTagsStats(sql, visitor.getUid());
if (tags.isEmpty()) {
return;
}
- int min = tags.get(0).UsageCnt;
- int max = tags.get(0).UsageCnt;
+ int min = tags.get(0).getUsageCount();
+ int max = tags.get(0).getUsageCount();
for (int i = 1; i < tags.size(); i++) {
- int usagecnt = tags.get(i).UsageCnt;
+ int usagecnt = tags.get(i).getUsageCount();
if (usagecnt < min) {
min = usagecnt;
}
@@ -126,12 +127,12 @@ public class NewMessage {
}
String taglink = "";
try {
- taglink = "<a onclick=\"return addTag('" + StringEscapeUtils.escapeHtml4(tags.get(i).getName()) + "')\" href=\"/" +
- visitor.getName() + "/?tag=" + URLEncoder.encode(tags.get(i).getName(), "utf-8") +
- "\" title=\"" + tags.get(i).UsageCnt + "\">" + StringEscapeUtils.escapeHtml4(tags.get(i).getName()) + "</a>";
+ taglink = "<a onclick=\"return addTag('" + StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()) + "')\" href=\"/" +
+ visitor.getName() + "/?tag=" + URLEncoder.encode(tags.get(i).getTag().getName(), "utf-8") +
+ "\" title=\"" + tags.get(i).getUsageCount() + "\">" + StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()) + "</a>";
} catch (UnsupportedEncodingException e) {
}
- int usagecnt = tags.get(i).UsageCnt;
+ int usagecnt = tags.get(i).getUsageCount();
if (usagecnt <= max / 5 + min) {
out.print("<span style=\"font-size: small\">" + taglink + "</span>");
} else if (usagecnt <= max / 5 * 2 + min) {
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 180e852f..504a4b8b 100644
--- a/juick-www/src/main/java/com/juick/www/PageTemplates.java
+++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java
@@ -18,10 +18,10 @@
package com.juick.www;
import com.juick.Message;
-import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import com.juick.server.helpers.TagStats;
import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
@@ -185,13 +185,13 @@ public class PageTemplates {
out.println("</body></html>");
}
- public static String formatTags(List<Tag> tags) {
+ public static String formatTags(List<TagStats> tags) {
String ret = "";
- for (Tag tag : tags) {
- String tagName = StringEscapeUtils.escapeHtml4(tag.getName());
+ for (TagStats tag : tags) {
+ String tagName = StringEscapeUtils.escapeHtml4(tag.getTag().getName());
try {
- ret += "<a href=\"/tag/" + URLEncoder.encode(tag.getName(), "utf-8") + "\"";
- if (tag.UsageCnt < 2) {
+ ret += "<a href=\"/tag/" + URLEncoder.encode(tag.getTag().getName(), "utf-8") + "\"";
+ if (tag.getUsageCount() < 2) {
ret += " rel=\"nofollow\"";
}
ret += ">" + tagName + "</a>";
@@ -301,7 +301,7 @@ public class PageTemplates {
for (Message msg : msgs) {
- List<Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMid());
+ List<TagStats> tags = MessagesQueries.getMessageTags(sql, msg.getMid());
String tagsStr = formatTags(tags);
if (msg.ReadOnly) {
tagsStr += "<a>readonly</a>";
diff --git a/juick-www/src/main/java/com/juick/www/User.java b/juick-www/src/main/java/com/juick/www/User.java
index 3cc38b37..088fb004 100644
--- a/juick-www/src/main/java/com/juick/www/User.java
+++ b/juick-www/src/main/java/com/juick/www/User.java
@@ -17,10 +17,10 @@
*/
package com.juick.www;
-import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import com.juick.server.helpers.TagStats;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -323,22 +324,22 @@ public class User {
}
public static String pageUserTags(JdbcTemplate sql, com.juick.User user, com.juick.User visitor, int cnt) {
- List<Tag> tags = TagQueries.getUserTagsAll(sql, user.getUid()).stream()
- .sorted((e1, e2) -> Integer.compare(e2.UsageCnt, e1.UsageCnt)).collect(Collectors.toList());
- int maxUsageCnt = tags.stream().map(t -> t.UsageCnt).max(Integer::max).orElse(0);
+ List<TagStats> tags = TagQueries.getTagsStats(sql, user.getUid()).stream()
+ .sorted((e1, e2) -> Integer.compare(e2.getUsageCount(), e1.getUsageCount())).collect(Collectors.toList());
+ int maxUsageCnt = tags.stream().map(TagStats::getUsageCount).max(Comparator.naturalOrder()).orElse(0);
String ret = "";
int count = cnt > 0 ? Math.min(tags.size(), cnt) : tags.size();
for (int i = 0; i < count; i++) {
- String tag = StringEscapeUtils.escapeHtml4(tags.get(i).getName());
+ String tag = StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName());
try {
- tag = "<a href=\"./?tag=" + URLEncoder.encode(tags.get(i).getName(), "UTF-8") + "\" title=\""
- + tags.get(i).UsageCnt + "\" rel=\"nofollow\">" + tag + "</a>";
+ tag = "<a href=\"./?tag=" + URLEncoder.encode(tags.get(i).getTag().getName(), "UTF-8") + "\" title=\""
+ + tags.get(i).getUsageCount() + "\" rel=\"nofollow\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
- if (tags.get(i).UsageCnt > maxUsageCnt / 3 * 2) {
+ if (tags.get(i).getUsageCount() > maxUsageCnt / 3 * 2) {
ret += "<big>" + tag + "</big> ";
- } else if (tags.get(i).UsageCnt > maxUsageCnt / 3) {
+ } else if (tags.get(i).getUsageCount() > maxUsageCnt / 3) {
ret += "<small>" + tag + "</small> ";
} else {
ret += tag + " ";
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 d94f2156..79ec42fc 100644
--- a/juick-www/src/main/java/com/juick/www/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/UserThread.java
@@ -18,19 +18,19 @@
package com.juick.www;
import com.juick.Message;
-import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
+import com.juick.server.helpers.TagStats;
import com.juick.util.MessageUtils;
import org.springframework.jdbc.core.JdbcTemplate;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
*
@@ -95,7 +95,7 @@ public class UserThread {
public static com.juick.Message printMessage(PrintWriter out, JdbcTemplate sql, com.juick.Message msg, com.juick.User visitor) {
msg.VisitorCanComment = visitor.getUid() > 0;
- List<Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMid());
+ List<TagStats> tags = MessagesQueries.getMessageTags(sql, msg.getMid());
String tagsStr = PageTemplates.formatTags(tags);
if (msg.ReadOnly) {
tagsStr += "<a>readonly</a>";