Commit c79fbf5d authored by Liang Ding's avatar Liang Ding

c

parent 47aaabf8
This source diff could not be displayed because it is too large. You can view the blob instead.
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.processor; package org.b3log.solo.processor;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.annotation.RequestProcessing; import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor; import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.servlet.HTTPRequestContext; import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Statistic; import org.b3log.solo.model.Statistic;
import org.b3log.solo.repository.StatisticRepository; import org.b3log.solo.repository.StatisticRepository;
import org.b3log.solo.repository.impl.StatisticRepositoryImpl; import org.b3log.solo.repository.impl.StatisticRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.TagQueryService; 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.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Jun 28, 2012 * @version 1.0.0.0, Jun 28, 2012
* @since 0.4.6 * @since 0.4.6
*/ */
@RequestProcessor @RequestProcessor
public final class BlogProcessor { 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();
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance(); private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/** /**
* Statistic repository. * Statistic repository.
*/ */
private StatisticRepository statisticRepository = StatisticRepositoryImpl.getInstance(); private StatisticRepository statisticRepository = StatisticRepositoryImpl.getInstance();
/** /**
* Gets blog information. * Gets blog information.
* *
* <ul> * <ul>
* <li>Time of the recent updated article</li> * <li>Time of the recent updated article</li>
* <li>Article count</li> * <li>Article count</li>
* <li>Comment count</li> * <li>Comment count</li>
* <li>Tag count</li> * <li>Tag count</li>
* <li>Serve path</li> * <li>Serve path</li>
* <li>Static serve path</li> * <li>Static serve path</li>
* <li>Solo version</li> * <li>Solo version</li>
* <li>Runtime environment (GAE/LOCAL)</li> * <li>Runtime environment (GAE/LOCAL)</li>
* <li>Locale</li> * <li>Locale</li>
* </ul> * </ul>
* *
* @param context the specified context * @param context the specified context
* @throws Exception exception * @throws Exception exception
*/ */
@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 = statisticRepository.get(Statistic.STATISTIC); final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
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());
jsonObject.put("servePath", Latkes.getServePath()); jsonObject.put("servePath", Latkes.getServePath());
jsonObject.put("staticServePath", Latkes.getStaticServePath()); jsonObject.put("staticServePath", Latkes.getStaticServePath());
jsonObject.put("version", SoloServletListener.VERSION); jsonObject.put("version", SoloServletListener.VERSION);
jsonObject.put("runtimeEnv", Latkes.getRuntimeEnv()); jsonObject.put("runtimeEnv", Latkes.getRuntimeEnv());
jsonObject.put("locale", Latkes.getLocale()); jsonObject.put("locale", Latkes.getLocale());
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
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;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.plugin.AbstractPlugin; import org.b3log.latke.plugin.AbstractPlugin;
import org.b3log.latke.plugin.PluginManager; import org.b3log.latke.plugin.PluginManager;
import org.b3log.latke.plugin.PluginStatus; import org.b3log.latke.plugin.PluginStatus;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.latke.service.LangPropsService; import org.b3log.latke.service.LangPropsService;
import org.b3log.solo.repository.PluginRepository; import org.b3log.solo.repository.PluginRepository;
import org.b3log.solo.repository.impl.PluginRepositoryImpl; import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Plugin management service. * Plugin management service.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Oct 27, 2011 * @version 1.0.0.0, Oct 27, 2011
* @since 0.4.0 * @since 0.4.0
*/ */
public final class PluginMgmtService { public final class PluginMgmtService {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER =
Logger.getLogger(PluginMgmtService.class.getName()); Logger.getLogger(PluginMgmtService.class.getName());
/** /**
* Plugin repository. * Plugin repository.
*/ */
private PluginRepository pluginRepository = private PluginRepository pluginRepository =
PluginRepositoryImpl.getInstance(); PluginRepositoryImpl.getInstance();
/** /**
* Language service. * Language service.
*/ */
private LangPropsService langPropsService = LangPropsService.getInstance(); private LangPropsService langPropsService = LangPropsService.getInstance();
/** /**
* Sets a plugin's status with the specified plugin id, status. * Sets a plugin's status with the specified plugin id, status.
* *
* @param pluginId the specified plugin id * @param pluginId the specified plugin id
* @param status the specified status, see {@link PluginStatus} * @param status the specified status, see {@link PluginStatus}
* @return for example, * @return for example,
* <pre> * <pre>
* { * {
* "sc": boolean, * "sc": boolean,
* "msg": "" * "msg": ""
* } * }
* </pre> * </pre>
*/ */
public JSONObject setPluginStatus(final String pluginId, final String status) { public JSONObject setPluginStatus(final String pluginId, final String status) {
final Map<String, String> langs = final Map<String, String> langs =
langPropsService.getAll(Latkes.getLocale()); langPropsService.getAll(Latkes.getLocale());
final PluginManager pluginManager = PluginManager.getInstance(); final PluginManager pluginManager = PluginManager.getInstance();
final List<AbstractPlugin> plugins = pluginManager.getPlugins(); final List<AbstractPlugin> plugins = pluginManager.getPlugins();
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
for (final AbstractPlugin plugin : plugins) { for (final AbstractPlugin plugin : plugins) {
if (plugin.getId().equals(pluginId)) { if (plugin.getId().equals(pluginId)) {
final Transaction transaction = final Transaction transaction =
pluginRepository.beginTransaction(); pluginRepository.beginTransaction();
try { try {
plugin.setStatus(PluginStatus.valueOf(status)); plugin.setStatus(PluginStatus.valueOf(status));
pluginRepository.update(pluginId, plugin.toJSONObject()); pluginRepository.update(pluginId, plugin.toJSONObject());
transaction.commit(); transaction.commit();
pluginManager.update(plugin); pluginManager.update(plugin);
ret.put(Keys.STATUS_CODE, true); ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langs.get("setSuccLabel")); ret.put(Keys.MSG, langs.get("setSuccLabel"));
return ret; return ret;
} catch (final Exception e) { } catch (final Exception e) {
if (transaction.isActive()) { if (transaction.isActive()) {
transaction.rollback(); transaction.rollback();
} }
LOGGER.log(Level.SEVERE, "Set plugin status error", e); LOGGER.log(Level.SEVERE, "Set plugin status error", e);
ret.put(Keys.STATUS_CODE, false); ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langs.get("setFailLabel")); ret.put(Keys.MSG, langs.get("setFailLabel"));
return ret; return ret;
} }
} }
} }
ret.put(Keys.STATUS_CODE, false); ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langs.get("refreshAndRetryLabel")); ret.put(Keys.MSG, langs.get("refreshAndRetryLabel"));
return ret; return ret;
} }
/** /**
* Gets the {@link PluginMgmtService} singleton. * Gets the {@link PluginMgmtService} singleton.
* *
* @return the singleton * @return the singleton
*/ */
public static PluginMgmtService getInstance() { public static PluginMgmtService getInstance() {
return SingletonHolder.SINGLETON; return SingletonHolder.SINGLETON;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private PluginMgmtService() { private PluginMgmtService() {
} }
/** /**
* Singleton holder. * Singleton holder.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Oct 27, 2011 * @version 1.0.0.0, Oct 27, 2011
*/ */
private static final class SingletonHolder { private static final class SingletonHolder {
/** /**
* Singleton. * Singleton.
*/ */
private static final PluginMgmtService SINGLETON = private static final PluginMgmtService SINGLETON =
new PluginMgmtService(); new PluginMgmtService();
/** /**
* Private default constructor. * Private default constructor.
*/ */
private SingletonHolder() { private SingletonHolder() {
} }
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.RepositoryException;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.PreferenceRepository; import org.b3log.solo.repository.PreferenceRepository;
import org.b3log.solo.repository.impl.PreferenceRepositoryImpl; import org.b3log.solo.repository.impl.PreferenceRepositoryImpl;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Preference query service. * Preference query service.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Oct 31, 2011 * @version 1.0.0.1, Oct 31, 2011
* @since 0.4.0 * @since 0.4.0
*/ */
public final class PreferenceQueryService { public final class PreferenceQueryService {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(PreferenceQueryService.class.getName()); private static final Logger LOGGER = Logger.getLogger(PreferenceQueryService.class.getName());
/** /**
* Preference repository. * Preference repository.
*/ */
private PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance(); private PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance();
/** /**
* Gets the reply notification template. * Gets the reply notification template.
* *
* @return reply notification template, returns {@code null} if not found * @return reply notification template, returns {@code null} if not found
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public JSONObject getReplyNotificationTemplate() throws ServiceException { public JSONObject getReplyNotificationTemplate() throws ServiceException {
try { try {
return preferenceRepository.get(Preference.REPLY_NOTIFICATION_TEMPLATE); return preferenceRepository.get(Preference.REPLY_NOTIFICATION_TEMPLATE);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Updates reply notification template failed", e); LOGGER.log(Level.SEVERE, "Updates reply notification template failed", e);
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
/** /**
* Gets the user preference. * Gets the user preference.
* *
* <p> * <p>
* <b>Note</b>: Invoking the method will not load skin. * <b>Note</b>: Invoking the method will not load skin.
* </p> * </p>
* *
* @return user preference, returns {@code null} if not found * @return user preference, returns {@code null} if not found
* @throws ServiceException if repository exception * @throws ServiceException if repository exception
*/ */
public JSONObject getPreference() throws ServiceException { public JSONObject getPreference() throws ServiceException {
try { try {
final JSONObject ret = preferenceRepository.get(Preference.PREFERENCE); final JSONObject ret = preferenceRepository.get(Preference.PREFERENCE);
if (null == ret) { if (null == ret) {
LOGGER.log(Level.WARNING, "Can not load preference from datastore"); LOGGER.log(Level.WARNING, "Can not load preference from datastore");
return null; return null;
} }
return ret; return ret;
} catch (final RepositoryException e) { } catch (final RepositoryException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e);
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
} }
/** /**
* Gets the {@link PreferenceQueryService} singleton. * Gets the {@link PreferenceQueryService} singleton.
* *
* @return the singleton * @return the singleton
*/ */
public static PreferenceQueryService getInstance() { public static PreferenceQueryService getInstance() {
return SingletonHolder.SINGLETON; return SingletonHolder.SINGLETON;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private PreferenceQueryService() { private PreferenceQueryService() {
} }
/** /**
* Singleton holder. * Singleton holder.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Oct 24, 2011 * @version 1.0.0.0, Oct 24, 2011
*/ */
private static final class SingletonHolder { private static final class SingletonHolder {
/** /**
* Singleton. * Singleton.
*/ */
private static final PreferenceQueryService SINGLETON = private static final PreferenceQueryService SINGLETON =
new PreferenceQueryService(); new PreferenceQueryService();
/** /**
* Private default constructor. * Private default constructor.
*/ */
private SingletonHolder() { private SingletonHolder() {
} }
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
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;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.latke.service.ServiceException; import org.b3log.latke.service.ServiceException;
import org.b3log.solo.model.Tag; import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.TagRepository; import org.b3log.solo.repository.TagRepository;
import org.b3log.solo.repository.impl.TagRepositoryImpl; import org.b3log.solo.repository.impl.TagRepositoryImpl;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Tag management service. * Tag management service.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Oct 26, 2011 * @version 1.0.0.1, Oct 26, 2011
* @since 0.4.0 * @since 0.4.0
*/ */
public final class TagMgmtService { public final class TagMgmtService {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER =
Logger.getLogger(TagMgmtService.class.getName()); Logger.getLogger(TagMgmtService.class.getName());
/** /**
* Tag query service. * Tag query service.
*/ */
private TagQueryService tagQueryService = TagQueryService.getInstance(); private TagQueryService tagQueryService = TagQueryService.getInstance();
/** /**
* Tag repository. * Tag repository.
*/ */
private TagRepository tagRepository = TagRepositoryImpl.getInstance(); private TagRepository tagRepository = TagRepositoryImpl.getInstance();
/** /**
* Removes all unused tags. * Removes all unused tags.
* *
* @throws ServiceException if get tags failed, or remove failed * @throws ServiceException if get tags failed, or remove failed
*/ */
public void removeUnusedTags() throws ServiceException { public void removeUnusedTags() throws ServiceException {
final Transaction transaction = tagRepository.beginTransaction(); final Transaction transaction = tagRepository.beginTransaction();
try { try {
final List<JSONObject> tags = tagQueryService.getTags(); final List<JSONObject> tags = tagQueryService.getTags();
for (int i = 0; i < tags.size(); i++) { for (int i = 0; i < tags.size(); i++) {
final JSONObject tag = tags.get(i); final JSONObject tag = tags.get(i);
final int tagRefCnt = tag.getInt(Tag.TAG_REFERENCE_COUNT); final int tagRefCnt = tag.getInt(Tag.TAG_REFERENCE_COUNT);
if (0 == tagRefCnt) { if (0 == tagRefCnt) {
final String tagId = tag.getString(Keys.OBJECT_ID); final String tagId = tag.getString(Keys.OBJECT_ID);
tagRepository.remove(tagId); tagRepository.remove(tagId);
} }
} }
transaction.commit(); transaction.commit();
} catch (final Exception e) { } catch (final Exception e) {
if (transaction.isActive()) { if (transaction.isActive()) {
transaction.rollback(); transaction.rollback();
} }
LOGGER.log(Level.SEVERE, "Removes unused tags failed", e); LOGGER.log(Level.SEVERE, "Removes unused tags failed", e);
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
/** /**
* Gets the {@link TagMgmtService} singleton. * Gets the {@link TagMgmtService} singleton.
* *
* @return the singleton * @return the singleton
*/ */
public static TagMgmtService getInstance() { public static TagMgmtService getInstance() {
return SingletonHolder.SINGLETON; return SingletonHolder.SINGLETON;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private TagMgmtService() { private TagMgmtService() {
} }
/** /**
* Singleton holder. * Singleton holder.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Oct 24, 2011 * @version 1.0.0.0, Oct 24, 2011
*/ */
private static final class SingletonHolder { private static final class SingletonHolder {
/** /**
* Singleton. * Singleton.
*/ */
private static final TagMgmtService SINGLETON = private static final TagMgmtService SINGLETON =
new TagMgmtService(); new TagMgmtService();
/** /**
* Private default constructor. * Private default constructor.
*/ */
private SingletonHolder() { private SingletonHolder() {
} }
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.tautua.markdownpapers.Markdown; import org.tautua.markdownpapers.Markdown;
/** /**
* <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities. * <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities.
* *
* <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p> * <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 28, 2012 * @version 1.0.0.0, Apr 28, 2012
* @since 0.4.5 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
/** /**
* Converts the specified markdown text to HTML. * Converts the specified markdown text to HTML.
* *
* @param markdownText the specified markdown text * @param markdownText the specified markdown text
* @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null} * @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}
* @throws Exception exception * @throws Exception exception
*/ */
public static String toHTML(final String markdownText) throws Exception { public static String toHTML(final String markdownText) throws Exception {
if (Strings.isEmptyOrNull(markdownText)) { if (Strings.isEmptyOrNull(markdownText)) {
return null; return null;
} }
final StringWriter writer = new StringWriter(); final StringWriter writer = new StringWriter();
final Markdown markdown = new Markdown(); final Markdown markdown = new Markdown();
markdown.transform(new StringReader(markdownText), writer); markdown.transform(new StringReader(markdownText), writer);
return writer.toString(); return writer.toString();
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private Markdowns() { private Markdowns() {
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
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;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.model.Plugin; import org.b3log.latke.model.Plugin;
import org.b3log.latke.plugin.AbstractPlugin; import org.b3log.latke.plugin.AbstractPlugin;
import org.b3log.latke.plugin.PluginStatus; import org.b3log.latke.plugin.PluginStatus;
import org.b3log.latke.repository.Query; import org.b3log.latke.repository.Query;
import org.b3log.latke.util.CollectionUtils; import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.repository.impl.PluginRepositoryImpl; import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Plugin utilities. * Plugin utilities.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Sep 11, 2011 * @version 1.0.0.3, Sep 11, 2011
*/ */
public final class Plugins { public final class Plugins {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER =
Logger.getLogger(Plugins.class.getName()); Logger.getLogger(Plugins.class.getName());
/** /**
* Plugin repository. * Plugin repository.
*/ */
private static final PluginRepositoryImpl PLUGIN_REPOS = private static final PluginRepositoryImpl PLUGIN_REPOS =
PluginRepositoryImpl.getInstance(); PluginRepositoryImpl.getInstance();
/** /**
* Updates datastore plugin descriptions with the specified plugins. * Updates datastore plugin descriptions with the specified plugins.
* *
* @param plugins the specified plugins * @param plugins the specified plugins
* @throws Exception exception * @throws Exception exception
*/ */
public static void refresh(final List<AbstractPlugin> plugins) public static void refresh(final List<AbstractPlugin> plugins)
throws Exception { throws Exception {
final JSONObject result = PLUGIN_REPOS.get(new Query()); final JSONObject result = PLUGIN_REPOS.get(new Query());
final JSONArray pluginArray = result.getJSONArray(Keys.RESULTS); final JSONArray pluginArray = result.getJSONArray(Keys.RESULTS);
final List<JSONObject> persistedPlugins = final List<JSONObject> persistedPlugins =
CollectionUtils.jsonArrayToList(pluginArray); CollectionUtils.jsonArrayToList(pluginArray);
// Disables plugin repository cache to avoid remove all cache // Disables plugin repository cache to avoid remove all cache
PLUGIN_REPOS.setCacheEnabled(false); PLUGIN_REPOS.setCacheEnabled(false);
try { try {
// Reads plugin status from datastore and clear plugin datastore // Reads plugin status from datastore and clear plugin datastore
for (final JSONObject oldPluginDesc : persistedPlugins) { for (final JSONObject oldPluginDesc : persistedPlugins) {
final String descId = oldPluginDesc.getString(Keys.OBJECT_ID); final String descId = oldPluginDesc.getString(Keys.OBJECT_ID);
final AbstractPlugin plugin = get(plugins, descId); final AbstractPlugin plugin = get(plugins, descId);
PLUGIN_REPOS.remove(descId); PLUGIN_REPOS.remove(descId);
if (null != plugin) { if (null != plugin) {
final String status = final String status =
oldPluginDesc.getString(Plugin.PLUGIN_STATUS); oldPluginDesc.getString(Plugin.PLUGIN_STATUS);
plugin.setStatus(PluginStatus.valueOf(status)); plugin.setStatus(PluginStatus.valueOf(status));
} }
} }
// Adds these plugins into datastore // Adds these plugins into datastore
for (final AbstractPlugin plugin : plugins) { for (final AbstractPlugin plugin : plugins) {
final JSONObject pluginDesc = plugin.toJSONObject(); final JSONObject pluginDesc = plugin.toJSONObject();
PLUGIN_REPOS.add(pluginDesc); PLUGIN_REPOS.add(pluginDesc);
LOGGER.log(Level.FINEST, "Refreshed plugin[{0}]", pluginDesc); LOGGER.log(Level.FINEST, "Refreshed plugin[{0}]", pluginDesc);
} }
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Refresh plugins failed", e); LOGGER.log(Level.SEVERE, "Refresh plugins failed", e);
} }
PLUGIN_REPOS.setCacheEnabled(true); PLUGIN_REPOS.setCacheEnabled(true);
} }
/** /**
* Gets a plugin in the specified plugins with the specified id. * Gets a plugin in the specified plugins with the specified id.
* *
* @param plugins the specified plugins * @param plugins the specified plugins
* @param id the specified id, must NOT be {@code null} * @param id the specified id, must NOT be {@code null}
* @return a plugin, returns {@code null} if not found * @return a plugin, returns {@code null} if not found
*/ */
private static AbstractPlugin get(final List<AbstractPlugin> plugins, private static AbstractPlugin get(final List<AbstractPlugin> plugins,
final String id) { final String id) {
if (null == id) { if (null == id) {
throw new IllegalArgumentException("id must not be null"); throw new IllegalArgumentException("id must not be null");
} }
for (final AbstractPlugin plugin : plugins) { for (final AbstractPlugin plugin : plugins) {
if (id.equals(plugin.getId())) { if (id.equals(plugin.getId())) {
return plugin; return plugin;
} }
} }
return null; return null;
} }
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Plugins() { private Plugins() {
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.model.Pagination; import org.b3log.latke.model.Pagination;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Query result utilities. * Query result utilities.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Oct 25, 2011 * @version 1.0.0.1, Oct 25, 2011
* @since 0.3.5 * @since 0.3.5
*/ */
public final class QueryResults { public final class QueryResults {
/** /**
* Constructs a default query result. * Constructs a default query result.
* *
* @return a default query result, * @return a default query result,
* <pre> * <pre>
* { * {
* "sc": false * "sc": false
* } * }
* </pre> * </pre>
*/ */
public static JSONObject defaultResult() { public static JSONObject defaultResult() {
return new JSONObject().put(Keys.STATUS_CODE, false); return new JSONObject().put(Keys.STATUS_CODE, false);
} }
/** /**
* Constructs a default query results. * Constructs a default query results.
* *
* @return a default query results, * @return a default query results,
* <pre> * <pre>
* { * {
* "pagination": { * "pagination": {
* "paginationPageCount": 0 * "paginationPageCount": 0
* }, * },
* "rslts": [] * "rslts": []
* } * }
* </pre> * </pre>
*/ */
public static JSONObject defaultResults() { public static JSONObject defaultResults() {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
final JSONObject pagination = new JSONObject(); final JSONObject pagination = new JSONObject();
ret.put(Pagination.PAGINATION, pagination); ret.put(Pagination.PAGINATION, pagination);
pagination.put(Pagination.PAGINATION_PAGE_COUNT, 0); pagination.put(Pagination.PAGINATION_PAGE_COUNT, 0);
final JSONArray results = new JSONArray(); final JSONArray results = new JSONArray();
ret.put(Keys.RESULTS, results); ret.put(Keys.RESULTS, results);
return ret; return ret;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private QueryResults() { private QueryResults() {
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.solo.model.Tag; import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.TagRepository; import org.b3log.solo.repository.TagRepository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.RepositoryException;
import org.b3log.solo.repository.impl.TagRepositoryImpl; import org.b3log.solo.repository.impl.TagRepositoryImpl;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Tag utilities. * Tag utilities.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.6, Mar 8, 2011 * @version 1.0.0.6, Mar 8, 2011
*/ */
public final class Tags { public final class Tags {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER =
Logger.getLogger(Tags.class.getName()); Logger.getLogger(Tags.class.getName());
/** /**
* Tag repository. * Tag repository.
*/ */
private TagRepository tagRepository = private TagRepository tagRepository =
TagRepositoryImpl.getInstance(); TagRepositoryImpl.getInstance();
/** /**
* Article utilities. * Article utilities.
*/ */
private Articles articleUtils = Articles.getInstance(); private Articles articleUtils = Articles.getInstance();
/** /**
* Decrements reference count of every tag of an published article specified * Decrements reference count of every tag of an published article specified
* by the given article id. * by the given article id.
* *
* @param articleId the given article id * @param articleId the given article id
* @throws JSONException json exception * @throws JSONException json exception
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
public void decTagPublishedRefCount(final String articleId) public void decTagPublishedRefCount(final String articleId)
throws JSONException, RepositoryException { throws JSONException, RepositoryException {
final List<JSONObject> tags = tagRepository.getByArticleId(articleId); final List<JSONObject> tags = tagRepository.getByArticleId(articleId);
for (final JSONObject tag : tags) { for (final JSONObject tag : tags) {
final String tagId = tag.getString(Keys.OBJECT_ID); final String tagId = tag.getString(Keys.OBJECT_ID);
final int refCnt = tag.getInt(Tag.TAG_REFERENCE_COUNT); final int refCnt = tag.getInt(Tag.TAG_REFERENCE_COUNT);
tag.put(Tag.TAG_REFERENCE_COUNT, refCnt); tag.put(Tag.TAG_REFERENCE_COUNT, refCnt);
final int publishedRefCnt = final int publishedRefCnt =
tag.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT); tag.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT);
tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, publishedRefCnt - 1); tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, publishedRefCnt - 1);
tagRepository.update(tagId, tag); tagRepository.update(tagId, tag);
} }
} }
/** /**
* Removes tags of unpublished articles from the specified tags. * Removes tags of unpublished articles from the specified tags.
* *
* @param tags the specified tags * @param tags the specified tags
* @throws JSONException json exception * @throws JSONException json exception
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
public void removeForUnpublishedArticles( public void removeForUnpublishedArticles(
final List<JSONObject> tags) throws JSONException, final List<JSONObject> tags) throws JSONException,
RepositoryException { RepositoryException {
final Iterator<JSONObject> iterator = tags.iterator(); final Iterator<JSONObject> iterator = tags.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final JSONObject tag = iterator.next(); final JSONObject tag = iterator.next();
if (0 == tag.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT)) { if (0 == tag.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT)) {
iterator.remove(); iterator.remove();
} }
} }
} }
/** /**
* Gets the {@link Tags} singleton. * Gets the {@link Tags} singleton.
* *
* @return the singleton * @return the singleton
*/ */
public static Tags getInstance() { public static Tags getInstance() {
return SingletonHolder.SINGLETON; return SingletonHolder.SINGLETON;
} }
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Tags() { private Tags() {
} }
/** /**
* Singleton holder. * Singleton holder.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Jan 12, 2011 * @version 1.0.0.0, Jan 12, 2011
*/ */
private static final class SingletonHolder { private static final class SingletonHolder {
/** /**
* Singleton. * Singleton.
*/ */
private static final Tags SINGLETON = new Tags(); private static final Tags SINGLETON = new Tags();
/** /**
* Private default constructor. * Private default constructor.
*/ */
private SingletonHolder() { private SingletonHolder() {
} }
} }
} }
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import org.b3log.latke.util.freemarker.Templates; import org.b3log.latke.util.freemarker.Templates;
import org.b3log.solo.model.ArchiveDate; import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
/** /**
* Time zone utilities. * Time zone utilities.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Dec 29, 2011 * @version 1.0.0.3, Dec 29, 2011
*/ */
public final class TimeZones { public final class TimeZones {
/** /**
* Gets the current date with the specified time zone id. * Gets the current date with the specified time zone id.
* *
* @param timeZoneId the specified time zone id * @param timeZoneId the specified time zone id
* @return date * @return date
*/ */
public static Date getTime(final String timeZoneId) { public static Date getTime(final String timeZoneId) {
final TimeZone timeZone = TimeZone.getTimeZone(timeZoneId); final TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
final TimeZone defaultTimeZone = TimeZone.getDefault(); final TimeZone defaultTimeZone = TimeZone.getDefault();
TimeZone.setDefault(timeZone); TimeZone.setDefault(timeZone);
final Date ret = new Date(); final Date ret = new Date();
TimeZone.setDefault(defaultTimeZone); TimeZone.setDefault(defaultTimeZone);
return ret; return ret;
} }
/** /**
* Sets time zone by the specified time zone id. * Sets time zone by the specified time zone id.
* *
* <p> * <p>
* This method will call {@linkplain TimeZone#setDefault(java.util.TimeZone)}, * This method will call {@linkplain TimeZone#setDefault(java.util.TimeZone)},
* and set time zone for all date formats and template configuration. * and set time zone for all date formats and template configuration.
* </p> * </p>
* *
* @param timeZoneId the specified time zone id * @param timeZoneId the specified time zone id
*/ */
public static void setTimeZone(final String timeZoneId) { public static void setTimeZone(final String timeZoneId) {
final TimeZone timeZone = TimeZone.getTimeZone(timeZoneId); final TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
TimeZone.setDefault(timeZone); TimeZone.setDefault(timeZone);
System.setProperty("user.timezone", timeZoneId); System.setProperty("user.timezone", timeZoneId);
ArchiveDate.DATE_FORMAT.setTimeZone(timeZone); ArchiveDate.DATE_FORMAT.setTimeZone(timeZone);
Comment.DATE_FORMAT.setTimeZone(timeZone); Comment.DATE_FORMAT.setTimeZone(timeZone);
Templates.MAIN_CFG.setTimeZone(timeZone); Templates.MAIN_CFG.setTimeZone(timeZone);
Templates.MOBILE_CFG.setTimeZone(timeZone); Templates.MOBILE_CFG.setTimeZone(timeZone);
} }
/** /**
* Private default constructor. * Private default constructor.
*/ */
private TimeZones() { private TimeZones() {
} }
} }
/** /**
* Utilities. * Utilities.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
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