Mercurial Hosting > nabble
view src/global/web/RootForums.java @ 28:03e68185c2f5
block spam forums
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 02 Jul 2020 21:19:24 -0600 |
parents | 7ecd1a4ef557 |
children | 56accc959f8c |
line wrap: on
line source
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); } }; out.print( "\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n <head>\r\n " ); HtmlGlobalUtils.head(request, response, title + " | Page " + page); out.print( "\r\n <link rel=\"canonical\" href=\"https://www.nabble.com" ); out.print( (path(page)) ); out.print( "\">\r\n <style>\r\n h2{margin-bottom:.2em}\r\n div[sites] > div{min-height:70px}\r\n </style>\r\n </head>\r\n <body lato>\r\n " ); HtmlGlobalUtils.header(request,response); out.print( "\r\n <div content center paddingTop>\r\n <h1 oswald>" ); out.print( (title) ); out.print( "</h1>\r\n </div>\r\n <div gray content marginBottom>\r\n Page " ); out.print( (page) ); out.print( " of " ); out.print( (PAGES) ); out.print( "\r\n " ); HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, "0 4em .5em", true, 10); out.print( "\r\n </div>\r\n <div content paddingTop sites>\r\n " ); 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"; out.print( "\r\n <div marginBottom>\r\n <h2>" ); out.print( (site.link()) ); out.print( "</h2>\r\n <div gray>\r\n " ); out.print( (message) ); out.print( "\r\n </div>\r\n </div>\r\n" ); } out.print( "\r\n" ); HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, ".4em 4em", true, 10); out.print( "\r\n</div>\r\n" ); HtmlGlobalUtils.footer(request,response); out.print( "\r\n</body>\r\n</html>\r\n" ); } finally { searcher.close(); } } }