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 --- .../main/java/com/juick/api/configuration/ApiInitializer.java | 4 ++-- .../src/main/java/com/juick/components/Crosspost.java | 9 +++++---- .../juick/components/configuration/CrosspostInitializer.java | 5 ++--- .../components/configuration/NotificationsInitializer.java | 4 ++-- .../main/java/com/juick/rss/configuration/RssInitializer.java | 4 ++-- .../java/com/juick/www/configuration/WebAppConfiguration.java | 3 ++- .../main/java/com/juick/www/configuration/WwwInitializer.java | 3 ++- .../com/juick/www/configuration/WwwServletConfiguration.java | 5 +++-- .../main/java/com/juick/www/controllers/IndexController.java | 3 ++- .../main/java/com/juick/www/controllers/TagController.java | 7 ++++--- juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java | 3 ++- .../java/com/juick/ws/configuration/WebsocketInitializer.java | 3 ++- 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 +++-- .../com/juick/components/configuration/BotInitializer.java | 4 ++-- .../components/configuration/FileTransferInitializer.java | 4 ++-- .../com/juick/components/configuration/XmppInitializer.java | 5 ++--- src/test/java/com/juick/rss/LegacyRSS.java | 3 ++- src/test/java/com/juick/tests/MessageTests.java | 3 ++- 25 files changed, 71 insertions(+), 55 deletions(-) diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java index 63ba52e8..41fe8b2d 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java @@ -1,7 +1,7 @@ package com.juick.api.configuration; import com.juick.configuration.DataConfiguration; -import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -29,7 +29,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Filter[] getServletFilters() { - return new Filter[]{new CharacterEncodingFilter("UTF-8")}; + return new Filter[]{new CharacterEncodingFilter(CharEncoding.UTF_8)}; } @Override diff --git a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java index 6daa8ddd..5e28c71e 100644 --- a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java +++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java @@ -21,6 +21,7 @@ import com.juick.Tag; import com.juick.service.CrosspostService; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; @@ -83,7 +84,7 @@ public class Crosspost implements AutoCloseable { public static String percentEncode(final String s) { String ret = ""; try { - ret = URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); + ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (UnsupportedEncodingException e) { } return ret; @@ -136,9 +137,9 @@ public class Crosspost implements AutoCloseable { boolean ret = false; try { String body = "access_token=" - + URLEncoder.encode(token, "UTF-8") + + URLEncoder.encode(token, CharEncoding.UTF_8) + "&message=" - + URLEncoder.encode(status, "UTF-8") + + URLEncoder.encode(status, CharEncoding.UTF_8) + "&link=http%3A%2F%2Fjuick.com%2F" + jmsg.getMid(); @@ -177,7 +178,7 @@ public class Crosspost implements AutoCloseable { boolean ret = false; try { - String body = "owner_id=" + tokens.getLeft() + "&access_token=" + URLEncoder.encode(tokens.getRight(), "UTF-8") + "&from_group=1&message=" + URLEncoder.encode(status, "UTF-8"); + String body = "owner_id=" + tokens.getLeft() + "&access_token=" + URLEncoder.encode(tokens.getRight(), CharEncoding.UTF_8) + "&from_group=1&message=" + URLEncoder.encode(status, CharEncoding.UTF_8); HttpsURLConnection conn = (HttpsURLConnection) new URL(VKURL).openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java index baedfa29..d486e201 100644 --- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java +++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java @@ -1,6 +1,7 @@ package com.juick.components.configuration; import com.juick.configuration.DataConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -28,9 +29,7 @@ public class CrosspostInitializer extends AbstractAnnotationConfigDispatcherServ @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); - + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java index ddd734d1..617f8686 100644 --- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java +++ b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java @@ -1,5 +1,6 @@ package com.juick.components.configuration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -27,8 +28,7 @@ public class NotificationsInitializer extends AbstractAnnotationConfigDispatcher @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/juick-rss/src/main/java/com/juick/rss/configuration/RssInitializer.java b/juick-rss/src/main/java/com/juick/rss/configuration/RssInitializer.java index a66fcca7..2dd6d117 100644 --- a/juick-rss/src/main/java/com/juick/rss/configuration/RssInitializer.java +++ b/juick-rss/src/main/java/com/juick/rss/configuration/RssInitializer.java @@ -1,6 +1,7 @@ package com.juick.rss.configuration; import com.juick.configuration.DataConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -28,8 +29,7 @@ public class RssInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java index 28a0f29a..4482dce1 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java @@ -2,6 +2,7 @@ package com.juick.www.configuration; import com.juick.www.HelpService; import com.juick.www.WebApp; +import org.apache.commons.lang3.CharEncoding; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.guava.GuavaCacheManager; import org.springframework.cache.interceptor.KeyGenerator; @@ -29,7 +30,7 @@ public class WebAppConfiguration { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasenames("messages", "errors"); - messageSource.setDefaultEncoding("UTF-8"); + messageSource.setDefaultEncoding(CharEncoding.UTF_8); messageSource.setFallbackToSystemLocale(false); messageSource.setUseCodeAsDefaultMessage(true); diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java index edb9a9fc..33687983 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java @@ -2,6 +2,7 @@ package com.juick.www.configuration; import com.juick.configuration.DataConfiguration; import com.juick.configuration.SearchConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -43,7 +44,7 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni super.onStartup(servletContext); FilterRegistration.Dynamic registration = servletContext.addFilter( - "encodingFilter", new CharacterEncodingFilter("UTF-8", true)); + "encodingFilter", new CharacterEncodingFilter(CharEncoding.UTF_8, true)); registration.addMappingForUrlPatterns(null, true, "/*"); } diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 15f85c9a..5cd251e6 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.www.formatter.SpringDateFormatter; import nz.net.ultraq.thymeleaf.LayoutDialect; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.CharEncoding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -55,7 +56,7 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { // templates to be automatically updated when modified. templateResolver.setCacheable(true); - templateResolver.setCharacterEncoding("UTF-8"); + templateResolver.setCharacterEncoding(CharEncoding.UTF_8); return templateResolver; } @@ -83,7 +84,7 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { public ThymeleafViewResolver viewResolver() { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); - viewResolver.setCharacterEncoding("UTF-8"); + viewResolver.setCharacterEncoding(CharEncoding.UTF_8); viewResolver.addStaticVariable( "showSape", BooleanUtils.toBoolean(env.getProperty("template.showSape", "true"))); diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java index ffc64221..54d83b61 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java @@ -7,6 +7,7 @@ import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.UserUtils; import com.juick.www.util.EncodeUtils; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.context.MessageSource; @@ -48,7 +49,7 @@ public class IndexController { ModelMap model) throws IOException { if (paramTagStr.isPresent()) - return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), "UTF-8"); + return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), CharEncoding.UTF_8); if (StringUtils.isNotEmpty(paramSearch) && paramSearch.length() > 64) paramSearch = ""; diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java index 69688513..8c4ab46d 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java @@ -9,6 +9,7 @@ import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.UserUtils; import com.juick.www.helpers.QueryString; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -51,13 +52,13 @@ public class TagController { throw new HttpNotFoundException(); } else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) { com.juick.Tag synTag = tagService.getTag(paramTag.SynonymID); - String url = "/tag/" + URLEncoder.encode(synTag.getName(), "UTF-8"); + String url = "/tag/" + URLEncoder.encode(synTag.getName(), CharEncoding.UTF_8); if (queryString.isPresent()) { url += "?" + queryString.get(); } return "redirect:" + url; } 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 (queryString.isPresent()) { url += "?" + queryString.get(); } @@ -97,7 +98,7 @@ public class TagController { }).collect(Collectors.toList()) ); 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); model.addAttribute("nextpage", nextpage); } model.addAttribute("tags", tagService.getPopularTags()); diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java index 85f936b5..c73c50e5 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -3,6 +3,7 @@ package com.juick.ws; import com.juick.User; import com.juick.service.MessagesService; import com.juick.service.UserService; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.math.NumberUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; @@ -45,7 +46,7 @@ public class WebsocketComponent extends TextWebSocketHandler { // Auth User visitor = new User(); - List params = URLEncodedUtils.parse(hLocation, "UTF-8"); + List params = URLEncodedUtils.parse(hLocation, CharEncoding.UTF_8); for (NameValuePair param : params) { if (param.getName().equals("hash")) { String hash = param.getValue(); diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java index 6feea4c7..ed6b1069 100644 --- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java @@ -1,6 +1,7 @@ package com.juick.ws.configuration; import com.juick.configuration.DataConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -28,7 +29,7 @@ public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServ @Override protected Filter[] getServletFilters() { - return new Filter[]{new CharacterEncodingFilter("UTF-8")}; + return new Filter[]{new CharacterEncodingFilter(CharEncoding.UTF_8)}; } @Override 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("
"); out.println("

Сообщение опубликовано

"); out.println("

Поделитесь своим новым постом в социальных сетях:

"); if (CrosspostQueries.getTwitterTokens(sql, visitor.getUid()).isPresent()) { - out.println("

Отправить в Twitter

"); + out.println("

Отправить в Twitter

"); } - out.println("

Отправить в LiveJournal

"); + out.println("

Отправить в LiveJournal

"); out.println("

Отправить в ВКонтакте

"); if (CrosspostQueries.getFacebookToken(sql, visitor.getUid()).isPresent()) { out.println("

Отправить в Facebook

"); 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); diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java index 1b8dd249..54dd6ff2 100644 --- a/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java +++ b/juick-xmpp-bot/src/main/java/com/juick/components/configuration/BotInitializer.java @@ -1,6 +1,7 @@ package com.juick.components.configuration; import com.juick.configuration.DataConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -28,8 +29,7 @@ public class BotInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java index bf0e7257..7fac43d4 100644 --- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java +++ b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java @@ -1,6 +1,7 @@ package com.juick.components.configuration; import com.juick.configuration.DataConfiguration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -28,8 +29,7 @@ public class FileTransferInitializer extends AbstractAnnotationConfigDispatcherS @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java index ee2ddceb..6453ef01 100644 --- a/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java +++ b/juick-xmpp/src/main/java/com/juick/components/configuration/XmppInitializer.java @@ -1,5 +1,6 @@ package com.juick.components.configuration; +import org.apache.commons.lang3.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -27,9 +28,7 @@ public class XmppInitializer extends AbstractAnnotationConfigDispatcherServletIn @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); - + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); return new Filter[]{characterEncodingFilter}; } diff --git a/src/test/java/com/juick/rss/LegacyRSS.java b/src/test/java/com/juick/rss/LegacyRSS.java index ff84b784..1d6ef151 100644 --- a/src/test/java/com/juick/rss/LegacyRSS.java +++ b/src/test/java/com/juick/rss/LegacyRSS.java @@ -24,6 +24,7 @@ import com.juick.server.UserQueries; import com.juick.util.DateFormattersHolder; import com.juick.util.MessageUtils; import org.apache.commons.dbcp2.BasicDataSource; +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; @@ -52,7 +53,7 @@ public class LegacyRSS { 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(); diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java index a0cfd444..6bc291e2 100644 --- a/src/test/java/com/juick/tests/MessageTests.java +++ b/src/test/java/com/juick/tests/MessageTests.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import com.juick.json.MessageSerializer; import com.juick.util.DateFormattersHolder; import com.juick.xmpp.extensions.JuickMessage; +import org.apache.commons.lang3.CharEncoding; import org.json.JSONObject; import org.junit.Test; @@ -40,7 +41,7 @@ public class MessageTests { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(xmppMessage.toString().getBytes("UTF-8"))); + Document doc = db.parse(new ByteArrayInputStream(xmppMessage.toString().getBytes(CharEncoding.UTF_8))); Node juickNode = doc.getElementsByTagName("juick").item(0); NamedNodeMap attrs = juickNode.getAttributes(); assertEquals("date should be in ts field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate), -- cgit v1.2.3