01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.servlet;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.directwebremoting.extend.Compressor;
26:
27: /**
28: * Basically a file servlet component that does some <b>very limited</b>
29: * EL type processing on the file. See the source for the cheat.
30: * @author Joe Walker [joe at getahead dot ltd dot uk]
31: */
32: public abstract class JavaScriptHandler extends TemplateHandler {
33: /* (non-Javadoc)
34: * @see org.directwebremoting.servlet.CachingFileHandler#generate(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
35: */
36: @Override
37: protected String generateCachableContent(
38: HttpServletRequest request, HttpServletResponse response)
39: throws IOException {
40: String output = super
41: .generateCachableContent(request, response);
42: try {
43: return compressor.compressJavaScript(output);
44: } catch (Exception ex) {
45: log.warn("Compression system ("
46: + compressor.getClass().getSimpleName()
47: + ") failed to compress script", ex);
48: return output;
49: }
50: }
51:
52: /**
53: * Setter for the current JavaScript compression library
54: * @param compressor The new compression library
55: */
56: public void setCompressor(Compressor compressor) {
57: this .compressor = compressor;
58: }
59:
60: /**
61: * Are we compressing the script?
62: */
63: private Compressor compressor;
64:
65: /**
66: * The log stream
67: */
68: private static final Log log = LogFactory
69: .getLog(JavaScriptHandler.class);
70: }
|