From 1d837a835c04078ec66325e9fb9de21ac401874e Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Wed, 30 Nov 2016 15:10:15 +0700 Subject: prevent string concatenation for disabled loggers --- juick-www/src/main/java/com/juick/www/FacebookLogin.java | 2 +- juick-www/src/main/java/com/juick/www/NewMessage.java | 11 +++++------ juick-www/src/main/java/com/juick/www/PageTemplates.java | 15 +++++++-------- juick-www/src/main/java/com/juick/www/VKontakteLogin.java | 9 ++++----- juick-www/src/main/java/ru/sape/SapeConnection.java | 2 +- 5 files changed, 18 insertions(+), 21 deletions(-) (limited to 'juick-www/src') 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 34385a3d..e9c4b786 100644 --- a/juick-www/src/main/java/com/juick/www/FacebookLogin.java +++ b/juick-www/src/main/java/com/juick/www/FacebookLogin.java @@ -85,7 +85,7 @@ public class FacebookLogin { 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")); if (token == null || token.isEmpty() || !token.startsWith("access_token=")) { - logger.error("FACEBOOK TOKEN ERROR: " + token); + logger.error("FACEBOOK TOKEN ERROR: {}", token); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } 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 f6e8ec47..c066c5b3 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -48,7 +48,6 @@ import java.util.ArrayList; import java.util.List; /** - * * @author Ugnich Anton */ public class NewMessage { @@ -185,7 +184,7 @@ public class NewMessage { } String paramImg = request.getParameter("img"); - if (attachmentFName == null && paramImg != null && paramImg.length() > 10 ) { + if (attachmentFName == null && paramImg != null && paramImg.length() > 10) { try { URL imgUrl = new URL(paramImg); attachmentFName = Utils.downloadImage(imgUrl); @@ -225,7 +224,7 @@ public class NewMessage { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.warn("invalid uri: " + attachmentURL, e); + logger.warn("invalid uri: {} exception {}", attachmentURL, e); } } if (xmpp != null) { @@ -296,8 +295,8 @@ public class NewMessage { out.println("

Отправить в Google+

"); out.println("

Ссылка на сообщение: http://juick.com/" + mid + "

"); out.println(""); - - PageTemplates.pageHomeColumn(out, sql, visitor); + + PageTemplates.pageHomeColumn(out, sql, visitor); PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); @@ -393,7 +392,7 @@ public class NewMessage { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.warn("invalid uri: " + attachmentURL, e); + logger.warn("invalid uri: {}, exception {}", attachmentURL, e); } } 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 f0974e69..74b8b543 100644 --- a/juick-www/src/main/java/com/juick/www/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java @@ -42,7 +42,6 @@ import java.util.List; import java.util.stream.Collectors; /** - * * @author Ugnich Anton */ public class PageTemplates { @@ -254,7 +253,7 @@ public class PageTemplates { ret = sdfFull.format(fulldate); } } catch (Exception e) { - logger.error("PARSE EXCEPTION: " + fulldate); + logger.error("PARSE EXCEPTION: {}, exception {}", fulldate, e); } } return ret; @@ -263,9 +262,9 @@ public class PageTemplates { public static String formatJSLocalTime(Date ts) { return ""; + + "var d=new Date(" + ts.getTime() + ");" + + "document.write((d.getDate()<10?'0':'')+d.getDate()+'.'+(d.getMonth()<9?'0':'')+(d.getMonth()+1)+'.'+d.getFullYear()+' '+(d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes());" + + ""; } public static String formatReplies(int replies) { @@ -326,10 +325,10 @@ public class PageTemplates { out.println(" @" + msg.getUser().getName() + ":"); out.println("
\""
"); out.println("
"); - + out.println("
" + tagsStr + "
"); out.println(" "); - + if (msg.AttachmentType != null) { String fname = msg.getMid() + "." + msg.AttachmentType; out.println("

\"\"/

"); @@ -346,7 +345,7 @@ public class PageTemplates { out.print("Мне нравится"); } if (visitor.getUid() == 0 && !msg.ReadOnly) { - out.print("Комментировать "); + out.print("Комментировать "); } else if (visitor.getUid() > 0 && (!msg.ReadOnly || visitor.getUid() == msg.getUser().getUid())) { out.print("Комментировать "); } 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 55dfd202..6b1d4571 100644 --- a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java +++ b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java @@ -20,7 +20,8 @@ package com.juick.www; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; -import com.juick.www.vk.*; +import com.juick.www.vk.Token; +import com.juick.www.vk.UsersResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; @@ -35,7 +36,6 @@ import java.net.URLEncoder; import java.util.UUID; /** - * * @author Ugnich Anton */ public class VKontakteLogin { @@ -50,6 +50,7 @@ public class VKontakteLogin { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); } + private final ObjectMapper mapper; protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -73,13 +74,11 @@ public class VKontakteLogin { token = json.getAccessToken(); vkID = json.getUserId(); if (token == null || vkID == 0) { - logger.error("VK TOKEN EMPTY: " + tokenjson); + logger.error("VK TOKEN EMPTY: {}", tokenjson); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } - - String graph = Utils.fetchURL("https://api.vk.com/method/users.get?uids=" + vkID + "&fields=screen_name&access_token=" + token); if (graph == null || graph.isEmpty()) { logger.error("VK GRAPH ERROR"); diff --git a/juick-www/src/main/java/ru/sape/SapeConnection.java b/juick-www/src/main/java/ru/sape/SapeConnection.java index 5c2e3397..a15658fa 100644 --- a/juick-www/src/main/java/ru/sape/SapeConnection.java +++ b/juick-www/src/main/java/ru/sape/SapeConnection.java @@ -81,7 +81,7 @@ public class SapeConnection { } if (data.startsWith("FATAL ERROR:")) { - logger.error("Sape responded with error: " + data); + logger.error("Sape responded with error: {}", data); continue; } -- cgit v1.2.3