comparison src/global/web/RootForums.jtp @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children 56accc959f8c
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
1 <%
2 package global.web;
3
4 import fschmidt.util.java.HtmlUtils;
5 import fschmidt.util.servlet.JtpContext;
6 import global.HtmlGlobalUtils;
7 import global.Site;
8 import nabble.model.MessageUtils;
9 import nabble.model.NodeSearcher;
10 import nabble.view.lib.HtmlViewUtils;
11 import org.apache.lucene.search.IndexSearcher;
12 import org.apache.lucene.search.Query;
13 import org.apache.lucene.search.TopDocs;
14
15 import javax.servlet.ServletException;
16 import javax.servlet.http.HttpServlet;
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21
22
23 public final class RootForums extends HttpServlet {
24
25 public static final int PAGES = 200;
26 private static final int ROWS_PER_PAGE = 50;
27
28 static String path() {
29 return path(1);
30 }
31
32 static String path(int page) {
33 return "/free-apps/page" + page + ".html";
34 }
35
36 protected void service(HttpServletRequest request,HttpServletResponse response)
37 throws ServletException, IOException
38 {
39 JtpContext jtpContext = (JtpContext)getServletContext().getAttribute(JtpContext.attrName);
40 jtpContext.setEtag(request,response,"x");
41
42 PrintWriter out = response.getWriter();
43
44 String title = "Browse Apps";
45
46 String pageS = request.getParameter("page");
47 int page = Integer.parseInt(pageS);
48 int iRec = (page-1)*ROWS_PER_PAGE;
49
50 IndexSearcher searcher;
51 TopDocs hits;
52 try {
53 searcher = new IndexSearcher(Site.dir());
54 hits = searcher.search( Index.query, iRec+ROWS_PER_PAGE, Site.SORT_BY_VALUE );
55 } catch(IOException e) {
56 throw new RuntimeException(e);
57 }
58 try {
59 HtmlViewUtils.PagingPath pagingPath = new HtmlViewUtils.PagingPath() {
60 public String path(int row) {
61 return RootForums.path(1+row/ROWS_PER_PAGE);
62 }
63 };
64
65 %>
66 <!DOCTYPE html>
67 <html lang="en">
68 <head>
69 <% HtmlGlobalUtils.head(request, response, title + " | Page " + page); %>
70 <link rel="canonical" href="https://www.nabble.com<%=path(page)%>">
71 <style>
72 h2{margin-bottom:.2em}
73 div[sites] > div{min-height:70px}
74 </style>
75 </head>
76 <body lato>
77 <% HtmlGlobalUtils.header(request,response); %>
78 <div content center paddingTop>
79 <h1 oswald><%=title%></h1>
80 </div>
81 <div gray content marginBottom>
82 Page <%=page%> of <%=PAGES%>
83 <% HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, "0 4em .5em", true, 10); %>
84 </div>
85 <div content paddingTop sites>
86 <%
87 for( int i = iRec; i<hits.scoreDocs.length; i++ ) {
88 Site site = new Site(searcher.doc(hits.scoreDocs[i].doc));
89 String message = site.message();
90 message = MessageUtils.getTextWithoutQuotes(message);
91 message = NodeSearcher.getStartingFragment(message,200,"...");
92 message = MessageUtils.hideAllEmails(message);
93 message = HtmlUtils.htmlEncode(message);
94 String what = site.type();
95 if (what == null || what.matches("mixed|category|board|null"))
96 what = "forum";
97 %>
98 <div marginBottom>
99 <h2><%=site.link()%></h2>
100 <div gray>
101 <%=message%>
102 </div>
103 </div>
104 <%
105 }
106 %>
107 <% HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, ".4em 4em", true, 10); %>
108 </div>
109 <% HtmlGlobalUtils.footer(request,response); %>
110 </body>
111 </html>
112 <%
113 } finally {
114 searcher.close();
115 }
116 }
117
118 }
119 %>