aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick/api')
-rw-r--r--juick-api/src/main/java/com/juick/api/Main.java7
-rw-r--r--juick-api/src/main/java/com/juick/api/Messages.java15
-rw-r--r--juick-api/src/main/java/com/juick/api/Utils.java11
3 files changed, 12 insertions, 21 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java
index 47c4e448..cad991ef 100644
--- a/juick-api/src/main/java/com/juick/api/Main.java
+++ b/juick-api/src/main/java/com/juick/api/Main.java
@@ -32,6 +32,7 @@ import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
@@ -223,7 +224,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
}
switch (uri) {
case "/post":
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
if (mid == 0) {
doPostMessage(jdbc, request, response, xmpp, vuid);
} else {
@@ -356,7 +357,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid)
throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
return;
@@ -367,7 +368,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
return;
}
- int rid = Utils.parseInt(request.getParameter("rid"), 0);
+ int rid = NumberUtils.toInt(request.getParameter("rid"), 0);
com.juick.Message reply = null;
if (rid > 0) {
reply = MessagesQueries.getReply(sql, mid, rid);
diff --git a/juick-api/src/main/java/com/juick/api/Messages.java b/juick-api/src/main/java/com/juick/api/Messages.java
index e461ac07..b1c875d2 100644
--- a/juick-api/src/main/java/com/juick/api/Messages.java
+++ b/juick-api/src/main/java/com/juick/api/Messages.java
@@ -11,6 +11,7 @@ import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Stream;
import com.juick.xmpp.extensions.JuickMessage;
+import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
@@ -55,7 +56,7 @@ public class Messages {
public void doGetHome(HttpServletRequest request,
HttpServletResponse response, int vuid)
throws ServletException, IOException {
- int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
+ int before_mid = NumberUtils.toInt(request.getParameter("before_mid"), 0);
List<Integer> mids = MessagesQueries.getMyFeed(sql, vuid, before_mid);
feedMessages(request, response, MessagesQueries.getMessages(sql, mids));
}
@@ -63,7 +64,7 @@ public class Messages {
public void doGet(HttpServletRequest request,
HttpServletResponse response, int vuid)
throws ServletException, IOException {
- int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
+ int before_mid = NumberUtils.toInt(request.getParameter("before_mid"), 0);
String uname = request.getParameter("uname");
String popular = request.getParameter("popular");
String media = request.getParameter("media");
@@ -107,7 +108,7 @@ public class Messages {
}
public void doThreadGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
com.juick.Message msg = MessagesQueries.getMessage(sql, mid);
if (msg != null) {
if (!MessagesQueries.canViewThread(sql, mid, vuid)) {
@@ -125,7 +126,7 @@ public class Messages {
public void doGetRecommended(HttpServletRequest request,
HttpServletResponse response, int vuid)
throws ServletException, IOException {
- int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0);
+ int before_mid = NumberUtils.toInt(request.getParameter("before_mid"), 0);
List<Integer> mids = MessagesQueries.getUserRecommendations(sql, vuid, before_mid);
if (mids != null && !mids.isEmpty()) {
@@ -144,7 +145,7 @@ public class Messages {
public void doSetPrivacy(HttpServletRequest request,
HttpServletResponse response, Stream xmpp, int vuid)
throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
com.juick.User user = MessagesQueries.getMessageAuthor(sql, mid);
if (user != null && user.getUID() == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) {
Main.replyJSON(request, response, "{\"status\":\"ok\"}");
@@ -156,8 +157,8 @@ public class Messages {
public void doSetPopular(HttpServletRequest request,
HttpServletResponse response, Stream xmpp)
throws ServletException, IOException {
- int mid = Utils.parseInt(request.getParameter("mid"), 0);
- int popular = Utils.parseInt(request.getParameter("popular"), 0);
+ int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
+ int popular = NumberUtils.toInt(request.getParameter("popular"), 0);
if (mid > 0) {
boolean ret = MessagesQueries.setMessagePopular(sql, mid, popular);
diff --git a/juick-api/src/main/java/com/juick/api/Utils.java b/juick-api/src/main/java/com/juick/api/Utils.java
index 0ce69e4b..c324a2df 100644
--- a/juick-api/src/main/java/com/juick/api/Utils.java
+++ b/juick-api/src/main/java/com/juick/api/Utils.java
@@ -54,17 +54,6 @@ public class Utils {
}
return 0;
}
-
- public static int parseInt(String str, int def) {
- int ret = def;
- if (str != null) {
- try {
- ret = Integer.parseInt(str);
- } catch (Exception e) {
- }
- }
- return ret;
- }
public static String getPartFilename(Part part) {
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")) {