projects
/
pnews.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup and refactored to move to net.wpitchoune package
[pnews.git]
/
war
/
src
/
main
/
java
/
pnews
/
servlet
/
Pnews.java
diff --git
a/war/src/main/java/pnews/servlet/Pnews.java
b/war/src/main/java/pnews/servlet/Pnews.java
index
e254a61
..
c51f946
100644
(file)
--- a/
war/src/main/java/pnews/servlet/Pnews.java
+++ b/
war/src/main/java/pnews/servlet/Pnews.java
@@
-20,8
+20,11
@@
import javax.servlet.http.HttpServletResponse;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.FeedException;
-import pnews.Article;
-import pnews.Category;
+import net.wpitchoune.pnews.Article;
+import net.wpitchoune.pnews.ArticleStore;
+import net.wpitchoune.pnews.Category;
+import net.wpitchoune.pnews.Config;
+import net.wpitchoune.pnews.Language;
public class Pnews extends HttpServlet {
private static final String CLASS_NAME = Pnews.class.getName();
public class Pnews extends HttpServlet {
private static final String CLASS_NAME = Pnews.class.getName();
@@
-71,7
+74,7
@@
public class Pnews extends HttpServlet {
if (redirectURL != null) {
a = ArticleStore.singleton.get(redirectURL);
if (a != null)
if (redirectURL != null) {
a = ArticleStore.singleton.get(redirectURL);
if (a != null)
- a.
readCount.incrementAndGe
t();
+ a.
incrementReadCoun
t();
else
LOG.severe("Cannot find the article " + redirectURL);
else
LOG.severe("Cannot find the article " + redirectURL);
@@
-90,29
+93,34
@@
public class Pnews extends HttpServlet {
LOG.exiting(Pnews.class.getName(), "redirect");
}
LOG.exiting(Pnews.class.getName(), "redirect");
}
+
+ private static void doTemporaryRedirect(String newURL, HttpServletResponse rp) {
+ rp.setHeader("Location", newURL);
+ rp.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
+ }
private void writeStats(HttpServletResponse rp) throws IOException {
rp.setContentType("application/json;charset=utf-8");
rp.setCharacterEncoding("utf-8");
private void writeStats(HttpServletResponse rp) throws IOException {
rp.setContentType("application/json;charset=utf-8");
rp.setCharacterEncoding("utf-8");
- rp.getWriter().write(JSON.getStats(
config.getCategories()
));
+ rp.getWriter().write(JSON.getStats(
provider, config
));
}
}
- private void writeArticles(Category cat, HttpServletResponse rp) {
+ private void writeArticles(Category cat,
String entity,
HttpServletResponse rp) {
String html;
List<Article> articles;
try {
String html;
List<Article> articles;
try {
- articles = provider.getArticles(cat);
+ articles = provider.getArticles(cat
, entity
);
if (articles != null) {
if (articles != null) {
- html = HTML.toHTML(articles, cat,
config.getCategories()
);
+ html = HTML.toHTML(articles, cat,
entity, config, provider
);
rp.setContentType("text/html;charset=utf-8");
rp.getWriter().write(html);
rp.setCharacterEncoding("utf-8");
} else {
LOG.severe("writeArticles cannot retrieve any articles");
rp.setContentType("text/html;charset=utf-8");
rp.getWriter().write(html);
rp.setCharacterEncoding("utf-8");
} else {
LOG.severe("writeArticles cannot retrieve any articles");
- html = HTML.toHTML(new ArrayList<Article>(), cat,
config.getCategories()
);
+ html = HTML.toHTML(new ArrayList<Article>(), cat,
entity, config, provider
);
rp.setContentType("text/html");
rp.getWriter().write(html);
}
rp.setContentType("text/html");
rp.getWriter().write(html);
}
@@
-168,12
+176,11
@@
public class Pnews extends HttpServlet {
}
if (path.equals("/")) {
}
if (path.equals("/")) {
-
writeArticles(config.getDefaultCategory
(), resp);
+
doTemporaryRedirect(config.getDefaultLanguage().toURL
(), resp);
return ;
}
try {
return ;
}
try {
-
if (path.equals("/stats")) {
writeStats(resp);
return ;
if (path.equals("/stats")) {
writeStats(resp);
return ;
@@
-181,14
+188,21
@@
public class Pnews extends HttpServlet {
for (Category cat: config.getCategories()) {
if (path.equals(cat.getURL())) {
for (Category cat: config.getCategories()) {
if (path.equals(cat.getURL())) {
- writeArticles(cat, resp);
+ writeArticles(cat, getQueryParameter(req, "entity"), resp);
+ return ;
+ }
+ }
+
+ for (Language l: config.getLanguages()) {
+ if (path.equals(l.toURL())) {
+ doTemporaryRedirect(config.getDefaultCategory(l).getURL(), resp);
return ;
}
}
resp.getWriter().write("Not found " + req.getPathInfo());
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return ;
}
}
resp.getWriter().write("Not found " + req.getPathInfo());
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
- } catch (IOException e) {
+ } catch (IOException
| RuntimeException
e) {
LOG.log(Level.SEVERE, "doGet failure", e);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
LOG.log(Level.SEVERE, "doGet failure", e);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
@@
-199,7
+213,11
@@
public class Pnews extends HttpServlet {
LOG.info("Pnews servlet init " + cfg.getServletContext().getContextPath());
config = new Config();
LOG.info("Pnews servlet init " + cfg.getServletContext().getContextPath());
config = new Config();
- config.loadConfig();
+ try {
+ config.loadConfig();
+ } catch (UnsupportedEncodingException e) {
+ throw new ServletException(e);
+ }
provider = new ArticleProvider(config);
}
provider = new ArticleProvider(config);
}