diff src/cachingfilter/ResponseAction.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cachingfilter/ResponseAction.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,135 @@
+package cachingfilter;
+
+import java.io.Serializable;
+import javax.servlet.http.HttpServletResponse;
+
+
+abstract class ResponseAction implements Serializable {
+	final String name;
+
+	ResponseAction(String name) {
+		this.name = name;
+	}
+
+	abstract void apply(HttpServletResponse response);
+
+	public abstract String toString();
+
+	static abstract class StringHeader extends ResponseAction {
+		final String value;
+
+		StringHeader(String name,String value) {
+			super(name);
+			this.value = value;
+		}
+	}
+
+	static abstract class DateHeader extends ResponseAction {
+		final long value;
+
+		DateHeader(String name,long value) {
+			super(name);
+			this.value = value;
+		}
+	}
+
+	static abstract class IntHeader extends ResponseAction {
+		final int value;
+
+		IntHeader(String name,int value) {
+			super(name);
+			this.value = value;
+		}
+	}
+
+	static class SetHeader extends StringHeader {
+
+		SetHeader(String name,String value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.setHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction setHeader(\""+name+"\",\""+value+"\")";
+		}
+	}
+
+	static class AddHeader extends StringHeader {
+
+		AddHeader(String name,String value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.addHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction addHeader(\""+name+"\",\""+value+"\")";
+		}
+	}
+
+	static class SetDateHeader extends DateHeader {
+
+		SetDateHeader(String name,long value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.setDateHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction setDateHeader(\""+name+"\","+value+")";
+		}
+	}
+
+	static class AddDateHeader extends DateHeader {
+
+		AddDateHeader(String name,long value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.addDateHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction addDateHeader(\""+name+"\","+value+")";
+		}
+	}
+
+	static class SetIntHeader extends IntHeader {
+
+		SetIntHeader(String name,int value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.setIntHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction setIntHeader(\""+name+"\","+value+")";
+		}
+	}
+
+	static class AddIntHeader extends IntHeader {
+
+		AddIntHeader(String name,int value) {
+			super(name,value);
+		}
+
+		void apply(HttpServletResponse response) {
+			response.addIntHeader(name,value);
+		}
+
+		public String toString() {
+			return "ResponseAction addIntHeader(\""+name+"\","+value+")";
+		}
+	}
+
+}