Commit 2caafaa9 authored by Liang Ding's avatar Liang Ding

Fixed #161

parent 21772b2f
...@@ -7,4 +7,12 @@ ...@@ -7,4 +7,12 @@
<goal>cobertura:cobertura</goal> <goal>cobertura:cobertura</goal>
</goals> </goals>
</action> </action>
<action>
<actionName>CUSTOM-jacobe-jacobe</actionName>
<displayName>jacobe-jacobe</displayName>
<goals>
<goal>jacobe:jacobe</goal>
</goals>
</action>
</actions> </actions>
...@@ -96,6 +96,36 @@ ...@@ -96,6 +96,36 @@
</resources> </resources>
<plugins> <plugins>
<plugin>
<groupId>com.tiobe.jacobe</groupId>
<artifactId>maven-jacobe-plugin</artifactId>
<version>1.0</version>
<configuration>
<jacobeExecutable>${jacobeExecutable}</jacobeExecutable>
<rules>
<param>indent=4</param>
<param>continuationindent=2</param>
</rules>
<configurationFile>../src/main/resources/etc/jacobe/sun.cfg</configurationFile>
<comparisonThreshold>0.01</comparisonThreshold>
<javadoc>private</javadoc>
<noAssert>true</noAssert>
<noEnum>false</noEnum>
<noBackup>true</noBackup>
<overwrite>true</overwrite>
<outputExtension>formatted</outputExtension>
<input>${basedir}/src/main/java</input>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>jacobe</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
...@@ -123,7 +153,7 @@ ...@@ -123,7 +153,7 @@
<configLocation>src/main/resources/etc/beyondtrack_checks.xml</configLocation> <configLocation>src/main/resources/etc/beyondtrack_checks.xml</configLocation>
<includeTestSourceDirectory>false</includeTestSourceDirectory> <includeTestSourceDirectory>false</includeTestSourceDirectory>
<excludes> <excludes>
com/**/*.java, com/**/*.java,
</excludes> </excludes>
<consoleOutput>true</consoleOutput> <consoleOutput>true</consoleOutput>
<failOnViolation>true</failOnViolation> <failOnViolation>true</failOnViolation>
...@@ -160,5 +190,34 @@ ...@@ -160,5 +190,34 @@
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<properties>
<jacobeExecutable>
../src/main/resources/etc/jacobe/linux/jacobe.exe
</jacobeExecutable>
</properties>
</profile>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<jacobeExecutable>
../src/main/resources/etc/jacobe/win32/jacobe.exe
</jacobeExecutable>
</properties>
</profile>
</profiles>
</project> </project>
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo; package org.b3log.solo;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
...@@ -49,6 +50,7 @@ import org.b3log.solo.util.Skins; ...@@ -49,6 +50,7 @@ import org.b3log.solo.util.Skins;
import org.b3log.solo.util.Statistics; import org.b3log.solo.util.Statistics;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* B3log Solo servlet listener. * B3log Solo servlet listener.
* *
...@@ -62,14 +64,17 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -62,14 +64,17 @@ public final class SoloServletListener extends AbstractServletListener {
* B3log Solo version. * B3log Solo version.
*/ */
public static final String VERSION = "0.5.5"; public static final String VERSION = "0.5.5";
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(SoloServletListener.class.getName()); private static final Logger LOGGER = Logger.getLogger(SoloServletListener.class.getName());
/** /**
* JSONO print indent factor. * JSONO print indent factor.
*/ */
public static final int JSON_PRINT_INDENT_FACTOR = 4; public static final int JSON_PRINT_INDENT_FACTOR = 4;
/** /**
* Enter escape. * Enter escape.
*/ */
...@@ -109,7 +114,7 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -109,7 +114,7 @@ public final class SoloServletListener extends AbstractServletListener {
LOGGER.info("Initialized the context"); LOGGER.info("Initialized the context");
Stopwatchs.end(); Stopwatchs.end();
LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[]{Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()}); LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[] {Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()});
} }
@Override @Override
...@@ -120,18 +125,17 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -120,18 +125,17 @@ public final class SoloServletListener extends AbstractServletListener {
} }
@Override @Override
public void sessionCreated(final HttpSessionEvent httpSessionEvent) { public void sessionCreated(final HttpSessionEvent httpSessionEvent) {}
}
// Note: This method will never invoked on GAE production environment // Note: This method will never invoked on GAE production environment
@Override @Override
public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) { public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {}
}
@Override @Override
public void requestInitialized(final ServletRequestEvent servletRequestEvent) { public void requestInitialized(final ServletRequestEvent servletRequestEvent) {
final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest(); final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest();
final String requestURI = httpServletRequest.getRequestURI(); final String requestURI = httpServletRequest.getRequestURI();
Stopwatchs.start("Request Initialized[requestURI=" + requestURI + "]"); Stopwatchs.start("Request Initialized[requestURI=" + requestURI + "]");
if (Requests.searchEngineBotRequest(httpServletRequest)) { if (Requests.searchEngineBotRequest(httpServletRequest)) {
...@@ -140,9 +144,9 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -140,9 +144,9 @@ public final class SoloServletListener extends AbstractServletListener {
} else { } else {
// Gets the session of this request // Gets the session of this request
final HttpSession session = httpServletRequest.getSession(); final HttpSession session = httpServletRequest.getSession();
LOGGER.log(Level.FINE, "Gets a session[id={0}, remoteAddr={1}, User-Agent={2}, isNew={3}]",
new Object[]{session.getId(), httpServletRequest.getRemoteAddr(), httpServletRequest.getHeader("User-Agent"), LOGGER.log(Level.FINE, "Gets a session[id={0}, remoteAddr={1}, User-Agent={2}, isNew={3}]", new Object[] {
session.isNew()}); session.getId(), httpServletRequest.getRemoteAddr(), httpServletRequest.getHeader("User-Agent"), session.isNew()});
// Online visitor count // Online visitor count
Statistics.onlineVisitorCount(httpServletRequest); Statistics.onlineVisitorCount(httpServletRequest);
} }
...@@ -154,7 +158,7 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -154,7 +158,7 @@ public final class SoloServletListener extends AbstractServletListener {
public void requestDestroyed(final ServletRequestEvent servletRequestEvent) { public void requestDestroyed(final ServletRequestEvent servletRequestEvent) {
Stopwatchs.end(); Stopwatchs.end();
LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[]{Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()}); LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[] {Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()});
Stopwatchs.release(); Stopwatchs.release();
super.requestDestroyed(servletRequestEvent); super.requestDestroyed(servletRequestEvent);
...@@ -193,6 +197,7 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -193,6 +197,7 @@ public final class SoloServletListener extends AbstractServletListener {
Skins.loadSkins(preference); Skins.loadSkins(preference);
final boolean pageCacheEnabled = preference.getBoolean(Preference.PAGE_CACHE_ENABLED); final boolean pageCacheEnabled = preference.getBoolean(Preference.PAGE_CACHE_ENABLED);
Templates.enableCache(pageCacheEnabled); Templates.enableCache(pageCacheEnabled);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
...@@ -258,7 +263,8 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -258,7 +263,8 @@ public final class SoloServletListener extends AbstractServletListener {
try { try {
final PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance(); final PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance();
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE); final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
if (null == preference) { // Did not initialize yet
if (null == preference) { // Did not initialize yet
return; return;
} }
...@@ -266,8 +272,7 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -266,8 +272,7 @@ public final class SoloServletListener extends AbstractServletListener {
String desiredView = Requests.mobileSwitchToggle(httpServletRequest); String desiredView = Requests.mobileSwitchToggle(httpServletRequest);
if (desiredView == null && !Requests.mobileRequest(httpServletRequest) if (desiredView == null && !Requests.mobileRequest(httpServletRequest) || desiredView != null && desiredView.equals("normal")) {
|| desiredView != null && desiredView.equals("normal")) {
desiredView = preference.getString(Skin.SKIN_DIR_NAME); desiredView = preference.getString(Skin.SKIN_DIR_NAME);
} else { } else {
desiredView = "mobile"; desiredView = "mobile";
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.api.symphony; package org.b3log.solo.api.symphony;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -38,6 +39,7 @@ import org.b3log.solo.util.QueryResults; ...@@ -38,6 +39,7 @@ import org.b3log.solo.util.QueryResults;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
/** /**
* Article receiver (from B3log Symphony). * Article receiver (from B3log Symphony).
* *
...@@ -52,14 +54,17 @@ public final class ArticleReceiver { ...@@ -52,14 +54,17 @@ public final class ArticleReceiver {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class.getName()); private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class.getName());
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/** /**
* Article management service. * Article management service.
*/ */
private ArticleMgmtService articleMgmtService = ArticleMgmtService.getInstance(); private ArticleMgmtService articleMgmtService = ArticleMgmtService.getInstance();
/** /**
* Article abstract length. * Article abstract length.
*/ */
...@@ -98,8 +103,9 @@ public final class ArticleReceiver { ...@@ -98,8 +103,9 @@ public final class ArticleReceiver {
*/ */
@RequestProcessing(value = "/apis/symphony/article", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/apis/symphony/article", method = HTTPRequestMethod.PUT)
public void addArticle(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void addArticle(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception { throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
...@@ -122,6 +128,7 @@ public final class ArticleReceiver { ...@@ -122,6 +128,7 @@ public final class ArticleReceiver {
article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL)); article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL));
final String plainTextContent = Jsoup.parse(article.optString(Article.ARTICLE_CONTENT)).text(); final String plainTextContent = Jsoup.parse(article.optString(Article.ARTICLE_CONTENT)).text();
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) { if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
article.put(Article.ARTICLE_ABSTRACT, plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "...."); article.put(Article.ARTICLE_ABSTRACT, plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....");
} else { } else {
...@@ -133,8 +140,9 @@ public final class ArticleReceiver { ...@@ -133,8 +140,9 @@ public final class ArticleReceiver {
article.put(Article.ARTICLE_VIEW_PWD, ""); article.put(Article.ARTICLE_VIEW_PWD, "");
String content = article.getString(Article.ARTICLE_CONTENT); String content = article.getString(Article.ARTICLE_CONTENT);
final String articleId = article.getString(Keys.OBJECT_ID); final String articleId = article.getString(Keys.OBJECT_ID);
content += "<br/><br/><p style='font-size: 12px;'><i>该文章同步自 <a href='http://symphony.b3log.org/article/"
+ articleId + "' target='_blank>B3log 社区</a></i></p>"; content += "<br/><br/><p style='font-size: 12px;'><i>该文章同步自 <a href='http://symphony.b3log.org/article/" + articleId
+ "' target='_blank>B3log 社区</a></i></p>";
article.put(Article.ARTICLE_CONTENT, content); article.put(Article.ARTICLE_CONTENT, content);
articleMgmtService.addArticle(requestJSONObject); articleMgmtService.addArticle(requestJSONObject);
...@@ -148,6 +156,7 @@ public final class ArticleReceiver { ...@@ -148,6 +156,7 @@ public final class ArticleReceiver {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult(); final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, e.getMessage()); jsonObject.put(Keys.MSG, e.getMessage());
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.dev; package org.b3log.solo.dev;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -34,6 +35,7 @@ import org.b3log.solo.service.ArticleMgmtService; ...@@ -34,6 +35,7 @@ import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.UserQueryService; import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Generates some dummy articles for development testing. * Generates some dummy articles for development testing.
* *
...@@ -47,8 +49,7 @@ public final class ArticleGenerator { ...@@ -47,8 +49,7 @@ public final class ArticleGenerator {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(ArticleGenerator.class.getName());
Logger.getLogger(ArticleGenerator.class.getName());
/** /**
* Generates some dummy articles with the specified context. * Generates some dummy articles with the specified context.
...@@ -60,10 +61,10 @@ public final class ArticleGenerator { ...@@ -60,10 +61,10 @@ public final class ArticleGenerator {
*/ */
@RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET)
public void genArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void genArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException { throws IOException {
if (RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) { if (RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) {
LOGGER.log(Level.WARNING, "Article generation just for development mode, " + "current runtime mode is [{0}]", LOGGER.log(Level.WARNING, "Article generation just for development mode, " + "current runtime mode is [{0}]",
Latkes.getRuntimeMode()); Latkes.getRuntimeMode());
response.sendRedirect("/"); response.sendRedirect("/");
return; return;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event; package org.b3log.solo.event;
/** /**
* Event types. * Event types.
* *
...@@ -28,26 +29,32 @@ public final class EventTypes { ...@@ -28,26 +29,32 @@ public final class EventTypes {
* Indicates a add article event. * Indicates a add article event.
*/ */
public static final String ADD_ARTICLE = "Add Article"; public static final String ADD_ARTICLE = "Add Article";
/** /**
* Indicates a update article event. * Indicates a update article event.
*/ */
public static final String UPDATE_ARTICLE = "Update Article"; public static final String UPDATE_ARTICLE = "Update Article";
/** /**
* Indicates a remove article event. * Indicates a remove article event.
*/ */
public static final String REMOVE_ARTICLE = "Remove Article"; public static final String REMOVE_ARTICLE = "Remove Article";
/** /**
* Indicates an add comment to article event. * Indicates an add comment to article event.
*/ */
public static final String ADD_COMMENT_TO_ARTICLE = "Add Comment To Article"; public static final String ADD_COMMENT_TO_ARTICLE = "Add Comment To Article";
/** /**
* Indicates an add comment (from symphony) to article event. * Indicates an add comment (from symphony) to article event.
*/ */
public static final String ADD_COMMENT_TO_ARTICLE_FROM_SYMPHONY = "Add Comment To Article From Symphony"; public static final String ADD_COMMENT_TO_ARTICLE_FROM_SYMPHONY = "Add Comment To Article From Symphony";
/** /**
* Indicates an add comment to page event. * Indicates an add comment to page event.
*/ */
public static final String ADD_COMMENT_TO_PAGE = "Add Comment To Page"; public static final String ADD_COMMENT_TO_PAGE = "Add Comment To Page";
/** /**
* Indicates a remove comment event. * Indicates a remove comment event.
*/ */
...@@ -56,6 +63,5 @@ public final class EventTypes { ...@@ -56,6 +63,5 @@ public final class EventTypes {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private EventTypes() { private EventTypes() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.comment; package org.b3log.solo.event.comment;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
...@@ -35,6 +36,7 @@ import org.b3log.solo.repository.impl.CommentRepositoryImpl; ...@@ -35,6 +36,7 @@ import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for processing article comment reply. * This listener is responsible for processing article comment reply.
* *
...@@ -48,14 +50,17 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -48,14 +50,17 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class.getName()); private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = CommentRepositoryImpl.getInstance(); private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
private MailService mailService = MailServiceFactory.getMailService(); private MailService mailService = MailServiceFactory.getMailService();
/** /**
* Preference query service. * Preference query service.
*/ */
...@@ -66,9 +71,11 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -66,9 +71,11 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject article = eventData.optJSONObject(Article.ARTICLE); final JSONObject article = eventData.optJSONObject(Article.ARTICLE);
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()}); new Object[] {event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()});
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID); final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID)); LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return; return;
...@@ -78,11 +85,13 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -78,11 +85,13 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId); final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
...@@ -93,10 +102,12 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -93,10 +102,12 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>"); final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL); final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate(); final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String articleTitle = article.getString(Article.ARTICLE_TITLE); final String articleTitle = article.getString(Article.ARTICLE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
...@@ -104,22 +115,19 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -104,22 +115,19 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>"; commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
final String mailBody = replyNotificationTemplate.getString("body"). final String mailBody = replyNotificationTemplate.getString("body").replace("${postLink}", articleLink).replace("${postTitle}", articleTitle).replace("${replier}", commenter).replace("${replyURL}", "http://" + blogHost + commentSharpURL).replace(
replace("${postLink}", articleLink). "${replyContent}", commentContent);
replace("${postTitle}", articleTitle).
replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost
+ commentSharpURL).
replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody, originalCommentEmail}); new Object[] {mailSubject, mailBody, originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.comment; package org.b3log.solo.event.comment;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
...@@ -35,6 +36,7 @@ import org.b3log.solo.repository.impl.CommentRepositoryImpl; ...@@ -35,6 +36,7 @@ import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for processing page comment reply. * This listener is responsible for processing page comment reply.
* *
...@@ -48,14 +50,17 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -48,14 +50,17 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class.getName()); private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = CommentRepositoryImpl.getInstance(); private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
private MailService mailService = MailServiceFactory.getMailService(); private MailService mailService = MailServiceFactory.getMailService();
/** /**
* Preference query service. * Preference query service.
*/ */
...@@ -66,9 +71,11 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -66,9 +71,11 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject page = eventData.optJSONObject(Page.PAGE); final JSONObject page = eventData.optJSONObject(Page.PAGE);
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), eventData, PageCommentReplyNotifier.class.getName()}); new Object[] {event.getType(), eventData, PageCommentReplyNotifier.class.getName()});
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID); final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID)); LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return; return;
...@@ -78,11 +85,13 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -78,11 +85,13 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId); final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
...@@ -90,14 +99,15 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -90,14 +99,15 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
final String blogTitle = preference.getString(Preference.BLOG_TITLE); final String blogTitle = preference.getString(Preference.BLOG_TITLE);
final String adminEmail = preference.getString(Preference.ADMIN_EMAIL); final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String commentContent = comment.getString(Comment.COMMENT_CONTENT). final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL); final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate(); final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String pageTitle = page.getString(Page.PAGE_TITLE); final String pageTitle = page.getString(Page.PAGE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
...@@ -105,22 +115,19 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -105,22 +115,19 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>"; commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
final String mailBody = replyNotificationTemplate.getString("body"). final String mailBody = replyNotificationTemplate.getString("body").replace("${postLink}", pageLink).replace("${postTitle}", pageTitle).replace("${replier}", commenter).replace("${replyURL}", "http://" + blogHost + commentSharpURL).replace(
replace("${postLink}", pageLink). "${replyContent}", commentContent);
replace("${postTitle}", pageTitle).
replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost
+ commentSharpURL).
replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody, originalCommentEmail}); new Object[] {mailSubject, mailBody, originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.ping; package org.b3log.solo.event.ping;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Preference; ...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for pinging <a href="http://blogsearch.google.com"> * This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while adding an article. * Google Blog Search Service</a> asynchronously while adding an article.
...@@ -54,6 +56,7 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene ...@@ -54,6 +56,7 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(AddArticleGoogleBlogSearchPinger.class.getName()); private static final Logger LOGGER = Logger.getLogger(AddArticleGoogleBlogSearchPinger.class.getName());
/** /**
* URL fetch service. * URL fetch service.
*/ */
...@@ -74,28 +77,31 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene ...@@ -74,28 +77,31 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
String articleTitle = null; String articleTitle = null;
try { try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE); final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE); articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference(); final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE); final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST). String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim();
toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) { if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not ping " LOGGER.log(Level.INFO,
+ "Google Blog Search Service for the article[title={0}]", "Blog Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]",
new Object[]{article.getString(Article.ARTICLE_TITLE)}); new Object[] {article.getString(Article.ARTICLE_TITLE)});
return; return;
} }
blogHost = StringUtils.removeEnd("http://" + blogHost, "/"); blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK); final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url="
+ URLEncoder.encode(blogTitle, "UTF-8") + "&url=" + URLEncoder.encode(blogHost, "UTF-8") + URLEncoder.encode(blogHost, "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while adding an " LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while adding an " + "article[title=" + articleTitle + "]",
+ "article[title=" + articleTitle + "]", spec); spec);
final HTTPRequest request = new HTTPRequest(); final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec)); request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request); URL_FETCH_SERVICE.fetchAsync(request);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.ping; package org.b3log.solo.event.ping;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Preference; ...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for pinging <a href="http://blogsearch.google.com"> * This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while updating an article. * Google Blog Search Service</a> asynchronously while updating an article.
...@@ -48,13 +50,13 @@ import org.json.JSONObject; ...@@ -48,13 +50,13 @@ import org.json.JSONObject;
* @see AddArticleGoogleBlogSearchPinger * @see AddArticleGoogleBlogSearchPinger
* @since 0.3.1 * @since 0.3.1
*/ */
public final class UpdateArticleGoogleBlogSearchPinger public final class UpdateArticleGoogleBlogSearchPinger extends AbstractEventListener<JSONObject> {
extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(UpdateArticleGoogleBlogSearchPinger.class.getName()); private static final Logger LOGGER = Logger.getLogger(UpdateArticleGoogleBlogSearchPinger.class.getName());
/** /**
* URL fetch service. * URL fetch service.
*/ */
...@@ -75,27 +77,31 @@ public final class UpdateArticleGoogleBlogSearchPinger ...@@ -75,27 +77,31 @@ public final class UpdateArticleGoogleBlogSearchPinger
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
String articleTitle = null; String articleTitle = null;
try { try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE); final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE); articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference(); final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE); final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim(); String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) { if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not ping " LOGGER.log(Level.INFO,
+ "Google Blog Search Service for the article[title={0}]", "Blog Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]",
new Object[]{article.getString(Article.ARTICLE_TITLE)}); new Object[] {article.getString(Article.ARTICLE_TITLE)});
return; return;
} }
blogHost = StringUtils.removeEnd("http://" + blogHost, "/"); blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK); final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url="
+ "&url=" + URLEncoder.encode(blogHost, "UTF-8") + URLEncoder.encode(blogHost, "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while updateing " LOGGER.log(Level.FINER,
+ "an article[title=" + articleTitle + "]", spec); "Request Google Blog Search Service API[{0}] while updateing " + "an article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest(); final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec)); request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request); URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) { } catch (final Exception e) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.plugin; package org.b3log.solo.event.plugin;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -28,6 +29,7 @@ import org.b3log.solo.repository.PluginRepository; ...@@ -28,6 +29,7 @@ import org.b3log.solo.repository.PluginRepository;
import org.b3log.solo.repository.impl.PluginRepositoryImpl; import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.b3log.solo.util.Plugins; import org.b3log.solo.util.Plugins;
/** /**
* This listener is responsible for refreshing plugin after every loaded. * This listener is responsible for refreshing plugin after every loaded.
* *
...@@ -40,25 +42,23 @@ public final class PluginRefresher extends AbstractEventListener<List<AbstractPl ...@@ -40,25 +42,23 @@ public final class PluginRefresher extends AbstractEventListener<List<AbstractPl
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(PluginRefresher.class.getName());
Logger.getLogger(PluginRefresher.class.getName());
/** /**
* Plugin repository. * Plugin repository.
*/ */
private PluginRepository pluginRepository = private PluginRepository pluginRepository = PluginRepositoryImpl.getInstance();
PluginRepositoryImpl.getInstance();
@Override @Override
public void action(final Event<List<AbstractPlugin>> event) throws public void action(final Event<List<AbstractPlugin>> event) throws
EventException { EventException {
final List<AbstractPlugin> plugins = event.getData(); final List<AbstractPlugin> plugins = event.getData();
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[] {event.getType(), plugins, PluginRefresher.class.getName()});
new Object[]{event.getType(), plugins,
PluginRefresher.class.getName()});
final Transaction transaction = pluginRepository.beginTransaction(); final Transaction transaction = pluginRepository.beginTransaction();
transaction.clearQueryCache(false); transaction.clearQueryCache(false);
try { try {
Plugins.refresh(plugins); Plugins.refresh(plugins);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.rhythm; package org.b3log.solo.event.rhythm;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Date; import java.util.Date;
...@@ -38,6 +39,7 @@ import org.b3log.solo.model.Preference; ...@@ -38,6 +39,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for sending article to B3log Rhythm. * This listener is responsible for sending article to B3log Rhythm.
* *
...@@ -52,18 +54,22 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -52,18 +54,22 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(ArticleSender.class.getName()); private static final Logger LOGGER = Logger.getLogger(ArticleSender.class.getName());
/** /**
* URL fetch service. * URL fetch service.
*/ */
private final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); private final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/** /**
* B3log Rhythm address. * B3log Rhythm address.
*/ */
public static final String B3LOG_RHYTHM_ADDRESS = "http://rhythm.b3log.org:80"; public static final String B3LOG_RHYTHM_ADDRESS = "http://rhythm.b3log.org:80";
/** /**
* URL of adding article to Rhythm. * URL of adding article to Rhythm.
*/ */
...@@ -81,10 +87,12 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -81,10 +87,12 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject data = event.getData(); final JSONObject data = event.getData();
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), data, ArticleSender.class.getName()}); new Object[] {event.getType(), data, ArticleSender.class.getName()});
try { try {
final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE); final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE);
if (!originalArticle.getBoolean(Article.ARTICLE_IS_PUBLISHED)) { if (!originalArticle.getBoolean(Article.ARTICLE_IS_PUBLISHED)) {
LOGGER.log(Level.FINER, "Ignores post article[title={0}] to Rhythm", originalArticle.getString(Article.ARTICLE_TITLE)); LOGGER.log(Level.FINER, "Ignores post article[title={0}] to Rhythm", originalArticle.getString(Article.ARTICLE_TITLE));
...@@ -92,6 +100,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -92,6 +100,7 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
} }
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
...@@ -99,17 +108,20 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -99,17 +108,20 @@ public final class ArticleSender extends AbstractEventListener<JSONObject> {
// Use configured host if Preference.BLOG_HOST is empty. // Use configured host if Preference.BLOG_HOST is empty.
final String perferHost = preference.getString(Preference.BLOG_HOST); final String perferHost = preference.getString(Preference.BLOG_HOST);
final String blogHost = !Strings.isEmptyOrNull(perferHost) ? perferHost.toLowerCase() : Latkes.getServePath().toLowerCase(); final String blogHost = !Strings.isEmptyOrNull(perferHost) ? perferHost.toLowerCase() : Latkes.getServePath().toLowerCase();
if (blogHost.contains("localhost")) { if (blogHost.contains("localhost")) {
LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm", LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm",
new Object[]{originalArticle.getString(Keys.OBJECT_ID), originalArticle.getString(Article.ARTICLE_TITLE)}); new Object[] {originalArticle.getString(Keys.OBJECT_ID), originalArticle.getString(Article.ARTICLE_TITLE)});
return; return;
} }
final HTTPRequest httpRequest = new HTTPRequest(); final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(ADD_ARTICLE_URL); httpRequest.setURL(ADD_ARTICLE_URL);
httpRequest.setRequestMethod(HTTPRequestMethod.POST); httpRequest.setRequestMethod(HTTPRequestMethod.POST);
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
final JSONObject article = new JSONObject(); final JSONObject article = new JSONObject();
article.put(Keys.OBJECT_ID, originalArticle.getString(Keys.OBJECT_ID)); article.put(Keys.OBJECT_ID, originalArticle.getString(Keys.OBJECT_ID));
article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE)); article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK)); article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK));
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.symphony; package org.b3log.solo.event.symphony;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -36,6 +37,7 @@ import org.b3log.solo.model.Preference; ...@@ -36,6 +37,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for sending comment to B3log Symphony. * This listener is responsible for sending comment to B3log Symphony.
* *
...@@ -49,18 +51,22 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -49,18 +51,22 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(CommentSender.class.getName()); private static final Logger LOGGER = Logger.getLogger(CommentSender.class.getName());
/** /**
* URL fetch service. * URL fetch service.
*/ */
private final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); private final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/** /**
* B3log Symphony address. * B3log Symphony address.
*/ */
public static final String B3LOG_SYMPHONY_ADDRESS = "http://symphony.b3log.org:80"; public static final String B3LOG_SYMPHONY_ADDRESS = "http://symphony.b3log.org:80";
/** /**
* URL of adding comment to Symphony. * URL of adding comment to Symphony.
*/ */
...@@ -78,28 +84,33 @@ public final class CommentSender extends AbstractEventListener<JSONObject> { ...@@ -78,28 +84,33 @@ public final class CommentSender extends AbstractEventListener<JSONObject> {
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject data = event.getData(); final JSONObject data = event.getData();
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), data, ArticleSender.class.getName()}); new Object[] {event.getType(), data, ArticleSender.class.getName()});
try { try {
final JSONObject originalComment = data.getJSONObject(Comment.COMMENT); final JSONObject originalComment = data.getJSONObject(Comment.COMMENT);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
final String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase(); final String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase();
if (blogHost.contains("localhost")) { if (blogHost.contains("localhost")) {
LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this comment[id={0}] to Symphony", LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this comment[id={0}] to Symphony",
new Object[]{originalComment.getString(Keys.OBJECT_ID)}); new Object[] {originalComment.getString(Keys.OBJECT_ID)});
return; return;
} }
final HTTPRequest httpRequest = new HTTPRequest(); final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(ADD_COMMENT_URL); httpRequest.setURL(ADD_COMMENT_URL);
httpRequest.setRequestMethod(HTTPRequestMethod.PUT); httpRequest.setRequestMethod(HTTPRequestMethod.PUT);
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
final JSONObject comment = new JSONObject(); final JSONObject comment = new JSONObject();
comment.put("commentId", originalComment.optString(Keys.OBJECT_ID)); comment.put("commentId", originalComment.optString(Keys.OBJECT_ID));
comment.put("commentAuthorName", originalComment.getString(Comment.COMMENT_NAME)); comment.put("commentAuthorName", originalComment.getString(Comment.COMMENT_NAME));
comment.put("commentAuthorEmail", originalComment.getString(Comment.COMMENT_EMAIL)); comment.put("commentAuthorEmail", originalComment.getString(Comment.COMMENT_EMAIL));
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.filter; package org.b3log.solo.filter;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.IOException; import java.io.IOException;
...@@ -32,6 +33,7 @@ import org.b3log.latke.user.UserServiceFactory; ...@@ -32,6 +33,7 @@ import org.b3log.latke.user.UserServiceFactory;
import org.b3log.solo.processor.LoginProcessor; import org.b3log.solo.processor.LoginProcessor;
import org.b3log.solo.util.Users; import org.b3log.solo.util.Users;
/** /**
* Authentication filter. * Authentication filter.
* *
...@@ -45,18 +47,19 @@ public final class AuthFilter implements Filter { ...@@ -45,18 +47,19 @@ public final class AuthFilter implements Filter {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(AuthFilter.class.getName()); private static final Logger LOGGER = Logger.getLogger(AuthFilter.class.getName());
/** /**
* User service. * User service.
*/ */
private UserService userService = UserServiceFactory.getUserService(); private UserService userService = UserServiceFactory.getUserService();
/** /**
* User utilities. * User utilities.
*/ */
private Users users = Users.getInstance(); private Users users = Users.getInstance();
@Override @Override
public void init(final FilterConfig filterConfig) throws ServletException { public void init(final FilterConfig filterConfig) throws ServletException {}
}
/** /**
* If the specified request is NOT made by an authenticated user, sends * If the specified request is NOT made by an authenticated user, sends
...@@ -70,9 +73,9 @@ public final class AuthFilter implements Filter { ...@@ -70,9 +73,9 @@ public final class AuthFilter implements Filter {
*/ */
@Override @Override
public void doFilter(final ServletRequest request, public void doFilter(final ServletRequest request,
final ServletResponse response, final ServletResponse response,
final FilterChain chain) throws IOException, final FilterChain chain) throws IOException,
ServletException { ServletException {
final HttpServletResponse httpServletResponse = (HttpServletResponse) response; final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
...@@ -80,6 +83,7 @@ public final class AuthFilter implements Filter { ...@@ -80,6 +83,7 @@ public final class AuthFilter implements Filter {
LoginProcessor.tryLogInWithCookie(httpServletRequest, httpServletResponse); LoginProcessor.tryLogInWithCookie(httpServletRequest, httpServletResponse);
final GeneralUser currentUser = userService.getCurrentUser(httpServletRequest); final GeneralUser currentUser = userService.getCurrentUser(httpServletRequest);
if (null == currentUser) { if (null == currentUser) {
LOGGER.warning("The request has been forbidden"); LOGGER.warning("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -88,6 +92,7 @@ public final class AuthFilter implements Filter { ...@@ -88,6 +92,7 @@ public final class AuthFilter implements Filter {
} }
final String currentUserEmail = currentUser.getEmail(); final String currentUserEmail = currentUser.getEmail();
LOGGER.log(Level.FINER, "Current user email[{0}]", currentUserEmail); LOGGER.log(Level.FINER, "Current user email[{0}]", currentUserEmail);
if (users.isSoloUser(currentUserEmail)) { if (users.isSoloUser(currentUserEmail)) {
chain.doFilter(request, response); chain.doFilter(request, response);
...@@ -103,6 +108,5 @@ public final class AuthFilter implements Filter { ...@@ -103,6 +108,5 @@ public final class AuthFilter implements Filter {
} }
@Override @Override
public void destroy() { public void destroy() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.filter; package org.b3log.solo.filter;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -36,6 +37,7 @@ import org.b3log.solo.SoloServletListener; ...@@ -36,6 +37,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Checks initialization filter. * Checks initialization filter.
* *
...@@ -49,14 +51,14 @@ public final class InitCheckFilter implements Filter { ...@@ -49,14 +51,14 @@ public final class InitCheckFilter implements Filter {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(InitCheckFilter.class.getName()); private static final Logger LOGGER = Logger.getLogger(InitCheckFilter.class.getName());
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
@Override @Override
public void init(final FilterConfig filterConfig) throws ServletException { public void init(final FilterConfig filterConfig) throws ServletException {}
}
/** /**
* If Solo has not been initialized, so redirects to /init. * If Solo has not been initialized, so redirects to /init.
...@@ -69,9 +71,10 @@ public final class InitCheckFilter implements Filter { ...@@ -69,9 +71,10 @@ public final class InitCheckFilter implements Filter {
*/ */
@Override @Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final String requestURI = httpServletRequest.getRequestURI(); final String requestURI = httpServletRequest.getRequestURI();
LOGGER.log(Level.FINEST, "Request[URI={0}]", requestURI); LOGGER.log(Level.FINEST, "Request[URI={0}]", requestURI);
if (requestURI.startsWith("/latke/remote")) { if (requestURI.startsWith("/latke/remote")) {
...@@ -88,8 +91,7 @@ public final class InitCheckFilter implements Filter { ...@@ -88,8 +91,7 @@ public final class InitCheckFilter implements Filter {
return; return;
} }
if ("POST".equalsIgnoreCase(httpServletRequest.getMethod()) if ("POST".equalsIgnoreCase(httpServletRequest.getMethod()) && (Latkes.getContextPath() + "/init").equals(requestURI)) {
&& (Latkes.getContextPath() + "/init").equals(requestURI)) {
// Do initailization // Do initailization
chain.doFilter(request, response); chain.doFilter(request, response);
...@@ -98,10 +100,12 @@ public final class InitCheckFilter implements Filter { ...@@ -98,10 +100,12 @@ public final class InitCheckFilter implements Filter {
LOGGER.finer("Try to get preference to confirm whether the preference exixts"); LOGGER.finer("Try to get preference to confirm whether the preference exixts");
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
LOGGER.log(Level.WARNING, "B3log Solo has not been initialized, so redirects to /init"); LOGGER.log(Level.WARNING, "B3log Solo has not been initialized, so redirects to /init");
final HTTPRequestContext context = new HTTPRequestContext(); final HTTPRequestContext context = new HTTPRequestContext();
context.setRequest((HttpServletRequest) request); context.setRequest((HttpServletRequest) request);
context.setResponse((HttpServletResponse) response); context.setResponse((HttpServletResponse) response);
...@@ -114,12 +118,10 @@ public final class InitCheckFilter implements Filter { ...@@ -114,12 +118,10 @@ public final class InitCheckFilter implements Filter {
chain.doFilter(request, response); chain.doFilter(request, response);
} }
} catch (final ServiceException e) { } catch (final ServiceException e) {
((HttpServletResponse) response).sendError( ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
HttpServletResponse.SC_NOT_FOUND);
} }
} }
@Override @Override
public void destroy() { public void destroy() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.filter; package org.b3log.solo.filter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -47,6 +48,7 @@ import org.b3log.solo.util.Statistics; ...@@ -47,6 +48,7 @@ import org.b3log.solo.util.Statistics;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Page cache filter. * Page cache filter.
* *
...@@ -60,26 +62,29 @@ public final class PageCacheFilter implements Filter { ...@@ -60,26 +62,29 @@ public final class PageCacheFilter implements Filter {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(PageCacheFilter.class.getName()); private static final Logger LOGGER = Logger.getLogger(PageCacheFilter.class.getName());
/** /**
* Statistic utilities. * Statistic utilities.
*/ */
private Statistics statistics = Statistics.getInstance(); private Statistics statistics = Statistics.getInstance();
/** /**
* Article repository. * Article repository.
*/ */
private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance(); private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance();
/** /**
* Language service. * Language service.
*/ */
private LangPropsService langPropsService = LangPropsService.getInstance(); private LangPropsService langPropsService = LangPropsService.getInstance();
/** /**
* Article utilities. * Article utilities.
*/ */
private Articles articles = Articles.getInstance(); private Articles articles = Articles.getInstance();
@Override @Override
public void init(final FilterConfig filterConfig) throws ServletException { public void init(final FilterConfig filterConfig) throws ServletException {}
}
/** /**
* Try to write response from cache. * Try to write response from cache.
...@@ -92,16 +97,19 @@ public final class PageCacheFilter implements Filter { ...@@ -92,16 +97,19 @@ public final class PageCacheFilter implements Filter {
*/ */
@Override @Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
final long startTimeMillis = System.currentTimeMillis(); final long startTimeMillis = System.currentTimeMillis();
request.setAttribute(Keys.HttpRequest.START_TIME_MILLIS, startTimeMillis); request.setAttribute(Keys.HttpRequest.START_TIME_MILLIS, startTimeMillis);
final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final String requestURI = httpServletRequest.getRequestURI(); final String requestURI = httpServletRequest.getRequestURI();
LOGGER.log(Level.FINER, "Request URI[{0}]", requestURI); LOGGER.log(Level.FINER, "Request URI[{0}]", requestURI);
if (StaticResources.isStatic(httpServletRequest)) { if (StaticResources.isStatic(httpServletRequest)) {
final String path = httpServletRequest.getServletPath() + httpServletRequest.getPathInfo(); final String path = httpServletRequest.getServletPath() + httpServletRequest.getPathInfo();
LOGGER.log(Level.FINEST, "Requests a static resource, forwards to servlet[path={0}]", path); LOGGER.log(Level.FINEST, "Requests a static resource, forwards to servlet[path={0}]", path);
request.getRequestDispatcher(path).forward(request, response); request.getRequestDispatcher(path).forward(request, response);
...@@ -116,6 +124,7 @@ public final class PageCacheFilter implements Filter { ...@@ -116,6 +124,7 @@ public final class PageCacheFilter implements Filter {
} }
final String skinDirName = (String) httpServletRequest.getAttribute(Keys.TEMAPLTE_DIR_NAME); final String skinDirName = (String) httpServletRequest.getAttribute(Keys.TEMAPLTE_DIR_NAME);
if ("mobile".equals(skinDirName)) { if ("mobile".equals(skinDirName)) {
// Mobile request, bypasses page caching // Mobile request, bypasses page caching
chain.doFilter(request, response); chain.doFilter(request, response);
...@@ -125,6 +134,7 @@ public final class PageCacheFilter implements Filter { ...@@ -125,6 +134,7 @@ public final class PageCacheFilter implements Filter {
String pageCacheKey; String pageCacheKey;
final String queryString = httpServletRequest.getQueryString(); final String queryString = httpServletRequest.getQueryString();
pageCacheKey = (String) request.getAttribute(Keys.PAGE_CACHE_KEY); pageCacheKey = (String) request.getAttribute(Keys.PAGE_CACHE_KEY);
if (Strings.isEmptyOrNull(pageCacheKey)) { if (Strings.isEmptyOrNull(pageCacheKey)) {
pageCacheKey = PageCaches.getPageCacheKey(requestURI, queryString); pageCacheKey = PageCaches.getPageCacheKey(requestURI, queryString);
...@@ -145,7 +155,7 @@ public final class PageCacheFilter implements Filter { ...@@ -145,7 +155,7 @@ public final class PageCacheFilter implements Filter {
try { try {
// If cached an article that has view password, dispatches the password form // If cached an article that has view password, dispatches the password form
if (langPropsService.get(PageTypes.ARTICLE.getLangeLabel()).equals(cachedType) if (langPropsService.get(PageTypes.ARTICLE.getLangeLabel()).equals(cachedType)
&& cachedPageContentObject.has(PageCaches.CACHED_PWD)) { && cachedPageContentObject.has(PageCaches.CACHED_PWD)) {
JSONObject article = new JSONObject(); JSONObject article = new JSONObject();
final String articleId = cachedPageContentObject.optString(PageCaches.CACHED_OID); final String articleId = cachedPageContentObject.optString(PageCaches.CACHED_OID);
...@@ -157,9 +167,10 @@ public final class PageCacheFilter implements Filter { ...@@ -157,9 +167,10 @@ public final class PageCacheFilter implements Filter {
article = articleRepository.get(articleId); // Loads the article entity article = articleRepository.get(articleId); // Loads the article entity
final HttpServletResponse httpServletResponse = (HttpServletResponse) response; final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
try { try {
httpServletResponse.sendRedirect(Latkes.getServePath() httpServletResponse.sendRedirect(
+ "/console/article-pwd?articleId=" + article.optString(Keys.OBJECT_ID)); Latkes.getServePath() + "/console/article-pwd?articleId=" + article.optString(Keys.OBJECT_ID));
return; return;
} catch (final Exception e) { } catch (final Exception e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -179,18 +190,19 @@ public final class PageCacheFilter implements Filter { ...@@ -179,18 +190,19 @@ public final class PageCacheFilter implements Filter {
final PrintWriter writer = response.getWriter(); final PrintWriter writer = response.getWriter();
String cachedPageContent = cachedPageContentObject.getString(PageCaches.CACHED_CONTENT); String cachedPageContent = cachedPageContentObject.getString(PageCaches.CACHED_CONTENT);
final String topBarHTML = TopBars.getTopBarHTML((HttpServletRequest) request, (HttpServletResponse) response); final String topBarHTML = TopBars.getTopBarHTML((HttpServletRequest) request, (HttpServletResponse) response);
cachedPageContent = cachedPageContent.replace(Common.TOP_BAR_REPLACEMENT_FLAG, topBarHTML);
cachedPageContent = cachedPageContent.replace(Common.TOP_BAR_REPLACEMENT_FLAG, topBarHTML);
final String cachedTitle = cachedPageContentObject.getString(PageCaches.CACHED_TITLE); final String cachedTitle = cachedPageContentObject.getString(PageCaches.CACHED_TITLE);
LOGGER.log(Level.FINEST, "Cached value[key={0}, type={1}, title={2}]",
new Object[]{pageCacheKey, cachedType, cachedTitle}); LOGGER.log(Level.FINEST, "Cached value[key={0}, type={1}, title={2}]", new Object[] {pageCacheKey, cachedType, cachedTitle});
statistics.incBlogViewCount((HttpServletRequest) request, (HttpServletResponse) response); statistics.incBlogViewCount((HttpServletRequest) request, (HttpServletResponse) response);
final long endimeMillis = System.currentTimeMillis(); final long endimeMillis = System.currentTimeMillis();
final String dateString = DateFormatUtils.format(endimeMillis, "yyyy/MM/dd HH:mm:ss"); final String dateString = DateFormatUtils.format(endimeMillis, "yyyy/MM/dd HH:mm:ss");
final String msg = String.format("<!-- Cached by B3log Solo(%1$d ms), %2$s -->", endimeMillis - startTimeMillis, dateString); final String msg = String.format("<!-- Cached by B3log Solo(%1$d ms), %2$s -->", endimeMillis - startTimeMillis, dateString);
LOGGER.finer(msg); LOGGER.finer(msg);
cachedPageContent += Strings.LINE_SEPARATOR + msg; cachedPageContent += Strings.LINE_SEPARATOR + msg;
writer.write(cachedPageContent); writer.write(cachedPageContent);
...@@ -209,6 +221,5 @@ public final class PageCacheFilter implements Filter { ...@@ -209,6 +221,5 @@ public final class PageCacheFilter implements Filter {
} }
@Override @Override
public void destroy() { public void destroy() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.filter; package org.b3log.solo.filter;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -43,6 +44,7 @@ import org.b3log.solo.util.Articles; ...@@ -43,6 +44,7 @@ import org.b3log.solo.util.Articles;
import org.b3log.solo.util.Permalinks; import org.b3log.solo.util.Permalinks;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Article/Page permalink filter. * Article/Page permalink filter.
* *
...@@ -59,22 +61,24 @@ public final class PermalinkFilter implements Filter { ...@@ -59,22 +61,24 @@ public final class PermalinkFilter implements Filter {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(PermalinkFilter.class.getName()); private static final Logger LOGGER = Logger.getLogger(PermalinkFilter.class.getName());
/** /**
* Article repository. * Article repository.
*/ */
private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance(); private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance();
/** /**
* Page repository. * Page repository.
*/ */
private PageRepository pageRepository = PageRepositoryImpl.getInstance(); private PageRepository pageRepository = PageRepositoryImpl.getInstance();
/** /**
* Article utilities. * Article utilities.
*/ */
private Articles articles = Articles.getInstance(); private Articles articles = Articles.getInstance();
@Override @Override
public void init(final FilterConfig filterConfig) throws ServletException { public void init(final FilterConfig filterConfig) throws ServletException {}
}
/** /**
* Tries to dispatch request to article processor. * Tries to dispatch request to article processor.
...@@ -87,11 +91,12 @@ public final class PermalinkFilter implements Filter { ...@@ -87,11 +91,12 @@ public final class PermalinkFilter implements Filter {
*/ */
@Override @Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final HttpServletResponse httpServletResponse = (HttpServletResponse) response; final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final String requestURI = httpServletRequest.getRequestURI(); final String requestURI = httpServletRequest.getRequestURI();
LOGGER.log(Level.FINER, "Request URI[{0}]", requestURI); LOGGER.log(Level.FINER, "Request URI[{0}]", requestURI);
final String contextPath = Latkes.getContextPath(); final String contextPath = Latkes.getContextPath();
...@@ -106,6 +111,7 @@ public final class PermalinkFilter implements Filter { ...@@ -106,6 +111,7 @@ public final class PermalinkFilter implements Filter {
JSONObject article; JSONObject article;
JSONObject page = null; JSONObject page = null;
try { try {
article = articleRepository.getByPermalink(permalink); article = articleRepository.getByPermalink(permalink);
if (null == article) { if (null == article) {
...@@ -128,8 +134,8 @@ public final class PermalinkFilter implements Filter { ...@@ -128,8 +134,8 @@ public final class PermalinkFilter implements Filter {
// If requests an article and the article need view passowrd, sends redirect to the password form // If requests an article and the article need view passowrd, sends redirect to the password form
if (null != article && articles.needViewPwd(httpServletRequest, article)) { if (null != article && articles.needViewPwd(httpServletRequest, article)) {
try { try {
httpServletResponse.sendRedirect(Latkes.getServePath() httpServletResponse.sendRedirect(
+ "/console/article-pwd?articleId=" + article.optString(Keys.OBJECT_ID)); Latkes.getServePath() + "/console/article-pwd?articleId=" + article.optString(Keys.OBJECT_ID));
return; return;
} catch (final Exception e) { } catch (final Exception e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -153,9 +159,10 @@ public final class PermalinkFilter implements Filter { ...@@ -153,9 +159,10 @@ public final class PermalinkFilter implements Filter {
* @see HTTPRequestDispatcher#dispatch(org.b3log.latke.servlet.HTTPRequestContext) * @see HTTPRequestDispatcher#dispatch(org.b3log.latke.servlet.HTTPRequestContext)
*/ */
private void dispatchToArticleOrPageProcessor(final ServletRequest request, final ServletResponse response, private void dispatchToArticleOrPageProcessor(final ServletRequest request, final ServletResponse response,
final JSONObject article, final JSONObject page) final JSONObject article, final JSONObject page)
throws ServletException, IOException { throws ServletException, IOException {
final HTTPRequestContext context = new HTTPRequestContext(); final HTTPRequestContext context = new HTTPRequestContext();
context.setRequest((HttpServletRequest) request); context.setRequest((HttpServletRequest) request);
context.setResponse((HttpServletResponse) response); context.setResponse((HttpServletResponse) response);
...@@ -173,6 +180,5 @@ public final class PermalinkFilter implements Filter { ...@@ -173,6 +180,5 @@ public final class PermalinkFilter implements Filter {
} }
@Override @Override
public void destroy() { public void destroy() {}
}
} }
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
/** /**
* This class defines all archive date model relevant keys. * This class defines all archive date model relevant keys.
* *
...@@ -30,41 +32,44 @@ public final class ArchiveDate { ...@@ -30,41 +32,44 @@ public final class ArchiveDate {
* Archive date. * Archive date.
*/ */
public static final String ARCHIVE_DATE = "archiveDate"; public static final String ARCHIVE_DATE = "archiveDate";
/** /**
* Archive dates. * Archive dates.
*/ */
public static final String ARCHIVE_DATES = "archiveDates"; public static final String ARCHIVE_DATES = "archiveDates";
/** /**
* Archive time. * Archive time.
*/ */
public static final String ARCHIVE_TIME = "archiveTime"; public static final String ARCHIVE_TIME = "archiveTime";
/** /**
* Key of archive date article count. * Key of archive date article count.
*/ */
public static final String ARCHIVE_DATE_ARTICLE_COUNT = public static final String ARCHIVE_DATE_ARTICLE_COUNT = "archiveDateArticleCount";
"archiveDateArticleCount";
/** /**
* Key of archive date article count. * Key of archive date article count.
*/ */
public static final String ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT = public static final String ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT = "archiveDatePublishedArticleCount";
"archiveDatePublishedArticleCount";
/** /**
* Archive date year. * Archive date year.
*/ */
public static final String ARCHIVE_DATE_YEAR = "archiveDateYear"; public static final String ARCHIVE_DATE_YEAR = "archiveDateYear";
/** /**
* Archive date month. * Archive date month.
*/ */
public static final String ARCHIVE_DATE_MONTH = "archiveDateMonth"; public static final String ARCHIVE_DATE_MONTH = "archiveDateMonth";
/** /**
* Date format(yyyy/MM). * Date format(yyyy/MM).
*/ */
public static final DateFormat DATE_FORMAT = public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM");
new SimpleDateFormat("yyyy/MM");
/** /**
* Private default constructor. * Private default constructor.
*/ */
private ArchiveDate() { private ArchiveDate() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all article model relevant keys. * This class defines all article model relevant keys.
* *
...@@ -28,90 +29,112 @@ public final class Article { ...@@ -28,90 +29,112 @@ public final class Article {
* Article. * Article.
*/ */
public static final String ARTICLE = "article"; public static final String ARTICLE = "article";
/** /**
* Articles. * Articles.
*/ */
public static final String ARTICLES = "articles"; public static final String ARTICLES = "articles";
/** /**
* Key of title. * Key of title.
*/ */
public static final String ARTICLE_TITLE = "articleTitle"; public static final String ARTICLE_TITLE = "articleTitle";
/** /**
* Key of abstract. * Key of abstract.
*/ */
public static final String ARTICLE_ABSTRACT = "articleAbstract"; public static final String ARTICLE_ABSTRACT = "articleAbstract";
/** /**
* Key of content. * Key of content.
*/ */
public static final String ARTICLE_CONTENT = "articleContent"; public static final String ARTICLE_CONTENT = "articleContent";
/** /**
* Key of create date. * Key of create date.
*/ */
public static final String ARTICLE_CREATE_DATE = "articleCreateDate"; public static final String ARTICLE_CREATE_DATE = "articleCreateDate";
/** /**
* Key of create time. * Key of create time.
*/ */
public static final String ARTICLE_CREATE_TIME = "articleCreateTime"; public static final String ARTICLE_CREATE_TIME = "articleCreateTime";
/** /**
* Key of update date. * Key of update date.
*/ */
public static final String ARTICLE_UPDATE_DATE = "articleUpdateDate"; public static final String ARTICLE_UPDATE_DATE = "articleUpdateDate";
/** /**
* Key of update time. * Key of update time.
*/ */
public static final String ARTICLE_UPDATE_TIME = "articleUpdateTime"; public static final String ARTICLE_UPDATE_TIME = "articleUpdateTime";
/** /**
* Key of tags. * Key of tags.
*/ */
public static final String ARTICLE_TAGS_REF = "articleTags"; public static final String ARTICLE_TAGS_REF = "articleTags";
/** /**
* Key of comment count. * Key of comment count.
*/ */
public static final String ARTICLE_COMMENT_COUNT = "articleCommentCount"; public static final String ARTICLE_COMMENT_COUNT = "articleCommentCount";
/** /**
* Key of view count. * Key of view count.
*/ */
public static final String ARTICLE_VIEW_COUNT = "articleViewCount"; public static final String ARTICLE_VIEW_COUNT = "articleViewCount";
/** /**
* Key of comments. * Key of comments.
*/ */
public static final String ARTICLE_COMMENTS_REF = "articleComments"; public static final String ARTICLE_COMMENTS_REF = "articleComments";
/** /**
* Key of sign id. * Key of sign id.
*/ */
public static final String ARTICLE_SIGN_ID = "articleSignId"; public static final String ARTICLE_SIGN_ID = "articleSignId";
/** /**
* Key of permalink. * Key of permalink.
*/ */
public static final String ARTICLE_PERMALINK = "articlePermalink"; public static final String ARTICLE_PERMALINK = "articlePermalink";
/** /**
* Key of put top. * Key of put top.
*/ */
public static final String ARTICLE_PUT_TOP = "articlePutTop"; public static final String ARTICLE_PUT_TOP = "articlePutTop";
/** /**
* Key of is published. * Key of is published.
*/ */
public static final String ARTICLE_IS_PUBLISHED = "articleIsPublished"; public static final String ARTICLE_IS_PUBLISHED = "articleIsPublished";
/** /**
* Key of author email. * Key of author email.
*/ */
public static final String ARTICLE_AUTHOR_EMAIL = "articleAuthorEmail"; public static final String ARTICLE_AUTHOR_EMAIL = "articleAuthorEmail";
/** /**
* Key of had been published. * Key of had been published.
*/ */
public static final String ARTICLE_HAD_BEEN_PUBLISHED = "articleHadBeenPublished"; public static final String ARTICLE_HAD_BEEN_PUBLISHED = "articleHadBeenPublished";
/** /**
* Key of random double. * Key of random double.
*/ */
public static final String ARTICLE_RANDOM_DOUBLE = "articleRandomDouble"; public static final String ARTICLE_RANDOM_DOUBLE = "articleRandomDouble";
/** /**
* Key of comment-able. * Key of comment-able.
*/ */
public static final String ARTICLE_COMMENTABLE = "articleCommentable"; public static final String ARTICLE_COMMENTABLE = "articleCommentable";
/** /**
* Key of view password. * Key of view password.
*/ */
public static final String ARTICLE_VIEW_PWD = "articleViewPwd"; public static final String ARTICLE_VIEW_PWD = "articleViewPwd";
/** /**
* Key of article editor type. * Key of article editor type.
* *
...@@ -122,6 +145,5 @@ public final class Article { ...@@ -122,6 +145,5 @@ public final class Article {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Article() { private Article() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all cache model relevant keys. * This class defines all cache model relevant keys.
* *
...@@ -27,22 +28,27 @@ public final class Cache { ...@@ -27,22 +28,27 @@ public final class Cache {
* Cache. * Cache.
*/ */
public static final String CACHE = "cache"; public static final String CACHE = "cache";
/** /**
* Cached count. * Cached count.
*/ */
public static final String CACHE_CACHED_COUNT = "cacheCachedCount"; public static final String CACHE_CACHED_COUNT = "cacheCachedCount";
/** /**
* Cache hit count. * Cache hit count.
*/ */
public static final String CACHE_HIT_COUNT = "cacheHitCount"; public static final String CACHE_HIT_COUNT = "cacheHitCount";
/** /**
* Cache hit bytes. * Cache hit bytes.
*/ */
public static final String CACHE_HIT_BYTES = "cacheHitBytes"; public static final String CACHE_HIT_BYTES = "cacheHitBytes";
/** /**
* Cached bytes. * Cached bytes.
*/ */
public static final String CACHE_CACHED_BYTES = "cacheCachedBytes"; public static final String CACHE_CACHED_BYTES = "cacheCachedBytes";
/** /**
* Cache miss count. * Cache miss count.
*/ */
...@@ -51,6 +57,5 @@ public final class Cache { ...@@ -51,6 +57,5 @@ public final class Cache {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Cache() { private Cache() {}
}
} }
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
/** /**
* This class defines all comment model relevant keys. * This class defines all comment model relevant keys.
* *
...@@ -31,69 +33,79 @@ public final class Comment { ...@@ -31,69 +33,79 @@ public final class Comment {
* Comment. * Comment.
*/ */
public static final String COMMENT = "comment"; public static final String COMMENT = "comment";
/** /**
* Comments. * Comments.
*/ */
public static final String COMMENTS = "comments"; public static final String COMMENTS = "comments";
/** /**
* Key of comment. * Key of comment.
*/ */
public static final String COMMENT_CONTENT = "commentContent"; public static final String COMMENT_CONTENT = "commentContent";
/** /**
* Key of comment name. * Key of comment name.
*/ */
public static final String COMMENT_NAME = "commentName"; public static final String COMMENT_NAME = "commentName";
/** /**
* Key of comment email. * Key of comment email.
*/ */
public static final String COMMENT_EMAIL = "commentEmail"; public static final String COMMENT_EMAIL = "commentEmail";
/** /**
* Key of comment URL. * Key of comment URL.
*/ */
public static final String COMMENT_URL = "commentURL"; public static final String COMMENT_URL = "commentURL";
/** /**
* Key of comment sharp URL. * Key of comment sharp URL.
*/ */
public static final String COMMENT_SHARP_URL = "commentSharpURL"; public static final String COMMENT_SHARP_URL = "commentSharpURL";
/** /**
* Key of comment date. * Key of comment date.
*/ */
public static final String COMMENT_DATE = "commentDate"; public static final String COMMENT_DATE = "commentDate";
/** /**
* Key of comment time. * Key of comment time.
*/ */
public static final String COMMENT_TIME = "commentTime"; public static final String COMMENT_TIME = "commentTime";
/** /**
* Key of comment thumbnail URL. * Key of comment thumbnail URL.
*/ */
public static final String COMMENT_THUMBNAIL_URL = "commentThumbnailURL"; public static final String COMMENT_THUMBNAIL_URL = "commentThumbnailURL";
/** /**
* Key of original comment id. * Key of original comment id.
*/ */
public static final String COMMENT_ORIGINAL_COMMENT_ID = public static final String COMMENT_ORIGINAL_COMMENT_ID = "commentOriginalCommentId";
"commentOriginalCommentId";
/** /**
* Key of original comment user name. * Key of original comment user name.
*/ */
public static final String COMMENT_ORIGINAL_COMMENT_NAME = public static final String COMMENT_ORIGINAL_COMMENT_NAME = "commentOriginalCommentName";
"commentOriginalCommentName";
/** /**
* Key of comment on type. * Key of comment on type.
*/ */
public static final String COMMENT_ON_TYPE = "commentOnType"; public static final String COMMENT_ON_TYPE = "commentOnType";
/** /**
* Key of comment on id. * Key of comment on id.
*/ */
public static final String COMMENT_ON_ID = "commentOnId"; public static final String COMMENT_ON_ID = "commentOnId";
/** /**
* Date format(yyyy/MM/dd hh:mm:ss). * Date format(yyyy/MM/dd hh:mm:ss).
*/ */
public static final DateFormat DATE_FORMAT = public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Comment() { private Comment() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all common model relevant keys. * This class defines all common model relevant keys.
* *
...@@ -29,218 +30,272 @@ public final class Common { ...@@ -29,218 +30,272 @@ public final class Common {
* Key of direction. * Key of direction.
*/ */
public static final String DIRECTION = "direction"; public static final String DIRECTION = "direction";
/** /**
* Most used tags. * Most used tags.
*/ */
public static final String MOST_USED_TAGS = "mostUsedTags"; public static final String MOST_USED_TAGS = "mostUsedTags";
/** /**
* Most comment count articles. * Most comment count articles.
*/ */
public static final String MOST_COMMENT_ARTICLES = "mostCommentArticles"; public static final String MOST_COMMENT_ARTICLES = "mostCommentArticles";
/** /**
* Most view count articles. * Most view count articles.
*/ */
public static final String MOST_VIEW_COUNT_ARTICLES = "mostViewCountArticles"; public static final String MOST_VIEW_COUNT_ARTICLES = "mostViewCountArticles";
/** /**
* Recent articles. * Recent articles.
*/ */
public static final String RECENT_ARTICLES = "recentArticles"; public static final String RECENT_ARTICLES = "recentArticles";
/** /**
* Recent comments. * Recent comments.
*/ */
public static final String RECENT_COMMENTS = "recentComments"; public static final String RECENT_COMMENTS = "recentComments";
/** /**
* Previous article permalink. * Previous article permalink.
*/ */
public static final String PREVIOUS_ARTICLE_PERMALINK = "previousArticlePermalink"; public static final String PREVIOUS_ARTICLE_PERMALINK = "previousArticlePermalink";
/** /**
* Next article permalink. * Next article permalink.
*/ */
public static final String NEXT_ARTICLE_PERMALINK = "nextArticlePermalink"; public static final String NEXT_ARTICLE_PERMALINK = "nextArticlePermalink";
/** /**
* Previous article title. * Previous article title.
*/ */
public static final String PREVIOUS_ARTICLE_TITLE = "previousArticleTitle"; public static final String PREVIOUS_ARTICLE_TITLE = "previousArticleTitle";
/** /**
* Next article title. * Next article title.
*/ */
public static final String NEXT_ARTICLE_TITLE = "nextArticleTitle"; public static final String NEXT_ARTICLE_TITLE = "nextArticleTitle";
/** /**
* index. * index.
*/ */
public static final String INDEX = "index"; public static final String INDEX = "index";
/** /**
* tag-articles. * tag-articles.
*/ */
public static final String TAG_ARTICLES = "tag-articles"; public static final String TAG_ARTICLES = "tag-articles";
/** /**
* archive-date-articles. * archive-date-articles.
*/ */
public static final String ARCHIVED_DATE_ARTICLES = "archive-date-articles"; public static final String ARCHIVED_DATE_ARTICLES = "archive-date-articles";
/** /**
* author-articles. * author-articles.
*/ */
public static final String AUTHOR_ARTICLES = "author-articles"; public static final String AUTHOR_ARTICLES = "author-articles";
/** /**
* Key of path. * Key of path.
*/ */
public static final String PATH = "path"; public static final String PATH = "path";
/** /**
* Version. * Version.
*/ */
public static final String VERSION = "version"; public static final String VERSION = "version";
/** /**
* Static resource version. * Static resource version.
*/ */
public static final String STATIC_RESOURCE_VERSION = "staticResourceVersion"; public static final String STATIC_RESOURCE_VERSION = "staticResourceVersion";
/** /**
* Year. * Year.
*/ */
public static final String YEAR = "year"; public static final String YEAR = "year";
/** /**
* Key of flag a comment is an reply or not. * Key of flag a comment is an reply or not.
*/ */
public static final String IS_REPLY = "isReply"; public static final String IS_REPLY = "isReply";
/** /**
* Key of page navigations. * Key of page navigations.
*/ */
public static final String PAGE_NAVIGATIONS = "pageNavigations"; public static final String PAGE_NAVIGATIONS = "pageNavigations";
/** /**
* Key of relevant articles. * Key of relevant articles.
*/ */
public static final String RELEVANT_ARTICLES = "relevantArticles"; public static final String RELEVANT_ARTICLES = "relevantArticles";
/** /**
* Key of random articles. * Key of random articles.
*/ */
public static final String RANDOM_ARTICLES = "randomArticles"; public static final String RANDOM_ARTICLES = "randomArticles";
/** /**
* Key of has updated. * Key of has updated.
*/ */
public static final String HAS_UPDATED = "hasUpdated"; public static final String HAS_UPDATED = "hasUpdated";
/** /**
* Author name. * Author name.
*/ */
public static final String AUTHOR_NAME = "authorName"; public static final String AUTHOR_NAME = "authorName";
/** /**
* Author id. * Author id.
*/ */
public static final String AUTHOR_ID = "authorId"; public static final String AUTHOR_ID = "authorId";
/** /**
* Author role. * Author role.
*/ */
public static final String AUTHOR_ROLE = "authorRole"; public static final String AUTHOR_ROLE = "authorRole";
/** /**
* Key of current user. * Key of current user.
*/ */
public static final String CURRENT_USER = "currentUser"; public static final String CURRENT_USER = "currentUser";
/** /**
* Key of enabled multiple user support. * Key of enabled multiple user support.
*/ */
public static final String ENABLED_MULTIPLE_USER_SUPPORT = "enabledMultipleUserSupport"; public static final String ENABLED_MULTIPLE_USER_SUPPORT = "enabledMultipleUserSupport";
/** /**
* Key of is logged in. * Key of is logged in.
*/ */
public static final String IS_LOGGED_IN = "isLoggedIn"; public static final String IS_LOGGED_IN = "isLoggedIn";
/** /**
* Key of is mobile request. * Key of is mobile request.
*/ */
public static final String IS_MOBILE_REQUEST = "isMobileRequest"; public static final String IS_MOBILE_REQUEST = "isMobileRequest";
/** /**
* Key of login URL. * Key of login URL.
*/ */
public static final String LOGIN_URL = "loginURL"; public static final String LOGIN_URL = "loginURL";
/** /**
* Key of logout URL. * Key of logout URL.
*/ */
public static final String LOGOUT_URL = "logoutURL"; public static final String LOGOUT_URL = "logoutURL";
/** /**
* Key of is administrator. * Key of is administrator.
*/ */
public static final String IS_ADMIN = "isAdmin"; public static final String IS_ADMIN = "isAdmin";
/** /**
* Key of URI. * Key of URI.
*/ */
public static final String URI = "URI"; public static final String URI = "URI";
/** /**
* Key of blog. * Key of blog.
*/ */
public static final String BLOG = "blog"; public static final String BLOG = "blog";
/** /**
* Key of blog version. * Key of blog version.
*/ */
public static final String BLOG_VERSION = "blogVersion"; public static final String BLOG_VERSION = "blogVersion";
/** /**
* Key of post to community. * Key of post to community.
*/ */
public static final String POST_TO_COMMUNITY = "postToCommunity"; public static final String POST_TO_COMMUNITY = "postToCommunity";
/** /**
* Key of page cached count. * Key of page cached count.
*/ */
public static final String PAGE_CACHED_CNT = "pageCachedCnt"; public static final String PAGE_CACHED_CNT = "pageCachedCnt";
/** /**
* Key of mini postfix. * Key of mini postfix.
*/ */
public static final String MINI_POSTFIX = "miniPostfix"; public static final String MINI_POSTFIX = "miniPostfix";
/** /**
* Value of mini postfix. * Value of mini postfix.
*/ */
public static final String MINI_POSTFIX_VALUE = ".min"; public static final String MINI_POSTFIX_VALUE = ".min";
/** /**
* Key of month name. * Key of month name.
*/ */
public static final String MONTH_NAME = "monthName"; public static final String MONTH_NAME = "monthName";
/** /**
* Key of comment title (article/page). * Key of comment title (article/page).
*/ */
public static final String COMMENT_TITLE = "commentTitle"; public static final String COMMENT_TITLE = "commentTitle";
/** /**
* /admin-index.do#main. * /admin-index.do#main.
*/ */
public static final String ADMIN_INDEX_URI = "/admin-index.do#main"; public static final String ADMIN_INDEX_URI = "/admin-index.do#main";
/** /**
* Key of type. * Key of type.
*/ */
public static final String TYPE = "type"; public static final String TYPE = "type";
/** /**
* Article comment type. * Article comment type.
*/ */
public static final String ARTICLE_COMMENT_TYPE = "articleComment"; public static final String ARTICLE_COMMENT_TYPE = "articleComment";
/** /**
* Page comment type. * Page comment type.
*/ */
public static final String PAGE_COMMENT_TYPE = "pageComment"; public static final String PAGE_COMMENT_TYPE = "pageComment";
/** /**
* Key of top bar replacement flag. * Key of top bar replacement flag.
*/ */
public static final String TOP_BAR_REPLACEMENT_FLAG_KEY = "topBarReplacement"; public static final String TOP_BAR_REPLACEMENT_FLAG_KEY = "topBarReplacement";
/** /**
* Top bar replacement flag. * Top bar replacement flag.
*/ */
public static final String TOP_BAR_REPLACEMENT_FLAG = "#B3logSolo#topBarReplacement#B3logSolo#"; public static final String TOP_BAR_REPLACEMENT_FLAG = "#B3logSolo#topBarReplacement#B3logSolo#";
/** /**
* Key of unused tags. * Key of unused tags.
*/ */
public static final String UNUSED_TAGS = "unusedTags"; public static final String UNUSED_TAGS = "unusedTags";
/** /**
* Key of go to. * Key of go to.
*/ */
public static final String GOTO = "goto"; public static final String GOTO = "goto";
/** /**
* Key of online visitor count. * Key of online visitor count.
*/ */
public static final String ONLINE_VISITOR_CNT = "onlineVisitorCnt"; public static final String ONLINE_VISITOR_CNT = "onlineVisitorCnt";
/** /**
* Key of article sign. * Key of article sign.
*/ */
public static final String ARTICLE_SIGN = "articleSign"; public static final String ARTICLE_SIGN = "articleSign";
/** /**
* Key of permalink. * Key of permalink.
*/ */
public static final String PERMALINK = "permalink"; public static final String PERMALINK = "permalink";
/** /**
* Key of commentable. * Key of commentable.
*/ */
public static final String COMMENTABLE = "commentable"; public static final String COMMENTABLE = "commentable";
/** /**
* Key of articles view password. * Key of articles view password.
*/ */
...@@ -249,6 +304,5 @@ public final class Common { ...@@ -249,6 +304,5 @@ public final class Common {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Common() { private Common() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all link model relevant keys. * This class defines all link model relevant keys.
* *
...@@ -28,22 +29,27 @@ public final class Link { ...@@ -28,22 +29,27 @@ public final class Link {
* Link. * Link.
*/ */
public static final String LINK = "link"; public static final String LINK = "link";
/** /**
* Links. * Links.
*/ */
public static final String LINKS = "links"; public static final String LINKS = "links";
/** /**
* Key of title. * Key of title.
*/ */
public static final String LINK_TITLE = "linkTitle"; public static final String LINK_TITLE = "linkTitle";
/** /**
* Key of address. * Key of address.
*/ */
public static final String LINK_ADDRESS = "linkAddress"; public static final String LINK_ADDRESS = "linkAddress";
/** /**
* Key of description. * Key of description.
*/ */
public static final String LINK_DESCRIPTION = "linkDescription"; public static final String LINK_DESCRIPTION = "linkDescription";
/** /**
* Key of order. * Key of order.
*/ */
...@@ -52,6 +58,5 @@ public final class Link { ...@@ -52,6 +58,5 @@ public final class Link {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Link() { private Link() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all page model relevant keys. * This class defines all page model relevant keys.
* *
...@@ -28,38 +29,47 @@ public final class Page { ...@@ -28,38 +29,47 @@ public final class Page {
* Page. * Page.
*/ */
public static final String PAGE = "page"; public static final String PAGE = "page";
/** /**
* Pages. * Pages.
*/ */
public static final String PAGES = "pages"; public static final String PAGES = "pages";
/** /**
* Key of title. * Key of title.
*/ */
public static final String PAGE_TITLE = "pageTitle"; public static final String PAGE_TITLE = "pageTitle";
/** /**
* Key of content. * Key of content.
*/ */
public static final String PAGE_CONTENT = "pageContent"; public static final String PAGE_CONTENT = "pageContent";
/** /**
* Key of order. * Key of order.
*/ */
public static final String PAGE_ORDER = "pageOrder"; public static final String PAGE_ORDER = "pageOrder";
/** /**
* Key of comment count. * Key of comment count.
*/ */
public static final String PAGE_COMMENT_COUNT = "pageCommentCount"; public static final String PAGE_COMMENT_COUNT = "pageCommentCount";
/** /**
* Key of permalink. * Key of permalink.
*/ */
public static final String PAGE_PERMALINK = "pagePermalink"; public static final String PAGE_PERMALINK = "pagePermalink";
/** /**
* Key of comments. * Key of comments.
*/ */
public static final String PAGE_COMMENTS_REF = "pageComments"; public static final String PAGE_COMMENTS_REF = "pageComments";
/** /**
* Key of comment-able. * Key of comment-able.
*/ */
public static final String PAGE_COMMENTABLE = "pageCommentable"; public static final String PAGE_COMMENTABLE = "pageCommentable";
/** /**
* Key of page type. * Key of page type.
* *
...@@ -74,6 +84,7 @@ public final class Page { ...@@ -74,6 +84,7 @@ public final class Page {
* </p> * </p>
*/ */
public static final String PAGE_TYPE = "pageType"; public static final String PAGE_TYPE = "pageType";
/** /**
* Key of open target. * Key of open target.
* *
...@@ -95,6 +106,7 @@ public final class Page { ...@@ -95,6 +106,7 @@ public final class Page {
* </p> * </p>
*/ */
public static final String PAGE_OPEN_TARGET = "pageOpenTarget"; public static final String PAGE_OPEN_TARGET = "pageOpenTarget";
/** /**
* Key of page editor type. * Key of page editor type.
* *
...@@ -105,6 +117,5 @@ public final class Page { ...@@ -105,6 +117,5 @@ public final class Page {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Page() { private Page() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all sign model relevant keys. * This class defines all sign model relevant keys.
* *
...@@ -27,10 +28,12 @@ public final class Sign { ...@@ -27,10 +28,12 @@ public final class Sign {
* Key of sign. * Key of sign.
*/ */
public static final String SIGN = "sign"; public static final String SIGN = "sign";
/** /**
* Key of signs. * Key of signs.
*/ */
public static final String SIGNS = "signs"; public static final String SIGNS = "signs";
/** /**
* Key of sign HTML. * Key of sign HTML.
*/ */
...@@ -39,6 +42,5 @@ public final class Sign { ...@@ -39,6 +42,5 @@ public final class Sign {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Sign() { private Sign() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all skin model relevant keys. * This class defines all skin model relevant keys.
* *
...@@ -27,18 +28,22 @@ public final class Skin { ...@@ -27,18 +28,22 @@ public final class Skin {
* Skin. * Skin.
*/ */
public static final String SKIN = "skin"; public static final String SKIN = "skin";
/** /**
* Skins. * Skins.
*/ */
public static final String SKINS = "skins"; public static final String SKINS = "skins";
/** /**
* Key of skin name, current selected skin name. * Key of skin name, current selected skin name.
*/ */
public static final String SKIN_NAME = "skinName"; public static final String SKIN_NAME = "skinName";
/** /**
* Key of skin names. * Key of skin names.
*/ */
public static final String SKIN_NAMES = "skinNames"; public static final String SKIN_NAMES = "skinNames";
/** /**
* Key of skin directory name. * Key of skin directory name.
*/ */
...@@ -47,6 +52,5 @@ public final class Skin { ...@@ -47,6 +52,5 @@ public final class Skin {
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Skin() { private Skin() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all statistic model relevant keys. * This class defines all statistic model relevant keys.
* *
...@@ -27,35 +28,34 @@ public final class Statistic { ...@@ -27,35 +28,34 @@ public final class Statistic {
* Statistic. * Statistic.
*/ */
public static final String STATISTIC = "statistic"; public static final String STATISTIC = "statistic";
/** /**
* Key of blog view count. * Key of blog view count.
*/ */
public static final String STATISTIC_BLOG_VIEW_COUNT = public static final String STATISTIC_BLOG_VIEW_COUNT = "statisticBlogViewCount";
"statisticBlogViewCount";
/** /**
* Key of blog comment count. * Key of blog comment count.
*/ */
public static final String STATISTIC_BLOG_COMMENT_COUNT = public static final String STATISTIC_BLOG_COMMENT_COUNT = "statisticBlogCommentCount";
"statisticBlogCommentCount";
/** /**
* Key of blog comment(published article) count. * Key of blog comment(published article) count.
*/ */
public static final String STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT = public static final String STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT = "statisticPublishedBlogCommentCount";
"statisticPublishedBlogCommentCount";
/** /**
* Key of blog article count. * Key of blog article count.
*/ */
public static final String STATISTIC_BLOG_ARTICLE_COUNT = public static final String STATISTIC_BLOG_ARTICLE_COUNT = "statisticBlogArticleCount";
"statisticBlogArticleCount";
/** /**
* Key of blog published article count. * Key of blog published article count.
*/ */
public static final String STATISTIC_PUBLISHED_ARTICLE_COUNT = public static final String STATISTIC_PUBLISHED_ARTICLE_COUNT = "statisticPublishedBlogArticleCount";
"statisticPublishedBlogArticleCount";
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Statistic() { private Statistic() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines all tag model relevant keys. * This class defines all tag model relevant keys.
* *
...@@ -27,27 +28,29 @@ public final class Tag { ...@@ -27,27 +28,29 @@ public final class Tag {
* Tag. * Tag.
*/ */
public static final String TAG = "tag"; public static final String TAG = "tag";
/** /**
* Tags. * Tags.
*/ */
public static final String TAGS = "tags"; public static final String TAGS = "tags";
/** /**
* Key of title. * Key of title.
*/ */
public static final String TAG_TITLE = "tagTitle"; public static final String TAG_TITLE = "tagTitle";
/** /**
* Key of tag reference count. * Key of tag reference count.
*/ */
public static final String TAG_REFERENCE_COUNT = "tagReferenceCount"; public static final String TAG_REFERENCE_COUNT = "tagReferenceCount";
/** /**
* Key of tag reference(published article) count. * Key of tag reference(published article) count.
*/ */
public static final String TAG_PUBLISHED_REFERENCE_COUNT = public static final String TAG_PUBLISHED_REFERENCE_COUNT = "tagPublishedRefCount";
"tagPublishedRefCount";
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Tag() { private Tag() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
/** /**
* This class defines ext of user model relevant keys. * This class defines ext of user model relevant keys.
* *
...@@ -29,6 +30,7 @@ public final class UserExt { ...@@ -29,6 +30,7 @@ public final class UserExt {
* Key of user article count. * Key of user article count.
*/ */
public static final String USER_ARTICLE_COUNT = "userArticleCount"; public static final String USER_ARTICLE_COUNT = "userArticleCount";
/** /**
* Key of user article count. * Key of user article count.
*/ */
...@@ -37,6 +39,5 @@ public final class UserExt { ...@@ -37,6 +39,5 @@ public final class UserExt {
/** /**
* Private constructor. * Private constructor.
*/ */
private UserExt() { private UserExt() {}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model.feed.atom; package org.b3log.solo.model.feed.atom;
/** /**
* Category. * Category.
* *
...@@ -28,10 +29,12 @@ public final class Category { ...@@ -28,10 +29,12 @@ public final class Category {
* Term variable. * Term variable.
*/ */
private static final String TERM_VARIABLE = "${term}"; private static final String TERM_VARIABLE = "${term}";
/** /**
* Category element. * Category element.
*/ */
private static final String CATEGORY_ELEMENT = "<category term=\"" + TERM_VARIABLE + "\" />"; private static final String CATEGORY_ELEMENT = "<category term=\"" + TERM_VARIABLE + "\" />";
/** /**
* Term. * Term.
*/ */
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model.feed.atom; package org.b3log.solo.model.feed.atom;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
...@@ -22,6 +23,7 @@ import java.util.Set; ...@@ -22,6 +23,7 @@ import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* Entry. * Entry.
* *
...@@ -35,103 +37,127 @@ public final class Entry { ...@@ -35,103 +37,127 @@ public final class Entry {
* Link variable. * Link variable.
*/ */
private static final String LINK_VARIABLE = "${link}"; private static final String LINK_VARIABLE = "${link}";
/** /**
* Start title element. * Start title element.
*/ */
private static final String START_TITLE_ELEMENT = "<title type=\"text\">"; private static final String START_TITLE_ELEMENT = "<title type=\"text\">";
/** /**
* End title element. * End title element.
*/ */
private static final String END_TITLE_ELEMENT = "</title>"; private static final String END_TITLE_ELEMENT = "</title>";
/** /**
* Start author element. * Start author element.
*/ */
private static final String START_AUTHOR_ELEMENT = "<author>"; private static final String START_AUTHOR_ELEMENT = "<author>";
/** /**
* End author element. * End author element.
*/ */
private static final String END_AUTHOR_ELEMENT = "</author>"; private static final String END_AUTHOR_ELEMENT = "</author>";
/** /**
* Start name element. * Start name element.
*/ */
private static final String START_NAME_ELEMENT = "<name>"; private static final String START_NAME_ELEMENT = "<name>";
/** /**
* End name element. * End name element.
*/ */
private static final String END_NAME_ELEMENT = "</name>"; private static final String END_NAME_ELEMENT = "</name>";
/** /**
* Start URI element. * Start URI element.
*/ */
private static final String START_URI_ELEMENT = "<uri>"; private static final String START_URI_ELEMENT = "<uri>";
/** /**
* End URI element. * End URI element.
*/ */
private static final String END_URI_ELEMENT = "</uri>"; private static final String END_URI_ELEMENT = "</uri>";
/** /**
* Start entry element. * Start entry element.
*/ */
private static final String START_ENTRY_ELEMENT = "<entry>"; private static final String START_ENTRY_ELEMENT = "<entry>";
/** /**
* End entry element. * End entry element.
*/ */
private static final String END_ENTRY_ELEMENT = "</entry>"; private static final String END_ENTRY_ELEMENT = "</entry>";
/** /**
* Start id element. * Start id element.
*/ */
private static final String START_ID_ELEMENT = "<id>"; private static final String START_ID_ELEMENT = "<id>";
/** /**
* End id element. * End id element.
*/ */
private static final String END_ID_ELEMENT = "</id>"; private static final String END_ID_ELEMENT = "</id>";
/** /**
* Start summary element. * Start summary element.
*/ */
private static final String START_SUMMARY_ELEMENT = "<summary type=\"html\">"; private static final String START_SUMMARY_ELEMENT = "<summary type=\"html\">";
/** /**
* End summary element. * End summary element.
*/ */
private static final String END_SUMMARY_ELEMENT = "</summary>"; private static final String END_SUMMARY_ELEMENT = "</summary>";
/** /**
* Link element. * Link element.
*/ */
private static final String LINK_ELEMENT = private static final String LINK_ELEMENT = "<link href=\"" + LINK_VARIABLE + "\" />";
"<link href=\"" + LINK_VARIABLE + "\" />";
/** /**
* Start updated element. * Start updated element.
*/ */
private static final String START_UPDATED_ELEMENT = "<updated>"; private static final String START_UPDATED_ELEMENT = "<updated>";
/** /**
* End updated element. * End updated element.
*/ */
private static final String END_UPDATED_ELEMENT = "</updated>"; private static final String END_UPDATED_ELEMENT = "</updated>";
/** /**
* Id. * Id.
*/ */
private String id; private String id;
/** /**
* Update date. * Update date.
*/ */
private Date updated; private Date updated;
/** /**
* Title. * Title.
*/ */
private String title; private String title;
/** /**
* Summary. * Summary.
*/ */
private String summary; private String summary;
/** /**
* Link. * Link.
*/ */
private String link; private String link;
/** /**
* Author. * Author.
*/ */
private String author; private String author;
/** /**
* URI. * URI.
*/ */
private String uri; private String uri;
/** /**
* Categories. * Categories.
*/ */
...@@ -298,7 +324,6 @@ public final class Entry { ...@@ -298,7 +324,6 @@ public final class Entry {
stringBuilder.append(END_URI_ELEMENT); stringBuilder.append(END_URI_ELEMENT);
stringBuilder.append(END_AUTHOR_ELEMENT); stringBuilder.append(END_AUTHOR_ELEMENT);
for (final Category category : categories) { for (final Category category : categories) {
stringBuilder.append(category.toString()); stringBuilder.append(category.toString());
} }
...@@ -311,9 +336,7 @@ public final class Entry { ...@@ -311,9 +336,7 @@ public final class Entry {
stringBuilder.append(START_UPDATED_ELEMENT); stringBuilder.append(START_UPDATED_ELEMENT);
stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339 stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339
updated, updated, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone(Feed.TIME_ZONE_ID)));
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(),
TimeZone.getTimeZone(Feed.TIME_ZONE_ID)));
stringBuilder.append(END_UPDATED_ELEMENT); stringBuilder.append(END_UPDATED_ELEMENT);
stringBuilder.append(START_SUMMARY_ELEMENT); stringBuilder.append(START_SUMMARY_ELEMENT);
......
...@@ -15,12 +15,14 @@ ...@@ -15,12 +15,14 @@
*/ */
package org.b3log.solo.model.feed.atom; package org.b3log.solo.model.feed.atom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* Feed. * Feed.
* *
...@@ -41,99 +43,122 @@ public final class Feed { ...@@ -41,99 +43,122 @@ public final class Feed {
* Id. * Id.
*/ */
private String id; private String id;
/** /**
* Title. * Title.
*/ */
private String title; private String title;
/** /**
* Subtitle. * Subtitle.
*/ */
private String subtitle; private String subtitle;
/** /**
* Update date. * Update date.
*/ */
private Date updated; private Date updated;
/** /**
* Author. * Author.
*/ */
private String author; private String author;
/** /**
* Link. * Link.
*/ */
private String link; private String link;
/** /**
* Entries. * Entries.
*/ */
private List<Entry> entries = new ArrayList<Entry>(); private List<Entry> entries = new ArrayList<Entry>();
/** /**
* Link variable. * Link variable.
*/ */
private static final String LINK_VARIABLE = "${link}"; private static final String LINK_VARIABLE = "${link}";
/** /**
* Time zone id. * Time zone id.
*/ */
public static final String TIME_ZONE_ID = "Asia/Shanghai"; public static final String TIME_ZONE_ID = "Asia/Shanghai";
/** /**
* Start document. * Start document.
*/ */
private static final String START_DOCUMENT = "<?xml version=\"1.0\"?>"; private static final String START_DOCUMENT = "<?xml version=\"1.0\"?>";
/** /**
* Start feed element. * Start feed element.
*/ */
private static final String START_FEED_ELEMENT = private static final String START_FEED_ELEMENT = "<feed xmlns=\"http://www.w3.org/2005/Atom\">";
"<feed xmlns=\"http://www.w3.org/2005/Atom\">";
/** /**
* End feed element. * End feed element.
*/ */
private static final String END_FEED_ELEMENT = "</feed>"; private static final String END_FEED_ELEMENT = "</feed>";
/** /**
* Start id element. * Start id element.
*/ */
private static final String START_ID_ELEMENT = "<id>"; private static final String START_ID_ELEMENT = "<id>";
/** /**
* End if element. * End if element.
*/ */
private static final String END_ID_ELEMENT = "</id>"; private static final String END_ID_ELEMENT = "</id>";
/** /**
* Start title element. * Start title element.
*/ */
private static final String START_TITLE_ELEMENT = "<title type=\"text\">"; private static final String START_TITLE_ELEMENT = "<title type=\"text\">";
/** /**
* End title element. * End title element.
*/ */
private static final String END_TITLE_ELEMENT = "</title>"; private static final String END_TITLE_ELEMENT = "</title>";
/** /**
* Start subtitle element. * Start subtitle element.
*/ */
private static final String START_SUBTITLE_ELEMENT = "<subtitle type=\"text\"> "; private static final String START_SUBTITLE_ELEMENT = "<subtitle type=\"text\"> ";
/** /**
* End subtitle element. * End subtitle element.
*/ */
private static final String END_SUBTITLE_ELEMENT = "</subtitle>"; private static final String END_SUBTITLE_ELEMENT = "</subtitle>";
/** /**
* Start updated element. * Start updated element.
*/ */
private static final String START_UPDATED_ELEMENT = "<updated>"; private static final String START_UPDATED_ELEMENT = "<updated>";
/** /**
* End updated element. * End updated element.
*/ */
private static final String END_UPDATED_ELEMENT = "</updated>"; private static final String END_UPDATED_ELEMENT = "</updated>";
/** /**
* Start author element. * Start author element.
*/ */
private static final String START_AUTHOR_ELEMENT = "<author>"; private static final String START_AUTHOR_ELEMENT = "<author>";
/** /**
* End author element. * End author element.
*/ */
private static final String END_AUTHOR_ELEMENT = "</author>"; private static final String END_AUTHOR_ELEMENT = "</author>";
/** /**
* Start name element. * Start name element.
*/ */
private static final String START_NAME_ELEMENT = "<name>"; private static final String START_NAME_ELEMENT = "<name>";
/** /**
* End name element. * End name element.
*/ */
private static final String END_NAME_ELEMENT = "</name>"; private static final String END_NAME_ELEMENT = "</name>";
/** /**
* Link element. * Link element.
*/ */
...@@ -259,6 +284,7 @@ public final class Feed { ...@@ -259,6 +284,7 @@ public final class Feed {
@Override @Override
public String toString() { public String toString() {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(START_DOCUMENT); stringBuilder.append(START_DOCUMENT);
stringBuilder.append(START_FEED_ELEMENT); stringBuilder.append(START_FEED_ELEMENT);
...@@ -276,9 +302,7 @@ public final class Feed { ...@@ -276,9 +302,7 @@ public final class Feed {
stringBuilder.append(START_UPDATED_ELEMENT); stringBuilder.append(START_UPDATED_ELEMENT);
stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339 stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339
updated, updated, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone(TIME_ZONE_ID)));
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(),
TimeZone.getTimeZone(TIME_ZONE_ID)));
stringBuilder.append(END_UPDATED_ELEMENT); stringBuilder.append(END_UPDATED_ELEMENT);
stringBuilder.append(START_AUTHOR_ELEMENT); stringBuilder.append(START_AUTHOR_ELEMENT);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
/** /**
* Category. * Category.
* *
...@@ -27,8 +28,8 @@ public final class Category { ...@@ -27,8 +28,8 @@ public final class Category {
/** /**
* Category element. * Category element.
*/ */
private static final String CATEGORY_ELEMENT = private static final String CATEGORY_ELEMENT = "<category>${term}</category>";
"<category>${term}</category>";
/** /**
* Term. * Term.
*/ */
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* RSS 2.0 channel. * RSS 2.0 channel.
* *
...@@ -40,104 +42,124 @@ public final class Channel { ...@@ -40,104 +42,124 @@ public final class Channel {
* Title. * Title.
*/ */
private String title; private String title;
/** /**
* Link. * Link.
*/ */
private String link; private String link;
/** /**
* Atom link. * Atom link.
*/ */
private String atomLink; private String atomLink;
/** /**
* Description. * Description.
*/ */
private String description; private String description;
/** /**
* Generator. * Generator.
*/ */
private String generator; private String generator;
/** /**
* Last build date. * Last build date.
*/ */
private Date lastBuildDate; private Date lastBuildDate;
/** /**
* Language. * Language.
*/ */
private String language; private String language;
/** /**
* Items. * Items.
*/ */
private List<Item> items = new ArrayList<Item>(); private List<Item> items = new ArrayList<Item>();
/** /**
* Time zone id. * Time zone id.
*/ */
public static final String TIME_ZONE_ID = "Asia/Shanghai"; public static final String TIME_ZONE_ID = "Asia/Shanghai";
/** /**
* Start. * Start.
*/ */
private static final String START = private static final String START = "<?xml version='1.0' encoding='UTF-8'?><rss version=\"2.0\" "
"<?xml version='1.0' encoding='UTF-8'?><rss version=\"2.0\" " + "xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel>";
+ "xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel>";
/** /**
* End. * End.
*/ */
private static final String END = "</channel></rss>"; private static final String END = "</channel></rss>";
/** /**
* Start title element. * Start title element.
*/ */
private static final String START_TITLE_ELEMENT = "<title>"; private static final String START_TITLE_ELEMENT = "<title>";
/** /**
* End title element. * End title element.
*/ */
private static final String END_TITLE_ELEMENT = "</title>"; private static final String END_TITLE_ELEMENT = "</title>";
/** /**
* Start link element. * Start link element.
*/ */
private static final String START_LINK_ELEMENT = "<link>"; private static final String START_LINK_ELEMENT = "<link>";
/** /**
* Atom link variable. * Atom link variable.
*/ */
private static final String ATOM_LINK_VARIABLE = "${atomLink}"; private static final String ATOM_LINK_VARIABLE = "${atomLink}";
/** /**
* End link element. * End link element.
*/ */
private static final String END_LINK_ELEMENT = "</link>"; private static final String END_LINK_ELEMENT = "</link>";
/** /**
* Atom link element. * Atom link element.
*/ */
private static final String ATOM_LINK_ELEMENT = private static final String ATOM_LINK_ELEMENT = "<atom:link href=\"" + ATOM_LINK_VARIABLE
"<atom:link href=\"" + "\" rel=\"self\" type=\"application/rss+xml\" />";
+ ATOM_LINK_VARIABLE
+ "\" rel=\"self\" type=\"application/rss+xml\" />";
/** /**
* Start description element. * Start description element.
*/ */
private static final String START_DESCRIPTION_ELEMENT = "<description>"; private static final String START_DESCRIPTION_ELEMENT = "<description>";
/** /**
* End description element. * End description element.
*/ */
private static final String END_DESCRIPTION_ELEMENT = "</description>"; private static final String END_DESCRIPTION_ELEMENT = "</description>";
/** /**
* Start generator element. * Start generator element.
*/ */
private static final String START_GENERATOR_ELEMENT = "<generator>"; private static final String START_GENERATOR_ELEMENT = "<generator>";
/** /**
* End generator element. * End generator element.
*/ */
private static final String END_GENERATOR_ELEMENT = "</generator>"; private static final String END_GENERATOR_ELEMENT = "</generator>";
/** /**
* Start language element. * Start language element.
*/ */
private static final String START_LANGUAGE_ELEMENT = "<language>"; private static final String START_LANGUAGE_ELEMENT = "<language>";
/** /**
* End language element. * End language element.
*/ */
private static final String END_LANGUAGE_ELEMENT = "</language>"; private static final String END_LANGUAGE_ELEMENT = "</language>";
/** /**
* Start last build date element. * Start last build date element.
*/ */
private static final String START_LAST_BUILD_DATE_ELEMENT = private static final String START_LAST_BUILD_DATE_ELEMENT = "<lastBuildDate>";
"<lastBuildDate>";
/** /**
* End last build date element. * End last build date element.
*/ */
...@@ -281,6 +303,7 @@ public final class Channel { ...@@ -281,6 +303,7 @@ public final class Channel {
@Override @Override
public String toString() { public String toString() {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(START); stringBuilder.append(START);
stringBuilder.append(START_TITLE_ELEMENT); stringBuilder.append(START_TITLE_ELEMENT);
...@@ -291,8 +314,7 @@ public final class Channel { ...@@ -291,8 +314,7 @@ public final class Channel {
stringBuilder.append(link); stringBuilder.append(link);
stringBuilder.append(END_LINK_ELEMENT); stringBuilder.append(END_LINK_ELEMENT);
stringBuilder.append(ATOM_LINK_ELEMENT.replace(ATOM_LINK_VARIABLE, stringBuilder.append(ATOM_LINK_ELEMENT.replace(ATOM_LINK_VARIABLE, atomLink));
atomLink));
stringBuilder.append(START_DESCRIPTION_ELEMENT); stringBuilder.append(START_DESCRIPTION_ELEMENT);
stringBuilder.append(description); stringBuilder.append(description);
...@@ -303,8 +325,7 @@ public final class Channel { ...@@ -303,8 +325,7 @@ public final class Channel {
stringBuilder.append(END_GENERATOR_ELEMENT); stringBuilder.append(END_GENERATOR_ELEMENT);
stringBuilder.append(START_LAST_BUILD_DATE_ELEMENT); stringBuilder.append(START_LAST_BUILD_DATE_ELEMENT);
stringBuilder.append(DateFormatUtils.SMTP_DATETIME_FORMAT.format( stringBuilder.append(DateFormatUtils.SMTP_DATETIME_FORMAT.format(lastBuildDate));
lastBuildDate));
stringBuilder.append(END_LAST_BUILD_DATE_ELEMENT); stringBuilder.append(END_LAST_BUILD_DATE_ELEMENT);
stringBuilder.append(START_LANGUAGE_ELEMENT); stringBuilder.append(START_LANGUAGE_ELEMENT);
......
...@@ -15,12 +15,14 @@ ...@@ -15,12 +15,14 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* Item. * Item.
* *
...@@ -33,86 +35,93 @@ public final class Item { ...@@ -33,86 +35,93 @@ public final class Item {
/** /**
* Start title element. * Start title element.
*/ */
private static final String START_TITLE_ELEMENT = private static final String START_TITLE_ELEMENT = "<title>";
"<title>";
/** /**
* End title element. * End title element.
*/ */
private static final String END_TITLE_ELEMENT = private static final String END_TITLE_ELEMENT = "</title>";
"</title>";
/** /**
* Start link element. * Start link element.
*/ */
private static final String START_LINK_ELEMENT = private static final String START_LINK_ELEMENT = "<link>";
"<link>";
/** /**
* End link element. * End link element.
*/ */
private static final String END_LINK_ELEMENT = "</link>"; private static final String END_LINK_ELEMENT = "</link>";
/** /**
* Start description element. * Start description element.
*/ */
private static final String START_DESCRIPTION_ELEMENT = private static final String START_DESCRIPTION_ELEMENT = "<description>";
"<description>";
/** /**
* End summary element. * End summary element.
*/ */
private static final String END_DESCRIPTION_ELEMENT = private static final String END_DESCRIPTION_ELEMENT = "</description>";
"</description>";
/** /**
* Start author element. * Start author element.
*/ */
private static final String START_AUTHOR_ELEMENT = private static final String START_AUTHOR_ELEMENT = "<author>";
"<author>";
/** /**
* End author element. * End author element.
*/ */
private static final String END_AUTHOR_ELEMENT = private static final String END_AUTHOR_ELEMENT = "</author>";
"</author>";
/** /**
* Categories. * Categories.
*/ */
private Set<Category> categories = new HashSet<Category>(); private Set<Category> categories = new HashSet<Category>();
/** /**
* Start guid element. * Start guid element.
*/ */
private static final String START_GUID_ELEMENT = private static final String START_GUID_ELEMENT = "<guid>";
"<guid>";
/** /**
* End guid element. * End guid element.
*/ */
private static final String END_GUID_ELEMENT = private static final String END_GUID_ELEMENT = "</guid>";
"</guid>";
/** /**
* Start pubDate element. * Start pubDate element.
*/ */
private static final String START_PUB_DATE_ELEMENT = private static final String START_PUB_DATE_ELEMENT = "<pubDate>";
"<pubDate>";
/** /**
* End pubDate element. * End pubDate element.
*/ */
private static final String END_PUB_DATE_ELEMENT = private static final String END_PUB_DATE_ELEMENT = "</pubDate>";
"</pubDate>";
/** /**
* Guid. * Guid.
*/ */
private String guid; private String guid;
/** /**
* Publish date. * Publish date.
*/ */
private Date pubDate; private Date pubDate;
/** /**
* Title. * Title.
*/ */
private String title; private String title;
/** /**
* Description. * Description.
*/ */
private String description; private String description;
/** /**
* Link. * Link.
*/ */
private String link; private String link;
/** /**
* Author. * Author.
*/ */
...@@ -264,9 +273,7 @@ public final class Item { ...@@ -264,9 +273,7 @@ public final class Item {
} }
stringBuilder.append(START_PUB_DATE_ELEMENT); stringBuilder.append(START_PUB_DATE_ELEMENT);
stringBuilder.append(DateFormatUtils.format( stringBuilder.append(DateFormatUtils.format(pubDate, "EEE, dd MMM yyyy HH:mm:ss z", TimeZone.getTimeZone(Channel.TIME_ZONE_ID)));
pubDate, "EEE, dd MMM yyyy HH:mm:ss z",
TimeZone.getTimeZone(Channel.TIME_ZONE_ID)));
stringBuilder.append(END_PUB_DATE_ELEMENT).append("</item>"); stringBuilder.append(END_PUB_DATE_ELEMENT).append("</item>");
return stringBuilder.toString(); return stringBuilder.toString();
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
*/ */
package org.b3log.solo.model.sitemap; package org.b3log.solo.model.sitemap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Sitemap. * Sitemap.
* *
...@@ -36,17 +38,18 @@ public final class Sitemap { ...@@ -36,17 +38,18 @@ public final class Sitemap {
/** /**
* Start document. * Start document.
*/ */
private static final String START_DOCUMENT = private static final String START_DOCUMENT = "<?xml version='1.0' encoding='UTF-8'?>";
"<?xml version='1.0' encoding='UTF-8'?>";
/** /**
* Start URL set element. * Start URL set element.
*/ */
private static final String START_URL_SET_ELEMENT = private static final String START_URL_SET_ELEMENT = "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
/** /**
* End URL set element. * End URL set element.
*/ */
private static final String END_URL_SET_ELEMENT = "</urlset>"; private static final String END_URL_SET_ELEMENT = "</urlset>";
/** /**
* URLs. * URLs.
*/ */
...@@ -64,6 +67,7 @@ public final class Sitemap { ...@@ -64,6 +67,7 @@ public final class Sitemap {
@Override @Override
public String toString() { public String toString() {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(START_DOCUMENT); stringBuilder.append(START_DOCUMENT);
stringBuilder.append(START_URL_SET_ELEMENT); stringBuilder.append(START_URL_SET_ELEMENT);
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
*/ */
package org.b3log.solo.model.sitemap; package org.b3log.solo.model.sitemap;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
/** /**
* Sitemap URL. * Sitemap URL.
* *
...@@ -30,30 +32,37 @@ public final class URL { ...@@ -30,30 +32,37 @@ public final class URL {
* Start URL element. * Start URL element.
*/ */
private static final String START_URL_ELEMENT = "<url>"; private static final String START_URL_ELEMENT = "<url>";
/** /**
* End URL element. * End URL element.
*/ */
private static final String END_URL_ELEMENT = "</url>"; private static final String END_URL_ELEMENT = "</url>";
/** /**
* Start loc element. * Start loc element.
*/ */
private static final String START_LOC_ELEMENT = "<loc>"; private static final String START_LOC_ELEMENT = "<loc>";
/** /**
* End loc element. * End loc element.
*/ */
private static final String END_LOC_ELEMENT = "</loc>"; private static final String END_LOC_ELEMENT = "</loc>";
/** /**
* Start last mod element. * Start last mod element.
*/ */
private static final String START_LAST_MOD_ELEMENT = "<lastmod>"; private static final String START_LAST_MOD_ELEMENT = "<lastmod>";
/** /**
* End last mod element. * End last mod element.
*/ */
private static final String END_LAST_MOD_ELEMENT = "</lastmod>"; private static final String END_LAST_MOD_ELEMENT = "</lastmod>";
/** /**
* Loc. * Loc.
*/ */
private String loc; private String loc;
/** /**
* Last mod. * Last mod.
*/ */
...@@ -98,6 +107,7 @@ public final class URL { ...@@ -98,6 +107,7 @@ public final class URL {
@Override @Override
public String toString() { public String toString() {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(START_URL_ELEMENT); stringBuilder.append(START_URL_ELEMENT);
stringBuilder.append(START_LOC_ELEMENT); stringBuilder.append(START_LOC_ELEMENT);
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
*/ */
package org.b3log.solo.plugin.cache; package org.b3log.solo.plugin.cache;
import org.b3log.latke.plugin.AbstractPlugin; import org.b3log.latke.plugin.AbstractPlugin;
/** /**
* Admin cache plugin. * Admin cache plugin.
* *
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.plugin.cache; package org.b3log.solo.plugin.cache;
import org.b3log.solo.model.Common; import org.b3log.solo.model.Common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -41,6 +42,7 @@ import org.b3log.solo.service.PreferenceQueryService; ...@@ -41,6 +42,7 @@ import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.QueryResults; import org.b3log.solo.util.QueryResults;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Admin cache service. * Admin cache service.
* *
...@@ -55,14 +57,17 @@ public final class AdminCacheService { ...@@ -55,14 +57,17 @@ public final class AdminCacheService {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(AdminCacheService.class.getName()); private static final Logger LOGGER = Logger.getLogger(AdminCacheService.class.getName());
/** /**
* User utilities. * User utilities.
*/ */
private Users userUtils = Users.getInstance(); private Users userUtils = Users.getInstance();
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/** /**
* Preference management service. * Preference management service.
*/ */
...@@ -89,24 +94,27 @@ public final class AdminCacheService { ...@@ -89,24 +94,27 @@ public final class AdminCacheService {
*/ */
@RequestProcessing(value = "/console/plugins/admin-cache/status/", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/console/plugins/admin-cache/status/", method = HTTPRequestMethod.GET)
public void getPageCache(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void getPageCache(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception { throws Exception {
if (!userUtils.isAdminLoggedIn(request)) { if (!userUtils.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
LOGGER.log(Level.INFO, "Cache status[cachedBytes={0}, cachedCount={1}]", LOGGER.log(Level.INFO, "Cache status[cachedBytes={0}, cachedCount={1}]",
new Object[]{PageCaches.getCache().getCachedBytes(), PageCaches.getCache().getCachedCount()}); new Object[] {PageCaches.getCache().getCachedBytes(), PageCaches.getCache().getCachedCount()});
try { try {
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
final boolean pageCacheEnabled = preference.getBoolean(Preference.PAGE_CACHE_ENABLED); final boolean pageCacheEnabled = preference.getBoolean(Preference.PAGE_CACHE_ENABLED);
ret.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled); ret.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled);
ret.put(Common.PAGE_CACHED_CNT, PageCaches.getKeys().size()); ret.put(Common.PAGE_CACHED_CNT, PageCaches.getKeys().size());
...@@ -117,6 +125,7 @@ public final class AdminCacheService { ...@@ -117,6 +125,7 @@ public final class AdminCacheService {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult(); final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage()); jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
} }
...@@ -154,19 +163,21 @@ public final class AdminCacheService { ...@@ -154,19 +163,21 @@ public final class AdminCacheService {
* @param context the specified http request context * @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/plugins/admin-cache/pages/" + Requests.PAGINATION_PATH_PATTERN, @RequestProcessing(value = "/console/plugins/admin-cache/pages/*/*/*"/* Requests.PAGINATION_PATH_PATTERN */,
method = HTTPRequestMethod.GET) method = HTTPRequestMethod.GET)
public void getPages(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void getPages(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception { throws Exception {
if (!userUtils.isLoggedIn(request, response)) { if (!userUtils.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
return; return;
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
...@@ -181,22 +192,25 @@ public final class AdminCacheService { ...@@ -181,22 +192,25 @@ public final class AdminCacheService {
List<String> keys = new ArrayList<String>(PageCaches.getKeys()); List<String> keys = new ArrayList<String>(PageCaches.getKeys());
// Paginates // Paginates
final int pageCount = final int pageCount = (int) Math.ceil((double) keys.size() / (double) pageSize);
(int) Math.ceil((double) keys.size() / (double) pageSize);
final JSONObject pagination = new JSONObject(); final JSONObject pagination = new JSONObject();
ret.put(Pagination.PAGINATION, pagination); ret.put(Pagination.PAGINATION, pagination);
final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize); final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount); pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
pagination.put(Pagination.PAGINATION_PAGE_NUMS, pageNums); pagination.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
final int start = pageSize * (currentPageNum - 1); final int start = pageSize * (currentPageNum - 1);
int end = start + pageSize; int end = start + pageSize;
end = end > keys.size() ? keys.size() : end; end = end > keys.size() ? keys.size() : end;
keys = keys.subList(start, end); keys = keys.subList(start, end);
// Retrives cached pages // Retrives cached pages
final List<JSONObject> pages = new ArrayList<JSONObject>(); final List<JSONObject> pages = new ArrayList<JSONObject>();
for (final String key : keys) { for (final String key : keys) {
LOGGER.log(Level.FINER, "Cached page[key={0}]", key); LOGGER.log(Level.FINER, "Cached page[key={0}]", key);
...@@ -204,8 +218,7 @@ public final class AdminCacheService { ...@@ -204,8 +218,7 @@ public final class AdminCacheService {
if (null != cachedPage) { if (null != cachedPage) {
// Do a copy for properties removing and retrieving // Do a copy for properties removing and retrieving
cachedPage = new JSONObject(cachedPage, cachedPage = new JSONObject(cachedPage, JSONObject.getNames(cachedPage));
JSONObject.getNames(cachedPage));
cachedPage.remove(PageCaches.CACHED_CONTENT); cachedPage.remove(PageCaches.CACHED_CONTENT);
pages.add(cachedPage); pages.add(cachedPage);
} }
...@@ -218,6 +231,7 @@ public final class AdminCacheService { ...@@ -218,6 +231,7 @@ public final class AdminCacheService {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult(); final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage()); jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
} }
...@@ -243,7 +257,7 @@ public final class AdminCacheService { ...@@ -243,7 +257,7 @@ public final class AdminCacheService {
*/ */
@RequestProcessing(value = "/console/plugins/admin-cache/enable/*", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/plugins/admin-cache/enable/*", method = HTTPRequestMethod.PUT)
public void setPageCache(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void setPageCache(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception { throws Exception {
if (!userUtils.isAdminLoggedIn(request)) { if (!userUtils.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN); response.sendError(HttpServletResponse.SC_FORBIDDEN);
...@@ -251,18 +265,21 @@ public final class AdminCacheService { ...@@ -251,18 +265,21 @@ public final class AdminCacheService {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
try { try {
final String path = request.getRequestURI().substring( final String path = request.getRequestURI().substring(
(Latkes.getContextPath() + "/console/plugins/admin-cache/enable/").length()); (Latkes.getContextPath() + "/console/plugins/admin-cache/enable/").length());
final boolean pageCacheEnabled = "true".equals(path) ? true : false; final boolean pageCacheEnabled = "true".equals(path) ? true : false;
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
preference.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled); preference.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled);
preferenceMgmtService.updatePreference(preference); preferenceMgmtService.updatePreference(preference);
...@@ -272,6 +289,7 @@ public final class AdminCacheService { ...@@ -272,6 +289,7 @@ public final class AdminCacheService {
LOGGER.log(Level.SEVERE, "Sets page cache error: {0}", e.getMessage()); LOGGER.log(Level.SEVERE, "Sets page cache error: {0}", e.getMessage());
final JSONObject jsonObject = QueryResults.defaultResult(); final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage()); jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
} }
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
*/ */
package org.b3log.solo.plugin.fancybox; package org.b3log.solo.plugin.fancybox;
import org.b3log.latke.plugin.AbstractPlugin; import org.b3log.latke.plugin.AbstractPlugin;
/** /**
* Shows images with <a href="http://fancybox.net/howto">jQuery Fancy</a>. * Shows images with <a href="http://fancybox.net/howto">jQuery Fancy</a>.
* *
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
*/ */
package org.b3log.solo.plugin.symphony; package org.b3log.solo.plugin.symphony;
import org.b3log.latke.plugin.AbstractPlugin; import org.b3log.latke.plugin.AbstractPlugin;
/** /**
* Getting news from <a href="http://symphony.b3log.org">B3log Symphony</a>. * Getting news from <a href="http://symphony.b3log.org">B3log Symphony</a>.
* *
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.processor; package org.b3log.solo.processor;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.servlet.HTTPRequestContext; import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
...@@ -28,6 +29,7 @@ import org.b3log.solo.service.TagQueryService; ...@@ -28,6 +29,7 @@ import org.b3log.solo.service.TagQueryService;
import org.b3log.solo.util.Articles; import org.b3log.solo.util.Articles;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Blog processor. * Blog processor.
* *
...@@ -42,10 +44,12 @@ public final class BlogProcessor { ...@@ -42,10 +44,12 @@ public final class BlogProcessor {
* Article utilities. * Article utilities.
*/ */
private Articles articleUtils = Articles.getInstance(); private Articles articleUtils = Articles.getInstance();
/** /**
* Tag query service. * Tag query service.
*/ */
private TagQueryService tagQueryService = TagQueryService.getInstance(); private TagQueryService tagQueryService = TagQueryService.getInstance();
/** /**
* Statistic query service. * Statistic query service.
*/ */
...@@ -72,13 +76,16 @@ public final class BlogProcessor { ...@@ -72,13 +76,16 @@ public final class BlogProcessor {
@RequestProcessing(value = "/blog/info", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/blog/info", method = HTTPRequestMethod.GET)
public void getRecentArticleTime(final HTTPRequestContext context) throws Exception { public void getRecentArticleTime(final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject(); final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
jsonObject.put("recentArticleTime", articleUtils.getRecentArticleTime()); jsonObject.put("recentArticleTime", articleUtils.getRecentArticleTime());
final JSONObject statistic = statisticQueryService.getStatistic(); final JSONObject statistic = statisticQueryService.getStatistic();
jsonObject.put("articleCount", statistic.getLong(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT)); jsonObject.put("articleCount", statistic.getLong(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT));
jsonObject.put("commentCount", statistic.getLong(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT)); jsonObject.put("commentCount", statistic.getLong(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT));
jsonObject.put("tagCount", tagQueryService.getTagCount()); jsonObject.put("tagCount", tagQueryService.getTagCount());
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.processor; package org.b3log.solo.processor;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Common; ...@@ -32,6 +33,7 @@ import org.b3log.solo.model.Common;
import org.b3log.solo.util.Users; import org.b3log.solo.util.Users;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Cache processor. * Cache processor.
* *
...@@ -46,6 +48,7 @@ public final class CacheProcessor { ...@@ -46,6 +48,7 @@ public final class CacheProcessor {
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(CacheProcessor.class.getName()); private static final Logger LOGGER = Logger.getLogger(CacheProcessor.class.getName());
/** /**
* User utilities. * User utilities.
*/ */
...@@ -61,7 +64,7 @@ public final class CacheProcessor { ...@@ -61,7 +64,7 @@ public final class CacheProcessor {
*/ */
@RequestProcessing(value = "/clear-cache.do", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/clear-cache.do", method = HTTPRequestMethod.POST)
public void clearCache(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void clearCache(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException { throws IOException {
LoginProcessor.tryLogInWithCookie(request, response); LoginProcessor.tryLogInWithCookie(request, response);
if (!userUtils.isAdminLoggedIn(request)) { if (!userUtils.isAdminLoggedIn(request)) {
...@@ -75,6 +78,7 @@ public final class CacheProcessor { ...@@ -75,6 +78,7 @@ public final class CacheProcessor {
if (Strings.isEmptyOrNull(all)) { // Just clears single page cache if (Strings.isEmptyOrNull(all)) { // Just clears single page cache
final String uri = requestJSONObject.optString(Common.URI); final String uri = requestJSONObject.optString(Common.URI);
clearPageCache(uri); clearPageCache(uri);
} else { // Clears all page caches } else { // Clears all page caches
clearAllPageCache(); clearAllPageCache();
...@@ -93,6 +97,7 @@ public final class CacheProcessor { ...@@ -93,6 +97,7 @@ public final class CacheProcessor {
*/ */
private void clearPageCache(final String uri) { private void clearPageCache(final String uri) {
final String pageCacheKey = PageCaches.getPageCacheKey(uri, null); final String pageCacheKey = PageCaches.getPageCacheKey(uri, null);
LOGGER.log(Level.INFO, "Clears page cache[pageCacheKey={0}]", pageCacheKey); LOGGER.log(Level.INFO, "Clears page cache[pageCacheKey={0}]", pageCacheKey);
PageCaches.remove(pageCacheKey); PageCaches.remove(pageCacheKey);
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import java.util.List; import java.util.List;
import org.b3log.latke.repository.Repository; import org.b3log.latke.repository.Repository;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.RepositoryException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Archive date repository. * Archive date repository.
* *
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import java.util.List; import java.util.List;
import org.b3log.latke.repository.Repository; import org.b3log.latke.repository.Repository;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.RepositoryException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Article repository. * Article repository.
* *
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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