Mercurial Hosting > nabble
diff src/nabble/view/lib/MyJtpServlet.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children | 72765b66e2c3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nabble/view/lib/MyJtpServlet.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,94 @@ +package nabble.view.lib; + +import fschmidt.util.servlet.DbCache; +import fschmidt.util.servlet.HttpCache; +import fschmidt.util.servlet.JtpContext; +import fschmidt.util.servlet.MemCache; +import nabble.model.Db; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +// misnamed for historical reasons +public final class MyJtpServlet { + private static final Logger logger = LoggerFactory.getLogger(MyJtpServlet.class); + + public static final HttpCache cache; + private static volatile JtpContextServlet jtpContext = null; + private static final Object jtpContextLock = new Object(); + + static { +// SitemapGen.runSitemap(new SitemapTemplate()); + cache = + new MemCache( + new DbCache(Db.dbGlobal()) + ) + ; + Cache.init(); + + synchronized(jtpContextLock) { + jtpContext = new JtpContextServlet(); + jtpContext.addDestroyListener( new JtpContextServlet.DestroyListener() { + public void destroyed() { + jtpContext = null; + } + } ); + jtpContext.setBase("nabble.view.web"); + jtpContextLock.notifyAll(); + } + jtpContext.setUrlMapper(new UrlMapperImpl(new Class[]{ + nabble.view.web.Index.class, + nabble.view.web.embed.NabbleEmbed.class, + nabble.view.web.forum.Permalink.class, + nabble.view.web.forum.FileDownload.class, + nabble.view.web.forum.Thumbnail.class, + nabble.view.web.forum.AttachmentDownload.class, + nabble.view.web.template.NamlDownload.class, + nabble.view.web.more.Forum.class, + nabble.view.web.more.MailingListRequest.class, + nabble.view.web.more.ForumStart.class, + nabble.view.web.seo.WidgetRedir.class, + nabble.view.web.util.GradientImage.class, + nabble.view.web.util.RoundedCorner.class, + nabble.view.web.w3c.PolicyXML.class, + nabble.view.web.w3c.PolicyHTML.class, + nabble.view.web.w3c.P3PXML.class, + nabble.view.web.tools.Index.class, + })); + if( cache != null ) { + jtpContext.setHttpCache(cache); + } + + /** + * Adds a P3P compact header information to a HttpServletResponse object. + * This is required for the embedding project because Internet Explorer (IE) blocks + * cookies from a third-party iframe (different domain). This piece of code + * solves the problem and allows IE to save the cookies without problems. + */ + jtpContext.addCustomHeader("p3p", "CP=\"IDC DSP TAIi PSAi PSDi OTPi OUR IND PHY ONL UNI NAV DEM PRE LOC\""); + } + + public static JtpContext getJtpContext() { + return jtpContext; + } + + public static JtpContext getJtpContextNotNull() { + synchronized(jtpContextLock) { + if( jtpContext==null ) { + try { + jtpContextLock.wait(10000L); + } catch(InterruptedException e) { + throw new RuntimeException(e); + } + if( jtpContext==null ) + throw new NullPointerException("jtpContext is null"); + } + return jtpContext; + } + } + + public static void nop() {} +}