aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/CrosspostComponent.java24
-rw-r--r--src/main/java/com/juick/PushComponent.java22
-rw-r--r--src/main/java/com/juick/http/www/Discover.java12
-rw-r--r--src/main/java/com/juick/http/www/Home.java17
-rw-r--r--src/main/java/com/juick/http/www/Login.java2
-rw-r--r--src/main/java/com/juick/http/www/Main.java67
-rw-r--r--src/main/java/com/juick/http/www/NewMessage.java50
-rw-r--r--src/main/java/com/juick/http/www/PM.java33
-rw-r--r--src/main/java/com/juick/http/www/PageTemplates.java79
-rw-r--r--src/main/java/com/juick/http/www/RSS.java36
-rw-r--r--src/main/java/com/juick/http/www/SignUp.java2
-rw-r--r--src/main/java/com/juick/http/www/TwitterAuth.java2
-rw-r--r--src/main/java/com/juick/http/www/User.java105
-rw-r--r--src/main/java/com/juick/http/www/UserThread.java148
-rw-r--r--src/main/java/com/juick/http/www/Utils.java2
-rw-r--r--src/main/java/com/juick/xmpp/extensions/JuickMessage.java172
-rw-r--r--src/main/java/com/juick/xmpp/extensions/JuickUser.java75
17 files changed, 538 insertions, 310 deletions
diff --git a/src/main/java/com/juick/CrosspostComponent.java b/src/main/java/com/juick/CrosspostComponent.java
index f6d830ec..7fd50564 100644
--- a/src/main/java/com/juick/CrosspostComponent.java
+++ b/src/main/java/com/juick/CrosspostComponent.java
@@ -159,7 +159,7 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
@Override
public void onMessage(com.juick.xmpp.Message msg) {
JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS);
- if (msg.to != null && msg.to.Username != null && jmsg != null && jmsg.RID == 0) {
+ if (msg.to != null && msg.to.Username != null && jmsg != null && jmsg.getRID() == 0) {
if (msg.to.Username.equals("twitter")) {
twitterPost(jmsg);
} else if (msg.to.Username.equals("fb")) {
@@ -171,18 +171,18 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean facebookPost(com.juick.Message jmsg) {
- String token = CrosspostQueries.getFacebookToken(sql, jmsg.User.UID);
+ String token = CrosspostQueries.getFacebookToken(sql, jmsg.getUser().getUID());
if (token == null) {
return false;
}
- logger.info("FB: #" + jmsg.MID);
+ logger.info("FB: #" + jmsg.getMID());
- String status = getMessageHashTags(jmsg) + "\n" + jmsg.Text;
+ String status = getMessageHashTags(jmsg) + "\n" + jmsg.getText();
boolean ret = false;
try {
- String body = "access_token=" + URLEncoder.encode(token, "UTF-8") + "&message=" + URLEncoder.encode(status, "UTF-8") + "&link=http%3A%2F%2Fjuick.com%2F" + jmsg.MID;
+ String body = "access_token=" + URLEncoder.encode(token, "UTF-8") + "&message=" + URLEncoder.encode(status, "UTF-8") + "&link=http%3A%2F%2Fjuick.com%2F" + jmsg.getMID();
HttpsURLConnection conn = (HttpsURLConnection) new URL(FBURL).openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@@ -208,14 +208,14 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean vkontaktePost(com.juick.Message jmsg) {
- String tokens[] = CrosspostQueries.getVKTokens(sql, jmsg.User.UID);
+ String tokens[] = CrosspostQueries.getVKTokens(sql, jmsg.getUser().getUID());
if (tokens == null || tokens.length != 2) {
return false;
}
- logger.info("VK: #" + jmsg.MID);
+ logger.info("VK: #" + jmsg.getMID());
- String status = getMessageHashTags(jmsg) + "\n" + jmsg.Text + "\nhttp://juick.com/" + jmsg.MID;
+ String status = getMessageHashTags(jmsg) + "\n" + jmsg.getText() + "\nhttp://juick.com/" + jmsg.getMID();
boolean ret = false;
try {
@@ -245,20 +245,20 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean twitterPost(com.juick.Message jmsg) {
- String tokens[] = CrosspostQueries.getTwitterTokens(sql, jmsg.User.UID);
+ String tokens[] = CrosspostQueries.getTwitterTokens(sql, jmsg.getUser().getUID());
if (tokens == null || tokens.length != 2) {
return false;
}
String token = percentEncode(tokens[0]);
String token_secret = percentEncode(tokens[1]);
- logger.info("TWITTER: #" + jmsg.MID);
+ logger.info("TWITTER: #" + jmsg.getMID());
- String status = getMessageHashTags(jmsg) + jmsg.Text;
+ String status = getMessageHashTags(jmsg) + jmsg.getText();
if (status.length() > 115) {
status = status.substring(0, 114) + "…";
}
- status += " http://juick.com/" + jmsg.MID;
+ status += " http://juick.com/" + jmsg.getMID();
status = percentEncode(status);
boolean ret = false;
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index 6fccce1e..533ca086 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -166,15 +166,15 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
logger.info("Message to push: " + msg.toString());
- boolean isPM = jmsg.MID == 0;
- boolean isReply = jmsg.RID > 0;
+ boolean isPM = jmsg.getMID() == 0;
+ boolean isReply = jmsg.getRID() > 0;
int senderID = 0, recipientID = 0;
// reply pushed to original sender
if (isReply) {
- com.juick.Message op = MessagesQueries.getMessage(sql, jmsg.MID);
- senderID = op.User.UID;
+ com.juick.Message op = MessagesQueries.getMessage(sql, jmsg.getMID());
+ senderID = op.getUser().getUID();
// do not notify self
- if (jmsg.User.UID == op.User.UID) {
+ if (jmsg.getUser().getUID() == op.getUser().getUID()) {
return;
}
}
@@ -189,7 +189,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
/*** ANDROID ***/
- ArrayList<String> regids;
+ List<String> regids;
if (isPM) {
regids = new ArrayList<String>();
String targetId = PushQueries.getAndroidRegID(sql, recipientID);
@@ -221,7 +221,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
/*** WinPhone ***/
- ArrayList<String> urls;
+ List<String> urls;
if (isPM) {
urls = new ArrayList<String>();
String targetURL = PushQueries.getWinPhoneURL(sql, recipientID);
@@ -233,11 +233,11 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
if (!urls.isEmpty()) {
- String text1 = "@" + jmsg.User.UName;
+ String text1 = "@" + jmsg.getUser().getUName();
if (!jmsg.Tags.isEmpty()) {
text1 += ":" + XmlUtils.escape(jmsg.getTagsString());
}
- String text2 = XmlUtils.escape(jmsg.Text);
+ String text2 = XmlUtils.escape(jmsg.getText());
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<toast>"
+ "<visual>"
@@ -248,7 +248,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
+ "</binding>"
+ "</visual>"
+ "<commands>"
- + "<command arguments=\"?mid=" + jmsg.MID + "\" />"
+ + "<command arguments=\"?mid=" + jmsg.getMID() + "\" />"
+ "</commands>"
+ "</toast>";
logger.fine(xml);
@@ -277,7 +277,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
ApnsService service = APNS.newService().withCert("/etc/juick/ios.p12", "juick")
.withSandboxDestination().build();
for (String token : tokens) {
- String payload = APNS.newPayload().alertTitle("@" + jmsg.User.UName).alertBody(jmsg.Text).build();
+ String payload = APNS.newPayload().alertTitle("@" + jmsg.getUser().getUName()).alertBody(jmsg.getText()).build();
logger.info("APNS: " + token);
service.push(token, payload);
}
diff --git a/src/main/java/com/juick/http/www/Discover.java b/src/main/java/com/juick/http/www/Discover.java
index 201139c4..e7d85d8a 100644
--- a/src/main/java/com/juick/http/www/Discover.java
+++ b/src/main/java/com/juick/http/www/Discover.java
@@ -26,6 +26,7 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.Connection;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -70,14 +71,13 @@ public class Discover {
}
}
- int visitor_uid = visitor != null ? visitor.UID : 0;
+ int visitor_uid = visitor != null ? visitor.getUID() : 0;
String title = "*" + Utils.encodeHTML(paramTag.Name);
- ArrayList<Integer> mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20);
+ List<Integer> mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20);
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String head = "";
if (TagQueries.getTagNoIndex(sql, paramTag.TID)) {
head = "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
@@ -91,7 +91,7 @@ public class Discover {
out.println("<section id=\"content\">");
if (mids.size() > 0) {
- int vuid = visitor != null ? visitor.UID : 0;
+ int vuid = visitor != null ? visitor.getUID() : 0;
int ad_mid = AdsQueries.getAdMID(sql, vuid);
if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) {
mids.add(0, ad_mid);
@@ -113,8 +113,6 @@ public class Discover {
PageTemplates.pageFooter(request, out, visitor, true);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
}
diff --git a/src/main/java/com/juick/http/www/Home.java b/src/main/java/com/juick/http/www/Home.java
index 20752a40..8dc3e70c 100644
--- a/src/main/java/com/juick/http/www/Home.java
+++ b/src/main/java/com/juick/http/www/Home.java
@@ -24,6 +24,7 @@ import java.io.PrintWriter;
import java.net.URLEncoder;
import java.sql.Connection;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -50,7 +51,7 @@ public class Home {
}
String title;
- ArrayList<Integer> mids;
+ List<Integer> mids;
String paramShow = request.getParameter("show");
if (paramSearch != null) {
@@ -68,27 +69,27 @@ public class Home {
return;
} else if (paramShow.equals("my") && visitor != null) {
title = "Моя лента";
- mids = MessagesQueries.getMyFeed(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getMyFeed(sql, visitor.getUID(), paramBefore);
} else if (paramShow.equals("private") && visitor != null) {
title = "Приватные";
- mids = MessagesQueries.getPrivate(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getPrivate(sql, visitor.getUID(), paramBefore);
} else if (paramShow.equals("discuss") && visitor != null) {
title = "Обсуждения";
- mids = MessagesQueries.getDiscussions(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getDiscussions(sql, visitor.getUID(), paramBefore);
} else if (paramShow.equals("recommended") && visitor != null) {
title = "Рекомендации";
- mids = MessagesQueries.getRecommended(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getRecommended(sql, visitor.getUID(), paramBefore);
} else if (paramShow.equals("photos")) {
title = "Фотографии";
if (visitor != null) {
- mids = MessagesQueries.getPhotos(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getPhotos(sql, visitor.getUID(), paramBefore);
} else {
mids = MessagesQueries.getPhotos(sql, 0, paramBefore);
}
} else if (paramShow.equals("all")) {
title = "Все сообщения";
if (visitor != null) {
- mids = MessagesQueries.getAll(sql, visitor.UID, paramBefore);
+ mids = MessagesQueries.getAll(sql, visitor.getUID(), paramBefore);
} else {
mids = MessagesQueries.getAll(sql, 0, paramBefore);
}
@@ -130,7 +131,7 @@ public class Home {
if (mids.size() > 0) {
int ad_mid = 0;
if (paramShow == null || paramShow.equals("top") || paramShow.equals("all")) {
- int vuid = visitor != null ? visitor.UID : 0;
+ int vuid = visitor != null ? visitor.getUID() : 0;
ad_mid = AdsQueries.getAdMID(sql, vuid);
if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) {
mids.add(0, ad_mid);
diff --git a/src/main/java/com/juick/http/www/Login.java b/src/main/java/com/juick/http/www/Login.java
index a24eac2b..3e9c5e09 100644
--- a/src/main/java/com/juick/http/www/Login.java
+++ b/src/main/java/com/juick/http/www/Login.java
@@ -236,7 +236,7 @@ public class Login {
PreparedStatement stmt = null;
try {
stmt = sql.prepareStatement("DELETE FROM logins WHERE user_id=?");
- stmt.setInt(1, visitor.UID);
+ stmt.setInt(1, visitor.getUID());
stmt.executeUpdate();
} catch (SQLException e) {
System.err.println(e);
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index cc4edd49..cabd50af 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -21,7 +21,14 @@ import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
-import java.io.FileInputStream;
+import ru.sape.Sape;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.MultipartConfig;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.Socket;
import java.net.URLEncoder;
@@ -29,14 +36,6 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
-import java.util.logging.Level;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.MultipartConfig;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import ru.sape.Sape;
/**
*
@@ -107,18 +106,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
return sqlSearch;
}
public void setupXmppComponent(final String password) {
- Thread thr = new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- Socket socket = new Socket("localhost", 5347);
- xmpp = new StreamComponent(new JID("", "www.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password);
- xmpp.addListener(Main.this);
- xmpp.startParsing();
- } catch (IOException e) {
- System.err.println(e);
- }
+ Thread thr = new Thread(() -> {
+ try {
+ Socket socket = new Socket("localhost", 5347);
+ xmpp = new StreamComponent(new JID("", "www.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password);
+ xmpp.addListener(Main.this);
+ xmpp.startParsing();
+ } catch (IOException e) {
+ log("xmpp exception", e);
}
});
thr.start();
@@ -194,12 +189,16 @@ public class Main extends HttpServlet implements Stream.StreamListener {
if (visitor == null) {
Utils.sendTemporaryRedirect(response, "/login");
} else {
- if (uri.equals("/pm/inbox")) {
- pm.doGetInbox(sql, request, response, visitor);
- } else if (uri.equals("/pm/sent")) {
- pm.doGetSent(sql, request, response, visitor);
- } else {
- Errors.doGet404(sql, request, response);
+ switch (uri) {
+ case "/pm/inbox":
+ pm.doGetInbox(sql, request, response, visitor);
+ break;
+ case "/pm/sent":
+ pm.doGetSent(sql, request, response, visitor);
+ break;
+ default:
+ Errors.doGet404(sql, request, response);
+ break;
}
}
} else if (uri.startsWith("/rss/")) {
@@ -239,7 +238,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
if (mid > 0) {
com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
if (author != null) {
- Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid);
+ Utils.sendPermanentRedirect(response, "/" + author.getUName() + "/" + mid);
return;
}
}
@@ -247,14 +246,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
} else if (uri.matches("^/[^/]+$")) {
com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, request.getRequestURI().substring(1));
if (user != null) {
- Utils.sendPermanentRedirect(response, "/" + user.UName + "/");
+ Utils.sendPermanentRedirect(response, "/" + user.getUName() + "/");
} else {
Errors.doGet404(sql, request, response);
}
} else if (uri.matches("^/.+/.*")) {
String uriparts[] = uri.split("/");
com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, uriparts[1]);
- if (user != null && user.UName.equals(uriparts[1]) && user.Banned == false) {
+ if (user != null && user.getUName().equals(uriparts[1]) && !user.Banned) {
if (uriparts.length == 2) { // http://juick.com/username/
pagesUser.doGetBlog(sql, getSqlSearch(), request, response, user);
closeSqlSearch();
@@ -273,8 +272,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
if (mid > 0) {
com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
if (author != null) {
- if (!author.UName.equals(user.UName)) {
- Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid);
+ if (!author.getUName().equals(user.getUName())) {
+ Utils.sendPermanentRedirect(response, "/" + author.getUName() + "/" + mid);
} else {
pagesUserThread.doGetThread(sql, request, response, mid);
}
@@ -285,8 +284,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Errors.doGet404(sql, request, response);
}
}
- } else if (user != null && user.Banned == false) {
- Utils.sendPermanentRedirect(response, "/" + user.UName + "/" + (uriparts.length > 2 ? uriparts[2] : ""));
+ } else if (user != null && !user.Banned) {
+ Utils.sendPermanentRedirect(response, "/" + user.getUName() + "/" + (uriparts.length > 2 ? uriparts[2] : ""));
} else {
Errors.doGet404(sql, request, response);
}
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java
index 3cf73882..86725db7 100644
--- a/src/main/java/com/juick/http/www/NewMessage.java
+++ b/src/main/java/com/juick/http/www/NewMessage.java
@@ -37,6 +37,7 @@ import java.net.URL;
import java.net.URLEncoder;
import java.sql.Connection;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -88,7 +89,7 @@ public class NewMessage {
}
void printUserTags(Connection sql, PrintWriter out, com.juick.User visitor) {
- ArrayList<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.UID);
+ List<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.getUID());
if (tags.isEmpty()) {
return;
@@ -114,7 +115,7 @@ public class NewMessage {
}
String taglink = "";
try {
- taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.UName + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>";
+ taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.getUName() + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>";
} catch (UnsupportedEncodingException e) {
}
int usagecnt = tags.get(i).UsageCnt;
@@ -142,7 +143,7 @@ public class NewMessage {
body = body.replace("\r", "");
String tagsStr = request.getParameter("tags");
- ArrayList<com.juick.Tag> tags = new ArrayList<Tag>();
+ List<com.juick.Tag> tags = new ArrayList<Tag>();
String tagsArr[] = new String[1];
if (tagsStr != null && !tagsStr.isEmpty()) {
tagsArr = tagsStr.split("[ \\,]");
@@ -182,8 +183,8 @@ public class NewMessage {
}
String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null;
- int mid = MessagesQueries.createMessage(sql, visitor.UID, body, attachmentType, tags);
- SubscriptionsQueries.subscribeMessage(sql, mid, visitor.UID);
+ int mid = MessagesQueries.createMessage(sql, visitor.getUID(), body, attachmentType, tags);
+ SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUID());
Message xmsg = new Message();
xmsg.from = new JID("juick", "juick.com", null);
@@ -194,7 +195,7 @@ public class NewMessage {
xmsg.addChild(jmsg);
Nickname nick = new Nickname();
- nick.Nickname = "@" + jmsg.User.UName;
+ nick.Nickname = "@" + jmsg.getUser().getUName();
xmsg.addChild(nick);
if (attachmentFName != null) {
@@ -210,10 +211,10 @@ public class NewMessage {
}
String tagsStr2 = "";
- for (int i = 0; i < tagsArr.length; i++) {
- tagsStr2 += " *" + tagsArr[i];
+ for (String tag : tagsArr) {
+ tagsStr2 += " *" + tag;
}
- xmsg.body = "@" + jmsg.User.UName + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid;
+ xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid;
xmsg.to = new JID("juick", "s2s.juick.com", null);
xmpp.send(xmsg);
@@ -237,8 +238,7 @@ public class NewMessage {
//
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Сообщение опубликовано", null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -265,12 +265,12 @@ public class NewMessage {
out.println("<section id=\"content\">");
out.println("<h1>Сообщение опубликовано</h1>");
out.println("<p>Поделитесь своим новым постом в социальных сетях:</p>");
- if (CrosspostQueries.getTwitterTokens(sql, visitor.UID) == null) {
+ if (CrosspostQueries.getTwitterTokens(sql, visitor.getUID()) == null) {
out.println("<p><a href=\"https://twitter.com/intent/tweet?text=" + URLEncoder.encode(sharetwi, "utf-8") + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-twi sharenew\">Отправить в Twitter</a></p>");
}
out.println("<p><a href=\"http://www.livejournal.com/update.bml?subject=" + URLEncoder.encode(hashtags, "utf-8") + "&event=" + sharelj + "&prop_taglist=" + URLEncoder.encode(tagscomma, "utf-8") + "\" target=\"_blank\" class=\"ico32-lj sharenew\">Отправить в LiveJournal</a></p>");
out.println("<p><a href=\"https://vk.com/share.php?url=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-vk sharenew\">Отправить в ВКонтакте</a></p>");
- if (CrosspostQueries.getFacebookToken(sql, visitor.UID) == null) {
+ if (CrosspostQueries.getFacebookToken(sql, visitor.getUID()) == null) {
out.println("<p><a href=\"https://www.facebook.com/sharer/sharer.php?u=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-fb sharenew\">Отправить в Facebook</a></p>");
}
out.println("<p><a href=\"https://plus.google.com/share?url=" + url + "\" onclick=\"return openSocialWindow(this)\" class=\"ico32-gp sharenew\">Отправить в Google+</a></p>");
@@ -279,8 +279,6 @@ public class NewMessage {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
@@ -313,7 +311,7 @@ public class NewMessage {
}
body = body.replace("\r", "");
- if ((msg.ReadOnly && msg.User.UID != visitor.UID) || UserQueries.isInBLAny(sql, msg.User.UID, visitor.UID) || (reply != null && UserQueries.isInBLAny(sql, reply.User.UID, visitor.UID))) {
+ if ((msg.ReadOnly && msg.getUser().getUID() != visitor.getUID()) || UserQueries.isInBLAny(sql, msg.getUser().getUID(), visitor.getUID()) || (reply != null && UserQueries.isInBLAny(sql, reply.getUser().getUID(), visitor.getUID()))) {
response.sendError(403);
return;
}
@@ -339,8 +337,8 @@ public class NewMessage {
}
String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null;
- int ridnew = MessagesQueries.createReply(sql, mid, rid, visitor.UID, body, attachmentType);
- SubscriptionsQueries.subscribeMessage(sql, mid, visitor.UID);
+ int ridnew = MessagesQueries.createReply(sql, mid, rid, visitor.getUID(), body, attachmentType);
+ SubscriptionsQueries.subscribeMessage(sql, mid, visitor.getUID());
Message xmsg = new Message();
xmsg.from = new JID("juick", "juick.com", null);
@@ -350,13 +348,13 @@ public class NewMessage {
JuickMessage jmsg = new JuickMessage(MessagesQueries.getReply(sql, mid, ridnew));
xmsg.addChild(jmsg);
- String quote = reply != null ? reply.Text : msg.Text;
+ String quote = reply != null ? reply.getText() : msg.getText();
if (quote.length() >= 50) {
quote = quote.substring(0, 47) + "...";
}
Nickname nick = new Nickname();
- nick.Nickname = "@" + jmsg.User.UName;
+ nick.Nickname = "@" + jmsg.getUser().getUName();
xmsg.addChild(nick);
if (attachmentFName != null) {
@@ -371,7 +369,7 @@ public class NewMessage {
xmsg.addChild(xoob);
}
- xmsg.body = "Reply by @" + jmsg.User.UName + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew;
+ xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew;
xmsg.to = new JID("juick", "s2s.juick.com", null);
xmpp.send(xmsg);
@@ -382,7 +380,7 @@ public class NewMessage {
xmsg.to.Host = "push.juick.com";
xmpp.send(xmsg);
- Utils.sendTemporaryRedirect(response, "/" + msg.User.UName + "/" + mid + "#" + ridnew);
+ Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew);
}
public void doPostRecomm(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
@@ -396,20 +394,20 @@ public class NewMessage {
response.sendError(404);
return;
}
- if (msg.User.UID == visitor.UID) {
+ if (msg.getUser().getUID() == visitor.getUID()) {
response.sendError(403);
return;
}
- boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.UID);
+ boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.getUID());
if (res) {
Message xmsg = new Message();
xmsg.from = new JID("juick", "juick.com", null);
xmsg.to = new JID("recomm", "s2s.juick.com", null);
JuickMessage jmsg = new JuickMessage();
- jmsg.MID = mid;
- jmsg.User = new JuickUser(visitor);
+ jmsg.setMID(mid);
+ jmsg.setUser(new JuickUser(visitor));
xmsg.addChild(jmsg);
xmpp.send(xmsg);
diff --git a/src/main/java/com/juick/http/www/PM.java b/src/main/java/com/juick/http/www/PM.java
index d0d2f514..a9505bdb 100644
--- a/src/main/java/com/juick/http/www/PM.java
+++ b/src/main/java/com/juick/http/www/PM.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -50,7 +51,7 @@ public class PM {
*/
String title = "PM: Inbox";
- ArrayList<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.UID);
+ List<com.juick.Message> msgs = PMQueries.getLastPMInbox(sql, visitor.getUID());
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
@@ -66,16 +67,16 @@ public class PM {
for (int i = msgs.size() - 1; i >= 0; i--) {
com.juick.Message msg = msgs.get(i);
- String txt = PageTemplates.formatMessage(msg.Text);
+ String txt = PageTemplates.formatMessage(msg.getText());
out.println(" <li class=\"msg\">");
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
+ out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></div>");
out.println(" <div class=\"msg-cont\">");
- out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
- out.println(" <form action=\"/pm/send\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"uname\" value=\"" + msg.User.UName + "\"/>");
+ out.println(" <form action=\"/pm/send\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"uname\" value=\"" + msg.getUser().getUName() + "\"/>");
out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"replypm\" placeholder=\"Написать ответ\" onkeypress=\"postformListener(this.form,event)\"></textarea></div></div>");
out.println(" </form>");
@@ -114,7 +115,7 @@ public class PM {
*/
String title = "PM: Sent";
- ArrayList<com.juick.Message> msgs = PMQueries.getLastPMSent(sql, visitor.UID);
+ List<com.juick.Message> msgs = PMQueries.getLastPMSent(sql, visitor.getUID());
String uname = request.getParameter("uname");
if (!UserQueries.checkUserNameValid(uname)) {
@@ -143,12 +144,12 @@ public class PM {
for (int i = msgs.size() - 1; i >= 0; i--) {
com.juick.Message msg = msgs.get(i);
- String txt = PageTemplates.formatMessage(msg.Text);
+ String txt = PageTemplates.formatMessage(msg.getText());
out.println(" <li class=\"msg\">");
- out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/a/" + visitor.UID + ".png\"/></div>");
+ out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/a/" + visitor.getUID() + ".png\"/></div>");
out.println(" <div class=\"msg-cont\">");
- out.println(" <div class=\"msg-header\">→ <a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
+ out.println(" <div class=\"msg-header\">→ <a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
out.println(" <div class=\"msg-ts\"><a href=\"#\" onclick=\"return false\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
out.println(" </div>");
@@ -189,18 +190,18 @@ public class PM {
return;
}
- if (UserQueries.isInBLAny(sql, uid, visitor.UID)) {
+ if (UserQueries.isInBLAny(sql, uid, visitor.getUID())) {
response.sendError(403);
return;
}
- if (PMQueries.createPM(sql, visitor.UID, uid, body)) {
+ if (PMQueries.createPM(sql, visitor.getUID(), uid, body)) {
Message msg = new Message();
msg.from = new JID("juick", "juick.com", null);
msg.to = new JID(Integer.toString(uid), "push.juick.com", null);
JuickMessage jmsg = new JuickMessage();
- jmsg.User = UserQueries.getUserByUID(sql, visitor.UID);
- jmsg.Text = body;
+ jmsg.setUser(UserQueries.getUserByUID(sql, visitor.getUID()));
+ jmsg.setText(body);
msg.childs.add(jmsg);
xmpp.send(msg);
@@ -212,12 +213,12 @@ public class PM {
Message mm = new Message();
mm.to = new JID(jid);
mm.type = Message.Type.chat;
- if (PMQueries.havePMinRoster(sql, visitor.UID, jid)) {
- mm.from = new JID(jmsg.User.UName, "juick.com", "Juick");
+ if (PMQueries.havePMinRoster(sql, visitor.getUID(), jid)) {
+ mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick");
mm.body = body;
} else {
mm.from = new JID("juick", "juick.com", "Juick");
- mm.body = "Private message from @" + jmsg.User.UName + ":\n" + body;
+ mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + body;
}
xmpp.send(mm);
}
diff --git a/src/main/java/com/juick/http/www/PageTemplates.java b/src/main/java/com/juick/http/www/PageTemplates.java
index 2b041cb2..2f9c8976 100644
--- a/src/main/java/com/juick/http/www/PageTemplates.java
+++ b/src/main/java/com/juick/http/www/PageTemplates.java
@@ -17,6 +17,8 @@
*/
package com.juick.http.www;
+import com.juick.Message;
+import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import java.io.PrintWriter;
@@ -30,6 +32,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
@@ -92,7 +95,7 @@ public class PageTemplates {
out.println("</ul></nav>");
out.print(" <nav id=\"actions\"><ul>");
out.print("<li><a href=\"/#post\">Написать</a></li>");
- out.print("<li><a href=\"/" + visitor.UName + "\">@" + visitor.UName + "</a></li>");
+ out.print("<li><a href=\"/" + visitor.getUName() + "\">@" + visitor.getUName() + "</a></li>");
out.print("<li><a href=\"/logout\">Выйти</a></li>");
out.println("</ul></nav>");
} else {
@@ -232,7 +235,7 @@ public class PageTemplates {
String queryString = request.getQueryString();
String requestURI = request.getRequestURI();
- if (sapeon && sape != null && (visitor == null || visitor.UID == 1) && queryString == null) {
+ if (sapeon && sape != null && (visitor == null || visitor.getUID() == 1) && queryString == null) {
String links = sape.getPageLinks(requestURI, request.getCookies()).render();
if (links != null && !links.isEmpty()) {
out.print("<br/>Спонсоры: " + links);
@@ -244,7 +247,7 @@ public class PageTemplates {
if (visitor != null) {
out.println("<script type=\"text/javascript\">");
- out.println("var hash=\"" + visitor.AuthHash + "\";");
+ out.println("var hash=\"" + visitor.getAuthHash() + "\";");
out.println("</script>");
}
@@ -272,10 +275,9 @@ public class PageTemplates {
out.println("</body></html>");
}
- public static String formatTags(ArrayList<com.juick.Tag> tags) {
+ public static String formatTags(List<Tag> tags) {
String ret = "";
- for (int i = 0; i < tags.size(); i++) {
- com.juick.Tag tag = tags.get(i);
+ for (Tag tag : tags) {
String tagName = tag.Name.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
try {
ret += " *<a href=\"/tag/" + URLEncoder.encode(tag.Name, "utf-8") + "\"";
@@ -290,10 +292,9 @@ public class PageTemplates {
return ret;
}
- public static String formatTags(ArrayList<String> tags, com.juick.User user) {
+ public static String formatTags(List<String> tags, com.juick.User user) {
String ret = "";
- for (int i = 0; i < tags.size(); i++) {
- String tag = tags.get(i);
+ for (String tag : tags) {
tag = tag.replaceAll("<", "&lt;");
tag = tag.replaceAll(">", "&gt;");
try {
@@ -301,9 +302,9 @@ public class PageTemplates {
if (user == null) {
ret += "/tag/";
} else {
- ret += "/" + user.UName + "/?tag=";
+ ret += "/" + user.getUName() + "/?tag=";
}
- ret += URLEncoder.encode(tags.get(i), "utf-8") + "\">" + tag + "</a>";
+ ret += URLEncoder.encode(tag, "utf-8") + "\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
}
@@ -491,24 +492,24 @@ public class PageTemplates {
return msg;
}
- public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList<Integer> mids, com.juick.User visitor, int YandexID, int ad_mid) {
- ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
+ public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, List<Integer> mids, com.juick.User visitor, int YandexID, int ad_mid) {
+ List<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
for (int i = 0; i < msgs.size(); i++) {
com.juick.Message msg = msgs.get(i);
- if (msg.MID == ad_mid) {
+ if (msg.getMID() == ad_mid) {
msgs.remove(i);
msgs.add(0, msg);
break;
}
}
- ArrayList<Integer> blUIDs = new ArrayList<Integer>(20);
+ List<Integer> blUIDs = new ArrayList<Integer>(20);
if (visitor != null) {
- for (int i = 0; i < msgs.size(); i++) {
- blUIDs.add(msgs.get(i).User.UID);
+ for (Message msg : msgs) {
+ blUIDs.add(msg.getUser().getUID());
}
- blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
+ blUIDs = UserQueries.checkBL(sql, visitor.getUID(), blUIDs);
}
for (int i = 0; i < msgs.size(); i++) {
@@ -519,7 +520,7 @@ public class PageTemplates {
com.juick.Message msg = msgs.get(i);
- ArrayList<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.MID);
+ List<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMID());
String tagsStr = formatTags(tags);
if (msg.ReadOnly) {
tagsStr += " *readonly";
@@ -527,23 +528,23 @@ public class PageTemplates {
if (msg.Privacy < 0) {
tagsStr += " *friends";
}
- if (msg.MID == ad_mid) {
+ if (msg.getMID() == ad_mid) {
tagsStr += " *реклама";
}
String txt;
if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) {
- txt = formatMessageCode(msg.Text);
+ txt = formatMessageCode(msg.getText());
} else {
- txt = formatMessage(msg.Text);
+ txt = formatMessage(msg.getText());
}
- out.println("<article data-mid=\"" + msg.MID + "\">");
- out.println(" <aside><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></aside>");
- out.println(" <header class=\"u\">@<a href=\"/" + msg.User.UName + "/\">" + msg.User.UName + "</a>:" + tagsStr + "</header>");
- out.println(" <header class=\"t\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\"><time datetime=\"" + msg.TimestampString + "Z\" title=\"" + msg.TimestampString + " GMT\">" + formatDate(msg.TimeAgo, msg.TimestampString) + "</time></a></header>");
+ out.println("<article data-mid=\"" + msg.getMID() + "\">");
+ out.println(" <aside><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></aside>");
+ out.println(" <header class=\"u\">@<a href=\"/" + msg.getUser().getUName() + "/\">" + msg.getUser().getUName() + "</a>:" + tagsStr + "</header>");
+ out.println(" <header class=\"t\"><a href=\"/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"><time datetime=\"" + msg.TimestampString + "Z\" title=\"" + msg.TimestampString + " GMT\">" + formatDate(msg.TimeAgo, msg.TimestampString) + "</time></a></header>");
if (msg.AttachmentType != null) {
- String fname = msg.MID + "." + msg.AttachmentType;
+ String fname = msg.getMID() + "." + msg.AttachmentType;
out.println(" <p class=\"ir\"><a href=\"//i.juick.com/photos-512/" + fname + "\" onclick=\"return showPhotoDialog('" + fname + "')\"><img src=\"//i.juick.com/photos-512/" + fname + "\" alt=\"\"/></a></p>");
}
out.println(" <p>" + txt + "</p>");
@@ -551,29 +552,29 @@ public class PageTemplates {
out.println(" <div class=\"irbr\"></div>");
}
out.print(" <nav class=\"l\">");
- msg.ReadOnly |= blUIDs.contains(msg.User.UID);
- if (visitor == null && msg.ReadOnly == false) {
+ msg.ReadOnly |= blUIDs.contains(msg.getUser().getUID());
+ if (visitor == null && !msg.ReadOnly) {
out.print("<a href=\"#\" onclick=\"return openDialogLogin()\">Комментировать</a> ");
- } else if (visitor != null && (msg.ReadOnly == false || visitor.UID == msg.User.UID)) {
+ } else if (visitor != null && (!msg.ReadOnly || visitor.getUID() == msg.getUser().getUID())) {
out.print("<a href=\"#\" onclick=\"return showCommentFooter(this)\">Комментировать</a> ");
}
- out.print("<a href=\"#\" onclick=\"return likeMessage(this," + msg.MID + ")\">Мне нравится</a>");
- if (visitor != null && msg.Privacy < 0 && msg.User.UID == visitor.UID) {
- out.print(" <a href=\"#\" onclick=\"return setPrivacy(this," + msg.MID + ")\">Открыть доступ</a>");
+ out.print("<a href=\"#\" onclick=\"return likeMessage(this," + msg.getMID() + ")\">Мне нравится</a>");
+ if (visitor != null && msg.Privacy < 0 && msg.getUser().getUID() == visitor.getUID()) {
+ out.print(" <a href=\"#\" onclick=\"return setPrivacy(this," + msg.getMID() + ")\">Открыть доступ</a>");
}
- if (visitor != null && visitor.UID == 3694) {
- out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.MID + ",2)\">+</a>");
- out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.MID + ",-1)\">-</a>");
- out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.MID + ",-2)\">x</a>");
+ if (visitor != null && visitor.getUID() == 3694) {
+ out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.getMID() + ",2)\">+</a>");
+ out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.getMID() + ",-1)\">-</a>");
+ out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.getMID() + ",-2)\">x</a>");
}
out.println("</nav>");
out.print(" <nav class=\"s\">");
if (msg.Likes > 0) {
- out.print("<a href=\"/" + msg.User.UName + "/" + msg.MID + "\" class=\"likes\">" + msg.Likes + "</a>");
+ out.print("<a href=\"/" + msg.getUser().getUName() + "/" + msg.getMID() + "\" class=\"likes\">" + msg.Likes + "</a>");
}
if (msg.Replies > 0) {
- out.print("<a href=\"/" + msg.User.UName + "/" + msg.MID + "\" class=\"replies\">" + msg.Replies + "</a>");
+ out.print("<a href=\"/" + msg.getUser().getUName() + "/" + msg.getMID() + "\" class=\"replies\">" + msg.Replies + "</a>");
}
out.println("</nav>");
out.print("</article>");
diff --git a/src/main/java/com/juick/http/www/RSS.java b/src/main/java/com/juick/http/www/RSS.java
index ab96221e..72893915 100644
--- a/src/main/java/com/juick/http/www/RSS.java
+++ b/src/main/java/com/juick/http/www/RSS.java
@@ -23,9 +23,9 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -40,17 +40,16 @@ public class RSS {
private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
- ArrayList<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
+ List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
if (mids.isEmpty()) {
response.sendError(404);
return;
}
- ArrayList<Message> msgs = MessagesQueries.getMessages(sql, mids);
+ List<Message> msgs = MessagesQueries.getMessages(sql, mids);
response.setContentType("application/rss+xml; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
out.println("<?xml version='1.0' encoding='utf-8'?>");
out.println("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:media='http://search.yahoo.com/mrss/' xmlns:juick='http://juick.com/'>");
out.println("<channel>");
@@ -60,22 +59,19 @@ public class RSS {
out.println("<description>The latest messages by @" + uname + " at Juick</description>");
out.println("<image><url>http://i.juick.com/a/" + uid + ".png</url><title>" + uname + " - Juick</title><link>http://juick.com/" + uname + "/</link></image>");
- Iterator<Message> i = msgs.iterator();
- while (i.hasNext()) {
- Message msg = i.next();
-
+ for (Message msg : msgs) {
out.println("<item>");
- out.println("<link>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</link>");
- out.println("<guid>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</guid>");
+ out.println("<link>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</link>");
+ out.println("<guid>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</guid>");
- out.print("<title><![CDATA[@" + msg.User.UName + ":");
+ out.print("<title><![CDATA[@" + msg.getUser().getUName() + ":");
if (!msg.Tags.isEmpty()) {
for (int n = 0; n < msg.Tags.size(); n++) {
out.print(" *" + msg.Tags.get(n));
}
}
out.println("]]></title>");
- out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.Text) + "]]></description>");
+ out.println("<description><![CDATA[" + PageTemplates.formatMessage(msg.getText()) + "]]></description>");
synchronized (sdfSQL) {
try {
@@ -86,7 +82,7 @@ public class RSS {
}
}
- out.println("<comments>http://juick.com/" + msg.User.UName + "/" + msg.MID + "</comments>");
+ out.println("<comments>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</comments>");
if (!msg.Tags.isEmpty()) {
for (int n = 0; n < msg.Tags.size(); n++) {
out.println("<category>" + msg.Tags.get(n) + "</category>");
@@ -94,20 +90,18 @@ public class RSS {
}
if (msg.AttachmentType != null) {
if (msg.AttachmentType.equals("jpg")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".jpg' type='image/jpeg'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".jpg'/>");
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".jpg' type='image/jpeg'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".jpg'/>");
} else if (msg.AttachmentType.equals("png")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.MID + ".png' type='image/png'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.MID + ".png'/>");
+ out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".png' type='image/png'/>");
+ out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".png'/>");
}
}
- out.println("<juick:user uid='" + msg.User.UID + "'/>");
+ out.println("<juick:user uid='" + msg.getUser().getUID() + "'/>");
out.println("</item>");
}
out.println("</channel></rss>");
- } finally {
- out.close();
}
}
}
diff --git a/src/main/java/com/juick/http/www/SignUp.java b/src/main/java/com/juick/http/www/SignUp.java
index 395232a6..2fae9b69 100644
--- a/src/main/java/com/juick/http/www/SignUp.java
+++ b/src/main/java/com/juick/http/www/SignUp.java
@@ -134,7 +134,7 @@ public class SignUp {
}
uid = com.juick.server.UserQueries.checkPassword(sql, username, password);
} else {
- uid = visitor.UID;
+ uid = visitor.getUID();
}
if (uid <= 0) {
diff --git a/src/main/java/com/juick/http/www/TwitterAuth.java b/src/main/java/com/juick/http/www/TwitterAuth.java
index d6abaa75..421c6f64 100644
--- a/src/main/java/com/juick/http/www/TwitterAuth.java
+++ b/src/main/java/com/juick/http/www/TwitterAuth.java
@@ -45,7 +45,7 @@ public class TwitterAuth {
}
}
com.juick.User user = UserQueries.getUserByHash(sql, hash);
- if ( user == null || user.UID == 0) {
+ if ( user == null || user.getUID() == 0) {
response.sendError(403);
return;
}
diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java
index 83601ade..84d1ad9a 100644
--- a/src/main/java/com/juick/http/www/User.java
+++ b/src/main/java/com/juick/http/www/User.java
@@ -30,6 +30,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -44,7 +45,7 @@ public class User {
protected void doGetBlog(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- ArrayList<Integer> mids;
+ List<Integer> mids;
String paramShow = request.getParameter("show");
@@ -58,7 +59,7 @@ public class User {
Errors.doGet404(sql, request, response);
return;
} else if (!paramTag.Name.equals(paramTagStr)) {
- String url = "/" + user.UName + "/?tag=" + URLEncoder.encode(paramTag.Name, "UTF-8");
+ String url = "/" + user.getUName() + "/?tag=" + URLEncoder.encode(paramTag.Name, "UTF-8");
Utils.sendPermanentRedirect(response, url);
return;
}
@@ -80,9 +81,9 @@ public class User {
int privacy = 0;
if (visitor != null) {
- if (user.UID == visitor.UID || visitor.UID == 1) {
+ if (user.getUID() == visitor.getUID() || visitor.getUID() == 1) {
privacy = -3;
- } else if (UserQueries.isInWL(sql, user.UID, visitor.UID)) {
+ } else if (UserQueries.isInWL(sql, user.getUID(), visitor.getUID())) {
privacy = -2;
}
}
@@ -90,34 +91,33 @@ public class User {
String title;
if (paramShow == null) {
if (paramTag != null) {
- title = "Блог " + user.UName + ": *" + Utils.encodeHTML(paramTag.Name);
- mids = MessagesQueries.getUserTag(sql, user.UID, paramTag.TID, privacy, paramBefore);
+ title = "Блог " + user.getUName() + ": *" + Utils.encodeHTML(paramTag.Name);
+ mids = MessagesQueries.getUserTag(sql, user.getUID(), paramTag.TID, privacy, paramBefore);
} else if (paramSearch != null) {
- title = "Блог " + user.UName + ": " + Utils.encodeHTML(paramSearch);
- mids = MessagesQueries.getUserSearch(sql, sqlSearch, user.UID, Utils.encodeSphinx(paramSearch), privacy, paramBefore);
+ title = "Блог " + user.getUName() + ": " + Utils.encodeHTML(paramSearch);
+ mids = MessagesQueries.getUserSearch(sql, sqlSearch, user.getUID(), Utils.encodeSphinx(paramSearch), privacy, paramBefore);
} else {
- title = "Блог " + user.UName;
- mids = MessagesQueries.getUserBlog(sql, user.UID, privacy, paramBefore);
+ title = "Блог " + user.getUName();
+ mids = MessagesQueries.getUserBlog(sql, user.getUID(), privacy, paramBefore);
}
} else if (paramShow.equals("recomm")) {
- title = "Рекомендации " + user.UName;
- mids = MessagesQueries.getUserRecommendations(sql, user.UID, paramBefore);
+ title = "Рекомендации " + user.getUName();
+ mids = MessagesQueries.getUserRecommendations(sql, user.getUID(), paramBefore);
} else if (paramShow.equals("photos")) {
- title = "Фотографии " + user.UName;
- mids = MessagesQueries.getUserPhotos(sql, user.UID, privacy, paramBefore);
+ title = "Фотографии " + user.getUName();
+ mids = MessagesQueries.getUserPhotos(sql, user.getUID(), privacy, paramBefore);
} else {
Errors.doGet404(sql, request, response);
return;
}
if (visitor == null) {
- pageUserRefCookie(request, response, user.UID);
+ pageUserRefCookie(request, response, user.getUID());
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
- String head = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + user.UName + "\" href=\"//rss.juick.com/" + user.UName + "/blog\"/>";
+ try (PrintWriter out = response.getWriter()) {
+ String head = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + user.getUName() + "\" href=\"//rss.juick.com/" + user.getUName() + "/blog\"/>";
if (paramTag != null && TagQueries.getTagNoIndex(sql, paramTag.TID)) {
head += "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
} else if (paramBefore > 0 || paramShow != null) {
@@ -155,8 +155,6 @@ public class User {
PageTemplates.pageFooter(request, out, visitor, true);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
@@ -164,14 +162,13 @@ public class User {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
- pageUserRefCookie(request, response, user.UID);
+ pageUserRefCookie(request, response, user.getUID());
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String head = "<meta name=\"robots\" content=\"noindex,nofollow\"/>";
- PageTemplates.pageHead(out, "Теги " + user.UName, head);
+ PageTemplates.pageHead(out, "Теги " + user.getUName(), head);
PageTemplates.pageNavigation(out, visitor, null);
pageUserColumn(out, sql, user, visitor);
@@ -181,8 +178,6 @@ public class User {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
@@ -190,14 +185,13 @@ public class User {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
- pageUserRefCookie(request, response, user.UID);
+ pageUserRefCookie(request, response, user.getUID());
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String head = "<meta name=\"robots\" content=\"noindex\"/>";
- PageTemplates.pageHead(out, "Подписки " + user.UName, head);
+ PageTemplates.pageHead(out, "Подписки " + user.getUName(), head);
PageTemplates.pageNavigation(out, visitor, null);
pageUserColumn(out, sql, user, visitor);
@@ -208,7 +202,7 @@ public class User {
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);
+ stmt.setInt(1, user.getUID());
rs = stmt.executeQuery();
rs.beforeFirst();
int cnt = 0;
@@ -230,8 +224,6 @@ public class User {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
@@ -239,14 +231,13 @@ public class User {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
- pageUserRefCookie(request, response, user.UID);
+ pageUserRefCookie(request, response, user.getUID());
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
String head = "<meta name=\"robots\" content=\"noindex\"/>";
- PageTemplates.pageHead(out, "Читатели " + user.UName, head);
+ PageTemplates.pageHead(out, "Читатели " + user.getUName(), head);
PageTemplates.pageNavigation(out, visitor, null);
pageUserColumn(out, sql, user, visitor);
@@ -257,7 +248,7 @@ public class User {
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);
+ stmt.setInt(1, user.getUID());
rs = stmt.executeQuery();
rs.beforeFirst();
int cnt = 0;
@@ -279,8 +270,6 @@ public class User {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
@@ -298,21 +287,21 @@ public class User {
public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor) {
out.println("<aside id=\"column\">");
- out.println(" <div id=\"ctitle\"><a href=\"./\"><img src=\"//i.juick.com/as/" + user.UID + ".png\" alt=\"\"/>" + user.UName + "</a></div>");
- if (visitor != null && visitor.UID > 0 && visitor.UID != user.UID) {
+ out.println(" <div id=\"ctitle\"><a href=\"./\"><img src=\"//i.juick.com/as/" + user.getUID() + ".png\" alt=\"\"/>" + user.getUName() + "</a></div>");
+ if (visitor != null && visitor.getUID() > 0 && visitor.getUID() != user.getUID()) {
out.println(" <ul id=\"ctoolbar\">");
- if (UserQueries.isSubscribed(sql, visitor.UID, user.UID)) {
- out.println(" <li><a href=\"/post?body=U+%40" + user.UName + "\" title=\"Подписан\"><div style=\"background-position: -48px 0\"></div></a></li>");
+ if (UserQueries.isSubscribed(sql, visitor.getUID(), user.getUID())) {
+ out.println(" <li><a href=\"/post?body=U+%40" + user.getUName() + "\" title=\"Подписан\"><div style=\"background-position: -48px 0\"></div></a></li>");
} else {
- out.println(" <li><a href=\"/post?body=S+%40" + user.UName + "\" title=\"Подписаться\"><div style=\"background-position: -16px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=S+%40" + user.getUName() + "\" title=\"Подписаться\"><div style=\"background-position: -16px 0\"></div></a></li>");
}
- if (UserQueries.isInBL(sql, visitor.UID, user.UID)) {
- out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"Разблокировать\"><div style=\"background-position: -96px 0\"></div></a></li>");
+ if (UserQueries.isInBL(sql, visitor.getUID(), user.getUID())) {
+ out.println(" <li><a href=\"/post?body=BL+%40" + user.getUName() + "\" title=\"Разблокировать\"><div style=\"background-position: -96px 0\"></div></a></li>");
} else {
- out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"Заблокировать\"><div style=\"background-position: -80px 0\"></div></a></li>");
+ out.println(" <li><a href=\"/post?body=BL+%40" + user.getUName() + "\" title=\"Заблокировать\"><div style=\"background-position: -80px 0\"></div></a></li>");
}
- if (!UserQueries.isInBLAny(sql, user.UID, visitor.UID)) {
- out.println(" <li><a href=\"/pm/sent?uname=" + user.UName + "\" title=\"Написать приватное сообщение\"><div style=\"background-position: -112px 0\"></div></a></li>");
+ if (!UserQueries.isInBLAny(sql, user.getUID(), visitor.getUID())) {
+ out.println(" <li><a href=\"/pm/sent?uname=" + user.getUName() + "\" title=\"Написать приватное сообщение\"><div style=\"background-position: -112px 0\"></div></a></li>");
}
out.println(" </ul>");
} else {
@@ -330,13 +319,13 @@ public class User {
out.println(" <p class=\"tags\">" + pageUserTags(sql, user, visitor, 20) + "<a href=\"./tags\" rel=\"nofollow\">...</a></p>");
out.println(" <hr/>");
out.println(" <div id=\"ustats\"><ul>");
- out.println(" <li><a href=\"./friends\">Я читаю: " + UserQueries.getStatsIRead(sql, user.UID) + "</a></li>");
- out.println(" <li><a href=\"./readers\">Мои подписчики: " + UserQueries.getStatsMyReaders(sql, user.UID) + "</a></li>");
- out.println(" <li>Сообщений: " + UserQueries.getStatsMessages(sql, user.UID) + "</li>");
- out.println(" <li>Комментариев: " + UserQueries.getStatsReplies(sql, user.UID) + "</li>");
+ out.println(" <li><a href=\"./friends\">Я читаю: " + UserQueries.getStatsIRead(sql, user.getUID()) + "</a></li>");
+ out.println(" <li><a href=\"./readers\">Мои подписчики: " + UserQueries.getStatsMyReaders(sql, user.getUID()) + "</a></li>");
+ out.println(" <li>Сообщений: " + UserQueries.getStatsMessages(sql, user.getUID()) + "</li>");
+ out.println(" <li>Комментариев: " + UserQueries.getStatsReplies(sql, user.getUID()) + "</li>");
out.println(" </ul>");
- ArrayList<com.juick.User> iread = UserQueries.getUserReadLeastPopular(sql, user.UID, 8);
+ List<com.juick.User> iread = UserQueries.getUserReadLeastPopular(sql, user.getUID(), 8);
if (!iread.isEmpty()) {
out.println("<table class=\"iread\"><tr>");
for (int i = 0; i < iread.size(); i++) {
@@ -344,7 +333,7 @@ public class User {
out.println("</tr><tr>");
}
com.juick.User u = iread.get(i);
- out.println("<td><a href=\"/" + u.UName + "/\"><img src=\"//i.juick.com/a/" + u.UID + ".png\" alt=\"" + u.UName + "\"/></a></td>");
+ out.println("<td><a href=\"/" + u.getUName() + "/\"><img src=\"//i.juick.com/a/" + u.getUID() + ".png\" alt=\"" + u.getUName() + "\"/></a></td>");
}
out.println("</tr></table>");
}
@@ -362,11 +351,11 @@ public class User {
try {
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(1, user.getUID());
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);
+ stmt.setInt(1, user.getUID());
}
rs = stmt.executeQuery();
rs.last();
diff --git a/src/main/java/com/juick/http/www/UserThread.java b/src/main/java/com/juick/http/www/UserThread.java
index 73809f6c..8b6707eb 100644
--- a/src/main/java/com/juick/http/www/UserThread.java
+++ b/src/main/java/com/juick/http/www/UserThread.java
@@ -17,12 +17,15 @@
*/
package com.juick.http.www;
+import com.juick.Message;
+import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -36,7 +39,7 @@ public class UserThread {
protected void doGetThread(Connection sql, HttpServletRequest request, HttpServletResponse response, int MID) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (!MessagesQueries.canViewThread(sql, MID, visitor != null ? visitor.UID : 0)) {
+ if (!MessagesQueries.canViewThread(sql, MID, visitor != null ? visitor.getUID() : 0)) {
response.sendError(403);
return;
}
@@ -49,27 +52,27 @@ public class UserThread {
if (paramView.equals("list")) {
listview = true;
if (visitor != null) {
- UserQueries.setUserOptionInt(sql, visitor.UID, "repliesview", 1);
+ UserQueries.setUserOptionInt(sql, visitor.getUID(), "repliesview", 1);
}
} else if (paramView.equals("tree") && visitor != null) {
- UserQueries.setUserOptionInt(sql, visitor.UID, "repliesview", 0);
+ UserQueries.setUserOptionInt(sql, visitor.getUID(), "repliesview", 0);
}
- } else if (visitor != null && UserQueries.getUserOptionInt(sql, visitor.UID, "repliesview", 0) == 1) {
+ } else if (visitor != null && UserQueries.getUserOptionInt(sql, visitor.getUID(), "repliesview", 0) == 1) {
listview = true;
}
- String title = msg.User.UName + ": " + msg.getTagsString();
+ String title = msg.getUser().getUName() + ": " + msg.getTagsString();
if (visitor == null) {
- User.pageUserRefCookie(request, response, msg.User.UID);
+ User.pageUserRefCookie(request, response, msg.getUser().getUID());
}
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
- String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.User.UName + "\" href=\"//rss.juick.com/" + msg.User.UName + "/blog\"/>";
+ String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getUName() + "\" href=\"//rss.juick.com/" + msg.getUser().getUName() + "/blog\"/>";
if (paramView != null) {
- headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.User.UName + "/" + msg.MID + "\"/>";
+ headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "\"/>";
}
if (msg.Hidden) {
headers += "<meta name=\"robots\" content=\"noindex\"/>";
@@ -85,10 +88,10 @@ public class UserThread {
PageTemplates.pageFooter(request, out, visitor, false);
out.println("<script type='text/javascript'>");
- if (visitor != null && visitor.UID == 1 && msg.User.UID == 1) {
+ if (visitor != null && visitor.getUID() == 1 && msg.getUser().getUID() == 1) {
out.println("var juickDebug=1;");
}
- out.println("var pageMID=" + msg.MID + ";");
+ out.println("var pageMID=" + msg.getMID() + ";");
out.println("initWS();");
out.println("</script>");
@@ -101,7 +104,7 @@ public class UserThread {
public static com.juick.Message printMessage(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor) {
msg.VisitorCanComment = visitor != null;
- ArrayList<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.MID);
+ List<Tag> tags = MessagesQueries.getMessageTags(sql, msg.getMID());
String tagsStr = PageTemplates.formatTags(tags);
if (msg.ReadOnly) {
tagsStr += " *readonly";
@@ -113,9 +116,9 @@ public class UserThread {
String txt;
if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) {
- txt = PageTemplates.formatMessageCode(msg.Text);
+ txt = PageTemplates.formatMessageCode(msg.getText());
} else {
- txt = PageTemplates.formatMessage(msg.Text);
+ txt = PageTemplates.formatMessage(msg.getText());
}
if (!tags.isEmpty()) {
@@ -123,24 +126,24 @@ public class UserThread {
}
out.println("<ul>");
- out.println(" <li id=\"msg-" + msg.MID + "\" class=\"msg msgthread\">");
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
+ out.println(" <li id=\"msg-" + msg.getMID() + "\" class=\"msg msgthread\">");
+ out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></div>");
out.println(" <div class=\"msg-cont\">");
- out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.MID + "); return false\"></a></div>");
- out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tagsStr + "</div>");
+ out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.getMID() + "); return false\"></a></div>");
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:" + tagsStr + "</div>");
out.println(" <div class=\"msg-ts\">" + PageTemplates.formatJSLocalTime(msg.TimestampString) + "</div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");
if (msg.AttachmentType != null) {
- out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.MID + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.MID + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
+ out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.getMID() + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.getMID() + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
}
boolean visitorInBL = false;
if (visitor != null) {
- if (visitor.UID == msg.User.UID) {
+ if (visitor.getUID() == msg.getUser().getUID()) {
msg.VisitorCanComment = true;
} else {
- visitorInBL = UserQueries.isInBL(sql, msg.User.UID, visitor.UID);
+ visitorInBL = UserQueries.isInBL(sql, msg.getUser().getUID(), visitor.getUID());
if (visitorInBL) {
msg.VisitorCanComment = false;
}
@@ -148,12 +151,12 @@ public class UserThread {
}
if (msg.VisitorCanComment) {
- out.println(" <form action=\"/comment\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + msg.MID + "\"/>");
+ out.println(" <form action=\"/comment\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + msg.getMID() + "\"/>");
out.println(" <div class=\"msg-comment\"><div class=\"ta-wrapper\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"Написать комментарий\" onkeypress=\"postformListener(this.form,event)\"></textarea></div></div>");
out.println(" </form>");
}
- ArrayList<String> recomm = MessagesQueries.getMessageRecommendations(sql, msg.MID);
+ List<String> recomm = MessagesQueries.getMessageRecommendations(sql, msg.getMID());
if (!recomm.isEmpty()) {
out.print(" <div class=\"" + (msg.VisitorCanComment ? "msg-recomms" : "msg-comments") + "\">Рекомендовали (" + recomm.size() + "): ");
for (int i = 0; i < recomm.size(); i++) {
@@ -168,19 +171,19 @@ public class UserThread {
out.println(" </li>");
out.println(" <li id=\"mtoolbar\"><ul>");
- out.println(" <li><a href=\"/" + msg.MID + "\"><div style=\"background-position: -64px 0\"></div>" + msg.MID + "</a></li>");
+ out.println(" <li><a href=\"/" + msg.getMID() + "\"><div style=\"background-position: -64px 0\"></div>" + msg.getMID() + "</a></li>");
if (visitor != null) {
- if (visitor.UID != msg.User.UID) {
- if (MessagesQueries.isSubscribed(sql, visitor.UID, msg.MID)) {
- out.println(" <li><a href=\"/post?body=U+%23" + msg.MID + "\"><div style=\"background-position: -48px 0\"></div>Подписан</a></li>");
+ if (visitor.getUID() != msg.getUser().getUID()) {
+ if (MessagesQueries.isSubscribed(sql, visitor.getUID(), msg.getMID())) {
+ out.println(" <li><a href=\"/post?body=U+%23" + msg.getMID() + "\"><div style=\"background-position: -48px 0\"></div>Подписан</a></li>");
} else {
- out.println(" <li><a href=\"/post?body=S+%23" + msg.MID + "\"><div style=\"background-position: -16px 0\"></div>Подписаться</a></li>");
+ out.println(" <li><a href=\"/post?body=S+%23" + msg.getMID() + "\"><div style=\"background-position: -16px 0\"></div>Подписаться</a></li>");
}
if (!visitorInBL) {
- out.println(" <li><a href=\"/post?body=%21+%23" + msg.MID + "\"><div style=\"background-position: -32px 0\"></div>Рекомендовать</a></li>");
+ out.println(" <li><a href=\"/post?body=%21+%23" + msg.getMID() + "\"><div style=\"background-position: -32px 0\"></div>Рекомендовать</a></li>");
}
} else {
- out.println(" <li><a href=\"/post?body=D+%23" + msg.MID + "\"><div style=\"background-position: 0\"></div>Удалить</a></li>");
+ out.println(" <li><a href=\"/post?body=D+%23" + msg.getMID() + "\"><div style=\"background-position: 0\"></div>Удалить</a></li>");
}
}
out.println(" </ul></li>");
@@ -190,18 +193,18 @@ public class UserThread {
}
public static void printReplies(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor, boolean listview) {
- ArrayList<com.juick.Message> replies = MessagesQueries.getReplies(sql, msg.MID);
+ List<com.juick.Message> replies = MessagesQueries.getReplies(sql, msg.getMID());
- ArrayList<Integer> blUIDs = new ArrayList<Integer>();
+ List<Integer> blUIDs = new ArrayList<Integer>();
for (int i = 0; i < replies.size(); i++) {
com.juick.Message reply = replies.get(i);
- if (reply.User.UID != msg.User.UID && !blUIDs.contains(reply.User.UID)) {
- blUIDs.add(reply.User.UID);
+ if (reply.getUser().getUID() != msg.getUser().getUID() && !blUIDs.contains(reply.getUser().getUID())) {
+ blUIDs.add(reply.getUser().getUID());
}
if (reply.ReplyTo > 0) {
boolean added = false;
for (int n = 0; n < replies.size(); n++) {
- if (replies.get(n).RID == reply.ReplyTo) {
+ if (replies.get(n).getRID() == reply.ReplyTo) {
replies.get(n).childs.add(reply);
added = true;
break;
@@ -214,19 +217,18 @@ public class UserThread {
}
if (!replies.isEmpty()) {
- if (visitor != null && msg.User.UID == visitor.UID) {
- for (int i = 0; i < replies.size(); i++) {
- replies.get(i).VisitorCanComment = true;
+ if (visitor != null && msg.getUser().getUID() == visitor.getUID()) {
+ for (Message reply : replies) {
+ reply.VisitorCanComment = true;
}
} else if (visitor != null && msg.VisitorCanComment) {
- blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
- for (int i = 0; i < replies.size(); i++) {
- com.juick.Message reply = replies.get(i);
- reply.VisitorCanComment = reply.User.UID == visitor.UID || !blUIDs.contains(reply.User.UID);
+ blUIDs = UserQueries.checkBL(sql, visitor.getUID(), blUIDs);
+ for (Message reply : replies) {
+ reply.VisitorCanComment = reply.getUser().getUID() == visitor.getUID() || !blUIDs.contains(reply.getUser().getUID());
}
} else {
- for (int i = 0; i < replies.size(); i++) {
- replies.get(i).VisitorCanComment = false;
+ for (Message reply : replies) {
+ reply.VisitorCanComment = false;
}
}
@@ -266,14 +268,14 @@ public class UserThread {
PageTemplates.pageYandexAd728(out, 1);
}
- for (int i = 0; i < replies.size(); i++) {
- replies.get(i).cleanupChilds();
+ for (Message reply : replies) {
+ reply.cleanupChilds();
}
replies.clear();
}
}
- public static void printTree(PrintWriter out, ArrayList<com.juick.Message> replies, com.juick.User visitor, int ReplyTo, int margin, boolean hidden) {
+ public static void printTree(PrintWriter out, List<com.juick.Message> replies, com.juick.User visitor, int ReplyTo, int margin, boolean hidden) {
if (margin > 240) {
margin = 240;
}
@@ -282,7 +284,7 @@ public class UserThread {
com.juick.Message msg = replies.get(i);
if (msg.ReplyTo == ReplyTo) {
- out.print(" <li id=\"" + msg.RID + "\" class=\"msg\" style=\"");
+ out.print(" <li id=\"" + msg.getRID() + "\" class=\"msg\" style=\"");
if (margin > 0) {
out.print("margin-left: " + margin + "px;");
}
@@ -290,25 +292,25 @@ public class UserThread {
out.print("display:none;");
}
out.println("\">");
- if (msg.User.Banned == false) {
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
+ if (!msg.getUser().Banned) {
+ out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></div>");
} else {
out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/av-96.png\"/></div>");
}
out.println(" <div class=\"msg-cont\">");
- out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.MID + "," + msg.RID + "); return false\"></a></div>");
- if (msg.User.Banned == false) {
- out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
+ out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.getMID() + "," + msg.getRID() + "); return false\"></a></div>");
+ if (!msg.getUser().Banned) {
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
} else {
out.println(" <div class=\"msg-header\">[удалено]:</div>");
}
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
- out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
- out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.MID + "-" + msg.RID + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.MID + "-" + msg.RID + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
+ 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>");
}
if (msg.VisitorCanComment) {
- out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">Ответить</a></div>");
+ out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return showCommentForm(" + msg.getMID() + "," + msg.getRID() + ")\">Ответить</a></div>");
out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
} else if (visitor == null) {
out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return openDialogLogin()\">Ответить</a></div>");
@@ -316,49 +318,47 @@ public class UserThread {
int childs = msg.getChildsCount();
if (ReplyTo == 0 && childs > 1 && replies.size() > 10) {
- out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.RID + ")\">" + PageTemplates.formatReplies(childs) + "</a></div>");
+ out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.getRID() + ")\">" + PageTemplates.formatReplies(childs) + "</a></div>");
}
out.println(" </div>");
out.println(" </li>");
if (ReplyTo == 0 && childs > 1 && replies.size() > 10) {
- printTree(out, msg.childs, visitor, msg.RID, margin + 20, true);
+ printTree(out, msg.childs, visitor, msg.getRID(), margin + 20, true);
} else if (childs > 0) {
- printTree(out, msg.childs, visitor, msg.RID, margin + 20, hidden);
+ printTree(out, msg.childs, visitor, msg.getRID(), margin + 20, hidden);
}
}
}
}
- public static void printList(PrintWriter out, ArrayList<com.juick.Message> replies, com.juick.User visitor) {
- for (int i = 0; i < replies.size(); i++) {
- com.juick.Message msg = replies.get(i);
-
- out.print(" <li id=\"" + msg.RID + "\" class=\"msg\">");
- if (msg.User.Banned == false) {
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
+ public static void printList(PrintWriter out, List<com.juick.Message> replies, com.juick.User visitor) {
+ for (Message msg : replies) {
+ out.print(" <li id=\"" + msg.getRID() + "\" class=\"msg\">");
+ if (!msg.getUser().Banned) {
+ out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getUName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUID() + ".png\" alt=\"" + msg.getUser().getUName() + "\"/></a></div>");
} else {
out.println(" <div class=\"msg-avatar\"><img src=\"//i.juick.com/av-96.png\"/></div>");
}
out.println(" <div class=\"msg-cont\">");
- out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.MID + "," + msg.RID + "); return false\"></a></div>");
- if (msg.User.Banned == false) {
- out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:</div>");
+ out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.getMID() + "," + msg.getRID() + "); return false\"></a></div>");
+ if (!msg.getUser().Banned) {
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.getUser().getUName() + "/\">@" + msg.getUser().getUName() + "</a>:</div>");
} else {
out.println(" <div class=\"msg-header\">[удалено]:</div>");
}
- out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.MID + "#" + msg.RID + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
- out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>");
+ out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getMID() + "#" + msg.getRID() + "\" title=\"" + msg.TimestampString + " GMT\">" + PageTemplates.formatDate(msg.TimeAgo, msg.TimestampString) + "</a></div>");
+ out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.getText()) + "</div>");
if (msg.AttachmentType != null) {
- out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/p/" + msg.MID + "-" + msg.RID + "." + msg.AttachmentType + "\"><img src=\"//i.juick.com/photos-512/" + msg.MID + "-" + msg.RID + "." + msg.AttachmentType + "\" alt=\"\"/></a></div>");
+ 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>");
}
- out.print(" <div class=\"msg-links\">/" + msg.RID);
+ out.print(" <div class=\"msg-links\">/" + msg.getRID());
if (msg.ReplyTo > 0) {
out.print(" в ответ на <a href=\"#" + msg.ReplyTo + "\">/" + msg.ReplyTo + "</a>");
}
if (msg.VisitorCanComment) {
- out.println(" &#183; <a href=\"#\" onclick=\"return showCommentForm(" + msg.MID + "," + msg.RID + ")\">Ответить</a></div>");
+ out.println(" &#183; <a href=\"#\" onclick=\"return showCommentForm(" + msg.getMID() + "," + msg.getRID() + ")\">Ответить</a></div>");
out.println(" <div class=\"msg-comment\" style=\"display: none\"></div>");
} else if (visitor == null) {
out.println(" <div class=\"msg-links\"><a href=\"#\" onclick=\"return openDialogLogin()\">Ответить</a></div>");
diff --git a/src/main/java/com/juick/http/www/Utils.java b/src/main/java/com/juick/http/www/Utils.java
index 21577a40..931e2c21 100644
--- a/src/main/java/com/juick/http/www/Utils.java
+++ b/src/main/java/com/juick/http/www/Utils.java
@@ -82,7 +82,7 @@ public class Utils {
if (hash != null) {
com.juick.User visitor = com.juick.server.UserQueries.getUserByHash(sql, hash);
if (response != null && visitor != null) {
- response.setHeader("X-Username", visitor.UName);
+ response.setHeader("X-Username", visitor.getUName());
}
return visitor;
} else {
diff --git a/src/main/java/com/juick/xmpp/extensions/JuickMessage.java b/src/main/java/com/juick/xmpp/extensions/JuickMessage.java
new file mode 100644
index 00000000..53dd6deb
--- /dev/null
+++ b/src/main/java/com/juick/xmpp/extensions/JuickMessage.java
@@ -0,0 +1,172 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick.xmpp.extensions;
+
+import com.juick.xmpp.utils.XmlUtils;
+import com.juick.xmpp.*;
+import java.io.IOException;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class JuickMessage extends com.juick.Message implements StanzaChild {
+
+ public final static String XMLNS = "http://juick.com/message";
+ public final static String TagName = "juick";
+
+ public JuickMessage() {
+ }
+
+ public JuickMessage(com.juick.Message msg) {
+ super(msg);
+ }
+
+ @Override
+ public String getXMLNS() {
+ return XMLNS;
+ }
+
+ @Override
+ public JuickMessage parse(XmlPullParser parser) throws XmlPullParserException, IOException {
+ JuickMessage jmsg = new JuickMessage();
+
+ final String sMID = parser.getAttributeValue(null, "mid");
+ if (sMID != null) {
+ jmsg.setMID(Integer.parseInt(sMID));
+ }
+ final String sRID = parser.getAttributeValue(null, "rid");
+ if (sRID != null) {
+ jmsg.setRID(Integer.parseInt(sRID));
+ }
+ final String sReplyTo = parser.getAttributeValue(null, "replyto");
+ if (sReplyTo != null) {
+ jmsg.ReplyTo = Integer.parseInt(sReplyTo);
+ }
+ final String sPrivacy = parser.getAttributeValue(null, "privacy");
+ if (sPrivacy != null) {
+ jmsg.Privacy = Integer.parseInt(sPrivacy);
+ }
+ final String sFriendsOnly = parser.getAttributeValue(null, "friendsonly");
+ if (sFriendsOnly != null) {
+ jmsg.FriendsOnly = true;
+ }
+ final String sReadOnly = parser.getAttributeValue(null, "readonly");
+ if (sReadOnly != null) {
+ jmsg.ReadOnly = true;
+ }
+ jmsg.TimestampString = parser.getAttributeValue(null, "ts");
+ jmsg.AttachmentType = parser.getAttributeValue(null, "attach");
+
+ while (parser.next() == XmlPullParser.START_TAG) {
+ final String tag = parser.getName();
+ final String xmlns = parser.getNamespace();
+ if (tag.equals("body")) {
+ jmsg.setText(XmlUtils.getTagText(parser));
+ } else if (tag.equals(JuickUser.TagName) && xmlns != null && xmlns.equals(JuickUser.XMLNS)) {
+ jmsg.setUser(new JuickUser().parse(parser));
+ } else if (tag.equals("tag")) {
+ jmsg.Tags.add(XmlUtils.getTagText(parser));
+ } else {
+ XmlUtils.skip(parser);
+ }
+ }
+ return jmsg;
+ }
+
+ @Override
+ public String toString() {
+ String ret = "";
+
+ ret = "<" + TagName + " xmlns=\"" + XMLNS + "\"";
+ if (getMID() > 0) {
+ ret += " mid=\"" + getMID() + "\"";
+ }
+ if (getRID() > 0) {
+ ret += " rid=\"" + getRID() + "\"";
+ }
+ if (ReplyTo > 0) {
+ ret += " replyto=\"" + ReplyTo + "\"";
+ }
+ ret += " privacy=\"" + Privacy + "\"";
+ if (FriendsOnly) {
+ ret += " friendsonly=\"1\"";
+ }
+ if (ReadOnly) {
+ ret += " readonly=\"1\"";
+ }
+ if (TimestampString != null) {
+ ret += " ts=\"" + TimestampString + "\"";
+ }
+ if (AttachmentType != null) {
+ ret += " attach=\"" + AttachmentType + "\"";
+ }
+ ret += ">";
+ if (getUser() != null) {
+ ret += JuickUser.toString(getUser());
+ }
+ if (getText() != null) {
+ ret += "<body>" + XmlUtils.escape(getText()) + "</body>";
+ }
+ if (!Tags.isEmpty()) {
+ for (int i = 0; i < Tags.size(); i++) {
+ ret += "<tag>" + XmlUtils.escape(Tags.get(i)) + "</tag>";
+ }
+ }
+ ret += "</" + TagName + ">";
+
+ return ret;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof JuickMessage)) {
+ return false;
+ }
+ JuickMessage jmsg = (JuickMessage) obj;
+ return (this.getMID() == jmsg.getMID() && this.getRID() == jmsg.getRID());
+ }
+
+ @Override
+ public int compareTo(Object obj) throws ClassCastException {
+ if (!(obj instanceof JuickMessage)) {
+ throw new ClassCastException();
+ }
+ JuickMessage jmsg = (JuickMessage) obj;
+
+ if (this.getMID() != jmsg.getMID()) {
+ if (this.getMID() > jmsg.getMID()) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ if (this.getRID() != jmsg.getRID()) {
+ if (this.getRID() < jmsg.getRID()) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+}
diff --git a/src/main/java/com/juick/xmpp/extensions/JuickUser.java b/src/main/java/com/juick/xmpp/extensions/JuickUser.java
new file mode 100644
index 00000000..edc6749a
--- /dev/null
+++ b/src/main/java/com/juick/xmpp/extensions/JuickUser.java
@@ -0,0 +1,75 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick.xmpp.extensions;
+
+import com.juick.xmpp.utils.XmlUtils;
+import com.juick.xmpp.*;
+import java.io.IOException;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class JuickUser extends com.juick.User implements StanzaChild {
+
+ public final static String XMLNS = "http://juick.com/user";
+ public final static String TagName = "user";
+
+ public JuickUser() {
+ }
+
+ public JuickUser(com.juick.User user) {
+ super(user);
+ }
+
+ @Override
+ public String getXMLNS() {
+ return XMLNS;
+ }
+
+ @Override
+ public JuickUser parse(final XmlPullParser parser) throws XmlPullParserException, IOException {
+ JuickUser juser = new JuickUser();
+ String strUID = parser.getAttributeValue(null, "uid");
+ if (strUID != null) {
+ juser.setUID(Integer.parseInt(strUID));
+ }
+ juser.setUName(parser.getAttributeValue(null, "uname"));
+ XmlUtils.skip(parser);
+ return juser;
+ }
+
+ public static String toString(com.juick.User user) {
+ String str = "<" + TagName + " xmlns='" + XMLNS + "'";
+ if (user.getUID() > 0) {
+ str += " uid='" + user.getUID() + "'";
+ }
+ if (user.getUName() != null && user.getUName().length() > 0) {
+ str += " uname='" + XmlUtils.escape(user.getUName()) + "'";
+ }
+ str += "/>";
+ return str;
+ }
+
+ @Override
+ public String toString() {
+ return toString(this);
+ }
+}