44
44
import java .util .regex .Pattern ;
45
45
import javax .servlet .http .Cookie ;
46
46
import javax .servlet .http .HttpServletRequest ;
47
+ import javax .servlet .ServletRequest ;
47
48
import org .apache .commons .jrcs .diff .Diff ;
48
49
import org .apache .commons .jrcs .diff .DifferentiationFailedException ;
49
50
import org .opensolaris .opengrok .analysis .AnalyzerGuru ;
58
59
import org .opensolaris .opengrok .util .IOUtils ;
59
60
60
61
/**
61
- * A simple container to lazy initialize common vars wrt. a single request. It
62
- * MUST NOT be shared between several requests and {@link #cleanup()} should be
63
- * called before the page context gets destroyed (e.g. by overwriting
64
- * {@code jspDestroy()} or when leaving the {@code service} method. <p> Purpose
62
+ * A simple container to lazy initialize common vars wrt. a single request.
63
+ * It MUST NOT be shared between several requests and
64
+ * {@link #cleanup(ServletRequest)} should be called before the page context
65
+ * gets destroyed (e.g. when leaving the {@code service} method) . <p> Purpose
65
66
* is to decouple implementation details from web design, so that the JSP
66
67
* developer does not need to know every implementation detail and normally has
67
68
* to deal with this class/wrapper, only (so some people may like to call this
@@ -1202,6 +1203,7 @@ public static PageConfig get(HttpServletRequest request) {
1202
1203
request .setAttribute (ATTR_NAME , pcfg );
1203
1204
return pcfg ;
1204
1205
}
1206
+
1205
1207
private static final String ATTR_NAME = PageConfig .class .getCanonicalName ();
1206
1208
private HttpServletRequest req ;
1207
1209
@@ -1210,17 +1212,24 @@ private PageConfig(HttpServletRequest req) {
1210
1212
}
1211
1213
1212
1214
/**
1213
- * Cleanup all allocated resources. Should always be called right before
1214
- * leaving the _jspService / service.
1215
+ * Cleanup all allocated resources (if any) from the instance attached to
1216
+ * the given request.
1217
+ * @param sr request to check, cleanup. Ignored if {@code null}.
1218
+ * @see PageConfig#get(HttpServletRequest)
1219
+ *
1215
1220
*/
1216
- public void cleanup () {
1217
- if (req != null ) {
1218
- req .removeAttribute (ATTR_NAME );
1219
- req = null ;
1221
+ public static void cleanup (ServletRequest sr ) {
1222
+ if (sr == null ) {
1223
+ return ;
1220
1224
}
1221
- env = null ;
1222
- if (eftarReader != null ) {
1223
- eftarReader .close ();
1225
+ PageConfig cfg = (PageConfig ) sr .getAttribute (ATTR_NAME );
1226
+ if (cfg == null ) {
1227
+ return ;
1228
+ }
1229
+ sr .removeAttribute (ATTR_NAME );
1230
+ cfg .env = null ;
1231
+ if (cfg .eftarReader != null ) {
1232
+ cfg .eftarReader .close ();
1224
1233
}
1225
1234
}
1226
1235
}
0 commit comments