| 0 | 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 		out.print( "\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n	<head>\r\n		" ); | 
|  | 67  HtmlGlobalUtils.head(request, response, title + " | Page " + page); | 
|  | 68 		out.print( "\r\n		<link rel=\"canonical\" href=\"https://www.nabble.com" ); | 
|  | 69 		out.print( (path(page)) ); | 
|  | 70 		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		" ); | 
|  | 71  HtmlGlobalUtils.header(request,response); | 
|  | 72 		out.print( "\r\n		<div content center paddingTop>\r\n			<h1 oswald>" ); | 
|  | 73 		out.print( (title) ); | 
|  | 74 		out.print( "</h1>\r\n		</div>\r\n		<div gray content marginBottom>\r\n			Page " ); | 
|  | 75 		out.print( (page) ); | 
|  | 76 		out.print( " of " ); | 
|  | 77 		out.print( (PAGES) ); | 
|  | 78 		out.print( "\r\n			" ); | 
|  | 79  HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, "0 4em .5em", true, 10); | 
|  | 80 		out.print( "\r\n		</div>\r\n		<div content paddingTop sites>\r\n			" ); | 
|  | 81 | 
|  | 82 			for( int i = iRec; i<hits.scoreDocs.length; i++ ) { | 
|  | 83 				Site site = new Site(searcher.doc(hits.scoreDocs[i].doc)); | 
|  | 84 				String message = site.message(); | 
|  | 85 				message = MessageUtils.getTextWithoutQuotes(message); | 
|  | 86 				message = NodeSearcher.getStartingFragment(message,200,"..."); | 
|  | 87 				message = MessageUtils.hideAllEmails(message); | 
|  | 88 				message = HtmlUtils.htmlEncode(message); | 
|  | 89 				String what = site.type(); | 
|  | 90 				if (what == null || what.matches("mixed|category|board|null")) | 
|  | 91 					what = "forum"; | 
|  | 92 | 
|  | 93 		out.print( "\r\n	<div marginBottom>\r\n		<h2>" ); | 
|  | 94 		out.print( (site.link()) ); | 
|  | 95 		out.print( "</h2>\r\n		<div gray>\r\n			" ); | 
|  | 96 		out.print( (message) ); | 
|  | 97 		out.print( "\r\n		</div>\r\n	</div>\r\n" ); | 
|  | 98 | 
|  | 99 			} | 
|  | 100 | 
|  | 101 		out.print( "\r\n" ); | 
|  | 102  HtmlViewUtils.genericPaging(request, response, PAGES*ROWS_PER_PAGE, iRec, ROWS_PER_PAGE, pagingPath, ".4em 4em", true, 10); | 
|  | 103 		out.print( "\r\n</div>\r\n" ); | 
|  | 104  HtmlGlobalUtils.footer(request,response); | 
|  | 105 		out.print( "\r\n</body>\r\n</html>\r\n" ); | 
|  | 106 | 
|  | 107 		} finally { | 
|  | 108 			searcher.close(); | 
|  | 109 		} | 
|  | 110 	} | 
|  | 111 | 
|  | 112 } | 
|  | 113 |