Mercurial Hosting > nabble
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.view.lib; | |
2 | |
3 import fschmidt.util.servlet.DbCache; | |
4 import fschmidt.util.servlet.HttpCache; | |
5 import fschmidt.util.servlet.JtpContext; | |
6 import fschmidt.util.servlet.MemCache; | |
7 import nabble.model.Db; | |
8 import org.slf4j.Logger; | |
9 import org.slf4j.LoggerFactory; | |
10 | |
11 import javax.servlet.http.HttpServletRequest; | |
12 import javax.servlet.http.HttpServletResponse; | |
13 | |
14 | |
15 // misnamed for historical reasons | |
16 public final class MyJtpServlet { | |
17 private static final Logger logger = LoggerFactory.getLogger(MyJtpServlet.class); | |
18 | |
19 public static final HttpCache cache; | |
20 private static volatile JtpContextServlet jtpContext = null; | |
21 private static final Object jtpContextLock = new Object(); | |
22 | |
23 static { | |
24 // SitemapGen.runSitemap(new SitemapTemplate()); | |
25 cache = | |
26 new MemCache( | |
27 new DbCache(Db.dbGlobal()) | |
28 ) | |
29 ; | |
30 Cache.init(); | |
31 | |
32 synchronized(jtpContextLock) { | |
33 jtpContext = new JtpContextServlet(); | |
34 jtpContext.addDestroyListener( new JtpContextServlet.DestroyListener() { | |
35 public void destroyed() { | |
36 jtpContext = null; | |
37 } | |
38 } ); | |
39 jtpContext.setBase("nabble.view.web"); | |
40 jtpContextLock.notifyAll(); | |
41 } | |
42 jtpContext.setUrlMapper(new UrlMapperImpl(new Class[]{ | |
43 nabble.view.web.Index.class, | |
44 nabble.view.web.embed.NabbleEmbed.class, | |
45 nabble.view.web.forum.Permalink.class, | |
46 nabble.view.web.forum.FileDownload.class, | |
47 nabble.view.web.forum.Thumbnail.class, | |
48 nabble.view.web.forum.AttachmentDownload.class, | |
49 nabble.view.web.template.NamlDownload.class, | |
50 nabble.view.web.more.Forum.class, | |
51 nabble.view.web.more.MailingListRequest.class, | |
52 nabble.view.web.more.ForumStart.class, | |
53 nabble.view.web.seo.WidgetRedir.class, | |
54 nabble.view.web.util.GradientImage.class, | |
55 nabble.view.web.util.RoundedCorner.class, | |
56 nabble.view.web.w3c.PolicyXML.class, | |
57 nabble.view.web.w3c.PolicyHTML.class, | |
58 nabble.view.web.w3c.P3PXML.class, | |
59 nabble.view.web.tools.Index.class, | |
60 })); | |
61 if( cache != null ) { | |
62 jtpContext.setHttpCache(cache); | |
63 } | |
64 | |
65 /** | |
66 * Adds a P3P compact header information to a HttpServletResponse object. | |
67 * This is required for the embedding project because Internet Explorer (IE) blocks | |
68 * cookies from a third-party iframe (different domain). This piece of code | |
69 * solves the problem and allows IE to save the cookies without problems. | |
70 */ | |
71 jtpContext.addCustomHeader("p3p", "CP=\"IDC DSP TAIi PSAi PSDi OTPi OUR IND PHY ONL UNI NAV DEM PRE LOC\""); | |
72 } | |
73 | |
74 public static JtpContext getJtpContext() { | |
75 return jtpContext; | |
76 } | |
77 | |
78 public static JtpContext getJtpContextNotNull() { | |
79 synchronized(jtpContextLock) { | |
80 if( jtpContext==null ) { | |
81 try { | |
82 jtpContextLock.wait(10000L); | |
83 } catch(InterruptedException e) { | |
84 throw new RuntimeException(e); | |
85 } | |
86 if( jtpContext==null ) | |
87 throw new NullPointerException("jtpContext is null"); | |
88 } | |
89 return jtpContext; | |
90 } | |
91 } | |
92 | |
93 public static void nop() {} | |
94 } |