diff --git a/src/main/java/org/b3log/symphony/SymphonyServletListener.java b/src/main/java/org/b3log/symphony/SymphonyServletListener.java index ce1a0fa53..0cdec528b 100644 --- a/src/main/java/org/b3log/symphony/SymphonyServletListener.java +++ b/src/main/java/org/b3log/symphony/SymphonyServletListener.java @@ -155,7 +155,7 @@ public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) { public void requestInitialized(final ServletRequestEvent servletRequestEvent) { Locales.setLocale(Latkes.getLocale()); - Sessions.setTemplateDir(Symphonys.get("skinDirName")); + Sessions.setTemplateDir(Symphonys.SKIN_DIR_NAME); Sessions.setMobile(false); Sessions.setAvatarViewMode(UserExt.USER_AVATAR_VIEW_MODE_C_ORIGINAL); @@ -222,7 +222,7 @@ public void requestDestroyed(final ServletRequestEvent servletRequestEvent) { if (null != isStaticObj && !(Boolean) isStaticObj) { Stopwatchs.end(); - final int threshold = Symphonys.getInt("performance.threshold"); + final int threshold = Symphonys.PERFORMANCE_THRESHOLD; if (0 < threshold) { final long elapsed = Stopwatchs.getElapsed("Request initialized [" + request.getRequestURI() + "]"); if (elapsed >= threshold) { diff --git a/src/main/java/org/b3log/symphony/event/ArticleBaiduSender.java b/src/main/java/org/b3log/symphony/event/ArticleBaiduSender.java index 14592d40b..8e27413f3 100644 --- a/src/main/java/org/b3log/symphony/event/ArticleBaiduSender.java +++ b/src/main/java/org/b3log/symphony/event/ArticleBaiduSender.java @@ -49,18 +49,13 @@ public class ArticleBaiduSender extends AbstractEventListener { */ private static final Logger LOGGER = Logger.getLogger(ArticleBaiduSender.class); - /** - * Baidu data token. - */ - private static final String TOKEN = Symphonys.get("baidu.data.token"); - /** * Sends the specified URLs to Baidu. * * @param urls the specified URLs */ public static void sendToBaidu(final String... urls) { - if (Latkes.RuntimeMode.PRODUCTION != Latkes.getRuntimeMode() || StringUtils.isBlank(TOKEN)) { + if (Latkes.RuntimeMode.PRODUCTION != Latkes.getRuntimeMode() || StringUtils.isBlank(Symphonys.BAIDU_DATA_TOKEN)) { return; } @@ -71,7 +66,7 @@ public static void sendToBaidu(final String... urls) { Symphonys.EXECUTOR_SERVICE.submit(() -> { try { final String urlsStr = StringUtils.join(urls, "\n"); - final HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/urls?site=" + Latkes.getServerHost() + "&token=" + TOKEN). + final HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/urls?site=" + Latkes.getServerHost() + "&token=" + Symphonys.BAIDU_DATA_TOKEN). header(Common.USER_AGENT, "curl/7.12.1"). header("Host", "data.zz.baidu.com"). header("Content-Type", "text/plain"). @@ -89,7 +84,7 @@ public void action(final Event event) { final JSONObject data = event.getData(); LOGGER.log(Level.TRACE, "Processing an event [type={0}, data={1}]", event.getType(), data); - if (Latkes.RuntimeMode.PRODUCTION != Latkes.getRuntimeMode() || StringUtils.isBlank(TOKEN)) { + if (Latkes.RuntimeMode.PRODUCTION != Latkes.getRuntimeMode() || StringUtils.isBlank(Symphonys.BAIDU_DATA_TOKEN)) { return; } diff --git a/src/main/java/org/b3log/symphony/event/ArticleSearchUpdater.java b/src/main/java/org/b3log/symphony/event/ArticleSearchUpdater.java index e4160bce6..e51e5754c 100644 --- a/src/main/java/org/b3log/symphony/event/ArticleSearchUpdater.java +++ b/src/main/java/org/b3log/symphony/event/ArticleSearchUpdater.java @@ -68,11 +68,11 @@ public void action(final Event event) { return; } - if (Symphonys.getBoolean("algolia.enabled")) { + if (Symphonys.ALGOLIA_ENABLED) { searchMgmtService.updateAlgoliaDocument(JSONs.clone(article)); } - if (Symphonys.getBoolean("es.enabled")) { + if (Symphonys.ES_ENABLED) { searchMgmtService.updateESDocument(JSONs.clone(article), Article.ARTICLE); } } diff --git a/src/main/java/org/b3log/symphony/processor/DomainProcessor.java b/src/main/java/org/b3log/symphony/processor/DomainProcessor.java index e8f327418..65217b451 100644 --- a/src/main/java/org/b3log/symphony/processor/DomainProcessor.java +++ b/src/main/java/org/b3log/symphony/processor/DomainProcessor.java @@ -104,7 +104,7 @@ public void showDomainArticles(final RequestContext context) { final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "domain-articles.ftl"); final Map dataModel = renderer.getDataModel(); final int pageNum = Paginator.getPage(request); - int pageSize = Symphonys.getInt("indexArticlesCnt"); + int pageSize = Symphonys.ARTICLE_LIST_CNT; final JSONObject user = Sessions.getUser(); if (null != user) { diff --git a/src/main/java/org/b3log/symphony/processor/advice/validate/Activity1A0001CollectValidation.java b/src/main/java/org/b3log/symphony/processor/advice/validate/Activity1A0001CollectValidation.java index df18366db..1836e710f 100644 --- a/src/main/java/org/b3log/symphony/processor/advice/validate/Activity1A0001CollectValidation.java +++ b/src/main/java/org/b3log/symphony/processor/advice/validate/Activity1A0001CollectValidation.java @@ -57,7 +57,7 @@ public class Activity1A0001CollectValidation extends ProcessAdvice { @Override public void doAdvice(final RequestContext context) throws RequestProcessAdviceException { - if (Symphonys.getBoolean("activity1A0001Closed")) { + if (Symphonys.ACTIVITY_1A0001_CLOSED) { throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityClosedLabel"))); } diff --git a/src/main/java/org/b3log/symphony/service/InitMgmtService.java b/src/main/java/org/b3log/symphony/service/InitMgmtService.java index abbff18ad..b8b991d52 100644 --- a/src/main/java/org/b3log/symphony/service/InitMgmtService.java +++ b/src/main/java/org/b3log/symphony/service/InitMgmtService.java @@ -646,7 +646,7 @@ public void initSym() { LOGGER.info("Initialized admin user"); // Add tags - String tagTitle = Symphonys.get("systemAnnounce"); + String tagTitle = Symphonys.SYS_ANNOUNCE_TAG; String tagId = tagMgmtService.addTag(adminId, tagTitle); JSONObject tag = tagRepository.get(tagId); tag.put(Tag.TAG_URI, "announcement"); diff --git a/src/main/java/org/b3log/symphony/util/Mails.java b/src/main/java/org/b3log/symphony/util/Mails.java index ea9d4182d..d5fba2201 100644 --- a/src/main/java/org/b3log/symphony/util/Mails.java +++ b/src/main/java/org/b3log/symphony/util/Mails.java @@ -70,61 +70,6 @@ public final class Mails { */ public static final String TEMPLATE_NAME_WEEKLY = "sym_weekly"; - /** - * Mail channel. - */ - private static final String MAIL_CHANNEL = Symphonys.get("mail.channel"); - - /** - * SendCloud API user. - */ - private static final String SENDCLOUD_API_USER = Symphonys.get("mail.sendcloud.apiUser"); - - /** - * SendCloud API key. - */ - private static final String SENDCLOUD_API_KEY = Symphonys.get("mail.sendcloud.apiKey"); - - /** - * SendCloud from. - */ - private static final String SENDCLOUD_FROM = Symphonys.get("mail.sendcloud.from"); - - /** - * SendCloud batch API User. - */ - private static final String SENDCLOUD_BATCH_API_USER = Symphonys.get("mail.sendcloud.batch.apiUser"); - - /** - * SendCloud batch API key. - */ - private static final String SENDCLOUD_BATCH_API_KEY = Symphonys.get("mail.sendcloud.batch.apiKey"); - - /** - * SendCloud batch sender email. - */ - private static final String SENDCLOUD_BATCH_FROM = Symphonys.get("mail.sendcloud.batch.from"); - - /** - * Aliyun accesskey. - */ - private static final String ALIYUN_ACCESSKEY = Symphonys.get("mail.aliyun.accessKey"); - - /** - * Aliyun access secret. - */ - private static final String ALIYUN_ACCESSSECRET = Symphonys.get("mail.aliyun.accessSecret"); - - /** - * Aliyun from. - */ - private static final String ALIYUN_FROM = Symphonys.get("mail.aliyun.from"); - - /** - * Aliyun batch from. - */ - private static final String ALIYUN_BATCH_FROM = Symphonys.get("mail.aliyun.batch.from"); - /** * Template configuration. */ @@ -145,7 +90,7 @@ public final class Mails { LOGGER.log(Level.ERROR, "Loads mail templates failed", e); } - final String mailDomains = Symphonys.get("mail.channel.mailDomains"); + final String mailDomains = Symphonys.MAIL_CHANNEL_MAIL_DOMAINS; if (StringUtils.isNotBlank(mailDomains)) { // aliyun:163.com,126.com;sendcloud:qq.com final String[] channelMaps = StringUtils.split(mailDomains, ";"); @@ -179,14 +124,14 @@ private Mails() { */ public static void sendHTML(final String fromName, final String subject, final String toMail, final String templateName, final Map dataModel) { - if ("sendcloud".equals(MAIL_CHANNEL)) { - if (StringUtils.isBlank(SENDCLOUD_API_USER) || StringUtils.isBlank(SENDCLOUD_API_KEY)) { + if ("sendcloud".equals(Symphonys.MAIL_CHANNEL)) { + if (StringUtils.isBlank(Symphonys.MAIL_SENDCLOUD_API_USER) || StringUtils.isBlank(Symphonys.MAIL_SENDCLOUD_API_KEY)) { LOGGER.warn("Please configure [#### SendCloud Mail channel ####] section in symphony.properties for sending mail"); return; } - } else if ("aliyun".equals(MAIL_CHANNEL)) { - if (StringUtils.isBlank(ALIYUN_ACCESSKEY) || StringUtils.isBlank(ALIYUN_ACCESSSECRET)) { + } else if ("aliyun".equals(Symphonys.MAIL_CHANNEL)) { + if (StringUtils.isBlank(Symphonys.MAIL_ALIYUN_AK) || StringUtils.isBlank(Symphonys.MAIL_ALIYUN_SK)) { LOGGER.warn("Please configure [#### Aliyun Mail channel ####] section in symphony.properties for sending mail"); return; @@ -211,10 +156,10 @@ public static void sendHTML(final String fromName, final String subject, final S final String html = stringWriter.toString(); final String domain = StringUtils.substringAfter(toMail, "@"); - final String channel = DOMAIN_CHANNEL.getOrDefault(domain, MAIL_CHANNEL); + final String channel = DOMAIN_CHANNEL.getOrDefault(domain, Symphonys.MAIL_CHANNEL); switch (channel) { case "aliyun": - aliSendHtml(ALIYUN_FROM, fromName, subject, toMail, html, ALIYUN_ACCESSKEY, ALIYUN_ACCESSSECRET); + aliSendHtml(Symphonys.MAIL_ALIYUN_FROM, fromName, subject, toMail, html, Symphonys.MAIL_ALIYUN_AK, Symphonys.MAIL_ALIYUN_SK); return; case "local": @@ -223,9 +168,9 @@ public static void sendHTML(final String fromName, final String subject, final S return; case "sendcloud": final Map formData = new HashMap<>(); - formData.put("apiUser", SENDCLOUD_API_USER); - formData.put("apiKey", SENDCLOUD_API_KEY); - formData.put("from", SENDCLOUD_FROM); + formData.put("apiUser", Symphonys.MAIL_SENDCLOUD_API_USER); + formData.put("apiKey", Symphonys.MAIL_SENDCLOUD_BATCH_API_KEY); + formData.put("from", Symphonys.MAIL_SENDCLOUD_FROM); formData.put("fromName", fromName); formData.put("subject", subject); formData.put("to", toMail); @@ -257,14 +202,14 @@ public static void sendHTML(final String fromName, final String subject, final S */ public static void batchSendHTML(final String fromName, final String subject, final List toMails, final String templateName, final Map dataModel) { - if ("sendcloud".equals(MAIL_CHANNEL)) { - if (StringUtils.isBlank(SENDCLOUD_BATCH_API_USER) || StringUtils.isBlank(SENDCLOUD_BATCH_API_KEY)) { + if ("sendcloud".equals(Symphonys.MAIL_CHANNEL)) { + if (StringUtils.isBlank(Symphonys.MAIL_SENDCLOUD_BATCH_API_USER) || StringUtils.isBlank(Symphonys.MAIL_SENDCLOUD_BATCH_API_KEY)) { LOGGER.warn("Please configure [#### SendCloud Mail channel ####] section in symphony.properties for sending mail"); return; } - } else if ("aliyun".equals(MAIL_CHANNEL)) { - if (StringUtils.isBlank(ALIYUN_ACCESSKEY) || StringUtils.isBlank(ALIYUN_ACCESSSECRET)) { + } else if ("aliyun".equals(Symphonys.MAIL_CHANNEL)) { + if (StringUtils.isBlank(Symphonys.MAIL_ALIYUN_AK) || StringUtils.isBlank(Symphonys.MAIL_ALIYUN_SK)) { LOGGER.warn("Please configure [#### Aliyun Mail channel ####] section in symphony.properties for sending mail"); return; @@ -284,9 +229,9 @@ public static void batchSendHTML(final String fromName, final String subject, fi try { final Map formData = new HashMap<>(); - formData.put("apiUser", SENDCLOUD_BATCH_API_USER); - formData.put("apiKey", SENDCLOUD_BATCH_API_KEY); - formData.put("from", SENDCLOUD_BATCH_FROM); + formData.put("apiUser", Symphonys.MAIL_SENDCLOUD_BATCH_API_USER); + formData.put("apiKey", Symphonys.MAIL_SENDCLOUD_BATCH_API_KEY); + formData.put("from", Symphonys.MAIL_SENDCLOUD_BATCH_FROM); formData.put("fromName", fromName); formData.put("subject", subject); formData.put("templateInvokeName", templateName); @@ -298,7 +243,7 @@ public static void batchSendHTML(final String fromName, final String subject, fi final String html = stringWriter.toString(); // Creates or updates the SendCloud email template - if ("sendcloud".equals(MAIL_CHANNEL)) { + if ("sendcloud".equals(Symphonys.MAIL_CHANNEL)) { refreshWeeklyTemplate(html); } @@ -312,12 +257,12 @@ public static void batchSendHTML(final String fromName, final String subject, fi index++; if (batch.size() > 99) { - if ("aliyun".equals(MAIL_CHANNEL)) { + if ("aliyun".equals(Symphonys.MAIL_CHANNEL)) { final String toMail = getStringToMailByList(batch); - aliSendHtml(ALIYUN_BATCH_FROM, fromName, subject, toMail, html, ALIYUN_ACCESSKEY, ALIYUN_ACCESSSECRET); + aliSendHtml(Symphonys.MAIL_ALIYUN_BATCH_FROM, fromName, subject, toMail, html, Symphonys.MAIL_ALIYUN_AK, Symphonys.MAIL_ALIYUN_SK); LOGGER.info("Sent [" + batch.size() + "] mails"); - } else if ("local".equals(MAIL_CHANNEL.toLowerCase())) { + } else if ("local".equals(Symphonys.MAIL_CHANNEL.toLowerCase())) { MailSender.getInstance().sendHTML(fromName, subject, batch, html); } else { try { @@ -343,11 +288,11 @@ public static void batchSendHTML(final String fromName, final String subject, fi } if (!batch.isEmpty()) { // Process remains - if ("aliyun".equals(MAIL_CHANNEL)) { + if ("aliyun".equals(Symphonys.MAIL_CHANNEL)) { final String toMail = getStringToMailByList(batch); - aliSendHtml(ALIYUN_BATCH_FROM, fromName, subject, toMail, html, ALIYUN_ACCESSKEY, ALIYUN_ACCESSSECRET); + aliSendHtml(Symphonys.MAIL_ALIYUN_BATCH_FROM, fromName, subject, toMail, html, Symphonys.MAIL_ALIYUN_AK, Symphonys.MAIL_ALIYUN_SK); LOGGER.info("Sent [" + batch.size() + "] mails"); - } else if ("local".equals(MAIL_CHANNEL.toLowerCase())) { + } else if ("local".equals(Symphonys.MAIL_CHANNEL.toLowerCase())) { MailSender.getInstance().sendHTML(fromName, subject, batch, html); } else { try { @@ -448,8 +393,8 @@ private static String getStringToMailByList(final List toMails) { private static void refreshWeeklyTemplate(final String html) { final Map addData = new HashMap<>(); - addData.put("apiUser", SENDCLOUD_BATCH_API_USER); - addData.put("apiKey", SENDCLOUD_BATCH_API_KEY); + addData.put("apiUser", Symphonys.MAIL_SENDCLOUD_BATCH_API_USER); + addData.put("apiKey", Symphonys.MAIL_SENDCLOUD_BATCH_API_KEY); addData.put("invokeName", TEMPLATE_NAME_WEEKLY); addData.put("name", "Weekly Newsletter"); addData.put("subject", "Weekly Newsletter"); @@ -460,8 +405,8 @@ private static void refreshWeeklyTemplate(final String html) { connectionTimeout(5000).timeout(30000).send().close(); final Map updateData = new HashMap<>(); - updateData.put("apiUser", SENDCLOUD_BATCH_API_USER); - updateData.put("apiKey", SENDCLOUD_BATCH_API_KEY); + updateData.put("apiUser", Symphonys.MAIL_SENDCLOUD_BATCH_API_USER); + updateData.put("apiKey", Symphonys.MAIL_SENDCLOUD_BATCH_API_KEY); updateData.put("invokeName", TEMPLATE_NAME_WEEKLY); updateData.put("html", html); @@ -487,20 +432,20 @@ private static void refreshWeeklyTemplate(final String html) { */ final class MailSender implements java.io.Serializable { - public static final String sender = Symphonys.get("mail.local.smtp.sender"); - public static final String username = Symphonys.get("mail.local.smtp.username"); - public static final String password = Symphonys.get("mail.local.smtp.passsword"); + public static final String sender = Symphonys.MAIL_LOCAL_SMTP_SENDER; + public static final String username = Symphonys.MAIL_LOCAL_SMTP_USERNAME; + public static final String password = Symphonys.MAIL_LOCAL_SMTP_PASSWORD; private static final long serialVersionUID = -1000794424345267933L; private static final String CHARSET = "text/html;charset=UTF-8"; private static final Logger LOGGER = Logger.getLogger(Markdowns.class); - private static final boolean is_debug = Boolean.valueOf(Symphonys.get("mail.local.isdebug")); - private static final String mail_transport_protocol = Symphonys.get("mail.local.transport.protocol"); - private static final String mail_host = Symphonys.get("mail.local.host"); - private static final String mail_port = Symphonys.get("mail.local.port"); - private static final String mail_smtp_auth = Symphonys.get("mail.local.smtp.auth"); - private static final String mail_smtp_ssl = Symphonys.get("mail.local.smtp.ssl"); - private static final String mail_smtp_starttls_enable = Symphonys.get("mail.local.smtp.starttls.enable"); + private static final boolean is_debug = Boolean.valueOf(Symphonys.MAIL_LOCAL_ISDEBUG); + private static final String mail_transport_protocol = Symphonys.MAIL_LOCAL_TRANSPORT_PROTOCOL; + private static final String mail_host = Symphonys.MAIL_LOCAL_HOST; + private static final String mail_port = Symphonys.MAIL_LOCAL_PORT; + private static final String mail_smtp_auth = Symphonys.MAIL_LOCAL_SMTP_AUTH; + private static final String mail_smtp_ssl = Symphonys.MAIL_LOCAL_SMTP_SSL; + private static final String mail_smtp_starttls_enable = Symphonys.MAIL_LOCAL_SMTP_STARTTLS; private static MailSender mailSender; private static Properties prop = new Properties(); diff --git a/src/main/java/org/b3log/symphony/util/Markdowns.java b/src/main/java/org/b3log/symphony/util/Markdowns.java index 092c2b3a3..cc87b9785 100644 --- a/src/main/java/org/b3log/symphony/util/Markdowns.java +++ b/src/main/java/org/b3log/symphony/util/Markdowns.java @@ -79,11 +79,6 @@ public final class Markdowns { */ private static final Map MD_CACHE = new ConcurrentHashMap<>(); - /** - * Markdown to HTML timeout. - */ - private static final int MD_TIMEOUT = Symphonys.getInt("markdown.timeout"); - /** * Marked engine serve path. */ @@ -352,7 +347,7 @@ public void tail(org.jsoup.nodes.Node node, int depth) { return; } - if (StringUtils.startsWithAny(src, new String[]{Latkes.getServePath(), Symphonys.get("qiniu.domain")}) + if (StringUtils.startsWithAny(src, new String[]{Latkes.getServePath(), Symphonys.UPLOAD_QINIU_DOMAIN}) || StringUtils.endsWithIgnoreCase(src, ".mov")) { return; } @@ -377,7 +372,7 @@ public void tail(org.jsoup.nodes.Node node, int depth) { try { final Future future = pool.submit(call); - return future.get(MD_TIMEOUT, TimeUnit.MILLISECONDS); + return future.get(Symphonys.MARKDOWN_TIMEOUT, TimeUnit.MILLISECONDS); } catch (final TimeoutException e) { LOGGER.log(Level.ERROR, "Markdown timeout [md=" + StringUtils.substring(markdownText, 0, 256) + "]"); Callstacks.printCallstack(Level.ERROR, new String[]{"org.b3log"}, null);