diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/global/web/RootForums.jtp	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,119 @@
+<%
+package global.web;
+
+import fschmidt.util.java.HtmlUtils;
+import fschmidt.util.servlet.JtpContext;
+import global.HtmlGlobalUtils;
+import global.Site;
+import nabble.model.MessageUtils;
+import nabble.model.NodeSearcher;
+import nabble.view.lib.HtmlViewUtils;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TopDocs;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+public final class RootForums extends HttpServlet {
+
+	public static final int PAGES = 200;
+	private static final int ROWS_PER_PAGE = 50;
+
+	static String path() {
+		return path(1);
+	}
+
+	static String path(int page) {
+		return "/free-apps/page" + page + ".html";
+	}
+
+	protected void service(HttpServletRequest request,HttpServletResponse response)
+		throws ServletException, IOException
+	{
+		JtpContext jtpContext = (JtpContext)getServletContext().getAttribute(JtpContext.attrName);
+		jtpContext.setEtag(request,response,"x");
+
+		PrintWriter out = response.getWriter();
+
+		String title = "Browse Apps";
+
+		String pageS = request.getParameter("page");
+		int page = Integer.parseInt(pageS);
+		int iRec = (page-1)*ROWS_PER_PAGE;
+
+		IndexSearcher searcher;
+		TopDocs hits;
+		try {
+			searcher = new IndexSearcher(Site.dir());
+			hits = searcher.search( Index.query, iRec+ROWS_PER_PAGE, Site.SORT_BY_VALUE );
+		} catch(IOException e) {
+			throw new RuntimeException(e);
+		}
+		try {
+			HtmlViewUtils.PagingPath pagingPath = new HtmlViewUtils.PagingPath() {
+				public String path(int row) {
+					return RootForums.path(1+row/ROWS_PER_PAGE);
+				}
+			};
+
+%>
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<% HtmlGlobalUtils.head(request, response, title + " | Page " + page); %>
+		<link rel="canonical" href="https://www.nabble.com<%=path(page)%>">
+		<style>
+			h2{margin-bottom:.2em}
+			div[sites] > div{min-height:70px}
+		</style>
+	</head>
+	<body lato>
+		<% HtmlGlobalUtils.header(request,response); %>
+		<div content center paddingTop>
+			<h1 oswald><%=title%></h1>
+		</div>
+		<div gray content marginBottom>
+			Page <%=page%> of <%=PAGES%>
+			<% HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, "0 4em .5em", true, 10); %>
+		</div>
+		<div content paddingTop sites>
+			<%
+			for( int i = iRec; i<hits.scoreDocs.length; i++ ) {
+				Site site = new Site(searcher.doc(hits.scoreDocs[i].doc));
+				String message = site.message();
+				message = MessageUtils.getTextWithoutQuotes(message);
+				message = NodeSearcher.getStartingFragment(message,200,"...");
+				message = MessageUtils.hideAllEmails(message);
+				message = HtmlUtils.htmlEncode(message);
+				String what = site.type();
+				if (what == null || what.matches("mixed|category|board|null"))
+					what = "forum";
+				%>
+					<div marginBottom>
+						<h2><%=site.link()%></h2>
+						<div gray>
+							<%=message%>
+						</div>
+					</div>
+				<%
+			}
+			%>
+			<% HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, ".4em 4em", true, 10); %>
+		</div>
+		<% HtmlGlobalUtils.footer(request,response); %>
+	</body>
+</html>
+<%
+		} finally {
+			searcher.close();
+		}
+	}
+
+}
+%>