KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > util > UtilJ2eeCompat


1 /*
2  * $Id: UtilJ2eeCompat.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.base.util;
25
26 import javax.servlet.ServletContext JavaDoc;
27
28 /**
29  * Misc J2EE Compatibility Utility Functions
30  *
31  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
32  * @version $Rev: 5462 $
33  * @since 2.0
34  */

35 public class UtilJ2eeCompat {
36     
37     public static final String JavaDoc module = UtilJ2eeCompat.class.getName();
38
39     public static final String JavaDoc TOMCAT = "Apache Tomcat";
40     public static final String JavaDoc ORION = "Orion";
41     public static final String JavaDoc RESIN = "Resin";
42     public static final String JavaDoc REX_IP = "TradeCity";
43     public static final String JavaDoc OC4J = "Oracle";
44     public static final String JavaDoc JRUN = "JRun";
45     public static final String JavaDoc JETTY = "Jetty";
46     public static final String JavaDoc WEBSPHERE = "Websphere";
47
48     protected static Boolean JavaDoc doFlushOnRenderValue = null;
49     protected static Boolean JavaDoc useOutputStreamNotWriterValue = null;
50     protected static Boolean JavaDoc useNestedJspException = null;
51
52     public static boolean doFlushOnRender(ServletContext JavaDoc context) {
53         initCompatibilityOptions(context);
54         return doFlushOnRenderValue.booleanValue();
55     }
56
57     public static boolean useOutputStreamNotWriter(ServletContext JavaDoc context) {
58         initCompatibilityOptions(context);
59         return useOutputStreamNotWriterValue.booleanValue();
60     }
61
62     public static boolean useNestedJspException(ServletContext JavaDoc context) {
63         initCompatibilityOptions(context);
64         return useNestedJspException.booleanValue();
65     }
66
67     protected static void initCompatibilityOptions(ServletContext JavaDoc context) {
68         // this check to see if we should flush is done because on most servers this
69
// will just slow things down and not solve any problems, but on Tomcat, Orion, etc it is necessary
70
if (useOutputStreamNotWriterValue == null || doFlushOnRenderValue == null) {
71             boolean doflush = true;
72             boolean usestream = true;
73             boolean nestjspexception = true;
74             // if context is null use an empty string here which will cause the defaults to be used
75
String JavaDoc serverInfo = context == null ? "" : context.getServerInfo();
76
77             Debug.logInfo("serverInfo: " + serverInfo, module);
78
79             if (serverInfo.indexOf(RESIN) >= 0) {
80                 Debug.logImportant("Resin detected, disabling the flush on the region render from PageContext for better performance", module);
81                 doflush = false;
82             } else if (serverInfo.indexOf(REX_IP) >= 0) {
83                 Debug.logImportant("Trade City RexIP detected, using response.getWriter to write text out instead of response.getOutputStream", module);
84                 usestream = false;
85             } else if (serverInfo.indexOf(TOMCAT) >= 0) {
86                 Debug.logImportant("Apache Tomcat detected, using response.getWriter to write text out instead of response.getOutputStream", module);
87                 usestream = false;
88             } else if (serverInfo.indexOf(JRUN) >= 0) {
89                 Debug.logImportant("JRun detected, using response.getWriter to write text out instead of response.getOutputStream", module);
90                 usestream = false;
91             } else if (serverInfo.indexOf(JETTY) >= 0) {
92                 Debug.logImportant("Jetty detected, using response.getWriter to write text out instead of response.getOutputStream", module);
93                 usestream = false;
94             } else if (serverInfo.indexOf(ORION) >= 0) {
95                 Debug.logImportant("Orion detected, using response.getWriter to write text out instead of response.getOutputStream", module);
96                 usestream = false;
97                 Debug.logImportant("Orion detected, using non-nested JspException", module);
98                 nestjspexception = false;
99             } else if (serverInfo.indexOf(WEBSPHERE) >= 0) {
100                 Debug.logImportant("IBM Websphere Application Server detected, using response.getWriter to write text out instead of response.getOutputStream", module);
101                 usestream = false;
102             }
103
104             doFlushOnRenderValue = new Boolean JavaDoc(doflush);
105             useOutputStreamNotWriterValue = new Boolean JavaDoc(usestream);
106             useNestedJspException = new Boolean JavaDoc(nestjspexception);
107         }
108     }
109 }
110
Popular Tags