Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8cf7e7d5a80a82c587c20bdb282a2b5c8e711a86 (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, 2016 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.help.IToc;
import org.eclipse.help.ITopic;
import org.eclipse.help.internal.webapp.data.TocData;

public class TitleSearchData extends TocData {

public TitleSearchData(ServletContext context, HttpServletRequest request,
			HttpServletResponse response) {
		super(context, request, response);
}

private List<SearchResult> results;
private String searchTerm;

public static class SearchResult {
	public String title;
	public String href;
}

public SearchResult[] getSearchResults() {
		results = new ArrayList<>();
		searchTerm = request.getParameter("searchWord");
		IToc[] tocs = getTocs();
		for (IToc toc : tocs) {
			ITopic[] topics = toc.getTopics();
			for (ITopic topic : topics) {
				searchTopic(topic);
			}
		}
		return results.toArray(new SearchResult[results.size()]);
}

private void searchTopic(ITopic topic) {
	if (topic.getLabel().toLowerCase().contains(searchTerm.toLowerCase())
		&& topic.getHref() != null) {
		SearchResult result = new SearchResult();
		result.title = topic.getLabel();
		result.href = "../../../topic" + topic.getHref();
		results.add(result);
	}
	ITopic[] topics = topic.getSubtopics();
	for (ITopic topic2 : topics) {
		searchTopic(topic2);
	}
}

}

Back to the top