Commit eca2c958 authored by Vanessa's avatar Vanessa

c

parent f4d629b5
/* /*
* 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.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.Query; import org.b3log.latke.repository.Query;
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.latke.util.CollectionUtils; import org.b3log.latke.util.CollectionUtils;
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.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Tag query service. * Tag 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.2, Nov 11, 2011 * @version 1.0.0.2, Nov 11, 2011
* @since 0.4.0 * @since 0.4.0
*/ */
public final class TagQueryService { public final class TagQueryService {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER =
Logger.getLogger(TagQueryService.class.getName()); Logger.getLogger(TagQueryService.class.getName());
/** /**
* Tag repository. * Tag repository.
*/ */
private TagRepository tagRepository = TagRepositoryImpl.getInstance(); private TagRepository tagRepository = TagRepositoryImpl.getInstance();
/** /**
* Gets a tag by the specified tag title. * Gets a tag by the specified tag title.
* *
* @param tagTitle the specified tag title * @param tagTitle the specified tag title
* @return for example, * @return for example,
* <pre> * <pre>
* { * {
* "tag": { * "tag": {
* "oId": "", * "oId": "",
* "tagTitle": "", * "tagTitle": "",
* "tagReferenceCount": int, * "tagReferenceCount": int,
* "tagPublishedRefCount": int * "tagPublishedRefCount": int
* } * }
* } * }
* </pre>, returns {@code null} if not found * </pre>, returns {@code null} if not found
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public JSONObject getTagByTitle(final String tagTitle) public JSONObject getTagByTitle(final String tagTitle)
throws ServiceException { throws ServiceException {
try { try {
final JSONObject ret = new JSONObject(); final JSONObject ret = new JSONObject();
final JSONObject tag = tagRepository.getByTitle(tagTitle); final JSONObject tag = tagRepository.getByTitle(tagTitle);
if (null == tag) { if (null == tag) {
return null; return null;
} }
ret.put(Tag.TAG, tag); ret.put(Tag.TAG, tag);
LOGGER.log(Level.FINER, "Got an tag[title={0}]", tagTitle); LOGGER.log(Level.FINER, "Got an tag[title={0}]", tagTitle);
return ret; return ret;
} catch (final RepositoryException e) { } catch (final RepositoryException e) {
LOGGER.log(Level.SEVERE, "Gets an article failed", e); LOGGER.log(Level.SEVERE, "Gets an article failed", e);
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
/** /**
* Gets all tags. * Gets all tags.
* *
* @return for example, * @return for example,
* <pre> * <pre>
* [ * [
* {"tagTitle": "", "tagReferenceCount": int, ....}, * {"tagTitle": "", "tagReferenceCount": int, ....},
* .... * ....
* ] * ]
* </pre>, returns an empty list if not found * </pre>, returns an empty list if not found
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public List<JSONObject> getTags() throws ServiceException { public List<JSONObject> getTags() throws ServiceException {
try { try {
final Query query = new Query().setPageCount(1); final Query query = new Query().setPageCount(1);
final JSONObject result = tagRepository.get(query); final JSONObject result = tagRepository.get(query);
final JSONArray tagArray = result.optJSONArray(Keys.RESULTS); final JSONArray tagArray = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(tagArray); return CollectionUtils.jsonArrayToList(tagArray);
} catch (final RepositoryException e) { } catch (final RepositoryException e) {
LOGGER.log(Level.SEVERE, "Gets tags failed", e); LOGGER.log(Level.SEVERE, "Gets tags failed", e);
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
/** /**
* Gets the {@link TagQueryService} singleton. * Gets the {@link TagQueryService} singleton.
* *
* @return the singleton * @return the singleton
*/ */
public static TagQueryService getInstance() { public static TagQueryService getInstance() {
return SingletonHolder.SINGLETON; return SingletonHolder.SINGLETON;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private TagQueryService() { private TagQueryService() {
} }
/** /**
* 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 TagQueryService SINGLETON = private static final TagQueryService SINGLETON =
new TagQueryService(); new TagQueryService();
/** /**
* 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 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() {
} }
} }
/** /**
* Utilities. * Utilities.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
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