From 300a0439b2a6e26d9025247ef780c886616d4ae1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 16 Dec 2016 15:41:14 +0300 Subject: CharEncoding.UTF_8 --- juick-www/src/main/java/com/juick/www/Discover.java | 9 +++++---- juick-www/src/main/java/com/juick/www/FacebookLogin.java | 5 +++-- juick-www/src/main/java/com/juick/www/Home.java | 3 ++- juick-www/src/main/java/com/juick/www/Main.java | 7 ++++--- juick-www/src/main/java/com/juick/www/NewMessage.java | 11 ++++++----- juick-www/src/main/java/com/juick/www/PageTemplates.java | 3 ++- juick-www/src/main/java/com/juick/www/User.java | 11 ++++++----- juick-www/src/main/java/com/juick/www/VKontakteLogin.java | 5 +++-- 8 files changed, 31 insertions(+), 23 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www') diff --git a/juick-www/src/main/java/com/juick/www/Discover.java b/juick-www/src/main/java/com/juick/www/Discover.java index 860ad893..9cfad874 100644 --- a/juick-www/src/main/java/com/juick/www/Discover.java +++ b/juick-www/src/main/java/com/juick/www/Discover.java @@ -20,6 +20,7 @@ package com.juick.www; import com.juick.server.AdsQueries; import com.juick.server.MessagesQueries; import com.juick.server.TagQueries; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.springframework.jdbc.core.JdbcTemplate; @@ -41,21 +42,21 @@ public class Discover { protected void doGet(JdbcTemplate sql, JdbcTemplate sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - String paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8"); + String paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), CharEncoding.UTF_8); com.juick.Tag paramTag = TagQueries.getTag(sql, paramTagStr, false); if (paramTag == null) { Errors.doGet404(sql, request, response); return; } else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) { com.juick.Tag synTag = TagQueries.getTag(sql, paramTag.SynonymID); - String url = "/tag/" + URLEncoder.encode(synTag.getName(), "UTF-8"); + String url = "/tag/" + URLEncoder.encode(synTag.getName(), CharEncoding.UTF_8); if (request.getQueryString() != null) { url += "?" + request.getQueryString(); } Utils.sendPermanentRedirect(response, url); return; } else if (!paramTag.getName().equals(paramTagStr)) { - String url = "/tag/" + URLEncoder.encode(paramTag.getName(), "UTF-8"); + String url = "/tag/" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8); if (request.getQueryString() != null) { url += "?" + request.getQueryString(); } @@ -104,7 +105,7 @@ public class Discover { } if (mids.size() >= 20) { - String nextpage = "/tag/" + URLEncoder.encode(paramTag.getName(), "UTF-8") + "?before=" + mids.get(mids.size() - 1); + String nextpage = "/tag/" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8) + "?before=" + mids.get(mids.size() - 1); out.println("
"); } diff --git a/juick-www/src/main/java/com/juick/www/FacebookLogin.java b/juick-www/src/main/java/com/juick/www/FacebookLogin.java index e9c4b786..1dcbb39f 100644 --- a/juick-www/src/main/java/com/juick/www/FacebookLogin.java +++ b/juick-www/src/main/java/com/juick/www/FacebookLogin.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; import com.juick.www.facebook.Graph; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; @@ -69,7 +70,7 @@ public class FacebookLogin { response.addCookie(c); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); - response.setHeader("Location", "https://www.facebook.com/dialog/oauth?scope=publish_stream&client_id=" + FACEBOOK_APPID + "&redirect_uri=" + URLEncoder.encode(FACEBOOK_REDIRECT, "utf-8") + "&state=" + fbstate); + response.setHeader("Location", "https://www.facebook.com/dialog/oauth?scope=publish_stream&client_id=" + FACEBOOK_APPID + "&redirect_uri=" + URLEncoder.encode(FACEBOOK_REDIRECT, CharEncoding.UTF_8) + "&state=" + fbstate); return; } @@ -83,7 +84,7 @@ public class FacebookLogin { response.addCookie(c); } - String token = Utils.fetchURL("https://graph.facebook.com/oauth/access_token?client_id=" + FACEBOOK_APPID + "&redirect_uri=" + URLEncoder.encode(FACEBOOK_REDIRECT, "utf-8") + "&client_secret=" + FACEBOOK_SECRET + "&code=" + URLEncoder.encode(code, "utf-8")); + String token = Utils.fetchURL("https://graph.facebook.com/oauth/access_token?client_id=" + FACEBOOK_APPID + "&redirect_uri=" + URLEncoder.encode(FACEBOOK_REDIRECT, CharEncoding.UTF_8) + "&client_secret=" + FACEBOOK_SECRET + "&code=" + URLEncoder.encode(code, CharEncoding.UTF_8)); if (token == null || token.isEmpty() || !token.startsWith("access_token=")) { logger.error("FACEBOOK TOKEN ERROR: {}", token); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); diff --git a/juick-www/src/main/java/com/juick/www/Home.java b/juick-www/src/main/java/com/juick/www/Home.java index 870c2d55..6bad083c 100644 --- a/juick-www/src/main/java/com/juick/www/Home.java +++ b/juick-www/src/main/java/com/juick/www/Home.java @@ -19,6 +19,7 @@ package com.juick.www; import com.juick.server.AdsQueries; import com.juick.server.MessagesQueries; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.jdbc.core.JdbcTemplate; @@ -148,7 +149,7 @@ public class Home { nextpage += "&show=" + paramShow; } if (paramSearch != null) { - nextpage += "&search=" + URLEncoder.encode(paramSearch, "UTF-8"); + nextpage += "&search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8); } out.println(""); diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index 27ecf3ec..077a3e32 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -22,6 +22,7 @@ import com.juick.server.UserQueries; import com.mitchellbosecke.pebble.error.PebbleException; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.jdbc.core.JdbcTemplate; import rocks.xmpp.addr.Jid; @@ -147,14 +148,14 @@ public class Main extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(CharEncoding.UTF_8); } String uri = request.getRequestURI(); if (uri.equals("/")) { String tag = request.getParameter("tag"); if (tag != null) { - Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, "UTF-8")); + Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, CharEncoding.UTF_8)); } else { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); home.doGet(sql, sqlSearch, request, response, visitor); @@ -323,7 +324,7 @@ public class Main extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getCharacterEncoding() == null) { - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(CharEncoding.UTF_8); } String uri = request.getRequestURI(); diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java index 60ac08de..de6d8038 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -21,6 +21,7 @@ import com.juick.Tag; import com.juick.server.*; import com.juick.server.helpers.TagStats; import net.coobird.thumbnailator.Thumbnails; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; @@ -127,7 +128,7 @@ public class NewMessage { String taglink = ""; try { taglink = "" + StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()) + ""; } catch (UnsupportedEncodingException e) { } @@ -240,21 +241,21 @@ public class NewMessage { tagscomma += jmsg.getTags().get(i); } - String url = URLEncoder.encode("http://juick.com/" + mid, "utf-8"); + String url = URLEncoder.encode("http://juick.com/" + mid, CharEncoding.UTF_8); String sharetwi = hashtags + " " + body; if (sharetwi.length() > 115) { sharetwi = sharetwi.substring(0, 114) + "…"; } sharetwi += " http://juick.com/" + mid; - String sharelj = URLEncoder.encode(body + "\n", "utf-8") + url; + String sharelj = URLEncoder.encode(body + "\n", CharEncoding.UTF_8) + url; out.println("Поделитесь своим новым постом в социальных сетях:
"); if (CrosspostQueries.getTwitterTokens(sql, visitor.getUid()).isPresent()) { - out.println(" "); + out.println(" "); } - out.println(" "); + out.println(" "); out.println(" "); if (CrosspostQueries.getFacebookToken(sql, visitor.getUid()).isPresent()) { out.println(" "); diff --git a/juick-www/src/main/java/com/juick/www/PageTemplates.java b/juick-www/src/main/java/com/juick/www/PageTemplates.java index 72d58e70..068da3c1 100644 --- a/juick-www/src/main/java/com/juick/www/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java @@ -23,6 +23,7 @@ import com.juick.server.TagQueries; import com.juick.server.UserQueries; import com.juick.server.helpers.TagStats; import com.juick.util.MessageUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,7 +191,7 @@ public class PageTemplates { for (TagStats tag : tags) { String tagName = StringEscapeUtils.escapeHtml4(tag.getTag().getName()); try { - ret += "← Все записи с тегом " + + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8) + "\">← Все записи с тегом " + StringEscapeUtils.escapeHtml4(paramTag.getName()) + ""); } @@ -145,10 +146,10 @@ public class User { nextpage += "&show=" + paramShow; } if (paramTag != null) { - nextpage += "&tag=" + URLEncoder.encode(paramTag.getName(), "UTF-8"); + nextpage += "&tag=" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8); } if (paramSearch != null) { - nextpage += "&search=" + URLEncoder.encode(paramSearch, "UTF-8"); + nextpage += "&search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8); } out.println(""); } @@ -332,7 +333,7 @@ public class User { for (int i = 0; i < count; i++) { String tag = StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()); try { - tag = "" + tag + ""; } catch (UnsupportedEncodingException e) { } diff --git a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java index 6b1d4571..92b22805 100644 --- a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java +++ b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; import com.juick.www.vk.Token; import com.juick.www.vk.UsersResponse; +import org.apache.commons.lang3.CharEncoding; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; @@ -57,12 +58,12 @@ public class VKontakteLogin { String code = request.getParameter("code"); if (code == null || code.equals("")) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); - response.setHeader("Location", "https://oauth.vk.com/authorize?client_id=" + VK_APPID + "&redirect_uri=" + URLEncoder.encode(VK_REDIRECT, "utf-8") + "&scope=friends,wall,offline&response_type=code"); + response.setHeader("Location", "https://oauth.vk.com/authorize?client_id=" + VK_APPID + "&redirect_uri=" + URLEncoder.encode(VK_REDIRECT, CharEncoding.UTF_8) + "&scope=friends,wall,offline&response_type=code"); return; } - String tokenjson = Utils.fetchURL("https://oauth.vk.com/access_token?client_id=" + VK_APPID + "&redirect_uri=" + URLEncoder.encode(VK_REDIRECT, "utf-8") + "&client_secret=" + VK_SECRET + "&code=" + URLEncoder.encode(code, "utf-8")); + String tokenjson = Utils.fetchURL("https://oauth.vk.com/access_token?client_id=" + VK_APPID + "&redirect_uri=" + URLEncoder.encode(VK_REDIRECT, CharEncoding.UTF_8) + "&client_secret=" + VK_SECRET + "&code=" + URLEncoder.encode(code, CharEncoding.UTF_8)); if (tokenjson == null || tokenjson.isEmpty()) { logger.error("VK TOKEN EMPTY"); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); -- cgit v1.2.3