blob: 247603b8e2b78255ff34835b4493b63053cddaf4 (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2017 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.util;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Locale;
import org.eclipse.help.IHelpContentProducer;
import org.eclipse.help.internal.util.URLCoder;
public class UATestContentProducer implements IHelpContentProducer {
@Override
public InputStream getInputStream(String pluginId, String href,
Locale locale) {
if (href.startsWith("generated/")) {
return getGeneratedInputStream(href, locale);
}
return null;
}
// Format is generated/title/body content/suffix
private InputStream getGeneratedInputStream(String href, Locale locale) {
int slash1 = 9;
int slash2 = href.indexOf('/', slash1 + 1);
int dotHtml = href.indexOf(".html");
String title = href.substring(slash1 + 1, slash2);
String body = href.substring(slash2 + 1, dotHtml);
String result = "<head><title>";
result += filterNonAlpha(URLCoder.decode(title));
result += "</title></head><body>";
result +=filterNonAlpha(URLCoder.decode(body));
result += "</body>";
return new ByteArrayInputStream(result.getBytes());
}
private String filterNonAlpha(String input) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == ' ' || Character.isLetter(c)) {
output.append(c);
}
}
return output.toString();
}
}
|