view src/cachingfilter/ResponseAction.java @ 21:aba8ed4c8a06

semiprivate
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 13 Jun 2020 22:30:48 -0600
parents 7ecd1a4ef557
children
line wrap: on
line source

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+")";
		}
	}

}