Commit 6ebae514 authored by Liang Ding's avatar Liang Ding

#12515 合并工具方法

parent 0b78c072
...@@ -21,7 +21,7 @@ import org.b3log.latke.Keys; ...@@ -21,7 +21,7 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Named; import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton; import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.util.JSONs; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -60,7 +60,7 @@ public class ArticleCache { ...@@ -60,7 +60,7 @@ public class ArticleCache {
return null; return null;
} }
return JSONs.clone(article); return Solos.clone(article);
} }
/** /**
...@@ -75,7 +75,7 @@ public class ArticleCache { ...@@ -75,7 +75,7 @@ public class ArticleCache {
return null; return null;
} }
return JSONs.clone(article); return Solos.clone(article);
} }
/** /**
...@@ -84,8 +84,8 @@ public class ArticleCache { ...@@ -84,8 +84,8 @@ public class ArticleCache {
* @param article the specified article * @param article the specified article
*/ */
public void putArticle(final JSONObject article) { public void putArticle(final JSONObject article) {
idCache.put(article.optString(Keys.OBJECT_ID), JSONs.clone(article)); idCache.put(article.optString(Keys.OBJECT_ID), Solos.clone(article));
permalinkCache.put(article.optString(Article.ARTICLE_PERMALINK), JSONs.clone(article)); permalinkCache.put(article.optString(Article.ARTICLE_PERMALINK), Solos.clone(article));
} }
/** /**
......
...@@ -20,7 +20,7 @@ package org.b3log.solo.cache; ...@@ -20,7 +20,7 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Named; import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton; import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.util.JSONs; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -54,7 +54,7 @@ public class CommentCache { ...@@ -54,7 +54,7 @@ public class CommentCache {
return null; return null;
} }
return JSONs.clone(comment); return Solos.clone(comment);
} }
/** /**
...@@ -63,7 +63,7 @@ public class CommentCache { ...@@ -63,7 +63,7 @@ public class CommentCache {
* @param comment the specified comment * @param comment the specified comment
*/ */
public void putComment(final JSONObject comment) { public void putComment(final JSONObject comment) {
cache.put(comment.optString(Keys.OBJECT_ID), JSONs.clone(comment)); cache.put(comment.optString(Keys.OBJECT_ID), Solos.clone(comment));
} }
/** /**
......
...@@ -21,7 +21,7 @@ import org.b3log.latke.Keys; ...@@ -21,7 +21,7 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Named; import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton; import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.util.JSONs; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -69,7 +69,7 @@ public class OptionCache { ...@@ -69,7 +69,7 @@ public class OptionCache {
return null; return null;
} }
return JSONs.clone(ret); return Solos.clone(ret);
} }
/** /**
...@@ -94,7 +94,7 @@ public class OptionCache { ...@@ -94,7 +94,7 @@ public class OptionCache {
return null; return null;
} }
return JSONs.clone(option); return Solos.clone(option);
} }
/** /**
...@@ -103,7 +103,7 @@ public class OptionCache { ...@@ -103,7 +103,7 @@ public class OptionCache {
* @param option the specified option * @param option the specified option
*/ */
public void putOption(final JSONObject option) { public void putOption(final JSONObject option) {
cache.put(option.optString(Keys.OBJECT_ID), JSONs.clone(option)); cache.put(option.optString(Keys.OBJECT_ID), Solos.clone(option));
final String category = option.optString(Option.OPTION_CATEGORY); final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category); removeCategory(category);
......
...@@ -20,7 +20,7 @@ package org.b3log.solo.cache; ...@@ -20,7 +20,7 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.ioc.inject.Named; import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton; import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.util.JSONs; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -54,7 +54,7 @@ public class PageCache { ...@@ -54,7 +54,7 @@ public class PageCache {
return null; return null;
} }
return JSONs.clone(page); return Solos.clone(page);
} }
/** /**
...@@ -65,7 +65,7 @@ public class PageCache { ...@@ -65,7 +65,7 @@ public class PageCache {
public void putPage(final JSONObject page) { public void putPage(final JSONObject page) {
final String pageId = page.optString(Keys.OBJECT_ID); final String pageId = page.optString(Keys.OBJECT_ID);
cache.put(pageId, JSONs.clone(page)); cache.put(pageId, Solos.clone(page));
} }
/** /**
......
...@@ -22,7 +22,7 @@ import org.b3log.latke.ioc.inject.Named; ...@@ -22,7 +22,7 @@ import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton; import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.latke.model.Role; import org.b3log.latke.model.Role;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
import org.b3log.solo.util.JSONs; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -84,7 +84,7 @@ public class UserCache { ...@@ -84,7 +84,7 @@ public class UserCache {
return null; return null;
} }
return JSONs.clone(user); return Solos.clone(user);
} }
/** /**
...@@ -99,7 +99,7 @@ public class UserCache { ...@@ -99,7 +99,7 @@ public class UserCache {
return null; return null;
} }
return JSONs.clone(user); return Solos.clone(user);
} }
/** /**
...@@ -108,8 +108,8 @@ public class UserCache { ...@@ -108,8 +108,8 @@ public class UserCache {
* @param user the specified user * @param user the specified user
*/ */
public void putUser(final JSONObject user) { public void putUser(final JSONObject user) {
idCache.put(user.optString(Keys.OBJECT_ID), JSONs.clone(user)); idCache.put(user.optString(Keys.OBJECT_ID), Solos.clone(user));
emailCache.put(user.optString(User.USER_EMAIL), JSONs.clone(user)); emailCache.put(user.optString(User.USER_EMAIL), Solos.clone(user));
} }
/** /**
......
...@@ -38,7 +38,7 @@ import org.b3log.solo.model.Option; ...@@ -38,7 +38,7 @@ import org.b3log.solo.model.Option;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Mails; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
...@@ -84,7 +84,7 @@ public class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObjec ...@@ -84,7 +84,7 @@ public class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObjec
return; return;
} }
if (!Mails.isConfigured()) { if (!Solos.isConfigured()) {
return; return;
} }
......
...@@ -39,7 +39,7 @@ import org.b3log.solo.model.Page; ...@@ -39,7 +39,7 @@ import org.b3log.solo.model.Page;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Mails; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
...@@ -78,7 +78,7 @@ public class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> ...@@ -78,7 +78,7 @@ public class PageCommentReplyNotifier extends AbstractEventListener<JSONObject>
return; return;
} }
if (!Mails.isConfigured()) { if (!Solos.isConfigured()) {
return; return;
} }
......
...@@ -47,7 +47,7 @@ import org.b3log.solo.processor.console.ConsoleRenderer; ...@@ -47,7 +47,7 @@ import org.b3log.solo.processor.console.ConsoleRenderer;
import org.b3log.solo.service.DataModelService; import org.b3log.solo.service.DataModelService;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.b3log.solo.util.Skins; import org.b3log.solo.util.Skins;
import org.b3log.solo.util.Thumbnails; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
...@@ -768,7 +768,7 @@ public class ArticleProcessor { ...@@ -768,7 +768,7 @@ public class ArticleProcessor {
if (StringUtils.isNotBlank(userAvatar)) { if (StringUtils.isNotBlank(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar); article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else { } else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "128"); final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
} }
...@@ -864,7 +864,7 @@ public class ArticleProcessor { ...@@ -864,7 +864,7 @@ public class ArticleProcessor {
if (StringUtils.isNotBlank(userAvatar)) { if (StringUtils.isNotBlank(userAvatar)) {
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar); dataModel.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else { } else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "128"); final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); dataModel.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
} }
......
...@@ -41,7 +41,7 @@ import org.b3log.solo.model.UserExt; ...@@ -41,7 +41,7 @@ import org.b3log.solo.model.UserExt;
import org.b3log.solo.processor.console.ConsoleRenderer; import org.b3log.solo.processor.console.ConsoleRenderer;
import org.b3log.solo.service.DataModelService; import org.b3log.solo.service.DataModelService;
import org.b3log.solo.service.InitService; import org.b3log.solo.service.InitService;
import org.b3log.solo.util.Thumbnails; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -172,7 +172,7 @@ public class InitProcessor { ...@@ -172,7 +172,7 @@ public class InitProcessor {
admin.put(User.USER_PASSWORD, userPassword); admin.put(User.USER_PASSWORD, userPassword);
String avatar = requestJSONObject.optString(UserExt.USER_AVATAR); String avatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (StringUtils.isBlank(avatar)) { if (StringUtils.isBlank(avatar)) {
avatar = Thumbnails.getGravatarURL(userEmail, "128"); avatar = Solos.getGravatarURL(userEmail, "128");
} }
admin.put(UserExt.USER_AVATAR, avatar); admin.put(UserExt.USER_AVATAR, avatar);
......
...@@ -48,7 +48,7 @@ import org.b3log.solo.processor.console.ConsoleRenderer; ...@@ -48,7 +48,7 @@ import org.b3log.solo.processor.console.ConsoleRenderer;
import org.b3log.solo.service.DataModelService; import org.b3log.solo.service.DataModelService;
import org.b3log.solo.repository.OptionRepository; import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.b3log.solo.util.Mails; import org.b3log.solo.util.Solos;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -402,7 +402,7 @@ public class LoginProcessor { ...@@ -402,7 +402,7 @@ public class LoginProcessor {
message.setSubject(mailSubject); message.setSubject(mailSubject);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
if (Mails.isConfigured()) { if (Solos.isConfigured()) {
mailService.send(message); mailService.send(message);
} else { } else {
LOGGER.log(Level.INFO, "Do not send mail caused by not configure mail.properties"); LOGGER.log(Level.INFO, "Do not send mail caused by not configure mail.properties");
......
...@@ -44,7 +44,7 @@ import org.b3log.solo.service.PreferenceMgmtService; ...@@ -44,7 +44,7 @@ import org.b3log.solo.service.PreferenceMgmtService;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticMgmtService; import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.service.StatisticQueryService; import org.b3log.solo.service.StatisticQueryService;
import org.b3log.solo.util.Mails; import org.b3log.solo.util.Solos;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -139,7 +139,7 @@ public class RepairProcessor { ...@@ -139,7 +139,7 @@ public class RepairProcessor {
renderer.setContent("Restores signs succeeded."); renderer.setContent("Restores signs succeeded.");
// Sends the sample signs to developer // Sends the sample signs to developer
if (!Mails.isConfigured()) { if (!Solos.isConfigured()) {
return; return;
} }
......
...@@ -54,7 +54,7 @@ import org.b3log.solo.service.ExportService; ...@@ -54,7 +54,7 @@ import org.b3log.solo.service.ExportService;
import org.b3log.solo.service.OptionQueryService; import org.b3log.solo.service.OptionQueryService;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.UserQueryService; import org.b3log.solo.service.UserQueryService;
import org.b3log.solo.util.Thumbnails; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
...@@ -158,7 +158,7 @@ public class AdminConsole { ...@@ -158,7 +158,7 @@ public class AdminConsole {
if (StringUtils.isNotBlank(userAvatar)) { if (StringUtils.isNotBlank(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar); dataModel.put(Common.GRAVATAR, userAvatar);
} else { } else {
final String gravatar = Thumbnails.getGravatarURL(email, "128"); final String gravatar = Solos.getGravatarURL(email, "128");
dataModel.put(Common.GRAVATAR, gravatar); dataModel.put(Common.GRAVATAR, gravatar);
} }
......
...@@ -171,7 +171,7 @@ public class CommentMgmtService { ...@@ -171,7 +171,7 @@ public class CommentMgmtService {
final JSONObject comment, final JSONObject comment,
final JSONObject originalComment, final JSONObject originalComment,
final JSONObject preference) throws Exception { final JSONObject preference) throws Exception {
if (!Mails.isConfigured()) { if (!Solos.isConfigured()) {
return; return;
} }
...@@ -777,7 +777,7 @@ public class CommentMgmtService { ...@@ -777,7 +777,7 @@ public class CommentMgmtService {
} }
// 2. Gravatar // 2. Gravatar
String thumbnailURL = Thumbnails.getGravatarURL(commentEmail.toLowerCase(), "128"); String thumbnailURL = Solos.getGravatarURL(commentEmail.toLowerCase(), "128");
final URL gravatarURL = new URL(thumbnailURL); final URL gravatarURL = new URL(thumbnailURL);
int statusCode = HttpServletResponse.SC_OK; int statusCode = HttpServletResponse.SC_OK;
......
...@@ -37,7 +37,7 @@ import org.b3log.solo.repository.CommentRepository; ...@@ -37,7 +37,7 @@ import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.PageRepository; import org.b3log.solo.repository.PageRepository;
import org.b3log.solo.util.Emotions; import org.b3log.solo.util.Emotions;
import org.b3log.solo.util.Markdowns; import org.b3log.solo.util.Markdowns;
import org.b3log.solo.util.Thumbnails; import org.b3log.solo.util.Solos;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
...@@ -246,7 +246,7 @@ public class CommentQueryService { ...@@ -246,7 +246,7 @@ public class CommentQueryService {
final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL); final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL);
if (StringUtils.isBlank(thumbnailURL)) { if (StringUtils.isBlank(thumbnailURL)) {
comment.put(Comment.COMMENT_THUMBNAIL_URL, Thumbnails.getGravatarURL(email, "128")); comment.put(Comment.COMMENT_THUMBNAIL_URL, Solos.getGravatarURL(email, "128"));
} }
if (StringUtils.isNotBlank(comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID))) { if (StringUtils.isNotBlank(comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID))) {
......
...@@ -514,7 +514,7 @@ public class DataModelService { ...@@ -514,7 +514,7 @@ public class DataModelService {
final String email = comment.optString(Comment.COMMENT_EMAIL); final String email = comment.optString(Comment.COMMENT_EMAIL);
final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL); final String thumbnailURL = comment.optString(Comment.COMMENT_THUMBNAIL_URL);
if (StringUtils.isBlank(thumbnailURL)) { if (StringUtils.isBlank(thumbnailURL)) {
comment.put(Comment.COMMENT_THUMBNAIL_URL, Thumbnails.getGravatarURL(email, "128")); comment.put(Comment.COMMENT_THUMBNAIL_URL, Solos.getGravatarURL(email, "128"));
} }
} }
...@@ -580,7 +580,7 @@ public class DataModelService { ...@@ -580,7 +580,7 @@ public class DataModelService {
dataModel.put(Common.GRAVATAR, userAvatar); dataModel.put(Common.GRAVATAR, userAvatar);
} else { } else {
final String email = currentUser.optString(User.USER_EMAIL); final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Thumbnails.getGravatarURL(email, "128"); final String gravatar = Solos.getGravatarURL(email, "128");
dataModel.put(Common.GRAVATAR, gravatar); dataModel.put(Common.GRAVATAR, gravatar);
} }
...@@ -878,7 +878,7 @@ public class DataModelService { ...@@ -878,7 +878,7 @@ public class DataModelService {
if (StringUtils.isNotBlank(userAvatar)) { if (StringUtils.isNotBlank(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar); article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else { } else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "128"); final String thumbnailURL = Solos.getGravatarURL(author.optString(User.USER_EMAIL), "128");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
} }
......
...@@ -45,7 +45,6 @@ import org.b3log.solo.repository.*; ...@@ -45,7 +45,6 @@ import org.b3log.solo.repository.*;
import org.b3log.solo.util.Images; import org.b3log.solo.util.Images;
import org.b3log.solo.util.Skins; import org.b3log.solo.util.Skins;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -479,7 +478,7 @@ public class InitService { ...@@ -479,7 +478,7 @@ public class InitService {
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0); admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
String avatar = requestJSONObject.optString(UserExt.USER_AVATAR); String avatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (StringUtils.isBlank(avatar)) { if (StringUtils.isBlank(avatar)) {
avatar = Thumbnails.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "128"); avatar = Solos.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "128");
} }
admin.put(UserExt.USER_AVATAR, avatar); admin.put(UserExt.USER_AVATAR, avatar);
......
...@@ -43,8 +43,7 @@ import org.b3log.solo.repository.ArticleRepository; ...@@ -43,8 +43,7 @@ import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.OptionRepository; import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.repository.UserRepository; import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.util.Mails; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -263,7 +262,7 @@ public class UpgradeService { ...@@ -263,7 +262,7 @@ public class UpgradeService {
for (int i = 0; i < users.length(); i++) { for (int i = 0; i < users.length(); i++) {
final JSONObject user = users.getJSONObject(i); final JSONObject user = users.getJSONObject(i);
final String email = user.optString(User.USER_EMAIL); final String email = user.optString(User.USER_EMAIL);
user.put(UserExt.USER_AVATAR, Thumbnails.getGravatarURL(email, "128")); user.put(UserExt.USER_AVATAR, Solos.getGravatarURL(email, "128"));
userRepository.update(user.optString(Keys.OBJECT_ID), user); userRepository.update(user.optString(Keys.OBJECT_ID), user);
LOGGER.log(Level.INFO, "Updated user[email={0}]", email); LOGGER.log(Level.INFO, "Updated user[email={0}]", email);
...@@ -387,7 +386,7 @@ public class UpgradeService { ...@@ -387,7 +386,7 @@ public class UpgradeService {
* @throws Exception exception * @throws Exception exception
*/ */
private void notifyUserByEmail() throws Exception { private void notifyUserByEmail() throws Exception {
if (!Mails.isConfigured()) { if (!Solos.isConfigured()) {
return; return;
} }
......
...@@ -40,7 +40,7 @@ import org.b3log.latke.util.Strings; ...@@ -40,7 +40,7 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.model.UserExt; import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository; import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.util.Thumbnails; import org.b3log.solo.util.Solos;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -344,7 +344,7 @@ public class UserMgmtService { ...@@ -344,7 +344,7 @@ public class UserMgmtService {
String userAvatar = requestJSONObject.optString(UserExt.USER_AVATAR); String userAvatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (StringUtils.isBlank(userAvatar)) { if (StringUtils.isBlank(userAvatar)) {
userAvatar = Thumbnails.getGravatarURL(userEmail, "128"); userAvatar = Solos.getGravatarURL(userEmail, "128");
} }
user.put(UserExt.USER_AVATAR, userAvatar); user.put(UserExt.USER_AVATAR, userAvatar);
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.util;
import org.b3log.latke.util.CollectionUtils;
import org.json.JSONObject;
/**
* JSON utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jul 16, 2017
* @since 2.3.0
*/
public final class JSONs {
/**
* Private constructor.
*/
private JSONs() {
}
/**
* Clones a JSON object from the specified source object.
*
* @param src the specified source object
* @return cloned object
*/
public static JSONObject clone(final JSONObject src) {
return new JSONObject(src, CollectionUtils.jsonArrayToArray(src.names(), String[].class));
}
}
\ No newline at end of file
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.util;
import org.apache.commons.lang.StringUtils;
import java.util.ResourceBundle;
/**
* Mail utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jul 20, 2017
* @since 2.3.0
*/
public final class Mails {
/**
* Mail configuration (mail.properties).
*/
private static final ResourceBundle mailConf = ResourceBundle.getBundle("mail");
/**
* Private constructor.
*/
private Mails() {
}
/**
* Whether user configures the mail.properties.
*
* @return {@code true} if user configured, returns {@code false} otherwise
*/
public static boolean isConfigured() {
try {
return StringUtils.isNotBlank(mailConf.getString("mail.user")) &&
StringUtils.isNotBlank(mailConf.getString("mail.password")) &&
StringUtils.isNotBlank(mailConf.getString("mail.smtp.host")) &&
StringUtils.isNotBlank(mailConf.getString("mail.smtp.port"));
} catch (final Exception e) {
return false;
}
}
}
...@@ -17,10 +17,13 @@ ...@@ -17,10 +17,13 @@
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.json.JSONObject;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
...@@ -29,7 +32,7 @@ import java.util.ResourceBundle; ...@@ -29,7 +32,7 @@ import java.util.ResourceBundle;
* Solo utilities. * Solo utilities.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.1, Sep 28, 2018 * @version 1.3.0.0, Sep 28, 2018
* @since 2.8.0 * @since 2.8.0
*/ */
public final class Solos { public final class Solos {
...@@ -39,6 +42,11 @@ public final class Solos { ...@@ -39,6 +42,11 @@ public final class Solos {
*/ */
private static final Logger LOGGER = Logger.getLogger(Solos.class); private static final Logger LOGGER = Logger.getLogger(Solos.class);
/**
* Mail configuration (mail.properties).
*/
private static final ResourceBundle mailConf = ResourceBundle.getBundle("mail");
/** /**
* B3log Rhythm address. * B3log Rhythm address.
*/ */
...@@ -74,6 +82,7 @@ public final class Solos { ...@@ -74,6 +82,7 @@ public final class Solos {
*/ */
public static final String USER_AGENT = "Solo/" + SoloServletListener.VERSION + "; +https://github.com/b3log/solo"; public static final String USER_AGENT = "Solo/" + SoloServletListener.VERSION + "; +https://github.com/b3log/solo";
static { static {
ResourceBundle solo; ResourceBundle solo;
try { try {
...@@ -101,6 +110,43 @@ public final class Solos { ...@@ -101,6 +110,43 @@ public final class Solos {
MOBILE_SKIN = mobileSkin; MOBILE_SKIN = mobileSkin;
} }
/**
* Whether user configures the mail.properties.
*
* @return {@code true} if user configured, returns {@code false} otherwise
*/
public static boolean isConfigured() {
try {
return StringUtils.isNotBlank(mailConf.getString("mail.user")) &&
StringUtils.isNotBlank(mailConf.getString("mail.password")) &&
StringUtils.isNotBlank(mailConf.getString("mail.smtp.host")) &&
StringUtils.isNotBlank(mailConf.getString("mail.smtp.port"));
} catch (final Exception e) {
return false;
}
}
/**
* Gets the Gravatar URL for the specified email with the specified size.
*
* @param email the specified email
* @param size the specified size
* @return the Gravatar URL
*/
public static String getGravatarURL(final String email, final String size) {
return GRAVATAR + DigestUtils.md5Hex(email) + "?s=" + size;
}
/**
* Clones a JSON object from the specified source object.
*
* @param src the specified source object
* @return cloned object
*/
public static JSONObject clone(final JSONObject src) {
return new JSONObject(src, CollectionUtils.jsonArrayToArray(src.names(), String[].class));
}
/** /**
* Private constructor. * Private constructor.
*/ */
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.util;
import org.apache.commons.codec.digest.DigestUtils;
/**
* Thumbnail utilities.
* <p>
* By using <a href="http://gravatar.com">Gravatar</a> for user thumbnail.
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.2, Aug 2, 2018
* @since 0.6.1
*/
public final class Thumbnails {
/**
* Gets the Gravatar URL for the specified email with the specified size.
*
* @param email the specified email
* @param size the specified size
* @return the Gravatar URL
*/
public static String getGravatarURL(final String email, final String size) {
return Solos.GRAVATAR + DigestUtils.md5Hex(email) + "?s=" + size;
}
/**
* Private constructor.
*/
private Thumbnails() {
}
}
...@@ -33,7 +33,7 @@ import java.util.Locale; ...@@ -33,7 +33,7 @@ import java.util.Locale;
public final class ThumbnailsTestCase { public final class ThumbnailsTestCase {
/** /**
* Test method for {@linkplain Thumbnails#getGravatarURL(java.lang.String, java.lang.String)}. * Test method for {@linkplain Solos#getGravatarURL(String, String)}.
* *
* @throws Exception exception * @throws Exception exception
*/ */
...@@ -42,7 +42,7 @@ public final class ThumbnailsTestCase { ...@@ -42,7 +42,7 @@ public final class ThumbnailsTestCase {
Latkes.initRuntimeEnv(); Latkes.initRuntimeEnv();
Latkes.setLocale(Locale.SIMPLIFIED_CHINESE); Latkes.setLocale(Locale.SIMPLIFIED_CHINESE);
final String gravatarURL = Thumbnails.getGravatarURL("test@b3log.org", "128"); final String gravatarURL = Solos.getGravatarURL("test@b3log.org", "128");
Assert.assertEquals(gravatarURL, Solos.GRAVATAR + "bd7e4673cf7fa4b4777353008c86e093?s=128"); Assert.assertEquals(gravatarURL, Solos.GRAVATAR + "bd7e4673cf7fa4b4777353008c86e093?s=128");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment