Commit 821ca8d8 authored by Liang Ding's avatar Liang Ding

--no commit message

--no commit message
parent 79ea5dc3
/**
* Admin index.ftl template and upload/download processing, .
*/
package org.b3log.solo.action;
/**
* Admin index.ftl template and upload/download processing, .
*/
package org.b3log.solo.action;
/**
* <a href="http://www.xmlrpc.com/metaWeblogApi">MetaWeblog API</a> requests
* processing.
*/
package org.b3log.solo.api.metaweblog;
/**
* <a href="http://www.xmlrpc.com/metaWeblogApi">MetaWeblog API</a> requests
* processing.
*/
package org.b3log.solo.api.metaweblog;
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.dev;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeMode;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.solo.model.Article;
import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject;
/**
* Generates some dummy articles for development testing.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, May 21, 2012
* @since 0.4.0
*/
@RequestProcessor
public final class ArticleGenerator {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(ArticleGenerator.class.getName());
/**
* Generates some dummy articles with the specified context.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws IOException io exception
*/
@RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET)
public void genArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException {
if (RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) {
LOGGER.log(Level.WARNING, "Article generation just for development mode, " + "current runtime mode is [{0}]",
Latkes.getRuntimeMode());
response.sendRedirect("/");
return;
}
Stopwatchs.start("Gen Articles");
final String requestURI = request.getRequestURI();
final int num = Integer.valueOf(requestURI.substring((Latkes.getContextPath() + "/dev/articles/gen/").length()));
try {
final ArticleMgmtService articleMgmtService = ArticleMgmtService.getInstance();
final UserQueryService userQueryService = UserQueryService.getInstance();
final JSONObject admin = userQueryService.getAdmin();
final String authorEmail = admin.optString(User.USER_EMAIL);
for (int i = 0; i < num; i++) {
final JSONObject article = new JSONObject();
// XXX: http://en.wikipedia.org/wiki/Markov_chain
article.put(Article.ARTICLE_TITLE, "article title" + i);
article.put(Article.ARTICLE_ABSTRACT, "article" + i + " abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1,tag2");
article.put(Article.ARTICLE_AUTHOR_EMAIL, authorEmail);
article.put(Article.ARTICLE_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article" + i + " permalink");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, true);
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATE_DATE, new Date());
article.put(Article.ARTICLE_UPDATE_DATE, new Date());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_SIGN_ID, "1");
articleMgmtService.addArticle(new JSONObject().put(Article.ARTICLE, article));
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
Stopwatchs.end();
response.sendRedirect("/");
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.dev;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeMode;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.solo.model.Article;
import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject;
/**
* Generates some dummy articles for development testing.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, May 21, 2012
* @since 0.4.0
*/
@RequestProcessor
public final class ArticleGenerator {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(ArticleGenerator.class.getName());
/**
* Generates some dummy articles with the specified context.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws IOException io exception
*/
@RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET)
public void genArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException {
if (RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) {
LOGGER.log(Level.WARNING, "Article generation just for development mode, " + "current runtime mode is [{0}]",
Latkes.getRuntimeMode());
response.sendRedirect("/");
return;
}
Stopwatchs.start("Gen Articles");
final String requestURI = request.getRequestURI();
final int num = Integer.valueOf(requestURI.substring((Latkes.getContextPath() + "/dev/articles/gen/").length()));
try {
final ArticleMgmtService articleMgmtService = ArticleMgmtService.getInstance();
final UserQueryService userQueryService = UserQueryService.getInstance();
final JSONObject admin = userQueryService.getAdmin();
final String authorEmail = admin.optString(User.USER_EMAIL);
for (int i = 0; i < num; i++) {
final JSONObject article = new JSONObject();
// XXX: http://en.wikipedia.org/wiki/Markov_chain
article.put(Article.ARTICLE_TITLE, "article title" + i);
article.put(Article.ARTICLE_ABSTRACT, "article" + i + " abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1,tag2");
article.put(Article.ARTICLE_AUTHOR_EMAIL, authorEmail);
article.put(Article.ARTICLE_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article" + i + " permalink");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, true);
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATE_DATE, new Date());
article.put(Article.ARTICLE_UPDATE_DATE, new Date());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_SIGN_ID, "1");
articleMgmtService.addArticle(new JSONObject().put(Article.ARTICLE, article));
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
Stopwatchs.end();
response.sendRedirect("/");
}
}
/**
* Development usage.
*
* <p>
* All functions in this package just for development mode.
* </p>
*/
package org.b3log.solo.dev;
/**
* Development usage.
*
* <p>
* All functions in this package just for development mode.
* </p>
*/
package org.b3log.solo.dev;
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event;
/**
* Event types.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.6, Oct 19, 2011
* @since 0.3.1
*/
public final class EventTypes {
/**
* Indicates a add article event.
*/
public static final String ADD_ARTICLE = "Add Article";
/**
* Indicates a update article event.
*/
public static final String UPDATE_ARTICLE = "Update Article";
/**
* Indicates a remove article event.
*/
public static final String REMOVE_ARTICLE = "Remove Article";
/**
* Indicates an add comment to article event.
*/
public static final String ADD_COMMENT_TO_ARTICLE = "Add Comment To Article";
/**
* Indicates an add comment to page event.
*/
public static final String ADD_COMMENT_TO_PAGE = "Add Comment To Page";
/**
* Indicates a remove comment event.
*/
public static final String REMOVE_COMMENT = "Remove Comment";
/**
* Private default constructor.
*/
private EventTypes() {
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event;
/**
* Event types.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.6, Oct 19, 2011
* @since 0.3.1
*/
public final class EventTypes {
/**
* Indicates a add article event.
*/
public static final String ADD_ARTICLE = "Add Article";
/**
* Indicates a update article event.
*/
public static final String UPDATE_ARTICLE = "Update Article";
/**
* Indicates a remove article event.
*/
public static final String REMOVE_ARTICLE = "Remove Article";
/**
* Indicates an add comment to article event.
*/
public static final String ADD_COMMENT_TO_ARTICLE = "Add Comment To Article";
/**
* Indicates an add comment to page event.
*/
public static final String ADD_COMMENT_TO_PAGE = "Add Comment To Page";
/**
* Indicates a remove comment event.
*/
public static final String REMOVE_COMMENT = "Remove Comment";
/**
* Private default constructor.
*/
private EventTypes() {
}
}
/**
* Event processors.
*/
package org.b3log.solo.event;
/**
* Event processors.
*/
package org.b3log.solo.event;
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.ping;
import java.net.URL;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
/**
* This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while adding an article.
*
* <p>
* <li>
* <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* About Google Blog Search Pinging Service API</a>
* </li>
* </p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.2, Jun 23, 2011
* @see UpdateArticleGoogleBlogSearchPinger
* @since 0.3.1
*/
public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(AddArticleGoogleBlogSearchPinger.class.getName());
/**
* URL fetch service.
*/
private static final URLFetchService URL_FETCH_SERVICE = URLFetchServiceFactory.getURLFetchService();
/**
* Gets the event type {@linkplain EventTypes#ADD_ARTICLE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.ADD_ARTICLE;
}
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
String articleTitle = null;
try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST).
toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "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)});
return;
}
blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name="
+ URLEncoder.encode(blogTitle, "UTF-8") + "&url=" + URLEncoder.encode(blogHost, "UTF-8")
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while adding an "
+ "article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while adding an article[title=" + articleTitle + "]", e);
}
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.ping;
import java.net.URL;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
/**
* This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while adding an article.
*
* <p>
* <li>
* <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* About Google Blog Search Pinging Service API</a>
* </li>
* </p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.2, Jun 23, 2011
* @see UpdateArticleGoogleBlogSearchPinger
* @since 0.3.1
*/
public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(AddArticleGoogleBlogSearchPinger.class.getName());
/**
* URL fetch service.
*/
private static final URLFetchService URL_FETCH_SERVICE = URLFetchServiceFactory.getURLFetchService();
/**
* Gets the event type {@linkplain EventTypes#ADD_ARTICLE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.ADD_ARTICLE;
}
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
String articleTitle = null;
try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST).
toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "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)});
return;
}
blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name="
+ URLEncoder.encode(blogTitle, "UTF-8") + "&url=" + URLEncoder.encode(blogHost, "UTF-8")
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while adding an "
+ "article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while adding an article[title=" + articleTitle + "]", e);
}
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.ping;
import java.net.URL;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
/**
* This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while updating an article.
*
* <p>
* <li>
* <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* About Google Blog Search Pinging Service API</a>
* </li>
* </p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.2, Jun 23, 2011
* @see AddArticleGoogleBlogSearchPinger
* @since 0.3.1
*/
public final class UpdateArticleGoogleBlogSearchPinger
extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UpdateArticleGoogleBlogSearchPinger.class.getName());
/**
* URL fetch service.
*/
private static final URLFetchService URL_FETCH_SERVICE = URLFetchServiceFactory.getURLFetchService();
/**
* Gets the event type {@linkplain EventTypes#UPDATE_ARTICLE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.UPDATE_ARTICLE;
}
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
String articleTitle = null;
try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "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)});
return;
}
blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8")
+ "&url=" + URLEncoder.encode(blogHost, "UTF-8")
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while updateing "
+ "an article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while updating an " + "article[title=" + articleTitle + "]", e);
}
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.ping;
import java.net.URL;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.urlfetch.HTTPRequest;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
/**
* This listener is responsible for pinging <a href="http://blogsearch.google.com">
* Google Blog Search Service</a> asynchronously while updating an article.
*
* <p>
* <li>
* <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* About Google Blog Search Pinging Service API</a>
* </li>
* </p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.2, Jun 23, 2011
* @see AddArticleGoogleBlogSearchPinger
* @since 0.3.1
*/
public final class UpdateArticleGoogleBlogSearchPinger
extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UpdateArticleGoogleBlogSearchPinger.class.getName());
/**
* URL fetch service.
*/
private static final URLFetchService URL_FETCH_SERVICE = URLFetchServiceFactory.getURLFetchService();
/**
* Gets the event type {@linkplain EventTypes#UPDATE_ARTICLE}.
*
* @return event type
*/
@Override
public String getEventType() {
return EventTypes.UPDATE_ARTICLE;
}
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
String articleTitle = null;
try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = PreferenceQueryService.getInstance().getPreference();
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase().trim();
if ("localhost".equals(blogHost.split(":")[0].trim())) {
LOGGER.log(Level.INFO, "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)});
return;
}
blogHost = StringUtils.removeEnd("http://" + blogHost, "/");
final String articlePermalink = blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8")
+ "&url=" + URLEncoder.encode(blogHost, "UTF-8")
+ "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.FINER, "Request Google Blog Search Service API[{0}] while updateing "
+ "an article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Ping Google Blog Search Service fail while updating an " + "article[title=" + articleTitle + "]", e);
}
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.plugin;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.plugin.AbstractPlugin;
import org.b3log.latke.plugin.PluginManager;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.repository.PluginRepository;
import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.b3log.solo.util.Plugins;
/**
* This listener is responsible for refreshing plugin after every loaded.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Nov 28, 2011
* @since 0.3.1
*/
public final class PluginRefresher extends AbstractEventListener<List<AbstractPlugin>> {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(PluginRefresher.class.getName());
/**
* Plugin repository.
*/
private PluginRepository pluginRepository =
PluginRepositoryImpl.getInstance();
@Override
public void action(final Event<List<AbstractPlugin>> event) throws
EventException {
final List<AbstractPlugin> plugins = event.getData();
LOGGER.log(Level.FINER,
"Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), plugins,
PluginRefresher.class.getName()});
final Transaction transaction = pluginRepository.beginTransaction();
transaction.clearQueryCache(false);
try {
Plugins.refresh(plugins);
transaction.commit();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.SEVERE, "Processing plugin loaded event error", e);
throw new EventException(e);
}
}
/**
* Gets the event type {@linkplain PluginManager#PLUGIN_LOADED_EVENT}.
*
* @return event type
*/
@Override
public String getEventType() {
return PluginManager.PLUGIN_LOADED_EVENT;
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.event.plugin;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.plugin.AbstractPlugin;
import org.b3log.latke.plugin.PluginManager;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.repository.PluginRepository;
import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.b3log.solo.util.Plugins;
/**
* This listener is responsible for refreshing plugin after every loaded.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.1, Nov 28, 2011
* @since 0.3.1
*/
public final class PluginRefresher extends AbstractEventListener<List<AbstractPlugin>> {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(PluginRefresher.class.getName());
/**
* Plugin repository.
*/
private PluginRepository pluginRepository =
PluginRepositoryImpl.getInstance();
@Override
public void action(final Event<List<AbstractPlugin>> event) throws
EventException {
final List<AbstractPlugin> plugins = event.getData();
LOGGER.log(Level.FINER,
"Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), plugins,
PluginRefresher.class.getName()});
final Transaction transaction = pluginRepository.beginTransaction();
transaction.clearQueryCache(false);
try {
Plugins.refresh(plugins);
transaction.commit();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.SEVERE, "Processing plugin loaded event error", e);
throw new EventException(e);
}
}
/**
* Gets the event type {@linkplain PluginManager#PLUGIN_LOADED_EVENT}.
*
* @return event type
*/
@Override
public String getEventType() {
return PluginManager.PLUGIN_LOADED_EVENT;
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.filter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.user.GeneralUser;
import org.b3log.latke.user.UserService;
import org.b3log.latke.user.UserServiceFactory;
import org.b3log.solo.processor.LoginProcessor;
import org.b3log.solo.util.Users;
/**
* Authentication filter.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Oct 4, 2011
* @since 0.3.1
*/
public final class AuthFilter implements Filter {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(AuthFilter.class.getName());
/**
* User service.
*/
private UserService userService = UserServiceFactory.getUserService();
/**
* User utilities.
*/
private Users users = Users.getInstance();
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
}
/**
* If the specified request is NOT made by an authenticated user, sends
* error 403.
*
* @param request the specified request
* @param response the specified response
* @param chain filter chain
* @throws IOException io exception
* @throws ServletException servlet exception
*/
@Override
public void doFilter(final ServletRequest request,
final ServletResponse response,
final FilterChain chain) throws IOException,
ServletException {
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
try {
LoginProcessor.tryLogInWithCookie(httpServletRequest, httpServletResponse);
final GeneralUser currentUser = userService.getCurrentUser(httpServletRequest);
if (null == currentUser) {
LOGGER.warning("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final String currentUserEmail = currentUser.getEmail();
LOGGER.log(Level.FINER, "Current user email[{0}]", currentUserEmail);
if (users.isSoloUser(currentUserEmail)) {
chain.doFilter(request, response);
return;
}
LOGGER.warning("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
} catch (final Exception e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
@Override
public void destroy() {
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.filter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.user.GeneralUser;
import org.b3log.latke.user.UserService;
import org.b3log.latke.user.UserServiceFactory;
import org.b3log.solo.processor.LoginProcessor;
import org.b3log.solo.util.Users;
/**
* Authentication filter.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Oct 4, 2011
* @since 0.3.1
*/
public final class AuthFilter implements Filter {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(AuthFilter.class.getName());
/**
* User service.
*/
private UserService userService = UserServiceFactory.getUserService();
/**
* User utilities.
*/
private Users users = Users.getInstance();
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
}
/**
* If the specified request is NOT made by an authenticated user, sends
* error 403.
*
* @param request the specified request
* @param response the specified response
* @param chain filter chain
* @throws IOException io exception
* @throws ServletException servlet exception
*/
@Override
public void doFilter(final ServletRequest request,
final ServletResponse response,
final FilterChain chain) throws IOException,
ServletException {
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
try {
LoginProcessor.tryLogInWithCookie(httpServletRequest, httpServletResponse);
final GeneralUser currentUser = userService.getCurrentUser(httpServletRequest);
if (null == currentUser) {
LOGGER.warning("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final String currentUserEmail = currentUser.getEmail();
LOGGER.log(Level.FINER, "Current user email[{0}]", currentUserEmail);
if (users.isSoloUser(currentUserEmail)) {
chain.doFilter(request, response);
return;
}
LOGGER.warning("The request has been forbidden");
httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
} catch (final Exception e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
@Override
public void destroy() {
}
}
/**
* Filters for page caching, URL transformation.
*/
package org.b3log.solo.filter;
/**
* Filters for page caching, URL transformation.
*/
package org.b3log.solo.filter;
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.model;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* This class defines all archive date model relevant keys.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Jul 2, 2011
*/
public final class ArchiveDate {
/**
* Archive date.
*/
public static final String ARCHIVE_DATE = "archiveDate";
/**
* Archive dates.
*/
public static final String ARCHIVE_DATES = "archiveDates";
/**
* Archive time.
*/
public static final String ARCHIVE_TIME = "archiveTime";
/**
* Key of archive date article count.
*/
public static final String ARCHIVE_DATE_ARTICLE_COUNT =
"archiveDateArticleCount";
/**
* Key of archive date article count.
*/
public static final String ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT =
"archiveDatePublishedArticleCount";
/**
* Archive date year.
*/
public static final String ARCHIVE_DATE_YEAR = "archiveDateYear";
/**
* Archive date month.
*/
public static final String ARCHIVE_DATE_MONTH = "archiveDateMonth";
/**
* Date format(yyyy/MM).
*/
public static final DateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy/MM");
/**
* Private default constructor.
*/
private ArchiveDate() {
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.model;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* This class defines all archive date model relevant keys.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.3, Jul 2, 2011
*/
public final class ArchiveDate {
/**
* Archive date.
*/
public static final String ARCHIVE_DATE = "archiveDate";
/**
* Archive dates.
*/
public static final String ARCHIVE_DATES = "archiveDates";
/**
* Archive time.
*/
public static final String ARCHIVE_TIME = "archiveTime";
/**
* Key of archive date article count.
*/
public static final String ARCHIVE_DATE_ARTICLE_COUNT =
"archiveDateArticleCount";
/**
* Key of archive date article count.
*/
public static final String ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT =
"archiveDatePublishedArticleCount";
/**
* Archive date year.
*/
public static final String ARCHIVE_DATE_YEAR = "archiveDateYear";
/**
* Archive date month.
*/
public static final String ARCHIVE_DATE_MONTH = "archiveDateMonth";
/**
* Date format(yyyy/MM).
*/
public static final DateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy/MM");
/**
* Private default constructor.
*/
private ArchiveDate() {
}
}
/**
* Keys.
*/
package org.b3log.solo.model;
/**
* Keys.
*/
package org.b3log.solo.model;
/**
* <a href="http://b3log-solo.googlecode.com">B3log Solo</a>.
*/
package org.b3log.solo;
/**
* <a href="http://b3log-solo.googlecode.com">B3log Solo</a>.
*/
package org.b3log.solo;
/**
* Plugins.
*/
package org.b3log.solo.plugin;
/**
* Plugins.
*/
package org.b3log.solo.plugin;
/**
* Console requests (Articles, Comments, Preference, etc, management) processing.
*/
package org.b3log.solo.processor.console;
/**
* Console requests (Articles, Comments, Preference, etc, management) processing.
*/
package org.b3log.solo.processor.console;
/**
* HTTP request processing.
*/
package org.b3log.solo.processor;
/**
* HTTP request processing.
*/
package org.b3log.solo.processor;
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