Implementing.
@@ -150,7 +150,7 @@ | ||
150 | 150 | |
151 | 151 | int prevCtxtId = 0; |
152 | 152 | |
153 | - final List<String> kwdNameList = new ArrayList<String>(); | |
153 | + List<String> kwdNameList = new ArrayList<String>(); | |
154 | 154 | |
155 | 155 | for (; ite.next();) { |
156 | 156 | final DaoCtxtSel005Row row = ite.getRow(); |
@@ -164,7 +164,7 @@ | ||
164 | 164 | item.setFullCtxtLine(ManjyuCtxtUtil.concatCtxtLineList(kwdNameList)); |
165 | 165 | ctxtLineList.add(item); |
166 | 166 | } |
167 | - kwdNameList.clear(); | |
167 | + kwdNameList = new ArrayList<String>(); | |
168 | 168 | prevCtxtId = row.getCtxtId(); |
169 | 169 | } |
170 | 170 |
@@ -29,7 +29,7 @@ | ||
29 | 29 | |
30 | 30 | import blanco.constants.BlancoConstantsVersion; |
31 | 31 | |
32 | -@BlancoConstantsVersion(prefix = "0.1.0-") | |
32 | +@BlancoConstantsVersion(prefix = "0.1.0-", format = "yyyyMMddHHmm") | |
33 | 33 | public abstract class AbstractManjyuConstants { |
34 | 34 | /** |
35 | 35 | * Locale string for initial version. |
@@ -0,0 +1,101 @@ | ||
1 | +/******************************************************************************* | |
2 | + * Manjyu | |
3 | + * Copyright (C) 2012 Toshiki IGA | |
4 | + * | |
5 | + * This library is free software: you can redistribute it and/or modify | |
6 | + * it under the terms of the GNU Lesser General Public License as published by | |
7 | + * the Free Software Foundation, either version 3 of the License, or | |
8 | + * any later version. | |
9 | + * | |
10 | + * This program is distributed in the hope that it will be useful, | |
11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | + * GNU Lesser General Public License for more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU Lesser General Public License | |
16 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | + *******************************************************************************/ | |
18 | +/******************************************************************************* | |
19 | + * Copyright (c) 2012 Toshiki IGA and others. | |
20 | + * All rights reserved. This program and the accompanying materials | |
21 | + * are made available under the terms of the Eclipse Public License v1.0 | |
22 | + * which accompanies this distribution, and is available at | |
23 | + * http://www.eclipse.org/legal/epl-v10.html | |
24 | + * | |
25 | + * Contributors: | |
26 | + * Toshiki IGA - initial implementation | |
27 | + *******************************************************************************/ | |
28 | +package org.manjyu.util; | |
29 | + | |
30 | +import java.util.Calendar; | |
31 | +import java.util.List; | |
32 | + | |
33 | +import javax.faces.context.FacesContext; | |
34 | + | |
35 | +import org.manjyu.ManjyuConstants; | |
36 | +import org.manjyu.rss.vo.ManjyuRssCategory; | |
37 | +import org.manjyu.rss.vo.ManjyuRssItem; | |
38 | +import org.manjyu.vo.ManjyuDirectoryItem; | |
39 | +import org.manjyu.vo.ManjyuMurmurItem; | |
40 | + | |
41 | +public class ManjyuMurmurItemUtil { | |
42 | + public static ManjyuRssItem item2RssItem(final ManjyuMurmurItem item, | |
43 | + final List<ManjyuDirectoryItem> directoryList, final FacesContext ctx) { | |
44 | + final ManjyuRssItem rssItem = new ManjyuRssItem(); | |
45 | + // TODO Length switch case | |
46 | + if (item.getMurmurType() < ManjyuConstants.MURMUR_TYPE_PLAIN_URL) { | |
47 | + rssItem.setTitle(item.getText()); | |
48 | + // TODO trim title length check. | |
49 | + // FIXME | |
50 | + | |
51 | + rssItem.setLink(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx.getExternalContext()) | |
52 | + + "/murmur/murmur.jsf?murmurId=" + item.getMurmurId()); | |
53 | + } else if (item.getMurmurType() <= ManjyuConstants.MURMUR_TYPE_WIKI_URL) { | |
54 | + rssItem.setTitle(item.getText()); | |
55 | + rssItem.setLink(item.getText()); | |
56 | + } else { | |
57 | + rssItem.setTitle("[NOT SUPPORTED] " + item.getText()); | |
58 | + } | |
59 | + | |
60 | + { | |
61 | + // ROUND HMS | |
62 | + final Calendar cal = Calendar.getInstance(); | |
63 | + cal.setTime(item.getDate()); | |
64 | + cal.set(Calendar.HOUR_OF_DAY, 0); | |
65 | + cal.set(Calendar.MINUTE, 0); | |
66 | + cal.set(Calendar.SECOND, 0); | |
67 | + cal.set(Calendar.MILLISECOND, 0); | |
68 | + rssItem.setPubDate(cal.getTime()); | |
69 | + } | |
70 | + | |
71 | + // Set GUID | |
72 | + rssItem.setGuid(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx.getExternalContext()) | |
73 | + + "/murmur/murmur.jsf?murmurId=" + item.getMurmurId()); | |
74 | + | |
75 | + // TODO ADD CATEGORY FOR MANJYU SPECIFIED | |
76 | + | |
77 | + { | |
78 | + final ManjyuRssCategory category = new ManjyuRssCategory(); | |
79 | + category.setDomain("http://manjyu.org/manjyu/murmur/type"); | |
80 | + category.setCharacters(String.valueOf(item.getMurmurType())); | |
81 | + rssItem.getCategoryList().add(category); | |
82 | + } | |
83 | + { | |
84 | + final ManjyuRssCategory category = new ManjyuRssCategory(); | |
85 | + category.setDomain("http://manjyu.org/manjyu/murmur/localeId"); | |
86 | + category.setCharacters(String.valueOf(item.getLocaleId())); | |
87 | + rssItem.getCategoryList().add(category); | |
88 | + } | |
89 | + | |
90 | + for (ManjyuDirectoryItem directory : directoryList) { | |
91 | + final ManjyuRssCategory category = new ManjyuRssCategory(); | |
92 | + category.setDomain("http://manjyu.org/manjyu/keyword/directory"); | |
93 | + category.setCharacters(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx.getExternalContext()) | |
94 | + + "/keyword/directory.jsf?path=" | |
95 | + + directory.getFullCtxtLine().replace("\t", "%09")); | |
96 | + rssItem.getCategoryList().add(category); | |
97 | + } | |
98 | + | |
99 | + return rssItem; | |
100 | + } | |
101 | +} |
@@ -1,64 +0,0 @@ | ||
1 | -/******************************************************************************* | |
2 | - * Manjyu | |
3 | - * Copyright (C) 2012 Toshiki IGA | |
4 | - * | |
5 | - * This library is free software: you can redistribute it and/or modify | |
6 | - * it under the terms of the GNU Lesser General Public License as published by | |
7 | - * the Free Software Foundation, either version 3 of the License, or | |
8 | - * any later version. | |
9 | - * | |
10 | - * This program is distributed in the hope that it will be useful, | |
11 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | - * GNU Lesser General Public License for more details. | |
14 | - * | |
15 | - * You should have received a copy of the GNU Lesser General Public License | |
16 | - * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | - *******************************************************************************/ | |
18 | -/******************************************************************************* | |
19 | - * Copyright (c) 2012 Toshiki IGA and others. | |
20 | - * All rights reserved. This program and the accompanying materials | |
21 | - * are made available under the terms of the Eclipse Public License v1.0 | |
22 | - * which accompanies this distribution, and is available at | |
23 | - * http://www.eclipse.org/legal/epl-v10.html | |
24 | - * | |
25 | - * Contributors: | |
26 | - * Toshiki IGA - initial implementation | |
27 | - *******************************************************************************/ | |
28 | -package org.manjyu.web.servlet.murmur; | |
29 | - | |
30 | -import java.io.IOException; | |
31 | - | |
32 | -import javax.faces.context.FacesContext; | |
33 | -import javax.servlet.ServletConfig; | |
34 | -import javax.servlet.ServletException; | |
35 | -import javax.servlet.annotation.WebServlet; | |
36 | -import javax.servlet.http.HttpServlet; | |
37 | -import javax.servlet.http.HttpServletRequest; | |
38 | -import javax.servlet.http.HttpServletResponse; | |
39 | - | |
40 | -import org.manjyu.util.JavaServerFacesServletUtil; | |
41 | - | |
42 | -@WebServlet(name = "ManjyuWebMurmurByDateServlet", urlPatterns = { "/murmur/bydate.rss" }) | |
43 | -public class ManjyuWebMurmurByDateServlet extends HttpServlet { | |
44 | - private static final long serialVersionUID = 1L; | |
45 | - | |
46 | - @Override | |
47 | - public void init(final ServletConfig config) throws ServletException { | |
48 | - super.init(config); | |
49 | - } | |
50 | - | |
51 | - @Override | |
52 | - protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, | |
53 | - IOException { | |
54 | - // GET == POST | |
55 | - doPost(request, response); | |
56 | - } | |
57 | - | |
58 | - @Override | |
59 | - protected void doPost(final HttpServletRequest request, final HttpServletResponse response) | |
60 | - throws ServletException, IOException { | |
61 | - final FacesContext ctx = JavaServerFacesServletUtil.getFacesContext(request, response); | |
62 | - new ManjyuWebMurmurByDateRssProcess().downloadMurmurRss(request, response, ctx); | |
63 | - } | |
64 | -} |
@@ -1,122 +0,0 @@ | ||
1 | -/******************************************************************************* | |
2 | - * Manjyu | |
3 | - * Copyright (C) 2012 Toshiki IGA | |
4 | - * | |
5 | - * This library is free software: you can redistribute it and/or modify | |
6 | - * it under the terms of the GNU Lesser General Public License as published by | |
7 | - * the Free Software Foundation, either version 3 of the License, or | |
8 | - * any later version. | |
9 | - * | |
10 | - * This program is distributed in the hope that it will be useful, | |
11 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | - * GNU Lesser General Public License for more details. | |
14 | - * | |
15 | - * You should have received a copy of the GNU Lesser General Public License | |
16 | - * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | - *******************************************************************************/ | |
18 | -/******************************************************************************* | |
19 | - * Copyright (c) 2012 Toshiki IGA and others. | |
20 | - * All rights reserved. This program and the accompanying materials | |
21 | - * are made available under the terms of the Eclipse Public License v1.0 | |
22 | - * which accompanies this distribution, and is available at | |
23 | - * http://www.eclipse.org/legal/epl-v10.html | |
24 | - * | |
25 | - * Contributors: | |
26 | - * Toshiki IGA - initial implementation | |
27 | - *******************************************************************************/ | |
28 | -package org.manjyu.web.servlet.murmur; | |
29 | - | |
30 | -import java.io.IOException; | |
31 | -import java.io.OutputStream; | |
32 | -import java.sql.Connection; | |
33 | -import java.sql.SQLException; | |
34 | -import java.util.Date; | |
35 | - | |
36 | -import javax.faces.context.FacesContext; | |
37 | -import javax.servlet.http.HttpServletRequest; | |
38 | -import javax.servlet.http.HttpServletResponse; | |
39 | - | |
40 | -import org.manjyu.ManjyuConstants; | |
41 | -import org.manjyu.model.ManjyuModelRelMurmurCtxt; | |
42 | -import org.manjyu.rss.ManjyuRssSerializer; | |
43 | -import org.manjyu.rss.vo.ManjyuRss; | |
44 | -import org.manjyu.rss.vo.ManjyuRssChannel; | |
45 | -import org.manjyu.rss.vo.ManjyuRssItem; | |
46 | -import org.manjyu.util.JavaServerFacesUtil; | |
47 | -import org.manjyu.vo.ManjyuMurmurItem; | |
48 | -import org.manjyu.web.bean.ManjyuWebSessionBean; | |
49 | - | |
50 | -import blanco.fw.BlancoInject; | |
51 | - | |
52 | -public abstract class AbstractManjyuWebMurmurByDateRssProcess { | |
53 | - protected void downloadMurmurRss(final HttpServletRequest request, final HttpServletResponse response, | |
54 | - final FacesContext ctx, @BlancoInject final ManjyuWebSessionBean sessionBean, | |
55 | - @BlancoInject final Connection conn) throws IOException { | |
56 | - // RSS 2.0 | |
57 | - response.setContentType("application/rss+xml"); | |
58 | - | |
59 | - // Cache control. | |
60 | - response.setHeader("Cache-Control", "no-cache"); | |
61 | - response.setHeader("Pragma", "no-cache"); | |
62 | - response.setHeader("Expires", "0"); | |
63 | - | |
64 | - response.setHeader("Accept-Ranges", "none"); | |
65 | - // Note: Can't set Content-Disposition in case of RSS 2.0 | |
66 | - | |
67 | - final OutputStream outStream = response.getOutputStream(); | |
68 | - try { | |
69 | - final ManjyuRss rss = new ManjyuRss(); | |
70 | - { | |
71 | - final ManjyuRssChannel channel = rss.getChannel(); | |
72 | - channel.setTitle("Manjyu RSS for Murmur"); | |
73 | - // TODO to real URL | |
74 | - channel.setLink(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx.getExternalContext()) | |
75 | - + "/murmur/bydate.jsf"); | |
76 | - channel.setDescription("Manjyu RSS for Murmur."); | |
77 | - // FIXME | |
78 | - channel.setLanguage("en_US"); | |
79 | - // TODO FIXME | |
80 | - channel.setCopyright("Copyright(C) Toshiki Iga"); | |
81 | - // Just now. | |
82 | - channel.setPubDate(new Date()); | |
83 | - } | |
84 | - | |
85 | - new ManjyuRssSerializer() { | |
86 | - @Override | |
87 | - protected void processItems() throws IOException { | |
88 | - try { | |
89 | - for (ManjyuMurmurItem item : new ManjyuModelRelMurmurCtxt().getMurmurListByDate(conn)) { | |
90 | - final ManjyuRssItem rssItem = new ManjyuRssItem(); | |
91 | - // TODO Length switch case | |
92 | - if (item.getMurmurType() < ManjyuConstants.MURMUR_TYPE_PLAIN_URL) { | |
93 | - rssItem.setTitle(item.getText()); | |
94 | - // TODO trim title length check. | |
95 | - // FIXME | |
96 | - | |
97 | - rssItem.setLink(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx | |
98 | - .getExternalContext()) + "/murmur/murmur.jsf?a=b"); | |
99 | - } else if (item.getMurmurType() <= ManjyuConstants.MURMUR_TYPE_WIKI_URL) { | |
100 | - rssItem.setTitle("[ext] " + item.getText()); | |
101 | - rssItem.setLink(item.getText()); | |
102 | - } else { | |
103 | - rssItem.setTitle("[NOT SUPPORTED] " + item.getText()); | |
104 | - } | |
105 | - rssItem.setPubDate(item.getDate()); | |
106 | - | |
107 | - // TODO ADD CATEGORY FOR MANJYU SPECIFIED | |
108 | - | |
109 | - serializeItem(rssItem); | |
110 | - } | |
111 | - } catch (SQLException ex) { | |
112 | - throw new IOException(ex); | |
113 | - } | |
114 | - } | |
115 | - }.serialize(rss, outStream); | |
116 | - | |
117 | - outStream.flush(); | |
118 | - } finally { | |
119 | - outStream.close(); | |
120 | - } | |
121 | - } | |
122 | -} |
@@ -0,0 +1,64 @@ | ||
1 | +/******************************************************************************* | |
2 | + * Manjyu | |
3 | + * Copyright (C) 2012 Toshiki IGA | |
4 | + * | |
5 | + * This library is free software: you can redistribute it and/or modify | |
6 | + * it under the terms of the GNU Lesser General Public License as published by | |
7 | + * the Free Software Foundation, either version 3 of the License, or | |
8 | + * any later version. | |
9 | + * | |
10 | + * This program is distributed in the hope that it will be useful, | |
11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | + * GNU Lesser General Public License for more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU Lesser General Public License | |
16 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | + *******************************************************************************/ | |
18 | +/******************************************************************************* | |
19 | + * Copyright (c) 2012 Toshiki IGA and others. | |
20 | + * All rights reserved. This program and the accompanying materials | |
21 | + * are made available under the terms of the Eclipse Public License v1.0 | |
22 | + * which accompanies this distribution, and is available at | |
23 | + * http://www.eclipse.org/legal/epl-v10.html | |
24 | + * | |
25 | + * Contributors: | |
26 | + * Toshiki IGA - initial implementation | |
27 | + *******************************************************************************/ | |
28 | +package org.manjyu.web.bean.murmur; | |
29 | + | |
30 | +import java.io.IOException; | |
31 | + | |
32 | +import javax.faces.context.FacesContext; | |
33 | +import javax.servlet.ServletConfig; | |
34 | +import javax.servlet.ServletException; | |
35 | +import javax.servlet.annotation.WebServlet; | |
36 | +import javax.servlet.http.HttpServlet; | |
37 | +import javax.servlet.http.HttpServletRequest; | |
38 | +import javax.servlet.http.HttpServletResponse; | |
39 | + | |
40 | +import org.manjyu.util.JavaServerFacesServletUtil; | |
41 | + | |
42 | +@WebServlet(name = "ManjyuWebMurmurBydateRssServlet", urlPatterns = { "/murmur/bydate.rss" }) | |
43 | +public class ManjyuWebMurmurBydateRssServlet extends HttpServlet { | |
44 | + private static final long serialVersionUID = 1L; | |
45 | + | |
46 | + @Override | |
47 | + public void init(final ServletConfig config) throws ServletException { | |
48 | + super.init(config); | |
49 | + } | |
50 | + | |
51 | + @Override | |
52 | + protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, | |
53 | + IOException { | |
54 | + // GET == POST | |
55 | + doPost(request, response); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + protected void doPost(final HttpServletRequest request, final HttpServletResponse response) | |
60 | + throws ServletException, IOException { | |
61 | + final FacesContext ctx = JavaServerFacesServletUtil.getFacesContext(request, response); | |
62 | + new ManjyuWebMurmurBydateRssProcess().downloadMurmurRss(request, response, ctx); | |
63 | + } | |
64 | +} |
@@ -0,0 +1,106 @@ | ||
1 | +/******************************************************************************* | |
2 | + * Manjyu | |
3 | + * Copyright (C) 2012 Toshiki IGA | |
4 | + * | |
5 | + * This library is free software: you can redistribute it and/or modify | |
6 | + * it under the terms of the GNU Lesser General Public License as published by | |
7 | + * the Free Software Foundation, either version 3 of the License, or | |
8 | + * any later version. | |
9 | + * | |
10 | + * This program is distributed in the hope that it will be useful, | |
11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | + * GNU Lesser General Public License for more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU Lesser General Public License | |
16 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | + *******************************************************************************/ | |
18 | +/******************************************************************************* | |
19 | + * Copyright (c) 2012 Toshiki IGA and others. | |
20 | + * All rights reserved. This program and the accompanying materials | |
21 | + * are made available under the terms of the Eclipse Public License v1.0 | |
22 | + * which accompanies this distribution, and is available at | |
23 | + * http://www.eclipse.org/legal/epl-v10.html | |
24 | + * | |
25 | + * Contributors: | |
26 | + * Toshiki IGA - initial implementation | |
27 | + *******************************************************************************/ | |
28 | +package org.manjyu.web.bean.murmur; | |
29 | + | |
30 | +import java.io.IOException; | |
31 | +import java.io.OutputStream; | |
32 | +import java.sql.Connection; | |
33 | +import java.sql.SQLException; | |
34 | +import java.util.Date; | |
35 | + | |
36 | +import javax.faces.context.FacesContext; | |
37 | +import javax.servlet.http.HttpServletRequest; | |
38 | +import javax.servlet.http.HttpServletResponse; | |
39 | + | |
40 | +import org.manjyu.model.ManjyuModelCtxt; | |
41 | +import org.manjyu.model.ManjyuModelRelMurmurCtxt; | |
42 | +import org.manjyu.rss.ManjyuRssSerializer; | |
43 | +import org.manjyu.rss.vo.ManjyuRss; | |
44 | +import org.manjyu.rss.vo.ManjyuRssChannel; | |
45 | +import org.manjyu.rss.vo.ManjyuRssItem; | |
46 | +import org.manjyu.util.JavaServerFacesUtil; | |
47 | +import org.manjyu.util.ManjyuMurmurItemUtil; | |
48 | +import org.manjyu.vo.ManjyuMurmurItem; | |
49 | +import org.manjyu.web.bean.ManjyuWebSessionBean; | |
50 | + | |
51 | +import blanco.fw.BlancoInject; | |
52 | + | |
53 | +public abstract class AbstractManjyuWebMurmurBydateRssProcess { | |
54 | + protected void downloadMurmurRss(final HttpServletRequest request, final HttpServletResponse response, | |
55 | + final FacesContext ctx, @BlancoInject final ManjyuWebSessionBean sessionBean, | |
56 | + @BlancoInject final Connection conn) throws IOException { | |
57 | + // RSS 2.0 | |
58 | + response.setContentType("application/rss+xml"); | |
59 | + | |
60 | + // Cache control. | |
61 | + response.setHeader("Cache-Control", "no-cache"); | |
62 | + response.setHeader("Pragma", "no-cache"); | |
63 | + response.setHeader("Expires", "0"); | |
64 | + | |
65 | + response.setHeader("Accept-Ranges", "none"); | |
66 | + // Note: Can't set Content-Disposition in case of RSS 2.0 | |
67 | + | |
68 | + final OutputStream outStream = response.getOutputStream(); | |
69 | + try { | |
70 | + final ManjyuRss rss = new ManjyuRss(); | |
71 | + { | |
72 | + final ManjyuRssChannel channel = rss.getChannel(); | |
73 | + channel.setTitle("Manjyu RSS for Murmur"); | |
74 | + channel.setLink(JavaServerFacesUtil.getFullyQualifiedRequestContextPath(ctx.getExternalContext()) | |
75 | + + "/murmur/bydate.jsf"); | |
76 | + channel.setDescription("Manjyu RSS for Murmur."); | |
77 | + // FIXME Should support locale switching. | |
78 | + channel.setLanguage("en_US"); | |
79 | + // TODO FIXME | |
80 | + channel.setCopyright("Copyright(C) Toshiki Iga"); | |
81 | + // Just now. | |
82 | + channel.setPubDate(new Date()); | |
83 | + } | |
84 | + | |
85 | + new ManjyuRssSerializer() { | |
86 | + @Override | |
87 | + protected void processItems() throws IOException { | |
88 | + try { | |
89 | + for (ManjyuMurmurItem item : new ManjyuModelRelMurmurCtxt().getMurmurListByDate(conn)) { | |
90 | + final ManjyuRssItem rssItem = ManjyuMurmurItemUtil.item2RssItem(item, | |
91 | + new ManjyuModelCtxt().getCtxtLineListByMurmurId(conn, item.getMurmurId()), ctx); | |
92 | + | |
93 | + serializeItem(rssItem); | |
94 | + } | |
95 | + } catch (SQLException ex) { | |
96 | + throw new IOException(ex); | |
97 | + } | |
98 | + } | |
99 | + }.serialize(rss, outStream); | |
100 | + | |
101 | + outStream.flush(); | |
102 | + } finally { | |
103 | + outStream.close(); | |
104 | + } | |
105 | + } | |
106 | +} |
@@ -0,0 +1,151 @@ | ||
1 | +package org.manjyu.web.bean.admin; | |
2 | + | |
3 | +import java.io.BufferedInputStream; | |
4 | +import java.io.IOException; | |
5 | +import java.io.InputStream; | |
6 | +import java.io.PrintWriter; | |
7 | +import java.sql.Connection; | |
8 | +import java.sql.SQLException; | |
9 | +import java.util.ArrayList; | |
10 | +import java.util.Date; | |
11 | +import java.util.List; | |
12 | + | |
13 | +import javax.faces.context.FacesContext; | |
14 | +import javax.servlet.ServletException; | |
15 | +import javax.servlet.http.HttpServletRequest; | |
16 | +import javax.servlet.http.HttpServletResponse; | |
17 | +import javax.servlet.http.Part; | |
18 | + | |
19 | +import org.manjyu.model.ManjyuModelCtxt; | |
20 | +import org.manjyu.model.ManjyuModelMurmur; | |
21 | +import org.manjyu.rss.ManjyuRssParser; | |
22 | +import org.manjyu.rss.vo.ManjyuRssCategory; | |
23 | +import org.manjyu.rss.vo.ManjyuRssChannel; | |
24 | +import org.manjyu.rss.vo.ManjyuRssItem; | |
25 | +import org.manjyu.util.ManjyuCtxtUtil; | |
26 | +import org.manjyu.vo.ManjyuMurmurItem; | |
27 | +import org.manjyu.web.bean.ManjyuWebSessionBean; | |
28 | + | |
29 | +import blanco.fw.BlancoInject; | |
30 | + | |
31 | +/** | |
32 | + * FIXME Token check should be implemented. | |
33 | + * | |
34 | + * @author ToshikiIga | |
35 | + */ | |
36 | +public abstract class AbstractManjyuWebAdminSetupByRssProcess { | |
37 | + protected void uploadRss(final HttpServletRequest request, final HttpServletResponse response, | |
38 | + final FacesContext ctx, @BlancoInject final ManjyuWebSessionBean sessionBean, | |
39 | + @BlancoInject final Connection conn) throws IOException, ServletException { | |
40 | + | |
41 | + // FIXME Token check should be implemented. | |
42 | + | |
43 | + if (sessionBean.getUserFlgAdmin() == false || sessionBean.getUserFlgEditorKwd() == false | |
44 | + || sessionBean.getUserFlgEditorMurmur() == false) { | |
45 | + // TODO Access rights is short. | |
46 | + return; | |
47 | + } | |
48 | + | |
49 | + final int[] processedItemCount = new int[] { 0 }; | |
50 | + final Part part = request.getPart("file"); | |
51 | + if (part == null) { | |
52 | + // TODO cannot process this request. | |
53 | + return; | |
54 | + } | |
55 | + | |
56 | + // Do upload here! | |
57 | + final InputStream inStream = new BufferedInputStream(part.getInputStream()); | |
58 | + new ManjyuRssParser() { | |
59 | + @Override | |
60 | + protected void processChannel(final ManjyuRssChannel channel) throws IOException { | |
61 | + System.out.println("Channel: " + channel.getTitle() + " [" + channel.getLink() + "]"); | |
62 | + System.out.println(" description: " + channel.getDescription()); | |
63 | + System.out.println(" pubDate : " + channel.getPubDate()); | |
64 | + } | |
65 | + | |
66 | + @Override | |
67 | + protected void processItem(final ManjyuRssItem rssItem) throws IOException { | |
68 | + processedItemCount[0]++; | |
69 | + | |
70 | + final ManjyuMurmurItem item = new ManjyuMurmurItem(); | |
71 | + | |
72 | + if (getCategoryByDomain(rssItem.getCategoryList(), "http://manjyu.org/manjyu/murmur/type") == null) { | |
73 | + // Not Manjyu RSS. | |
74 | + // TODO Add message. | |
75 | + return; | |
76 | + } | |
77 | + item.setMurmurType(Integer.parseInt(getCategoryByDomain(rssItem.getCategoryList(), | |
78 | + "http://manjyu.org/manjyu/murmur/type").getCharacters())); | |
79 | + | |
80 | + if (getCategoryByDomain(rssItem.getCategoryList(), "http://manjyu.org/manjyu/murmur/localeId") != null) { | |
81 | + item.setLocaleId(Integer.parseInt(getCategoryByDomain(rssItem.getCategoryList(), | |
82 | + "http://manjyu.org/manjyu/murmur/localeId").getCharacters())); | |
83 | + } | |
84 | + item.setText(rssItem.getTitle()); | |
85 | + item.setDate(rssItem.getPubDate()); | |
86 | + | |
87 | + // Expand Keyword Directory. | |
88 | + final List<String> directoryList = new ArrayList<String>(); | |
89 | + for (ManjyuRssCategory category : rssItem.getCategoryList()) { | |
90 | + if ("http://manjyu.org/manjyu/keyword/directory".equals(category.getDomain())) { | |
91 | + final int indexOf = category.getCharacters().indexOf("/keyword/directory.jsf?path="); | |
92 | + // TODO Implement error case | |
93 | + | |
94 | + String directory = category.getCharacters().substring( | |
95 | + indexOf + "/keyword/directory.jsf?path=".length()); | |
96 | + directory = directory.replace("%09", "\t"); | |
97 | + directoryList.add(directory); | |
98 | + } | |
99 | + } | |
100 | + for (String directory : directoryList) { | |
101 | + try { | |
102 | + new ManjyuModelCtxt().addCtxtLine(conn, directory, sessionBean.getUserId()); | |
103 | + } catch (SQLException ex) { | |
104 | + throw new IOException(ex); | |
105 | + } | |
106 | + } | |
107 | + | |
108 | + if (directoryList.size() == 0) { | |
109 | + // FIXME LOGGGGGG | |
110 | + return; | |
111 | + } | |
112 | + | |
113 | + // Expand Murmur item. | |
114 | + try { | |
115 | + // FIXME Other (Not first) directory must be processed. | |
116 | + final int ctxtId = new ManjyuModelCtxt().getCtxtId(conn, | |
117 | + ManjyuCtxtUtil.splitCtxtLine(directoryList.get(0))); | |
118 | + | |
119 | + new ManjyuModelMurmur().addMurmur(conn, ctxtId, item.getLocaleId(), item.getMurmurType(), | |
120 | + item.getDate(), item.getText(), 0/*FIXME */, sessionBean.getUserId(), new Date(), | |
121 | + sessionBean.getUserId()); | |
122 | + } catch (SQLException ex) { | |
123 | + throw new IOException(ex); | |
124 | + } | |
125 | + } | |
126 | + }.parse(inStream); | |
127 | + inStream.close(); | |
128 | + | |
129 | + try { | |
130 | + conn.commit(); | |
131 | + } catch (SQLException ex) { | |
132 | + throw new IOException(ex); | |
133 | + } | |
134 | + | |
135 | + final PrintWriter out = response.getWriter(); | |
136 | + out.println("<HTML><BODY>"); | |
137 | + out.println("Upload successful. " + processedItemCount[0] + " items imported."); | |
138 | + out.println("</BODY></HTML>"); | |
139 | + out.flush(); | |
140 | + } | |
141 | + | |
142 | + private static final ManjyuRssCategory getCategoryByDomain(final List<ManjyuRssCategory> categoryList, | |
143 | + final String domainName) { | |
144 | + for (ManjyuRssCategory category : categoryList) { | |
145 | + if (domainName.equals(category.getDomain())) { | |
146 | + return category; | |
147 | + } | |
148 | + } | |
149 | + return null; | |
150 | + } | |
151 | +} |
@@ -0,0 +1,66 @@ | ||
1 | +/******************************************************************************* | |
2 | + * Manjyu | |
3 | + * Copyright (C) 2012 Toshiki IGA | |
4 | + * | |
5 | + * This library is free software: you can redistribute it and/or modify | |
6 | + * it under the terms of the GNU Lesser General Public License as published by | |
7 | + * the Free Software Foundation, either version 3 of the License, or | |
8 | + * any later version. | |
9 | + * | |
10 | + * This program is distributed in the hope that it will be useful, | |
11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | + * GNU Lesser General Public License for more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU Lesser General Public License | |
16 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. | |
17 | + *******************************************************************************/ | |
18 | +/******************************************************************************* | |
19 | + * Copyright (c) 2012 Toshiki IGA and others. | |
20 | + * All rights reserved. This program and the accompanying materials | |
21 | + * are made available under the terms of the Eclipse Public License v1.0 | |
22 | + * which accompanies this distribution, and is available at | |
23 | + * http://www.eclipse.org/legal/epl-v10.html | |
24 | + * | |
25 | + * Contributors: | |
26 | + * Toshiki IGA - initial implementation | |
27 | + *******************************************************************************/ | |
28 | +package org.manjyu.web.bean.admin; | |
29 | + | |
30 | +import java.io.IOException; | |
31 | + | |
32 | +import javax.faces.context.FacesContext; | |
33 | +import javax.servlet.ServletConfig; | |
34 | +import javax.servlet.ServletException; | |
35 | +import javax.servlet.annotation.MultipartConfig; | |
36 | +import javax.servlet.annotation.WebServlet; | |
37 | +import javax.servlet.http.HttpServlet; | |
38 | +import javax.servlet.http.HttpServletRequest; | |
39 | +import javax.servlet.http.HttpServletResponse; | |
40 | + | |
41 | +import org.manjyu.util.JavaServerFacesServletUtil; | |
42 | + | |
43 | +@WebServlet(name = "ManjyuWebAdminSetupByRssServlet", urlPatterns = { "/admin/setupByRss" }) | |
44 | +@MultipartConfig(maxFileSize = 1024000000) | |
45 | +public class ManjyuWebAdminSetupByRssServlet extends HttpServlet { | |
46 | + private static final long serialVersionUID = 1L; | |
47 | + | |
48 | + @Override | |
49 | + public void init(final ServletConfig config) throws ServletException { | |
50 | + super.init(config); | |
51 | + } | |
52 | + | |
53 | + @Override | |
54 | + protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, | |
55 | + IOException { | |
56 | + // GET == POST | |
57 | + doPost(request, response); | |
58 | + } | |
59 | + | |
60 | + @Override | |
61 | + protected void doPost(final HttpServletRequest request, final HttpServletResponse response) | |
62 | + throws ServletException, IOException { | |
63 | + final FacesContext ctx = JavaServerFacesServletUtil.getFacesContext(request, response); | |
64 | + new ManjyuWebAdminSetupByRssProcess().uploadRss(request, response, ctx); | |
65 | + } | |
66 | +} |