Skip to main content
summaryrefslogtreecommitdiffstats
blob: b49b4e2b1e88fa0aebd9a4e5304aba2c2bbe9f77 (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
/*******************************************************************************
 * Copyright (c) 2009, 2015 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.remote;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.TransformerException;

import org.eclipse.help.internal.index.Index;
import org.eclipse.help.internal.index.IndexContribution;
import org.eclipse.help.internal.webapp.data.UrlUtil;
import org.eclipse.help.internal.webapp.servlet.IndexServlet;
import org.eclipse.ua.tests.help.other.UserIndex;
import org.eclipse.ua.tests.help.other.UserIndexEntry;
import org.eclipse.ua.tests.help.other.UserTopic;

public class MockIndexServlet extends IndexServlet {

	private static final long serialVersionUID = -930969620357059313L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String locale = UrlUtil.getLocale(req, resp);
		String response;
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$

		IndexContribution[] contributions = getIndex(req, locale);
		try {
			response = serialize(contributions, locale);
		} catch (TransformerException e) {
			throw new ServletException(e);
		}
		resp.getWriter().write(response);
	}

	private IndexContribution[] getIndex(HttpServletRequest req, String locale) {
		int port = req.getLocalPort();
		UserIndex index = new UserIndex(true);
		UserIndexEntry entry1 = new UserIndexEntry("entry1_" + locale, false); 	
		UserTopic topic1 = new UserTopic("topic1_", "href.html", false);
		index.addEntry(entry1);
		entry1.addTopic(topic1);
		UserIndexEntry entry2 = new UserIndexEntry("entry2_" + locale, false); 	
		UserTopic topic2 = new UserTopic("topic2_"  + port, "href" + port + ".html", false);
		index.addEntry(entry2);
		entry2.addTopic(topic2);
		IndexContribution contribution = new IndexContribution();
		contribution.setId("mock.index");
		contribution.setIndex(new Index(index));
		contribution.setLocale(locale);
		return new IndexContribution[] { contribution };
	}
	
}
	

Back to the top