Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9bddaf858c5104e39c53c843021bbde440ff3fac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*******************************************************************************
 * Copyright (c) 2008, 2014 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.help.webapp;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * Class used for tests which require an HttpServletRequest parameter
 */

public class MockServletResponse implements HttpServletResponse {
	
	private List<Cookie> cookies = new ArrayList<Cookie>();
	private String illegalCharactersFound = "";

	public String getCharacterEncoding() {
		return null;
	}

	public String getContentType() {
		return null;
	}

	public ServletOutputStream getOutputStream() throws IOException {
		return null;
	}

	public PrintWriter getWriter() throws IOException {
		return null;
	}

	public void setCharacterEncoding(String charset) {
		
	}

	public void setContentLength(int len) {
	}

	public void setContentType(String type) {
		
	}

	public void setBufferSize(int size) {
		
	}

	public int getBufferSize() {
		return 0;
	}

	public void flushBuffer() throws IOException {
		
	}

	public void resetBuffer() {
		
	}

	public boolean isCommitted() {
		return false;
	}

	public void reset() {
		
	}

	public void setLocale(Locale loc) {
		
	}

	public Locale getLocale() {
		return null;
	}

	public void addCookie(Cookie cookie) {
		checkForIllegalCharacters(cookie.getValue());
		// Replace if it already exists, otherwise set
		for (int i = 0; i < cookies.size(); i++) {
			Cookie nextCookie = cookies.get(i);
			if (nextCookie.getName().equals(cookie.getName())) {
				cookies.remove(i);
				cookies.add(cookie);
				return;
			}
		}
		cookies.add(cookie);
	}
	
	private void checkForIllegalCharacters(String value) {
		// Check for illegal characters 
		final String illegalChars = "()<>@,;:\\\"/[]?={} \t";
		for (int i = 0; i < illegalChars.length(); i++) {
			char ch = illegalChars.charAt(i);
			if (value.indexOf(ch) >= 0 && illegalCharactersFound.indexOf(ch) < 0) {
				illegalCharactersFound = illegalCharactersFound + ch;
			}
		}
	}

	public Cookie[] getCookies() {
		return cookies.toArray(new Cookie[cookies.size()]);
	}

	public boolean containsHeader(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	public String encodeURL(String url) {
		// TODO Auto-generated method stub
		return null;
	}

	public String encodeRedirectURL(String url) {
		// TODO Auto-generated method stub
		return null;
	}

	public String encodeUrl(String url) {
		// TODO Auto-generated method stub
		return null;
	}

	public String encodeRedirectUrl(String url) {
		// TODO Auto-generated method stub
		return null;
	}

	public void sendError(int sc, String msg) throws IOException {
		// TODO Auto-generated method stub
		
	}

	public void sendError(int sc) throws IOException {
		// TODO Auto-generated method stub
		
	}

	public void sendRedirect(String location) throws IOException {
		// TODO Auto-generated method stub
		
	}

	public void setDateHeader(String name, long date) {
		// TODO Auto-generated method stub
		
	}

	public void addDateHeader(String name, long date) {
		// TODO Auto-generated method stub
		
	}

	public void setHeader(String name, String value) {
		// TODO Auto-generated method stub
		
	}

	public void addHeader(String name, String value) {
		// TODO Auto-generated method stub
		
	}

	public void setIntHeader(String name, int value) {
		// TODO Auto-generated method stub
		
	}

	public void addIntHeader(String name, int value) {
		// TODO Auto-generated method stub
		
	}

	public void setStatus(int sc) {
		// TODO Auto-generated method stub
		
	}

	public void setStatus(int sc, String sm) {
		// TODO Auto-generated method stub
		
	}
	
	public String getIllegalCharatersFound() {
		return illegalCharactersFound;
	}

	public int getStatus() {
		// TODO Auto-generated method stub
		return 0;
	}

	public String getHeader(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	public Collection<String> getHeaders(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	public Collection<String> getHeaderNames() {
		// TODO Auto-generated method stub
		return null;
	}

	public void setContentLengthLong(long len) {
		// TODO Auto-generated method stub
		
	}
	
	
}

Back to the top