0
|
1 package cachingfilter;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4 import javax.servlet.http.HttpServletResponse;
|
|
5
|
|
6
|
|
7 abstract class ResponseAction implements Serializable {
|
|
8 final String name;
|
|
9
|
|
10 ResponseAction(String name) {
|
|
11 this.name = name;
|
|
12 }
|
|
13
|
|
14 abstract void apply(HttpServletResponse response);
|
|
15
|
|
16 public abstract String toString();
|
|
17
|
|
18 static abstract class StringHeader extends ResponseAction {
|
|
19 final String value;
|
|
20
|
|
21 StringHeader(String name,String value) {
|
|
22 super(name);
|
|
23 this.value = value;
|
|
24 }
|
|
25 }
|
|
26
|
|
27 static abstract class DateHeader extends ResponseAction {
|
|
28 final long value;
|
|
29
|
|
30 DateHeader(String name,long value) {
|
|
31 super(name);
|
|
32 this.value = value;
|
|
33 }
|
|
34 }
|
|
35
|
|
36 static abstract class IntHeader extends ResponseAction {
|
|
37 final int value;
|
|
38
|
|
39 IntHeader(String name,int value) {
|
|
40 super(name);
|
|
41 this.value = value;
|
|
42 }
|
|
43 }
|
|
44
|
|
45 static class SetHeader extends StringHeader {
|
|
46
|
|
47 SetHeader(String name,String value) {
|
|
48 super(name,value);
|
|
49 }
|
|
50
|
|
51 void apply(HttpServletResponse response) {
|
|
52 response.setHeader(name,value);
|
|
53 }
|
|
54
|
|
55 public String toString() {
|
|
56 return "ResponseAction setHeader(\""+name+"\",\""+value+"\")";
|
|
57 }
|
|
58 }
|
|
59
|
|
60 static class AddHeader extends StringHeader {
|
|
61
|
|
62 AddHeader(String name,String value) {
|
|
63 super(name,value);
|
|
64 }
|
|
65
|
|
66 void apply(HttpServletResponse response) {
|
|
67 response.addHeader(name,value);
|
|
68 }
|
|
69
|
|
70 public String toString() {
|
|
71 return "ResponseAction addHeader(\""+name+"\",\""+value+"\")";
|
|
72 }
|
|
73 }
|
|
74
|
|
75 static class SetDateHeader extends DateHeader {
|
|
76
|
|
77 SetDateHeader(String name,long value) {
|
|
78 super(name,value);
|
|
79 }
|
|
80
|
|
81 void apply(HttpServletResponse response) {
|
|
82 response.setDateHeader(name,value);
|
|
83 }
|
|
84
|
|
85 public String toString() {
|
|
86 return "ResponseAction setDateHeader(\""+name+"\","+value+")";
|
|
87 }
|
|
88 }
|
|
89
|
|
90 static class AddDateHeader extends DateHeader {
|
|
91
|
|
92 AddDateHeader(String name,long value) {
|
|
93 super(name,value);
|
|
94 }
|
|
95
|
|
96 void apply(HttpServletResponse response) {
|
|
97 response.addDateHeader(name,value);
|
|
98 }
|
|
99
|
|
100 public String toString() {
|
|
101 return "ResponseAction addDateHeader(\""+name+"\","+value+")";
|
|
102 }
|
|
103 }
|
|
104
|
|
105 static class SetIntHeader extends IntHeader {
|
|
106
|
|
107 SetIntHeader(String name,int value) {
|
|
108 super(name,value);
|
|
109 }
|
|
110
|
|
111 void apply(HttpServletResponse response) {
|
|
112 response.setIntHeader(name,value);
|
|
113 }
|
|
114
|
|
115 public String toString() {
|
|
116 return "ResponseAction setIntHeader(\""+name+"\","+value+")";
|
|
117 }
|
|
118 }
|
|
119
|
|
120 static class AddIntHeader extends IntHeader {
|
|
121
|
|
122 AddIntHeader(String name,int value) {
|
|
123 super(name,value);
|
|
124 }
|
|
125
|
|
126 void apply(HttpServletResponse response) {
|
|
127 response.addIntHeader(name,value);
|
|
128 }
|
|
129
|
|
130 public String toString() {
|
|
131 return "ResponseAction addIntHeader(\""+name+"\","+value+")";
|
|
132 }
|
|
133 }
|
|
134
|
|
135 }
|