From b4a7601a14c9077fcfefc083ed39348409d57b76 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Tue, 6 Mar 2012 01:12:39 +0700
Subject: User tags, friends, readers
---
src/java/com/juick/http/www/User.java | 177 ++++++++++++++++++++++++++++++----
1 file changed, 157 insertions(+), 20 deletions(-)
(limited to 'src/java/com/juick/http/www/User.java')
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java
index 940cbfc4..73dd5827 100644
--- a/src/java/com/juick/http/www/User.java
+++ b/src/java/com/juick/http/www/User.java
@@ -103,11 +103,9 @@ public class User {
out.println("
");
- out.println("
" + rb.getString("(Menu) Messages") + "
");
- out.println("
");
- out.println("
" + rb.getString("(Menu) Tags") + "
");
- pageUserTags(out, sql, user, visitor, 15);
- out.println("
" + rb.getString("(Menu) Search") + "
");
- out.println("
");
+ PageTemplates.pageFooter(request, out, locale, visitor);
+ } finally {
+ out.close();
+ }
+ }
+
+ protected void doGetInfo(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ }
+
+ protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request);
+ Locale locale = request.getLocale();
+ ResourceBundle rb = ResourceBundle.getBundle("User", locale);
+
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Menu) Tags"), null);
+ PageTemplates.pageNavigation(out, locale, visitor);
+ PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+
+ out.println("
");
+ out.println("
");
+
+ out.print("
");
+ pageUserTags(out, sql, user, visitor, 0);
+ out.print("
");
+
out.println("
");
+ pageUserColumn(out, sql, user, visitor, locale);
out.println("
");
PageTemplates.pageFooter(request, out, locale, visitor);
@@ -143,20 +161,137 @@ public class User {
}
}
- protected void doGetInfo(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ protected void doGetFriends(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request);
+ Locale locale = request.getLocale();
+ ResourceBundle rb = ResourceBundle.getBundle("User", locale);
+
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null);
+ PageTemplates.pageNavigation(out, locale, visitor);
+ PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+
+ out.println("
");
+ out.println("
");
+ out.println("
");
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.id,users.nick FROM subscr_users INNER JOIN users ON subscr_users.user_id=users.id WHERE subscr_users.suser_id=? ORDER BY users.nick");
+ stmt.setInt(1, user.UID);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ int cnt = 0;
+ while (rs.next()) {
+ if (cnt % 3 == 0 && cnt > 0) {
+ out.print("
");
+ }
+ out.print(" " + rs.getString(2) + " | ");
+ cnt++;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ out.println("
");
+ out.println("
");
+ pageUserColumn(out, sql, user, visitor, locale);
+ out.println("
");
+
+ PageTemplates.pageFooter(request, out, locale, visitor);
+ } finally {
+ out.close();
+ }
+ }
+
+ protected void doGetReaders(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request);
+ Locale locale = request.getLocale();
+ ResourceBundle rb = ResourceBundle.getBundle("User", locale);
+
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null);
+ PageTemplates.pageNavigation(out, locale, visitor);
+ PageTemplates.pageUserTitle(out, sql, locale, user, visitor);
+
+ out.println("
");
+ out.println("
");
+ out.println("
");
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.id,users.nick FROM subscr_users INNER JOIN users ON subscr_users.suser_id=users.id WHERE subscr_users.user_id=? ORDER BY users.nick");
+ stmt.setInt(1, user.UID);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ int cnt = 0;
+ while (rs.next()) {
+ if (cnt % 3 == 0 && cnt > 0) {
+ out.print("
");
+ }
+ out.print(" " + rs.getString(2) + " | ");
+ cnt++;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ out.println("
");
+ out.println("
");
+ pageUserColumn(out, sql, user, visitor, locale);
+ out.println("
");
+
+ PageTemplates.pageFooter(request, out, locale, visitor);
+ } finally {
+ out.close();
+ }
+ }
+
+ public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, Locale locale) {
+ ResourceBundle rb = ResourceBundle.getBundle("User", locale);
+
+ out.println("
");
+ out.println("
" + rb.getString("(Menu) Messages") + "
");
+ out.println("
");
+ out.println("
");
+ pageUserTags(out, sql, user, visitor, 15);
+ out.println("
" + rb.getString("(Menu) Search") + "
");
+ out.println("
");
+ out.println("
");
}
public static void pageUserTags(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, int cnt) {
- com.juick.Tag tags[] = new com.juick.Tag[cnt];
+ com.juick.Tag tags[] = null;
int maxUsageCnt = 0;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC LIMIT ?");
- stmt.setInt(1, user.UID);
- stmt.setInt(2, cnt);
+ if (cnt > 0) {
+ stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC LIMIT ?", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ stmt.setInt(1, user.UID);
+ stmt.setInt(2, cnt);
+ } else {
+ stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ stmt.setInt(1, user.UID);
+ }
rs = stmt.executeQuery();
+ rs.last();
+ tags = new com.juick.Tag[rs.getRow()];
rs.beforeFirst();
cnt = 0;
while (rs.next()) {
@@ -174,12 +309,14 @@ public class User {
Utils.finishSQL(rs, stmt);
}
- Arrays.sort(tags, 0, cnt);
+ if (tags != null && cnt > 0) {
+ Arrays.sort(tags, 0, cnt);
+ }
for (int i = 0; i < cnt; i++) {
String tag = Utils.encodeHTML(tags[i].Name);
try {
- tag = "
" + tag + "";
+ tag = "
" + tag + "";
} catch (UnsupportedEncodingException e) {
}
--
cgit v1.2.3