85
85
* @author chris
86
86
*/
87
87
public class SilkenServlet extends HttpServlet {
88
+
89
+ private static volatile SilkenServlet s_instance ;
88
90
89
91
private static final long serialVersionUID = 1L ;
90
92
@@ -99,10 +101,6 @@ public class SilkenServlet extends HttpServlet {
99
101
100
102
private final TemplateRenderer templateRenderer = new TemplateRenderer (config );
101
103
102
- public Config getConfig () {
103
- return config ;
104
- }
105
-
106
104
@ Override
107
105
public void init (ServletConfig servletConfig ) throws ServletException {
108
106
super .init (servletConfig );
@@ -205,6 +203,8 @@ public void init(ServletConfig servletConfig) throws ServletException {
205
203
}
206
204
}
207
205
}
206
+
207
+ s_instance = this ;
208
208
}
209
209
210
210
@ Override
@@ -344,4 +344,35 @@ private boolean isValueFalse(String value) {
344
344
return (value .startsWith ("f" ) || value .equals ("0" ) || value .startsWith ("n" ));
345
345
}
346
346
347
+ /**
348
+ * Advanced: A convenience method to get a reference to the currently loaded SilkenServlet. Use this method with
349
+ * care. It assumes only one instance if the SilkenServlet is loaded in your server's context.
350
+ *
351
+ * @return A reference to the currently loaded SilkenServlet.
352
+ */
353
+ public static SilkenServlet getInstance () {
354
+ if (s_instance == null ) throw new IllegalStateException ("The Silken Servlet is not yet initialized/loaded!" );
355
+ return s_instance ;
356
+ }
357
+
358
+ /**
359
+ * Advanced: A convenience method to get a reference to the currently loaded SilkenServlet's Config class. Use this
360
+ * method with care. Where possible obtain this reference from the "silken.config" servlet context attribute.
361
+ *
362
+ * @return A reference to the currently loaded SilkenServet's Config class.
363
+ */
364
+ public static Config getConfig () {
365
+ return getInstance ().config ;
366
+ }
367
+
368
+ /**
369
+ * Advanced: A convenience method to get a reference to the currently loaded TemplateRender. Use this method with
370
+ * care. Where possible obtain this reference from the "silken.templateRenderer" servlet context attribute.
371
+ *
372
+ * @return A reference to the currently loaded TemplateRenderer hosted by Silken.
373
+ */
374
+ public static TemplateRenderer getTemplateRenderer () {
375
+ return getInstance ().templateRenderer ;
376
+ }
377
+
347
378
}
0 commit comments