01: package org.wings.resource;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.InputStream;
05: import java.io.SequenceInputStream;
06:
07: public class ClassPathJavascriptResource extends ClassPathResource {
08:
09: private String callbackCode;
10:
11: public ClassPathJavascriptResource(String resourceFileName,
12: String callbackCode) {
13: this (resourceFileName, "text/javascript", callbackCode);
14: }
15:
16: public ClassPathJavascriptResource(String resourceFileName,
17: String mimeType, String callbackCode) {
18: super (resourceFileName, mimeType);
19: this .callbackCode = callbackCode;
20: }
21:
22: public ClassPathJavascriptResource(ClassLoader classLoader,
23: String resourceFileName, String callbackCode) {
24: super (classLoader, resourceFileName);
25: this .callbackCode = callbackCode;
26: }
27:
28: public ClassPathJavascriptResource(ClassLoader classLoader,
29: String resourceFileName, String mimeType,
30: String callbackCode) {
31: super (classLoader, resourceFileName, mimeType);
32: this .callbackCode = callbackCode;
33: }
34:
35: @Override
36: protected InputStream getResourceStream()
37: throws ResourceNotFoundException {
38: if (callbackCode == null) {
39: return super .getResourceStream();
40: }
41: return new SequenceInputStream(super .getResourceStream(),
42: new ByteArrayInputStream(("\n\n" + callbackCode)
43: .getBytes()));
44: }
45:
46: }
|