Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 319907 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+2 lines)
Lines 14-20 Link Here
14
 org.eclipse.core.expressions;bundle-version="3.4.200"
14
 org.eclipse.core.expressions;bundle-version="3.4.200"
15
Export-Package: org.eclipse.help.internal.webapp;x-friends:="org.eclipse.ua.tests",
15
Export-Package: org.eclipse.help.internal.webapp;x-friends:="org.eclipse.ua.tests",
16
 org.eclipse.help.internal.webapp.data;x-friends:="org.eclipse.ua.tests",
16
 org.eclipse.help.internal.webapp.data;x-friends:="org.eclipse.ua.tests",
17
 org.eclipse.help.internal.webapp.service;x-friends:="org.eclipse.ua.tests",
17
 org.eclipse.help.internal.webapp.servlet;x-friends:="org.eclipse.ua.tests,org.eclipse.ua.tests.doc",
18
 org.eclipse.help.internal.webapp.servlet;x-friends:="org.eclipse.ua.tests,org.eclipse.ua.tests.doc",
19
 org.eclipse.help.internal.webapp.utils;x-friends:="org.eclipse.ua.tests",
18
 org.eclipse.help.webapp
20
 org.eclipse.help.webapp
19
Bundle-RequiredExecutionEnvironment: J2SE-1.4
21
Bundle-RequiredExecutionEnvironment: J2SE-1.4
20
Import-Package: com.ibm.icu.text;version="3.8.0",
22
Import-Package: com.ibm.icu.text;version="3.8.0",
(-)plugin.xml (-2 / +83 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
<!--
2
<?eclipse version="3.0"?>
<!--
3
    Copyright (c) 2005, 2010 IBM Corporation and others.
3
    Copyright (c) 2005, 2011 IBM Corporation and others.
4
    All rights reserved. This program and the accompanying materials
4
    All rights reserved. This program and the accompanying materials
5
    are made available under the terms of the Eclipse Public License v1.0
5
    are made available under the terms of the Eclipse Public License v1.0
6
    which accompanies this distribution, and is available at
6
    which accompanies this distribution, and is available at
7
    http://www.eclipse.org/legal/epl-v10.html
7
    http://www.eclipse.org/legal/epl-v10.html
8
   
8
    
9
    Contributors:
9
    Contributors:
10
         IBM Corporation - initial API and implementation
10
         IBM Corporation - initial API and implementation
11
 -->
11
 -->
Lines 15-20 Link Here
15
   <extension-point id="view" name="View" schema="schema/view.exsd"/>
15
   <extension-point id="view" name="View" schema="schema/view.exsd"/>
16
   <extension-point id="frame" name="Webapp Frame" schema="schema/frame.exsd"/> 
16
   <extension-point id="frame" name="Webapp Frame" schema="schema/frame.exsd"/> 
17
   <extension-point id="toolbarButton" name="Toolbar Button" schema="schema/toolbarButton.exsd"/>
17
   <extension-point id="toolbarButton" name="Toolbar Button" schema="schema/toolbarButton.exsd"/>
18
   <extension-point id="validatedServlet" name="Validated Servlet" schema="schema/validatedServlet.exsd"/>
18
  <extension
19
  <extension
19
         point="org.eclipse.equinox.http.registry.httpcontexts">
20
         point="org.eclipse.equinox.http.registry.httpcontexts">
20
      <httpcontext
21
      <httpcontext
Lines 125-130 Link Here
125
      <serviceSelector
126
      <serviceSelector
126
            filter="(other.info=org.eclipse.help)">
127
            filter="(other.info=org.eclipse.help)">
127
      </serviceSelector>
128
      </serviceSelector>
129
      <servlet
130
            alias="/vs"
131
            class="org.eclipse.help.internal.webapp.servlet.ValidatorServlet"
132
            httpcontextId="help">
133
      </servlet>
128
   </extension>
134
   </extension>
129
   <extension
135
   <extension
130
         id="org.eclipse.help.webapp.remoteStatusProducer"
136
         id="org.eclipse.help.webapp.remoteStatusProducer"
Lines 134-137 Link Here
134
            producer="org.eclipse.help.internal.webapp.StatusProducer">
140
            producer="org.eclipse.help.internal.webapp.StatusProducer">
135
      </contentProducer>
141
      </contentProducer>
136
   </extension>
142
   </extension>
143
   <extension
144
         point="org.eclipse.help.webapp.validatedServlet">
145
      <servlet
146
            alias="/service/control"
147
            class="org.eclipse.help.internal.webapp.service.ControlService">
148
      </servlet>
149
      <servlet
150
            alias="/service/content"
151
            class="org.eclipse.help.internal.webapp.service.ContentService">
152
      </servlet>
153
      <servlet
154
            alias="/service/topic"
155
            class="org.eclipse.help.internal.webapp.service.ContentService">
156
      </servlet>
157
      <servlet
158
            alias="/service/nftopic"
159
            class="org.eclipse.help.internal.webapp.service.ContentService">
160
      </servlet>
161
      <servlet
162
            alias="/service/ntopic"
163
            class="org.eclipse.help.internal.webapp.service.ContentService">
164
      </servlet>
165
      <servlet
166
            alias="/service/rtopic"
167
            class="org.eclipse.help.internal.webapp.service.ContentService">
168
      </servlet>
169
      <servlet
170
            alias="/service/nav"
171
            class="org.eclipse.help.internal.webapp.service.NavService">
172
      </servlet>
173
      <servlet
174
            alias="/service/livehelp"
175
            class="org.eclipse.help.internal.webapp.service.LiveHelpService">
176
      </servlet>
177
      <servlet
178
            alias="/service/toc"
179
            class="org.eclipse.help.internal.webapp.service.TocService">
180
      </servlet>
181
      <servlet
182
            alias="/service/tocfragment"
183
            class="org.eclipse.help.internal.webapp.service.TocFragmentService">
184
      </servlet>
185
      <servlet
186
            alias="/service/index"
187
            class="org.eclipse.help.internal.webapp.service.IndexService">
188
      </servlet>
189
      <servlet
190
            alias="/service/indexfragment"
191
            class="org.eclipse.help.internal.webapp.service.IndexFragmentService">
192
      </servlet>
193
      <servlet
194
            alias="/service/advancedsearch"
195
            class="org.eclipse.help.internal.webapp.service.AdvancedSearchService">
196
      </servlet>
197
      <servlet
198
            alias="/service/search"
199
            class="org.eclipse.help.internal.webapp.service.SearchService">
200
      </servlet>
201
      <servlet
202
            alias="/service/context"
203
            class="org.eclipse.help.internal.webapp.service.ContextService">
204
      </servlet>
205
      <servlet
206
            alias="/service/extension"
207
            class="org.eclipse.help.internal.webapp.service.ExtensionService">
208
      </servlet>
209
      <servlet
210
            alias="/service/about.html"
211
            class="org.eclipse.help.internal.webapp.service.AboutService">
212
      </servlet>
213
      <servlet
214
            alias="/service/state"
215
            class="org.eclipse.help.internal.webapp.service.SearchStateService">
216
      </servlet>
217
   </extension>
137
</plugin>
218
</plugin>
(-)schema/validatedServlet.exsd (+129 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.help.webapp" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.help.webapp" id="validatedServlet" name="Validated Servlet"/>
7
      </appInfo>
8
      <documentation>
9
         This extension points implements a webapp security validator around a servlet.  All calls to the servlet are checked for known malicious threats before returning to the client.  Important: All context paths to servlet validator resources must start with /vs.  For example: http://host:port/help/vs/service/toc
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="0" maxOccurs="unbounded">
21
            <element ref="servlet"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="servlet">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="java" basedOn="javax.servlet.http.HttpServlet:"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="alias" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         3.7
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         Here is an example where a servlet &apos;ControlService&apos; will be called and validated with the URL:
87
(path)/vs/service/control
88
89
&lt;extension
90
      point=&quot;org.eclipse.help.webapp.validatedServlet&quot;&gt;
91
   &lt;servlet
92
         alias=&quot;/service/control&quot;
93
         class=&quot;org.eclipse.help.internal.webapp.service.ControlService&quot;&gt;
94
   &lt;/servlet&gt;
95
&lt;/extension&gt;
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="apiinfo"/>
102
      </appInfo>
103
      <documentation>
104
         The supplied servlet class must extend the class &lt;samp&gt;javax.servlet.http.HttpServlet&lt;/samp&gt;.  The servlet class should function no differently then general servlets.
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="implementation"/>
111
      </appInfo>
112
      <documentation>
113
         A supplied implementation of this point can be found in &lt;samp&gt;org.eclipse.help.webapp&lt;/samp&gt; for any of the services in org.eclipse.help.internal.webapp.services.
114
      </documentation>
115
   </annotation>
116
117
   <annotation>
118
      <appInfo>
119
         <meta.section type="copyright"/>
120
      </appInfo>
121
      <documentation>
122
         Copyright (c) 2011 IBM Corporation and others.&lt;br&gt;
123
All rights reserved. This program and the accompanying materials are made 
124
available under the terms of the Eclipse Public License v1.0 which accompanies 
125
this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
126
      </documentation>
127
   </annotation>
128
129
</schema>
(-)src/org/eclipse/help/internal/webapp/WebappResources.properties (+7 lines)
Lines 212-214 Link Here
212
criterionClosed=Criterion closed
212
criterionClosed=Criterion closed
213
criterionOpen=Criterion open
213
criterionOpen=Criterion open
214
Criteria=Criteria
214
Criteria=Criteria
215
216
# Validator Servlet
217
cantCreateServlet=Unable to create servlet: {0}
218
219
# Service API
220
StatusServlet_PARAM_MISSING=The "{0}" parameter is missing from the request.
221
(-)src/org/eclipse/help/internal/webapp/data/SearchData.java (-4 / +13 lines)
Lines 99-106 Link Here
99
		} 
99
		} 
100
		
100
		
101
		// try loading search results or get the indexing progress info.
101
		// try loading search results or get the indexing progress info.
102
		if (isSearchRequest() && !isScopeRequest()) {
102
		readSearchResults();
103
	}
103
104
105
	public void readSearchResults() {
106
		
107
		// try loading search results or get the indexing progress info.
108
		if (isSearchRequest() && !isScopeRequest()) {
109
			
110
			altList.clear();
111
			
104
			AbstractSearchProcessor processors[] = SearchManager.getSearchProcessors();
112
			AbstractSearchProcessor processors[] = SearchManager.getSearchProcessors();
105
			for (int p=0;p<processors.length;p++)
113
			for (int p=0;p<processors.length;p++)
106
			{
114
			{
Lines 151-163 Link Here
151
				}
159
				}
152
				if (reset)
160
				if (reset)
153
					hits = SearchManager.convertResultsToHits(results);
161
					hits = SearchManager.convertResultsToHits(results);
154
				
155
				
156
			}
162
			}
157
		}
163
		}
158
	}
164
	}
159
165
160
161
	/**
166
	/**
162
	 * Returns true when there is a search request
167
	 * Returns true when there is a search request
163
	 * 
168
	 * 
Lines 225-230 Link Here
225
	public int getResultsCount() {
230
	public int getResultsCount() {
226
		return hits.length;
231
		return hits.length;
227
	}
232
	}
233
	
234
	public SearchHit[] getResults() {
235
		return hits;
236
	}
228
237
229
	public String getSelectedTopicId() {
238
	public String getSelectedTopicId() {
230
		return selectedTopicId;
239
		return selectedTopicId;
(-)src/org/eclipse/help/internal/webapp/parser/ContextParser.java (+85 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.eclipse.help.internal.webapp.utils.XMLHelper;
17
import org.xml.sax.Attributes;
18
19
public class ContextParser extends ResultParser {
20
21
	private ParseElement element = null;
22
	private String currentTag;
23
24
	public ContextParser() {
25
		super(JSonHelper.TITLE);
26
	}
27
	
28
	public void startElement(String uri, String lname, String name, Attributes attrs) {
29
		
30
		currentTag = name;
31
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_DESCRIPTION))
32
			return;
33
		
34
		Properties properties = new Properties();
35
		properties.put(JSonHelper.PROPERTY_NAME, name);
36
		for (int i = 0; i < attrs.getLength(); i++) {
37
			String qname = attrs.getQName(i);
38
			String val = attrs.getValue(i);
39
			properties.put(qname, val);
40
		}
41
		
42
		ParseElement elem = new ParseElement(properties, element);
43
		if (element != null)
44
			element.addChild(elem);
45
		else
46
			items.add(elem);
47
		
48
		element = elem;
49
		
50
	}
51
	
52
	public void characters(char[] ch, int start, int length) {
53
		
54
		if (element != null 
55
				&& currentTag.equalsIgnoreCase(
56
						XMLHelper.ELEMENT_DESCRIPTION)) {
57
			
58
			Properties properties = element.getProps();
59
			if (properties != null) {
60
				
61
				String content = new String(ch, start, length);
62
				
63
				String existing = (String) properties.get(currentTag);
64
				if (existing == null)
65
					existing = ""; //$NON-NLS-1$
66
				
67
				content = content.replaceAll("[\\n\\t]", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
68
				
69
				properties.put(currentTag, existing + content);
70
				element.updateParseElement(properties);
71
			}
72
		}
73
	}
74
	
75
	public void endElement(String uri, String lname, String name) {
76
		
77
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_DESCRIPTION))
78
			return;
79
		
80
		if (element != null) {
81
			element = element.getParent();
82
		}		
83
	}
84
85
}
(-)src/org/eclipse/help/internal/webapp/parser/ExtensionParser.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.xml.sax.Attributes;
17
18
public class ExtensionParser extends ResultParser {
19
20
	private ParseElement element = null;
21
	private String currentTag;
22
23
	public ExtensionParser() {
24
		super(JSonHelper.TITLE);
25
	}
26
	
27
	public void startElement(String uri, String lname, String name, Attributes attrs) {
28
		
29
		currentTag = name;
30
		
31
		Properties properties = new Properties();
32
		properties.put(JSonHelper.PROPERTY_NAME, name);
33
		for (int i = 0; i < attrs.getLength(); i++) {
34
			String qname = attrs.getQName(i);
35
			String val = attrs.getValue(i);
36
			properties.put(qname, val);
37
		}
38
		
39
		ParseElement elem = new ParseElement(properties, element);
40
		if (element != null)
41
			element.addChild(elem);
42
		else
43
			items.add(elem);
44
		
45
		element = elem;
46
		
47
	}
48
	
49
	public void characters(char[] ch, int start, int length) {
50
		
51
		if (element != null) {
52
			
53
			Properties properties = element.getProps();
54
			if (properties != null) {
55
				
56
				String content = new String(ch, start, length);
57
				
58
				String existing = (String) properties.get(currentTag);
59
				if (existing == null)
60
					existing = ""; //$NON-NLS-1$
61
				
62
				content = content.replaceAll("[\\n\\t]", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
63
				
64
				properties.put(currentTag, existing + content);
65
				element.updateParseElement(properties);
66
			}
67
		}
68
	}
69
	
70
	public void endElement(String uri, String lname, String name) {
71
		
72
		if (element != null) {
73
			element = element.getParent();
74
		}		
75
	}
76
77
}
(-)src/org/eclipse/help/internal/webapp/parser/IndexFragmentParser.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.eclipse.help.internal.webapp.utils.XMLHelper;
17
import org.xml.sax.Attributes;
18
19
public class IndexFragmentParser extends ResultParser{
20
21
	private ParseElement element = null;
22
	
23
	public IndexFragmentParser() {
24
		super(JSonHelper.TITLE);
25
	}
26
	
27
	public void startElement(String uri, String lname, String name, Attributes attrs) {
28
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_NODE))
29
		{
30
			Properties properties = new Properties();
31
			properties.put(JSonHelper.PROPERTY_NAME, JSonHelper.INDEX);
32
			for (int i = 0; i < attrs.getLength(); i++) {
33
				String qname = attrs.getQName(i);
34
				String val = attrs.getValue(i);
35
				properties.put(qname, val);
36
			}
37
			
38
			ParseElement elem = new ParseElement(properties, element);
39
			if (element != null)
40
				element.addChild(elem);
41
			else
42
				items.add(elem);
43
			
44
			element = elem;
45
		}
46
		
47
	}
48
	
49
	public void endElement(String uri, String lname, String name) {
50
		if (element != null 
51
				&& name.equalsIgnoreCase(XMLHelper.ELEMENT_NODE)) {
52
			element = element.getParent();
53
		}		
54
	}
55
}
(-)src/org/eclipse/help/internal/webapp/parser/IndexParser.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.eclipse.help.internal.webapp.utils.XMLHelper;
17
import org.xml.sax.Attributes;
18
19
public class IndexParser extends ResultParser {
20
21
	private ParseElement element = null;
22
23
	public IndexParser() {
24
		super(JSonHelper.TITLE);
25
	}
26
	
27
	public void startElement(String uri, String lname, String name, Attributes attrs) {
28
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_INDEX_CONTRIBUTIONS) 
29
				|| name.equalsIgnoreCase(XMLHelper.ELEMENT_INDEX))
30
			return;
31
		
32
		Properties properties = new Properties();
33
		properties.put(JSonHelper.PROPERTY_NAME, name);
34
		for (int i = 0; i < attrs.getLength(); i++) {
35
			String qname = attrs.getQName(i);
36
			String val = attrs.getValue(i);
37
			properties.put(qname, val);
38
		}
39
		
40
		ParseElement elem = new ParseElement(properties, element);
41
		if (element != null)
42
			element.addChild(elem);
43
		else
44
			items.add(elem);
45
		
46
		element = elem;
47
		
48
	}
49
	
50
	public void endElement(String uri, String lname, String name) {
51
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_INDEX_CONTRIBUTIONS) 
52
				|| name.equalsIgnoreCase(XMLHelper.ELEMENT_INDEX))
53
			return;
54
		
55
		if (element != null) {
56
			element = element.getParent();
57
		}		
58
	}
59
60
}
(-)src/org/eclipse/help/internal/webapp/parser/ParseElement.java (+123 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.ArrayList;
14
import java.util.Enumeration;
15
import java.util.Properties;
16
17
import org.eclipse.help.internal.webapp.utils.JSonHelper;
18
19
public class ParseElement {
20
21
	private Properties props;
22
	private ArrayList children = new ArrayList();
23
	private ParseElement parent;
24
25
	public ParseElement(Properties props, ParseElement parent) {
26
		this.props = props;
27
		this.parent = parent;
28
	}
29
30
	public ParseElement(Properties props) {
31
		this(props, null);
32
	}
33
	
34
	public void updateParseElement(Properties props) {
35
		this.props = props;
36
	}
37
	
38
	public Properties getProps() {
39
		return props;
40
	}
41
	
42
	public ParseElement getParent() {
43
		return parent;
44
	}
45
	
46
	public String getProperty(String key) {
47
		return (props != null) ? props.getProperty(key) : ""; //$NON-NLS-1$
48
	}
49
	
50
	public String toString() {
51
		return (props != null) ? props.toString() : ""; //$NON-NLS-1$
52
	}
53
	
54
	public void addChild(ParseElement elem) {
55
		children.add(elem);
56
	}
57
	
58
	public int getChildrenCount() {
59
		return children.size();
60
	}
61
	
62
	public String toJSON(int level) {
63
		
64
		StringBuffer buff = new StringBuffer();
65
		
66
		String space = JSonHelper.SPACE;
67
		for (int s = 0; s < level; s++) {
68
			space += JSonHelper.SPACE;
69
		}
70
		
71
		buff.append(JSonHelper.NEWLINE + space);
72
		buff.append(JSonHelper.BEGIN_BRACE);
73
		
74
		if (props != null) {
75
			Enumeration enumObj = props.keys();
76
			while (enumObj.hasMoreElements()) {
77
				
78
				String key = (String) enumObj.nextElement();
79
				String val = props.getProperty(key);
80
				
81
				buff.append(JSonHelper.NEWLINE + space + JSonHelper.SPACE);
82
				buff.append(key);
83
				buff.append(JSonHelper.COLON);
84
				buff.append(JSonHelper.getQuotes(val));
85
				buff.append(JSonHelper.COMMA);
86
			}
87
		}
88
		
89
		if (children.size() <= 0) {
90
			int len = buff.length();
91
			char ch = buff.charAt(len - 1);
92
			if (ch == ',') {
93
				buff.deleteCharAt(len - 1);
94
				buff.append(JSonHelper.NEWLINE + space);
95
			}
96
			
97
		} else {
98
			
99
			buff.append(JSonHelper.NEWLINE + space + JSonHelper.SPACE);
100
			buff.append(JSonHelper.CHILDREN);
101
			buff.append(JSonHelper.COLON);
102
			buff.append(JSonHelper.BEGIN_BRACKET);
103
			
104
			for (int i = 0; i < children.size(); i++) {
105
				
106
				if (i > 0)
107
					buff.append(JSonHelper.COMMA);
108
				
109
				ParseElement element = (ParseElement) children.get(i);
110
				buff.append(element.toJSON(level + 2));
111
			}
112
			
113
			buff.append(JSonHelper.NEWLINE + space + JSonHelper.SPACE);
114
			
115
			buff.append(JSonHelper.END_BRACKET);
116
			buff.append(JSonHelper.NEWLINE + space);
117
		}
118
		
119
		buff.append(JSonHelper.END_BRACE);
120
		
121
		return buff.toString();
122
	}
123
}
(-)src/org/eclipse/help/internal/webapp/parser/ResultParser.java (+99 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.util.ArrayList;
17
18
import javax.xml.parsers.ParserConfigurationException;
19
import javax.xml.parsers.SAXParser;
20
import javax.xml.parsers.SAXParserFactory;
21
22
import org.eclipse.help.internal.webapp.utils.JSonHelper;
23
import org.xml.sax.SAXException;
24
import org.xml.sax.helpers.DefaultHandler;
25
26
public class ResultParser extends DefaultHandler {
27
28
	private String label = ""; //$NON-NLS-1$
29
	protected ArrayList items = new ArrayList(); //parser populates the items arrayList withe parsed data.
30
31
	public ResultParser(String label) {
32
		this.label = label;
33
	}
34
	
35
	public void parse(URL tocURL) 
36
		throws ParserConfigurationException, SAXException, IOException
37
	{
38
		parse(tocURL.openStream());
39
	}
40
	
41
	public void parse(InputStream in) 
42
		throws ParserConfigurationException, SAXException, IOException
43
	{
44
		SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
45
		parser.parse(in, this);
46
	}
47
	
48
	public ArrayList getItems()
49
	{
50
		return items;
51
	}
52
	
53
	public String toString()
54
	{
55
		return items.toString();
56
	}
57
	
58
	public String toJSON() {
59
		
60
		StringBuffer buf = new StringBuffer();
61
		
62
		buf.append(JSonHelper.BEGIN_BRACE);
63
		buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
64
		
65
		buf.append(JSonHelper.IDENTIFIER);
66
		buf.append(JSonHelper.COLON);
67
		buf.append(JSonHelper.getQuotes(JSonHelper.ID));
68
		buf.append(JSonHelper.COMMA);
69
70
		buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
71
		buf.append(JSonHelper.LABEL);
72
		buf.append(JSonHelper.COLON);
73
		buf.append(JSonHelper.getQuotes(label));
74
		buf.append(JSonHelper.COMMA);
75
76
		buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
77
		buf.append(JSonHelper.ITEMS);
78
		buf.append(JSonHelper.COLON);
79
		buf.append(JSonHelper.BEGIN_BRACKET);
80
		
81
		for (int i = 0; i < items.size(); i++) {
82
			
83
			if (i > 0)
84
				buf.append(JSonHelper.COMMA);
85
			
86
			ParseElement element = (ParseElement) items.get(i);
87
			buf.append(element.toJSON(1));
88
		}
89
		
90
		if (items.size() > 0)
91
			buf.append(JSonHelper.NEWLINE + JSonHelper.SPACE);
92
		
93
		buf.append(JSonHelper.END_BRACKET);
94
		buf.append(JSonHelper.NEWLINE);
95
		buf.append(JSonHelper.END_BRACE);
96
		
97
		return buf.toString();
98
	}
99
}
(-)src/org/eclipse/help/internal/webapp/parser/SearchParser.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.eclipse.help.internal.webapp.utils.XMLHelper;
17
import org.xml.sax.Attributes;
18
19
public class SearchParser extends ResultParser {
20
21
//	private ParseElement element;
22
	private Properties properties;
23
	private String currentTag;
24
	
25
	public SearchParser() {
26
		super(JSonHelper.LABEL);
27
	}
28
29
	public void startElement(String uri, 
30
			String lname, String name, Attributes attrs) {
31
		
32
		currentTag = name;
33
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_HIT)) {
34
			
35
			properties = new Properties();
36
			properties.put(JSonHelper.PROPERTY_NAME, name);
37
			for (int i = 0; i < attrs.getLength(); i++) {
38
				String qname = attrs.getQName(i);
39
				String val = attrs.getValue(i);
40
				properties.put(qname, val);
41
			}
42
			
43
			String id = "" + items.size(); //$NON-NLS-1$
44
			properties.put(JSonHelper.ID, id);
45
			
46
		} else if (name.equalsIgnoreCase(XMLHelper.ELEMENT_CATEGORY)) {
47
			for (int i = 0; i < attrs.getLength(); i++) {
48
				String qname = attrs.getQName(i);
49
				String val = attrs.getValue(i);
50
				if (qname.equalsIgnoreCase(XMLHelper.ATTR_HREF))
51
					qname = XMLHelper.CATEGORY_HREF;
52
				properties.put(qname, val);
53
			}
54
		}
55
	}
56
	
57
	public void characters(char[] ch, int start, int length) {
58
		
59
		if (currentTag.equalsIgnoreCase(XMLHelper.ELEMENT_HIT) 
60
				|| currentTag.equalsIgnoreCase(XMLHelper.ELEMENT_HITS))
61
			return;
62
		
63
		if (properties != null)
64
		{
65
			String content = new String(ch, start, length);
66
			
67
			String existing = (String) properties.get(currentTag);
68
			if (existing == null)
69
				existing = ""; //$NON-NLS-1$
70
			
71
			content = content.replaceAll("[\\n\\t]", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
72
			
73
			properties.put(currentTag, existing + content);
74
		}
75
	}
76
77
	public void endElement(String uri, String lname, String name) {
78
79
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_HIT)) {
80
			ParseElement element = new ParseElement(properties);
81
			items.add(element);
82
		}
83
	}
84
}
(-)src/org/eclipse/help/internal/webapp/parser/TocFragmentParser.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.util.Properties;
17
18
import javax.xml.parsers.ParserConfigurationException;
19
20
import org.eclipse.help.internal.webapp.utils.JSonHelper;
21
import org.eclipse.help.internal.webapp.utils.XMLHelper;
22
import org.xml.sax.Attributes;
23
import org.xml.sax.SAXException;
24
25
public class TocFragmentParser extends ResultParser {
26
27
	private Properties properties;
28
	private String parentId = ""; //$NON-NLS-1$
29
	private int tagLevel = -1;
30
	private int level = 0;
31
	
32
	public TocFragmentParser() {
33
		super(JSonHelper.TITLE);
34
	}
35
36
	public void parse(URL tocURL, int level) 
37
		throws ParserConfigurationException, SAXException, IOException
38
	{
39
		parse(tocURL.openStream(), level);
40
	}
41
	
42
	public void parse(InputStream in, int level) 
43
		throws ParserConfigurationException, SAXException, IOException
44
	{
45
		this.level = level;
46
		super.parse(in);
47
	}
48
49
	public void startElement(String uri, 
50
			String lname, String name, Attributes attrs) {
51
		
52
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_NODE))
53
		{
54
			tagLevel++;
55
			
56
			if (tagLevel == level) {
57
				properties = new Properties();
58
				properties.put(JSonHelper.PROPERTY_NAME, JSonHelper.TOPIC);
59
				for (int i = 0; i < attrs.getLength(); i++) {
60
					String qname = attrs.getQName(i);
61
					String val = attrs.getValue(i);
62
					if (qname.equals(XMLHelper.ATTR_ID)) {
63
						if (parentId.length() > 0)
64
							val = parentId + '$' + val;
65
					}
66
					properties.put(qname, val);
67
				}
68
			} else if (parentId.length() <= 0) {
69
				for (int i = 0; i < attrs.getLength(); i++) {
70
					if (attrs.getQName(i).equals(XMLHelper.ATTR_ID))
71
						parentId = attrs.getValue(i);
72
				}
73
			}
74
		}
75
	}
76
77
	public void endElement(String uri, String lname, String name) {
78
79
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_NODE))
80
		{
81
			if (tagLevel == level && properties != null ) {
82
				
83
				properties.setProperty("type", "toc"); //$NON-NLS-1$ //$NON-NLS-2$
84
				
85
				ParseElement element = new ParseElement(properties);
86
				items.add(element);
87
				
88
				properties = null;
89
			}
90
			
91
			tagLevel--;
92
		}
93
	}
94
}
(-)src/org/eclipse/help/internal/webapp/parser/TocParser.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.parser;
12
13
import java.util.Properties;
14
15
import org.eclipse.help.internal.webapp.utils.JSonHelper;
16
import org.eclipse.help.internal.webapp.utils.XMLHelper;
17
import org.xml.sax.Attributes;
18
19
public class TocParser extends ResultParser {
20
21
	private ParseElement element = null;
22
23
	public TocParser() {
24
		super(JSonHelper.LABEL);
25
	}
26
	
27
	public void startElement(String uri, String lname, String name, Attributes attrs) {
28
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_TOC_CONTRIBUTIONS))
29
			return;
30
		
31
		Properties properties = new Properties();
32
		properties.put(JSonHelper.PROPERTY_NAME, name);
33
		for (int i = 0; i < attrs.getLength(); i++) {
34
			String qname = attrs.getQName(i);
35
			String val = attrs.getValue(i);
36
			properties.put(qname, val);
37
		}
38
		
39
		ParseElement elem = new ParseElement(properties, element);
40
		if (element != null)
41
			element.addChild(elem);
42
		else
43
			items.add(elem);
44
		
45
		element = elem;
46
		
47
	}
48
	
49
	public void endElement(String uri, String lname, String name) {
50
		if (name.equalsIgnoreCase(XMLHelper.ELEMENT_TOC_CONTRIBUTIONS))
51
			return;
52
		
53
		if (element != null) {
54
			element = element.getParent();
55
		}		
56
	}
57
58
}
(-)src/org/eclipse/help/internal/webapp/service/AboutService.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import org.eclipse.help.internal.webapp.servlet.AboutServlet;
14
15
public class AboutService extends AboutServlet {
16
17
	private static final long serialVersionUID = 1L;
18
19
}
(-)src/org/eclipse/help/internal/webapp/service/AdvancedSearchService.java (+110 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletContext;
18
import javax.servlet.ServletException;
19
import javax.servlet.http.HttpServlet;
20
import javax.servlet.http.HttpServletRequest;
21
import javax.servlet.http.HttpServletResponse;
22
23
import org.eclipse.help.internal.search.SearchHit;
24
import org.eclipse.help.internal.search.SearchProgressMonitor;
25
import org.eclipse.help.internal.webapp.data.SearchData;
26
import org.eclipse.help.internal.webapp.data.UrlUtil;
27
import org.eclipse.help.internal.webapp.parser.SearchParser;
28
import org.eclipse.help.internal.webapp.utils.Utils;
29
import org.eclipse.help.internal.webapp.utils.SearchXMLGenerator;
30
31
/*
32
 * Returns the search hits for the query provided in the phrase parameter.
33
 * 
34
 * This is called on infocenters by client workbenches configured for remote
35
 * help in order to retrieve search hits from the remote help server.
36
 */
37
public class AdvancedSearchService extends HttpServlet {
38
	
39
	private static final long serialVersionUID = 1L;
40
	public static final String XID = "xid"; //$NON-NLS-1$
41
	
42
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
43
			throws ServletException, IOException {
44
		
45
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
46
		// Set standard HTTP/1.1 no-cache headers.
47
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
48
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
49
		
50
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
51
		
52
		ServletContext context = req.getSession().getServletContext();
53
		SearchData searchData = new SearchData(context, req, resp);
54
		
55
		String noCat = req.getParameter(Utils.NO_CATEGORY);
56
		boolean boolIsCategory = (noCat == null 
57
				|| !noCat.equalsIgnoreCase("true")); //$NON-NLS-1$
58
		
59
		String locale = UrlUtil.getLocale(req, resp);
60
		SearchProgressMonitor pm = SearchProgressMonitor
61
				.getProgressMonitor(locale);
62
		while (!pm.isDone()) {
63
			try {
64
				Thread.sleep(500); // Sleep for 0.5 sec
65
			} catch(InterruptedException ex) {}
66
		}
67
		
68
		// Load search results
69
		searchData.readSearchResults();
70
		SearchHit[] hits = searchData.getResults();
71
		
72
		String response = SearchXMLGenerator.serialize(hits, boolIsCategory);
73
		
74
		String returnType = req.getParameter(Utils.RETURN_TYPE);
75
		boolean boolIsJSON = (returnType != null 
76
				&& returnType.equalsIgnoreCase(Utils.JSON));
77
		
78
		// If JSON output is required
79
		if (boolIsJSON) {
80
			resp.setContentType("text/plain"); //$NON-NLS-1$
81
			response = getJSONResponse(response);
82
		}
83
		
84
		resp.getWriter().write(response);
85
	}
86
	
87
	protected String getJSONResponse(String response)
88
			throws IOException {
89
		SearchParser searchParser = new SearchParser();
90
		
91
		InputStream is = null;
92
		try {
93
			if (response != null) {
94
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
95
				searchParser.parse(is);
96
			}
97
			
98
		} catch (Exception e) {
99
			e.printStackTrace();
100
		}
101
		
102
		if (is != null)
103
			is.close();
104
        
105
        // Call after the catch.
106
		// An empty JSON is created if any Exception is thrown
107
		// Else returns the complete JSON
108
		return searchParser.toJSON();
109
	}
110
}
(-)src/org/eclipse/help/internal/webapp/service/ContentService.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.io.OutputStream;
16
import java.io.OutputStreamWriter;
17
import java.io.PrintWriter;
18
import java.net.URL;
19
import java.net.URLConnection;
20
21
import javax.servlet.ServletContext;
22
import javax.servlet.ServletException;
23
import javax.servlet.http.HttpServlet;
24
import javax.servlet.http.HttpServletRequest;
25
import javax.servlet.http.HttpServletResponse;
26
27
import org.eclipse.help.internal.webapp.utils.Utils;
28
29
public class ContentService extends HttpServlet {
30
31
	private static final long serialVersionUID = 1L;
32
	
33
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
34
			throws ServletException, IOException {
35
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
36
		
37
		String baseURL = req.getRequestURL().toString();
38
		String contentURL = baseURL.replaceFirst(Utils.SERVICE_CONTEXT, ""); //$NON-NLS-1$
39
		String query = req.getQueryString();
40
		if (query != null)
41
			contentURL += '?' + query;
42
		
43
		URL url = new URL(contentURL);
44
		URLConnection con = url.openConnection();
45
		con.setAllowUserInteraction(false);
46
		con.setDoInput(true);
47
		con.connect();
48
		
49
		String contentType;
50
		ServletContext context = getServletContext();
51
		String pathInfo = req.getPathInfo();
52
		String mimeType = context.getMimeType(pathInfo);
53
		if (mimeType != null && !mimeType.equals("application/xhtml+xml")) { //$NON-NLS-1$
54
			contentType = mimeType;
55
		} else {
56
			contentType = con.getContentType();
57
		}
58
		resp.setContentType(contentType);
59
		
60
		InputStream is = con.getInputStream();
61
		OutputStream out = resp.getOutputStream();
62
		if (!contentType.equals("application/xhtml+xml")  //$NON-NLS-1$
63
				&& !contentType.equals("text/html")  //$NON-NLS-1$
64
				&& !con.getContentType().equals("text/html")) { //$NON-NLS-1$
65
			Utils.transferContent(is, out);
66
			out.flush();
67
		} else {
68
			String response = Utils.convertStreamToString(url.openStream());
69
			response = Utils.updateResponse(response);
70
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); //$NON-NLS-1$
71
			writer.write(response);
72
			writer.close();
73
		}
74
	}
75
76
}
(-)src/org/eclipse/help/internal/webapp/service/ContextService.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.ContextParser;
22
import org.eclipse.help.internal.webapp.servlet.ContextServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
public class ContextService extends ContextServlet {
26
27
	private static final long serialVersionUID = 1L;
28
29
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
30
			throws ServletException, IOException {
31
		
32
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
33
		// Set standard HTTP/1.1 no-cache headers.
34
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
35
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
36
		
37
		String response = processRequest(req, resp);
38
		if ("400".equals(response)) { //$NON-NLS-1$
39
			resp.sendError(400); // bad request; missing parameter
40
			return;
41
		} else if ("404".equals(response)) { //$NON-NLS-1$
42
			resp.sendError(404); // Wrong context id; not found
43
			return;
44
		}
45
		
46
		String returnType = req.getParameter(Utils.RETURN_TYPE);
47
		boolean boolIsJSON = (returnType != null 
48
				&& returnType.equalsIgnoreCase(Utils.JSON));
49
		
50
		// If JSON output is required
51
		if (boolIsJSON) {
52
			resp.setContentType("text/plain"); //$NON-NLS-1$
53
			response = getJSONResponse(response);
54
		}
55
		
56
		resp.getWriter().write(response);
57
	}
58
59
	protected String getJSONResponse(String response)
60
			throws IOException {
61
		ContextParser searchParser = new ContextParser();
62
		InputStream is = null;
63
		try {
64
			if (response != null) {
65
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
66
				searchParser.parse(is);
67
			}
68
69
		} catch (Exception e) {
70
			e.printStackTrace();
71
		}
72
		
73
		if (is != null)
74
			is.close();
75
76
		// Call after the catch.
77
		// An empty JSON is created if any Exception is thrown
78
		// Else returns the complete JSON
79
		return searchParser.toJSON();
80
	}
81
82
}
(-)src/org/eclipse/help/internal/webapp/service/ControlService.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import org.eclipse.help.internal.webapp.servlet.ControlServlet;
14
15
public class ControlService extends ControlServlet {
16
17
	private static final long serialVersionUID = 1L;
18
19
}
(-)src/org/eclipse/help/internal/webapp/service/ExtensionService.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.ExtensionParser;
22
import org.eclipse.help.internal.webapp.servlet.ExtensionServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
public class ExtensionService extends ExtensionServlet {
26
27
	private static final long serialVersionUID = 1L;
28
29
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
30
			throws ServletException, IOException {
31
		
32
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
33
		// Set standard HTTP/1.1 no-cache headers.
34
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
35
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
36
		
37
		String response = processRequest(req, resp);
38
		String returnType = req.getParameter(Utils.RETURN_TYPE);
39
		boolean boolIsJSON = (returnType != null 
40
				&& returnType.equalsIgnoreCase(Utils.JSON));
41
		
42
		// If JSON output is required
43
		if (boolIsJSON) {
44
			resp.setContentType("text/plain"); //$NON-NLS-1$
45
			response = getJSONResponse(response);
46
		}
47
		
48
		resp.getWriter().write(response);
49
	}
50
51
	protected String getJSONResponse(String response)
52
			throws IOException {
53
		ExtensionParser searchParser = new ExtensionParser();
54
		InputStream is = null;
55
		try {
56
			if (response != null) {
57
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
58
				searchParser.parse(is);
59
			}
60
61
		} catch (Exception e) {
62
			e.printStackTrace();
63
		}
64
		
65
		if (is != null)
66
			is.close();
67
68
		// Call after the catch.
69
		// An empty JSON is created if any Exception is thrown
70
		// Else returns the complete JSON
71
		return searchParser.toJSON();
72
	}
73
74
}
(-)src/org/eclipse/help/internal/webapp/service/IndexFragmentService.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.IndexFragmentParser;
22
import org.eclipse.help.internal.webapp.servlet.IndexFragmentServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
/*
26
 * Sends all available keyword index data in XML form. The data is sent as one
27
 * large index contribution that includes all merged contributions from the
28
 * system.
29
 * 
30
 * This is called on infocenters by client workbenches configured for remote
31
 * help in order to gather all the index keywords and assemble them into a
32
 * complete index.
33
 */
34
public class IndexFragmentService extends IndexFragmentServlet {
35
36
	private static final long serialVersionUID = 1L;
37
38
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
39
			throws ServletException, IOException {
40
		
41
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
42
		// Set standard HTTP/1.1 no-cache headers.
43
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
44
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
45
		
46
		String response = processRequest(req, resp);
47
		
48
		String returnType = req.getParameter(Utils.RETURN_TYPE);
49
		boolean boolIsJSON = (returnType != null 
50
				&& returnType.equalsIgnoreCase(Utils.JSON));
51
		
52
		// If JSON output is required
53
		if (boolIsJSON) {
54
			resp.setContentType("text/plain"); //$NON-NLS-1$
55
			response = getJSONResponse(response);
56
		}
57
		
58
		resp.getWriter().write(response);
59
	}
60
61
	protected String getJSONResponse(String response)
62
			throws IOException {
63
		IndexFragmentParser indexParser = new IndexFragmentParser();
64
		InputStream is = null;
65
		try {
66
			if (response != null) {
67
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
68
				indexParser.parse(is);
69
			}
70
71
		} catch (Exception e) {
72
			e.printStackTrace();
73
		}
74
		
75
		if (is != null)
76
			is.close();
77
78
		// Call after the catch.
79
		// An empty JSON is created if any Exception is thrown
80
		// Else returns the complete JSON
81
		return indexParser.toJSON();
82
	}
83
84
}
(-)src/org/eclipse/help/internal/webapp/service/IndexService.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.IndexParser;
22
import org.eclipse.help.internal.webapp.servlet.IndexServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
public class IndexService extends IndexServlet {
26
27
	private static final long serialVersionUID = 1L;
28
29
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
30
			throws ServletException, IOException {
31
		
32
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
33
		// Set standard HTTP/1.1 no-cache headers.
34
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
35
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
36
		
37
		String response = processRequest(req, resp);
38
		
39
		String returnType = req.getParameter(Utils.RETURN_TYPE);
40
		boolean boolIsJSON = (returnType != null 
41
				&& returnType.equalsIgnoreCase(Utils.JSON));
42
		
43
		// If JSON output is required
44
		if (boolIsJSON) {
45
			resp.setContentType("text/plain"); //$NON-NLS-1$
46
			response = getJSONResponse(response);
47
		}
48
		
49
		resp.getWriter().write(response);
50
	}
51
52
	protected String getJSONResponse(String response)
53
			throws IOException {
54
		IndexParser indexParser = new IndexParser();
55
		InputStream is = null;
56
		try {
57
			if (response != null) {
58
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
59
				indexParser.parse(is);
60
			}
61
62
		} catch (Exception e) {
63
			e.printStackTrace();
64
		}
65
		
66
		if (is != null)
67
			is.close();
68
69
		// Call after the catch.
70
		// An empty JSON is created if any Exception is thrown
71
		// Else returns the complete JSON
72
		return indexParser.toJSON();
73
	}
74
75
}
(-)src/org/eclipse/help/internal/webapp/service/LiveHelpService.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import org.eclipse.help.internal.webapp.servlet.LiveHelpServlet;
14
15
public class LiveHelpService extends LiveHelpServlet {
16
17
	private static final long serialVersionUID = 1L;
18
19
}
(-)src/org/eclipse/help/internal/webapp/service/NavService.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.IOException;
14
import java.io.OutputStream;
15
import java.io.OutputStreamWriter;
16
import java.io.PrintWriter;
17
import java.net.URL;
18
19
import javax.servlet.ServletException;
20
import javax.servlet.http.HttpServlet;
21
import javax.servlet.http.HttpServletRequest;
22
import javax.servlet.http.HttpServletResponse;
23
24
import org.eclipse.help.internal.webapp.utils.Utils;
25
26
public class NavService extends HttpServlet {
27
28
	private static final long serialVersionUID = 1L;
29
30
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
31
			throws ServletException, IOException {
32
		
33
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
34
		resp.setContentType("text/html; charset=UTF-8"); //$NON-NLS-1$
35
		
36
		String baseURL = req.getRequestURL().toString();
37
		String navURL = baseURL.replaceFirst(Utils.SERVICE_CONTEXT, ""); //$NON-NLS-1$
38
		String query = req.getQueryString();
39
		if (query != null)
40
			navURL += '?' + query;
41
		URL url = new URL(navURL);
42
		String response = Utils.convertStreamToString(url.openStream());
43
		response = Utils.updateResponse(response);
44
		
45
		OutputStream out = resp.getOutputStream();
46
		PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); //$NON-NLS-1$
47
		writer.write(response);
48
		writer.close();
49
	}
50
51
}
(-)src/org/eclipse/help/internal/webapp/service/SearchService.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.SearchParser;
22
import org.eclipse.help.internal.webapp.servlet.SearchServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
public class SearchService extends SearchServlet {
26
27
	private static final long serialVersionUID = 1L;
28
29
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
30
			throws ServletException, IOException {
31
		
32
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
33
		// Set standard HTTP/1.1 no-cache headers.
34
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
35
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
36
		
37
		String response = processRequest(req, resp);
38
		if ("".equals(response)) { //$NON-NLS-1$
39
			resp.sendError(400); // bad request; missing parameter
40
			return;
41
		}
42
		
43
		String returnType = req.getParameter(Utils.RETURN_TYPE);
44
		boolean boolIsJSON = (returnType != null 
45
				&& returnType.equalsIgnoreCase(Utils.JSON));
46
		
47
		// If JSON output is required
48
		if (boolIsJSON) {
49
			resp.setContentType("text/plain"); //$NON-NLS-1$
50
			response = getJSONResponse(response);
51
		}
52
		
53
		resp.getWriter().write(response);
54
	}
55
56
	protected String getJSONResponse(String response)
57
			throws IOException {
58
		SearchParser searchParser = new SearchParser();
59
		InputStream is = null;
60
		try {
61
			if (response != null) {
62
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
63
				searchParser.parse(is);
64
			}
65
66
		} catch (Exception e) {
67
			e.printStackTrace();
68
		}
69
		
70
		if (is != null)
71
			is.close();
72
73
		// Call after the catch.
74
		// An empty JSON is created if any Exception is thrown
75
		// Else returns the complete JSON
76
		return searchParser.toJSON();
77
	}
78
79
}
(-)src/org/eclipse/help/internal/webapp/service/SearchStateService.java (+111 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.IOException;
14
15
import javax.servlet.ServletException;
16
import javax.servlet.http.HttpServlet;
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19
20
import org.eclipse.help.internal.search.SearchProgressMonitor;
21
import org.eclipse.help.internal.webapp.data.UrlUtil;
22
import org.eclipse.help.internal.webapp.utils.Utils;
23
24
/**
25
 * This is the main servlet for WAR Update Actions.  It delegates each action to the
26
 * appropriate <code>IDelegatorOperation</code>
27
 * 
28
 * @author snehpaul
29
 *
30
 */
31
public class SearchStateService extends HttpServlet {
32
	
33
	private static final long serialVersionUID = 1L;
34
	private final static String STATE = "state"; //$NON-NLS-1$
35
	private final static String PERCENT = "percent"; //$NON-NLS-1$
36
	
37
	public void init() throws ServletException {
38
	}
39
40
	/**
41
	 * Called by the server (via the <code>service</code> method) to allow a
42
	 * Servlet to handle a GET request.
43
	 */
44
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
45
			throws ServletException, IOException {
46
47
		process(req,resp);
48
	}
49
50
	/**
51
	 *
52
	 * Called by the server (via the <code>service</code> method) to allow a
53
	 * Servlet to handle a POST request.
54
	 *
55
	 * Handle the search requests,
56
	 *
57
	 */
58
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
59
			throws ServletException, IOException {
60
		process(req, resp);
61
	}
62
63
64
	/**
65
	 * Processes all requests to the servlet.
66
	 *
67
	 */
68
	private void process(HttpServletRequest req, HttpServletResponse resp)
69
			throws ServletException, IOException {
70
		
71
		resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
72
		resp.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
73
		
74
		int indexCompletion = 0;
75
		String locale = UrlUtil.getLocale(req, resp);
76
		SearchProgressMonitor pm = SearchProgressMonitor
77
				.getProgressMonitor(locale);
78
		if (pm.isDone()) {
79
			indexCompletion = 100;
80
		} else {
81
			indexCompletion = pm.getPercentage();
82
			if (indexCompletion >= 100) {
83
				// 38573 We do not have results, so index cannot be 100
84
				indexCompletion = 100 - 1;
85
			}
86
		}
87
		
88
		String returnType = req.getParameter(Utils.RETURN_TYPE);
89
		boolean isXML = Utils.XML.equalsIgnoreCase(returnType);
90
		if (isXML) {
91
			resp.setContentType("application/xml"); //$NON-NLS-1$
92
			resp.getWriter().write(toXML(indexCompletion));
93
		} else {
94
			resp.setContentType("text/plain"); //$NON-NLS-1$
95
			resp.getWriter().write(toString(indexCompletion));
96
		}
97
		resp.getWriter().flush();
98
	}
99
	
100
	public static String toXML(int percent) {
101
		String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; //$NON-NLS-1$
102
		xml += '<'+STATE+">\n"; //$NON-NLS-1$
103
		xml += "	<"+PERCENT+'>'+percent+"</"+PERCENT+">\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
104
		xml += "</"+STATE+">"; //$NON-NLS-1$ //$NON-NLS-2$
105
		return xml;
106
	}
107
	
108
	public static String toString(int percent) {
109
		return "Percent:" + percent; //$NON-NLS-1$
110
	}
111
}
(-)src/org/eclipse/help/internal/webapp/service/TocFragmentService.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.TocFragmentParser;
22
import org.eclipse.help.internal.webapp.servlet.TocFragmentServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
/*
26
 * Sends all toc contributions available on this host in XML form. The toc
27
 * is not send in assembled form, but instead fragments, because complete books
28
 * may be distributed between remote and local.
29
 * 
30
 */
31
public class TocFragmentService extends TocFragmentServlet {
32
	
33
	private static final long serialVersionUID = 1L;
34
35
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
36
			throws ServletException, IOException {
37
		
38
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
39
		// Set standard HTTP/1.1 no-cache headers.
40
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
41
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
42
		
43
		String response = processRequest(req, resp);
44
		
45
		String returnType = req.getParameter(Utils.RETURN_TYPE);
46
		boolean boolIsJSON = (returnType != null 
47
				&& returnType.equalsIgnoreCase(Utils.JSON));
48
		
49
		// If JSON output is required
50
		if (boolIsJSON) {
51
			resp.setContentType("text/plain"); //$NON-NLS-1$
52
			String toc = req.getParameter("toc"); //$NON-NLS-1$
53
			String path = req.getParameter("path"); //$NON-NLS-1$
54
			response = getJSONResponse(toc, path, response);
55
		}
56
		
57
		resp.getWriter().write(response);
58
	}
59
	
60
	protected String getJSONResponse(String toc, String path, String xmlResource)
61
			throws IOException {
62
		TocFragmentParser tocParser = new TocFragmentParser();
63
		InputStream is = null;
64
		try {
65
			if (xmlResource != null) {
66
	            is = new ByteArrayInputStream(xmlResource.getBytes("UTF-8")); //$NON-NLS-1$
67
	            
68
	            int level = 0;
69
				if (toc != null && toc.length() > 0) {
70
					level++;
71
					
72
					
73
					if (path != null && path.length() > 0) {
74
						String[] pathIdxs = path.split("_"); //$NON-NLS-1$
75
						level += pathIdxs.length;
76
					}
77
				}
78
				
79
				tocParser.parse(is, level);
80
			}
81
			
82
		} catch (Exception e) {
83
			e.printStackTrace();
84
		}
85
		
86
		if (is != null)
87
			is.close();
88
        
89
        // Call after the catch.
90
		// An empty JSON is created if any Exception is thrown
91
		// Else returns the complete JSON
92
		return tocParser.toJSON();
93
	}
94
}
(-)src/org/eclipse/help/internal/webapp/service/TocService.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.service;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import javax.servlet.ServletException;
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
21
import org.eclipse.help.internal.webapp.parser.TocParser;
22
import org.eclipse.help.internal.webapp.servlet.TocServlet;
23
import org.eclipse.help.internal.webapp.utils.Utils;
24
25
public class TocService extends TocServlet {
26
27
	private static final long serialVersionUID = 1L;
28
29
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
30
			throws ServletException, IOException {
31
		
32
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
33
		// Set standard HTTP/1.1 no-cache headers.
34
		resp.setHeader("Cache-Control",  //$NON-NLS-1$
35
				"no-store, no-cache, must-revalidate"); //$NON-NLS-1$
36
		
37
		String response = processRequest(req, resp);
38
		
39
		String returnType = req.getParameter(Utils.RETURN_TYPE);
40
		boolean boolIsJSON = (returnType != null 
41
				&& returnType.equalsIgnoreCase(Utils.JSON));
42
		
43
		// If JSON output is required
44
		if (boolIsJSON) {
45
			resp.setContentType("text/plain"); //$NON-NLS-1$
46
			response = getJSONResponse(response);
47
		}
48
		
49
		resp.getWriter().write(response);
50
	}
51
52
	protected String getJSONResponse(String response)
53
			throws IOException {
54
		TocParser tocParser = new TocParser();
55
		InputStream is = null;
56
		try {
57
			if (response != null) {
58
				is = new ByteArrayInputStream(response.getBytes("UTF-8")); //$NON-NLS-1$
59
				tocParser.parse(is);
60
			}
61
62
		} catch (Exception e) {
63
			e.printStackTrace();
64
		}
65
		
66
		if (is != null)
67
			is.close();
68
69
		// Call after the catch.
70
		// An empty JSON is created if any Exception is thrown
71
		// Else returns the complete JSON
72
		return tocParser.toJSON();
73
	}
74
75
}
(-)src/org/eclipse/help/internal/webapp/servlet/ContextServlet.java (-20 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-17 Link Here
11
package org.eclipse.help.internal.webapp.servlet;
11
package org.eclipse.help.internal.webapp.servlet;
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.io.Writer;
15
14
16
import javax.servlet.ServletException;
15
import javax.servlet.ServletException;
17
import javax.servlet.http.HttpServlet;
16
import javax.servlet.http.HttpServlet;
Lines 40-45 Link Here
40
	
39
	
41
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
40
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
42
			throws ServletException, IOException {
41
			throws ServletException, IOException {
42
		String response = processRequest(req, resp);
43
		if ("400".equals(response)) //$NON-NLS-1$
44
			resp.sendError(400); // bad request; missing parameter
45
		else if ("404".equals(response)) //$NON-NLS-1$
46
			resp.sendError(404); // Wrong context id; not found
47
		else
48
			resp.getWriter().write(response);
49
	}
50
	
51
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
52
			throws ServletException, IOException {
43
		BaseHelpSystem.checkMode();
53
		BaseHelpSystem.checkMode();
44
		String locale = UrlUtil.getLocale(req, resp);
54
		String locale = UrlUtil.getLocale(req, resp);
45
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
55
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
Lines 48-62 Link Here
48
		if (id != null) {
58
		if (id != null) {
49
			IContext context = getContext(locale, id);
59
			IContext context = getContext(locale, id);
50
			if (context != null) {
60
			if (context != null) {
51
				serialize(context, resp.getWriter());
61
				return serialize(context);
52
			}
62
			}
53
			else {
63
			// Wrong context id; not found
54
				resp.sendError(404);
64
			return "404"; //$NON-NLS-1$
55
			}
56
		}
57
		else {
58
			resp.sendError(400); // bad request; missing parameter
59
		}
65
		}
66
		// bad request; missing parameter
67
		return "400"; //$NON-NLS-1$
60
	}
68
	}
61
69
62
	protected IContext getContext(String locale, String id) {
70
	protected IContext getContext(String locale, String id) {
Lines 64-95 Link Here
64
		return context;
72
		return context;
65
	}
73
	}
66
	
74
	
67
	private void serialize(IContext context, Writer out) throws IOException {
75
	private String serialize(IContext context) throws IOException {
68
		out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
76
		StringBuffer buff = new StringBuffer();
69
		out.write('<' + Context.NAME );
77
		buff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
78
		buff.append('<' + Context.NAME );
70
		if (context instanceof IContext2) {
79
		if (context instanceof IContext2) {
71
			String title = ((IContext2)context).getTitle();
80
			String title = ((IContext2)context).getTitle();
72
			if (title != null && title.length() > 0) {
81
			if (title != null && title.length() > 0) {
73
				out.write(" title=\"" + title + "\""); //$NON-NLS-1$ //$NON-NLS-2$			
82
				buff.append(" title=\"" + title + "\""); //$NON-NLS-1$ //$NON-NLS-2$			
74
			}
83
			}
75
		}
84
		}
76
		out.write(">\n"); //$NON-NLS-1$
85
		buff.append(">\n"); //$NON-NLS-1$
77
		String description = context.getText();
86
		String description = context.getText();
78
		if (description != null) {
87
		if (description != null) {
79
			out.write("   <description>" + UrlUtil.htmlEncode(description) + "</description>\n"); //$NON-NLS-1$ //$NON-NLS-2$
88
			buff.append("   <description>" + UrlUtil.htmlEncode(description) + "</description>\n"); //$NON-NLS-1$ //$NON-NLS-2$
80
		}
89
		}
81
		
90
		
82
		IHelpResource[] topics = context.getRelatedTopics();
91
		IHelpResource[] topics = context.getRelatedTopics();
83
		for (int i=0;i<topics.length;++i) {
92
		for (int i=0;i<topics.length;++i) {
84
			out.write("   <" + Topic.NAME); //$NON-NLS-1$
93
			buff.append("   <" + Topic.NAME); //$NON-NLS-1$
85
			if (topics[i].getLabel() != null) {
94
			if (topics[i].getLabel() != null) {
86
				out.write("\n         " + Topic.ATTRIBUTE_LABEL + "=\"" + topics[i].getLabel() + '"'); //$NON-NLS-1$ //$NON-NLS-2$
95
				buff.append("\n         " + Topic.ATTRIBUTE_LABEL + "=\"" + topics[i].getLabel() + '"'); //$NON-NLS-1$ //$NON-NLS-2$
87
			}
96
			}
88
			if (topics[i].getHref() != null) {
97
			if (topics[i].getHref() != null) {
89
				out.write("\n         " + Topic.ATTRIBUTE_HREF + "=\"" + topics[i].getHref() + '"'); //$NON-NLS-1$ //$NON-NLS-2$
98
				buff.append("\n         " + Topic.ATTRIBUTE_HREF + "=\"" + topics[i].getHref() + '"'); //$NON-NLS-1$ //$NON-NLS-2$
90
			}
99
			}
91
			out.write(">\n   </topic>"); //$NON-NLS-1$
100
			buff.append(">   </" + Topic.NAME + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
92
		}
101
		}
93
		out.write("</" + Context.NAME + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
102
		buff.append("</" + Context.NAME + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
103
		return buff.toString();
94
	}
104
	}
95
}
105
}
(-)src/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java (-2 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-44 Link Here
39
39
40
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
40
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
41
			throws ServletException, IOException {
41
			throws ServletException, IOException {
42
			resp.getWriter().write(processRequest(req, resp));
43
	}
44
	
45
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
46
			throws ServletException, IOException {
42
		String locale = UrlUtil.getLocale(req, resp);
47
		String locale = UrlUtil.getLocale(req, resp);
43
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
48
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
44
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
49
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
Lines 57-63 Link Here
57
			}
62
			}
58
			responseByLocale.put(locale, response);
63
			responseByLocale.put(locale, response);
59
		}
64
		}
60
		resp.getWriter().write(response);
65
		return response;
61
	}
66
	}
62
	
67
	
63
	private String serialize(ContentExtension[] extensions) throws TransformerException {
68
	private String serialize(ContentExtension[] extensions) throws TransformerException {
(-)src/org/eclipse/help/internal/webapp/servlet/IndexFragmentServlet.java (-2 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
2
 * Copyright (c) 2007, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 68-73 Link Here
68
68
69
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
69
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
70
			throws ServletException, IOException {
70
			throws ServletException, IOException {
71
		resp.getWriter().write(processRequest(req, resp));
72
	}
73
	
74
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
75
			throws ServletException, IOException {
71
		String locale = UrlUtil.getLocale(req, resp);
76
		String locale = UrlUtil.getLocale(req, resp);
72
		startParameter = req.getParameter("start"); //$NON-NLS-1$
77
		startParameter = req.getParameter("start"); //$NON-NLS-1$
73
		if (startParameter != null) {
78
		if (startParameter != null) {
Lines 112-118 Link Here
112
		Serializer serializer = new Serializer(locale, scope);
117
		Serializer serializer = new Serializer(locale, scope);
113
		String response = serializer.generateIndexXml();	
118
		String response = serializer.generateIndexXml();	
114
		locale2Response.put(locale, response);
119
		locale2Response.put(locale, response);
115
		resp.getWriter().write(response);
120
		
121
		return response;
116
	}
122
	}
117
	
123
	
118
	/*
124
	/*
(-)src/org/eclipse/help/internal/webapp/servlet/IndexServlet.java (-2 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 44-49 Link Here
44
44
45
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
45
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
46
			throws ServletException, IOException {
46
			throws ServletException, IOException {
47
		resp.getWriter().write(processRequest(req, resp));
48
	}
49
	
50
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
51
			throws ServletException, IOException {
47
		BaseHelpSystem.checkMode();
52
		BaseHelpSystem.checkMode();
48
		String locale = UrlUtil.getLocale(req, resp);
53
		String locale = UrlUtil.getLocale(req, resp);
49
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
54
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
Lines 63-69 Link Here
63
			}
68
			}
64
			responseByLocale.put(locale, response);
69
			responseByLocale.put(locale, response);
65
		}
70
		}
66
		resp.getWriter().write(response);
71
		
72
		return (response != null) ? response : ""; //$NON-NLS-1$
67
	}
73
	}
68
		
74
		
69
	public String serialize(IndexContribution[] contributions, String locale) throws TransformerException {
75
	public String serialize(IndexContribution[] contributions, String locale) throws TransformerException {
(-)src/org/eclipse/help/internal/webapp/servlet/SearchServlet.java (-47 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-20 Link Here
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.Collections;
16
import java.util.Collections;
17
import java.util.Iterator;
18
import java.util.List;
17
import java.util.List;
19
18
20
import javax.servlet.ServletException;
19
import javax.servlet.ServletException;
Lines 27-36 Link Here
27
import org.eclipse.help.internal.search.ISearchHitCollector;
26
import org.eclipse.help.internal.search.ISearchHitCollector;
28
import org.eclipse.help.internal.search.ISearchQuery;
27
import org.eclipse.help.internal.search.ISearchQuery;
29
import org.eclipse.help.internal.search.QueryTooComplexException;
28
import org.eclipse.help.internal.search.QueryTooComplexException;
30
import org.eclipse.help.internal.search.SearchHit;
31
import org.eclipse.help.internal.search.SearchQuery;
29
import org.eclipse.help.internal.search.SearchQuery;
32
import org.eclipse.help.internal.util.URLCoder;
30
import org.eclipse.help.internal.util.URLCoder;
33
import org.eclipse.help.internal.webapp.data.UrlUtil;
31
import org.eclipse.help.internal.webapp.data.UrlUtil;
32
import org.eclipse.help.internal.webapp.utils.SearchXMLGenerator;
34
33
35
/*
34
/*
36
 * Returns the search hits for the query provided in the phrase parameter.
35
 * Returns the search hits for the query provided in the phrase parameter.
Lines 61-125 Link Here
61
	
60
	
62
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
61
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
63
			throws ServletException, IOException {
62
			throws ServletException, IOException {
63
		String response = processRequest(req, resp);
64
		if ("".equals(response)) //$NON-NLS-1$
65
			resp.sendError(400); // bad request; missing parameter
66
		else
67
			resp.getWriter().write(response);
68
	}
69
	
70
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
71
			throws ServletException, IOException {
64
		BaseHelpSystem.checkMode();
72
		BaseHelpSystem.checkMode();
65
		HitCollector collector = new HitCollector();
73
		HitCollector collector = new HitCollector();
66
		String locale = UrlUtil.getLocale(req, resp);
74
		String locale = UrlUtil.getLocale(req, resp);
67
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
75
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
68
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
76
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
69
		String phrase = req.getParameter(PARAMETER_PHRASE); 
77
		String phrase = req.getParameter(PARAMETER_PHRASE);
70
		if (phrase != null) {
78
		if (phrase != null) {
71
		    phrase = URLCoder.decode(phrase);
79
		    phrase = URLCoder.decode(phrase);
72
			ISearchQuery query = new SearchQuery(phrase, false, Collections.EMPTY_LIST, locale);
80
			ISearchQuery query = new SearchQuery(phrase, false, Collections.EMPTY_LIST, locale);
73
			collector.results.clear();
81
			collector.results.clear();
74
			BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor());
82
			BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor());
75
			if (searchException == null) {
83
			if (searchException == null) {
76
				String response = serialize(collector.results);
84
				return serialize(collector.results);
77
				resp.getWriter().write(response);
78
				return;
79
			}
85
			}
80
		}
86
		}
81
87
		return ""; //$NON-NLS-1$
82
		resp.sendError(400); // bad request; missing parameter
83
84
	}
88
	}
85
	
89
	
86
	public static String serialize(Collection results) {
90
	public static String serialize(Collection results) {
87
		StringBuffer buf = new StringBuffer();
91
		return SearchXMLGenerator.serialize(results);
88
		buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
89
		buf.append("<searchHits>\n"); //$NON-NLS-1$
90
		Iterator iter = results.iterator();
91
		while (iter.hasNext()) {
92
			SearchHit hit = (SearchHit)iter.next();
93
			serialize(hit, buf, "   "); //$NON-NLS-1$
94
		}
95
		buf.append("</searchHits>\n"); //$NON-NLS-1$
96
		return buf.toString();
97
	}
98
	
99
	private static void serialize(SearchHit hit, StringBuffer buf, String indent) {
100
		buf.append(indent + "<hit"); //$NON-NLS-1$
101
		if (hit.getHref() != null) {
102
			buf.append('\n' + indent	+ "      href=\"" + XMLGenerator.xmlEscape(hit.getHref()) + '"'); //$NON-NLS-1$
103
		}
104
		if (hit.getLabel() != null) {
105
			buf.append('\n' + indent	+ "      label=\"" + XMLGenerator.xmlEscape(hit.getLabel()) + '"'); //$NON-NLS-1$
106
		}
107
		if (hit.isPotentialHit()) {
108
			buf.append('\n' + indent	+ "      isPotentialHit=\"true\""); //$NON-NLS-1$
109
		}
110
		buf.append('\n' + indent + "      score=\"" + hit.getScore() + '"'); //$NON-NLS-1$
111
		buf.append(">\n"); //$NON-NLS-1$
112
		
113
		String summary = hit.getSummary();
114
		if (summary != null) {
115
			serialize(summary, buf, indent + "   "); //$NON-NLS-1$
116
		}
117
		buf.append(indent + "</hit>\n"); //$NON-NLS-1$
118
	}
119
120
	private static void serialize(String summary, StringBuffer buf, String indent) {
121
		buf.append(indent + "<summary>"); //$NON-NLS-1$
122
		buf.append(XMLGenerator.xmlEscape(summary));
123
		buf.append("</summary>\n"); //$NON-NLS-1$
124
	}
92
	}
125
}
93
}
(-)src/org/eclipse/help/internal/webapp/servlet/ServletPrintWriter.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.servlet;
12
13
import java.io.ByteArrayOutputStream;
14
import java.io.PrintWriter;
15
16
public class ServletPrintWriter extends PrintWriter{
17
18
	private StringBuffer buffer;
19
	
20
	public ServletPrintWriter() {
21
		super(new ByteArrayOutputStream());
22
		buffer = new StringBuffer();
23
	}
24
	
25
    /**
26
     * Writes a single character.
27
     * @param c int specifying a character to be written.
28
     */
29
    public void write(int c) {
30
	    synchronized (lock) {
31
	    	buffer.append((char)(c));
32
	    }
33
    }
34
35
    /**
36
     * Writes A Portion of an array of characters.
37
     * @param buf Array of characters
38
     * @param off Offset from which to start writing characters
39
     * @param len Number of characters to write
40
     */
41
    public void write(char buf[], int off, int len) {
42
	    synchronized (lock) {
43
	    	buffer.append(buf, off, len);
44
	    }
45
    }
46
47
    /**
48
     * Writes an array of characters.  This method cannot be inherited from the
49
     * Writer class because it must suppress I/O exceptions.
50
     * @param buf Array of characters to be written
51
     */
52
    public void write(char buf[]) {
53
    	write(buf, 0, buf.length);
54
    }
55
56
    /**
57
     * Writes a portion of a string.
58
     * @param s A String
59
     * @param off Offset from which to start writing characters
60
     * @param len Number of characters to write
61
     */
62
    public void write(String s, int off, int len) {
63
	    synchronized (lock) {
64
	    	buffer.append(s.toCharArray(), off, off+len);
65
	    }
66
    }
67
68
    /**
69
     * Writes a string.  This method cannot be inherited from the Writer class
70
     * because it must suppress I/O exceptions.
71
     * @param s String to be written
72
     */
73
    public void write(String s) {
74
	write(s, 0, s.length());
75
    }
76
	
77
    public String toString()
78
    {
79
    	return buffer.toString();
80
    }
81
}
(-)src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java (-2 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 46-51 Link Here
46
46
47
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
47
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
48
			throws ServletException, IOException {
48
			throws ServletException, IOException {
49
		resp.getWriter().write(processRequest(req, resp));
50
	}
51
	
52
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
53
			throws ServletException, IOException {
49
		String locale = UrlUtil.getLocale(req, resp);
54
		String locale = UrlUtil.getLocale(req, resp);
50
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
55
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
51
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
56
		resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
Lines 60-66 Link Here
60
		Serializer serializer = new Serializer(data, req.getLocale(), scope);
65
		Serializer serializer = new Serializer(data, req.getLocale(), scope);
61
		String response = serializer.generateTreeXml();	
66
		String response = serializer.generateTreeXml();	
62
		locale2Response.put(locale, response);
67
		locale2Response.put(locale, response);
63
		resp.getWriter().write(response);
68
		
69
		return response;
64
	}
70
	}
65
71
66
	private void readParameters(HttpServletRequest req) {
72
	private void readParameters(HttpServletRequest req) {
(-)src/org/eclipse/help/internal/webapp/servlet/TocServlet.java (-2 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 44-49 Link Here
44
44
45
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
45
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
46
			throws ServletException, IOException {
46
			throws ServletException, IOException {
47
		resp.getWriter().write(processRequest(req, resp));
48
	}
49
	
50
	protected String processRequest(HttpServletRequest req, HttpServletResponse resp)
51
			throws ServletException, IOException {
47
		BaseHelpSystem.checkMode();
52
		BaseHelpSystem.checkMode();
48
		String locale = UrlUtil.getLocale(req, resp);
53
		String locale = UrlUtil.getLocale(req, resp);
49
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
54
		req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
Lines 63-69 Link Here
63
			}
68
			}
64
			responseByLocale.put(locale, response);
69
			responseByLocale.put(locale, response);
65
		}
70
		}
66
		resp.getWriter().write(response);
71
		
72
		return (response != null) ? response : ""; //$NON-NLS-1$
67
	}
73
	}
68
		
74
		
69
	protected String serialize(TocContribution[] contributions, String locale) throws TransformerException {
75
	protected String serialize(TocContribution[] contributions, String locale) throws TransformerException {
(-)src/org/eclipse/help/internal/webapp/servlet/ValidatorServlet.java (+274 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.servlet;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayOutputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.OutputStream;
18
import java.io.PrintWriter;
19
import java.io.UnsupportedEncodingException;
20
import java.util.ArrayList;
21
import java.util.Enumeration;
22
import java.util.Hashtable;
23
import java.util.List;
24
import java.util.Locale;
25
26
import javax.servlet.ServletConfig;
27
import javax.servlet.ServletException;
28
import javax.servlet.ServletOutputStream;
29
import javax.servlet.http.HttpServlet;
30
import javax.servlet.http.HttpServletRequest;
31
import javax.servlet.http.HttpServletResponse;
32
import javax.servlet.http.HttpServletResponseWrapper;
33
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IConfigurationElement;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
38
import org.eclipse.help.internal.webapp.WebappResources;
39
import org.eclipse.help.internal.webapp.data.UrlUtil;
40
import org.eclipse.help.internal.webapp.utils.Utils;
41
42
/*
43
 * Class is responsible for implementing security protection.  All servlets
44
 * who use the org.eclipse.help.webapp.validatedServlet extension point will
45
 * will be processed for security failures by this class.
46
 * 
47
 * Any URL that starts with <path>/vs<etc> will be redirected here for further
48
 * processing.  If the validatedServlet extension point has an alias that 
49
 * matches the URL passed here, it will finish the processing and return 
50
 * results here for validation.  If there are no malicious threats detected,
51
 * this class will return the output to the client.
52
 *
53
 */
54
public class ValidatorServlet extends HttpServlet {
55
56
	private static final long serialVersionUID = -3783758607845176051L;
57
	private Hashtable servletTable = new Hashtable();
58
	
59
	protected void process(HttpServletRequest req, HttpServletResponse resp)
60
			throws ServletException, IOException {
61
62
		String baseURL = req.getRequestURL().toString();		
63
		baseURL = baseURL.substring(0, baseURL.indexOf(req.getServletPath()));
64
		
65
		Locale locale = UrlUtil.getLocaleObj(req,resp);
66
67
		String service = req.getRequestURL().toString().substring(
68
				(baseURL).length()+("/vs".length())); //$NON-NLS-1$
69
		
70
		try {
71
			HttpServletResponseAdv response = new HttpServletResponseAdv(resp);
72
			
73
			HttpServlet servlet = getServlet(service);
74
			ServletConfig config = getServletConfig();
75
			servlet.init(config);
76
			servlet.service(req, response);
77
			
78
			if (isSecure(req, response))
79
				response.commitOutput();
80
			
81
		} catch(Exception ex) {
82
			
83
			String errorMsg = WebappResources.getString("cantCreateServlet", //$NON-NLS-1$
84
					locale, service);
85
			HelpWebappPlugin.logError(errorMsg, ex);
86
			
87
			PrintWriter writer = resp.getWriter();
88
			writer.println(errorMsg);
89
			ex.printStackTrace(writer);
90
			
91
			resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
92
		}
93
	}
94
	
95
	private HttpServlet getServlet(String name) 
96
			throws CoreException {
97
		
98
		HttpServlet servlet = (HttpServlet)servletTable.get(name);
99
		
100
		if (servlet == null) {
101
			
102
			IConfigurationElement[] configs = 
103
				Platform.getExtensionRegistry().getConfigurationElementsFor(HelpWebappPlugin.PLUGIN_ID+".validatedServlet"); //$NON-NLS-1$
104
			
105
			for (int c=0; c < configs.length; c++) {
106
				
107
				String alias = configs[c].getAttribute("alias"); //$NON-NLS-1$
108
				if (alias != null) {
109
					
110
					if (isMatch(alias, name)) {
111
						servlet = (HttpServlet)configs[c].createExecutableExtension("class"); //$NON-NLS-1$
112
						servletTable.put(name, servlet);
113
						break;
114
					}
115
				}
116
			}
117
		}
118
		
119
		return servlet;
120
	}
121
	
122
	private boolean isMatch(String alias, String name) {
123
		
124
		int index = name.indexOf(alias);
125
		if (index == 0) {
126
			int offset = alias.length();
127
			if (name.length() == offset)
128
				return true;
129
			char ch = name.charAt(offset);
130
			if (ch == '/' || ch == '?')
131
				return true;
132
		}
133
		return false;
134
	}
135
136
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
137
			throws ServletException, IOException {
138
		process(req, resp);
139
	}
140
	
141
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
142
			throws ServletException, IOException {
143
		process(req, resp);
144
	}
145
	
146
	public boolean isSecure(HttpServletRequest req,HttpServletResponseAdv resp) 
147
			throws SecurityException {
148
		
149
		Enumeration names = req.getParameterNames();
150
		List values = new ArrayList();
151
		List scripts = new ArrayList();
152
		
153
		while (names.hasMoreElements()) {
154
			
155
			String name = (String)names.nextElement();
156
			String val = req.getParameter(name);
157
			values.add(val);
158
			if (replaceAll(val, '+', "").indexOf("<script")>-1) //$NON-NLS-1$ //$NON-NLS-2$
159
				scripts.add(val);
160
		}
161
		
162
		if (resp.getWriter() != null) {
163
			
164
			String data = resp.getString();
165
			for (int s=0; s < scripts.size(); s++)
166
				if (data.indexOf((String)scripts.get(s)) > -1)
167
					throw new SecurityException("Potential cross-site scripting detected."); //$NON-NLS-1$
168
		}
169
		
170
		return true;
171
	}
172
173
	public void isScript(List params,OutputStream out) {
174
		
175
//		ByteArrayOutputStream bOut = new ByteArrayOutputStream(out);
176
	}
177
178
	
179
	public String replaceAll(String str, char remove, String add) {
180
		
181
		StringBuffer buffer = new StringBuffer();
182
		for (int s=0; s < str.length(); s++) {
183
			
184
			char ch = str.charAt(s);
185
			if (ch == remove)
186
				buffer.append(add);
187
			else
188
				buffer.append(ch);
189
		}
190
		return buffer.toString();
191
	}
192
	
193
	private class HttpServletResponseAdv extends HttpServletResponseWrapper {
194
		
195
		private HttpServletResponse response;
196
		private ByteArrayOutputStream out;
197
		private ServletPrintWriter writer;
198
		private SecureServletOutputStream stream;
199
		
200
		public HttpServletResponseAdv(HttpServletResponse response) {
201
			super(response);
202
			out = new ByteArrayOutputStream();
203
			this.response = response;
204
		}
205
206
		public PrintWriter getWriter() {
207
			
208
			if (writer == null && stream == null)
209
				writer = new ServletPrintWriter();
210
			return writer;
211
		}
212
		
213
		public ServletOutputStream getOutputStream() {
214
			
215
			if (stream == null && writer == null)
216
				stream = new SecureServletOutputStream(out);
217
			return stream;
218
		}
219
		
220
		public void commitOutput() throws IOException {
221
			
222
			OutputStream os = response.getOutputStream();
223
			InputStream is = getInputStream();
224
			
225
			Utils.transferContent(is, os);
226
			
227
			os.flush();
228
		}
229
		
230
		public InputStream getInputStream() {
231
			
232
			if (stream != null) {
233
			
234
				try {
235
					out.flush();
236
				} catch (IOException e) {
237
					e.printStackTrace();
238
				}
239
				return new ByteArrayInputStream(out.toByteArray());
240
			}
241
			if (writer != null) {
242
				
243
				try {
244
					return new ByteArrayInputStream(writer.toString().getBytes(getCharacterEncoding()));
245
				} catch (UnsupportedEncodingException e) {
246
					e.printStackTrace();
247
				}
248
			}
249
			return null;
250
		}
251
		
252
		public String getString() {
253
			
254
			if (writer != null)
255
				return writer.toString();
256
			
257
			return null;
258
		}
259
	}
260
	
261
	
262
	private class SecureServletOutputStream extends ServletOutputStream {
263
264
		private OutputStream out;
265
266
		public SecureServletOutputStream(OutputStream out) {
267
			this.out = out;
268
		}
269
		
270
		public void write(int b) throws IOException {
271
			out.write(b);
272
		}
273
	}
274
}
(-)src/org/eclipse/help/internal/webapp/utils/JSonHelper.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.utils;
12
13
public final class JSonHelper {
14
	
15
	//JSON Characters
16
	public static final String BEGIN_BRACE = "{"; //$NON-NLS-1$
17
	public static final String END_BRACE  = "}"; //$NON-NLS-1$
18
	public static final String QUOTE  = "\'"; //$NON-NLS-1$
19
	public static final String COLON  = ":"; //$NON-NLS-1$
20
	public static final String BEGIN_BRACKET  = "["; //$NON-NLS-1$
21
	public static final String END_BRACKET  =   "]"; //$NON-NLS-1$
22
	public static final String COMMA  =   ","; //$NON-NLS-1$
23
	public static final String NEWLINE  =   "\n"; //$NON-NLS-1$
24
	public static final String SPACE  =   "   "; //$NON-NLS-1$
25
	
26
	//JSON items
27
	public static final String LABEL			= "label"; //$NON-NLS-1$
28
	public static final String IDENTIFIER		= "identifier"; //$NON-NLS-1$
29
	public static final String URL				= "url"; //$NON-NLS-1$
30
	public static final String PROVIDER			= "provider"; //$NON-NLS-1$
31
	public static final String ITEMS			= "items"; //$NON-NLS-1$
32
	public static final String NAME				= "name"; //$NON-NLS-1$
33
	public static final String TITLE			= "title"; //$NON-NLS-1$
34
	public static final String ID				= "id"; //$NON-NLS-1$
35
	public static final String HREF				= "href"; //$NON-NLS-1$
36
	public static final String TYPE				= "type"; //$NON-NLS-1$
37
	public static final String CHECKED			= "checked"; //$NON-NLS-1$
38
	public static final String CHILDREN			= "children"; //$NON-NLS-1$
39
	public static final String REFERENCE		= "_reference"; //$NON-NLS-1$
40
	public static final String IS_LEAF			= "is_leaf"; //$NON-NLS-1$
41
	public static final String IS_SELECTED		= "is_selected"; //$NON-NLS-1$
42
	public static final String IS_HIGHLIGHTED	= "is_highlighted"; //$NON-NLS-1$
43
	public static final String TOC				= "toc"; //$NON-NLS-1$
44
	public static final String PATH				= "path"; //$NON-NLS-1$
45
	public static final String CATEGORY			= "category"; //$NON-NLS-1$
46
	public static final String DESCRIPTION		= "description"; //$NON-NLS-1$
47
	public static final String CATEGORY_HREF	= CATEGORY+"_"+HREF; //$NON-NLS-1$
48
	public static final String PROPERTY_NAME	= "propertyName"; //$NON-NLS-1$
49
	public static final String INDEX			= "Index"; //$NON-NLS-1$
50
	public static final String TOPIC			= "Topic"; //$NON-NLS-1$
51
	
52
	public static String getQuotes(String str){
53
		return ((str != null)?QUOTE + str + QUOTE:""); //$NON-NLS-1$
54
	}
55
56
}
(-)src/org/eclipse/help/internal/webapp/utils/SearchXMLGenerator.java (+117 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.utils;
12
13
import java.util.Collection;
14
15
import org.eclipse.help.HelpSystem;
16
import org.eclipse.help.IHelpResource;
17
import org.eclipse.help.IToc;
18
import org.eclipse.help.ITopic;
19
import org.eclipse.help.internal.search.SearchHit;
20
import org.eclipse.help.internal.webapp.data.UrlUtil;
21
import org.eclipse.help.internal.webapp.servlet.XMLGenerator;
22
23
public class SearchXMLGenerator  {
24
25
	public static String serialize(Collection results) {
26
		return serialize((results != null) ? results.toArray() : null, false);
27
	}
28
	
29
	public static String serialize(Object[] hits, boolean boolIsCategory) {
30
		StringBuffer buf = new StringBuffer();
31
		buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
32
		buf.append("<searchHits>\n"); //$NON-NLS-1$
33
		
34
		if (hits != null) {
35
			for (int i = 0; i < hits.length; i++) {
36
				SearchHit hit = (SearchHit) hits[i];
37
				serialize(hit, buf, "   ", boolIsCategory); //$NON-NLS-1$
38
			}
39
		}
40
		
41
		buf.append("</searchHits>\n"); //$NON-NLS-1$
42
		
43
		return buf.toString();
44
	}
45
	
46
	private static void serialize(SearchHit hit, StringBuffer buf, 
47
			String indent, boolean boolIsCategory) {
48
		buf.append(indent + "<hit"); //$NON-NLS-1$
49
		if (hit.getHref() != null) {
50
			buf.append('\n' + indent	+ "      href=\"" + XMLGenerator.xmlEscape(hit.getHref()) + '"'); //$NON-NLS-1$
51
		}
52
		if (hit.getLabel() != null) {
53
			buf.append('\n' + indent	+ "      label=\"" + XMLGenerator.xmlEscape(hit.getLabel()) + '"'); //$NON-NLS-1$
54
		}
55
		if (hit.isPotentialHit()) {
56
			buf.append('\n' + indent	+ "      isPotentialHit=\"true\""); //$NON-NLS-1$
57
		}
58
		buf.append('\n' + indent + "      score=\"" + hit.getScore() + '"'); //$NON-NLS-1$
59
		buf.append(">\n"); //$NON-NLS-1$
60
		
61
		// get Category
62
		if (boolIsCategory) {
63
			IHelpResource categoryResource = hit.getCategory();
64
			if (categoryResource != null) {
65
				serializeCategory(categoryResource, buf, indent + "  "); //$NON-NLS-1$
66
			}
67
		}
68
		
69
		// get Summary/Description
70
		String summary = hit.getSummary();
71
		if (summary != null) {
72
			serialize(summary, buf, indent + "   "); //$NON-NLS-1$
73
		}
74
		buf.append(indent + "</hit>\n"); //$NON-NLS-1$
75
	}
76
77
	private static void serialize(String summary, StringBuffer buf, String indent) {
78
		buf.append(indent + "<summary>"); //$NON-NLS-1$
79
		buf.append(XMLGenerator.xmlEscape(summary));
80
		buf.append("</summary>\n"); //$NON-NLS-1$
81
	}
82
	
83
	private static void serializeCategory(IHelpResource categoryResource, 
84
			StringBuffer buf, String indent) {
85
		String category = categoryResource.getLabel();
86
		if (category == null) return;
87
		
88
		buf.append(indent + "<category"); //$NON-NLS-1$
89
		
90
		String catHref = getCategoryHref(categoryResource);
91
		if (catHref != null) {
92
			buf.append('\n' + indent	+ "      href=\""  //$NON-NLS-1$
93
					+ XMLGenerator.xmlEscape(catHref) + '"');
94
		}
95
		
96
		buf.append(">\n"); //$NON-NLS-1$
97
		buf.append(XMLGenerator.xmlEscape(category));
98
		
99
		buf.append("</category>\n"); //$NON-NLS-1$
100
	}
101
	
102
	private static String getCategoryHref(IHelpResource categoryResource) {
103
		String tocHref = categoryResource.getHref();
104
		IToc[] tocs = HelpSystem.getTocs();
105
		for (int j=0;j<tocs.length;++j) {
106
			if (tocHref.equals(tocs[j].getHref())) {
107
				ITopic topic = tocs[j].getTopic(null);
108
				String topicHref = topic.getHref();
109
				if (topicHref != null) {
110
					return UrlUtil.getHelpURL(topicHref);
111
				}
112
				return "../nav/" + j; //$NON-NLS-1$
113
			}
114
		}
115
		return null;
116
	}
117
}
(-)src/org/eclipse/help/internal/webapp/utils/Utils.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.utils;
12
13
import java.io.BufferedInputStream;
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
import java.io.OutputStream;
19
import java.io.Reader;
20
import java.io.StringWriter;
21
import java.io.Writer;
22
23
public class Utils {
24
25
	public static final String SERVICE_CONTEXT 		= "/vs/service"; //$NON-NLS-1$
26
	
27
	public static final String RETURN_TYPE 			= "returnType"; //$NON-NLS-1$
28
	public static final String NO_CATEGORY 			= "noCategory"; //$NON-NLS-1$
29
30
	// returnType values: xml (default) | json
31
	public static final String XML 					= "xml"; //$NON-NLS-1$
32
	public static final String JSON 				= "json"; //$NON-NLS-1$
33
	
34
	public static String convertStreamToString(InputStream is)
35
			throws IOException {
36
		if (is != null) {
37
			Writer writer = new StringWriter();
38
			char[] buffer = new char[1024];
39
			try {
40
				Reader reader = new BufferedReader(
41
						new InputStreamReader(is, "UTF-8")); //$NON-NLS-1$
42
				int n;
43
				while ((n = reader.read(buffer)) != -1) {
44
					writer.write(buffer, 0, n);
45
				}
46
			} finally {
47
				is.close();
48
			}
49
			return writer.toString();
50
		} else {
51
			return ""; //$NON-NLS-1$
52
		}
53
	}
54
	
55
	public static void transferContent(InputStream inputStream, OutputStream out)
56
			throws IOException {
57
		try {
58
			// Prepare the input stream for reading
59
			BufferedInputStream dataStream = new BufferedInputStream(
60
					inputStream);
61
62
			// Create a fixed sized buffer for reading.
63
			// We could create one with the size of available data...
64
			byte[] buffer = new byte[4096];
65
			int len = 0;
66
			while (true) {
67
				len = dataStream.read(buffer); // Read file into the byte array
68
				if (len == -1)
69
					break;
70
				out.write(buffer, 0, len);
71
			}
72
		} catch (Exception e) {
73
		}
74
	}
75
76
	public static String updateResponse(String response) {
77
		response = removeString(response, "advanced/synchWithToc.js"); //$NON-NLS-1$
78
		response = removeString(response, "index.jsp"); //$NON-NLS-1$
79
		return response;
80
	}
81
	
82
	private static String removeString(String response, String remove) {
83
		StringBuffer buff = new StringBuffer(response);
84
		int index = buff.indexOf(remove);
85
		if (index > -1) {
86
			int start = buff.lastIndexOf("<script", index); //$NON-NLS-1$
87
			int end = buff.indexOf("</script>", index); //$NON-NLS-1$
88
			if (start > -1 && end > -1 && start < end) {
89
				buff.delete(start, end + "</script>".length()); //$NON-NLS-1$
90
			}
91
		}
92
		return buff.toString();
93
	}
94
95
}
(-)src/org/eclipse/help/internal/webapp/utils/XMLHelper.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.help.internal.webapp.utils;
12
13
public final class XMLHelper {
14
15
	public static final String SESSION_URL				= "helpURL"; //$NON-NLS-1$
16
	
17
	public static final String URL36_PREFIX				= "/advanced"; //$NON-NLS-1$
18
	public static final String TOC_URL					= "/tocfragment"; //$NON-NLS-1$
19
	public static final String SEARCH_URL				= "/search"; //$NON-NLS-1$
20
	
21
	public static final String ATTR_TITLE				= "title"; //$NON-NLS-1$
22
	public static final String ATTR_ID					= "id"; //$NON-NLS-1$
23
	public static final String ATTR_HREF				= "href"; //$NON-NLS-1$
24
	public static final String ATTR_IMAGE				= "image"; //$NON-NLS-1$
25
	public static final String ATTR_LABEL				= "label"; //$NON-NLS-1$
26
	public static final String ATTR_SCORE				= "score"; //$NON-NLS-1$
27
	public static final String ATTR_LOCALE				= "locale"; //$NON-NLS-1$
28
	public static final String ATTR_KEYWORD				= "keyword"; //$NON-NLS-1$
29
	
30
	public static final String ELEMENT_NODE				= "node"; //$NON-NLS-1$
31
	public static final String ELEMENT_HIT				= "hit"; //$NON-NLS-1$
32
	public static final String ELEMENT_HITS				= "searchHits"; //$NON-NLS-1$
33
	public static final String ELEMENT_CATEGORY			= "category"; //$NON-NLS-1$
34
	public static final String ELEMENT_SUMMARY			= "summary"; //$NON-NLS-1$
35
	public static final String ELEMENT_DESCRIPTION		= "description"; //$NON-NLS-1$
36
	public static final String ELEMENT_INDEX			= "index"; //$NON-NLS-1$
37
	public static final String ELEMENT_INDEX_CONTRIBUTIONS	= "indexContributions"; //$NON-NLS-1$
38
	public static final String ELEMENT_TOC_CONTRIBUTIONS	= "tocContributions"; //$NON-NLS-1$
39
	
40
	public static final String CATEGORY_HREF			= "categoryHref"; //$NON-NLS-1$
41
}
(-)help/org/eclipse/ua/tests/help/AllHelpTests.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 23-28 Link Here
23
import org.eclipse.ua.tests.help.search.AllSearchTests;
23
import org.eclipse.ua.tests.help.search.AllSearchTests;
24
import org.eclipse.ua.tests.help.toc.AllTocTests;
24
import org.eclipse.ua.tests.help.toc.AllTocTests;
25
import org.eclipse.ua.tests.help.webapp.AllWebappTests;
25
import org.eclipse.ua.tests.help.webapp.AllWebappTests;
26
import org.eclipse.ua.tests.help.webapp.service.AllWebappServiceTests;
26
27
27
/*
28
/*
28
 * Tests help functionality (automated).
29
 * Tests help functionality (automated).
Lines 50-54 Link Here
50
		addTest(AllOtherHelpTests.suite());
51
		addTest(AllOtherHelpTests.suite());
51
		addTest(AllRemoteTests.suite());
52
		addTest(AllRemoteTests.suite());
52
		addTest(AllScopeTests.suite());
53
		addTest(AllScopeTests.suite());
54
		addTest(AllWebappServiceTests.suite());
53
	}
55
	}
54
}
56
}
(-)help/org/eclipse/ua/tests/help/remote/ContextServletTest.java (-3 / +4 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Snehasish Paul <snehpaul@in.ibm.com> - Eclipse help public API services
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.remote;
12
package org.eclipse.ua.tests.help.remote;
12
13
Lines 70-83 Link Here
70
		}
71
		}
71
	}
72
	}
72
73
73
	private Element[] getContextsFromServlet(String phrase)
74
	protected Element[] getContextsFromServlet(String phrase)
74
			throws Exception {
75
			throws Exception {
75
		int port = WebappManager.getPort();
76
		int port = WebappManager.getPort();
76
		URL url = new URL("http", "localhost", port, "/help/context?id=" + URLEncoder.encode(phrase, "UTF-8"));
77
		URL url = new URL("http", "localhost", port, "/help/context?id=" + URLEncoder.encode(phrase, "UTF-8"));
77
		return makeServletCall(url);
78
		return makeServletCall(url);
78
	}
79
	}
79
	
80
	
80
	private Element[] getContextsUsingLocale(String phrase, String locale)
81
	protected Element[] getContextsUsingLocale(String phrase, String locale)
81
			throws Exception {
82
			throws Exception {
82
		int port = WebappManager.getPort();
83
		int port = WebappManager.getPort();
83
		URL url = new URL("http", "localhost", port, "/help/context?id="
84
		URL url = new URL("http", "localhost", port, "/help/context?id="
Lines 85-91 Link Here
85
		return makeServletCall(url);
86
		return makeServletCall(url);
86
	}
87
	}
87
88
88
	private Element[] makeServletCall(URL url) throws IOException,
89
	protected Element[] makeServletCall(URL url) throws IOException,
89
			ParserConfigurationException, FactoryConfigurationError,
90
			ParserConfigurationException, FactoryConfigurationError,
90
			SAXException {
91
			SAXException {
91
		InputStream is = url.openStream();
92
		InputStream is = url.openStream();
(-)help/org/eclipse/ua/tests/help/remote/IndexServletTest.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Snehasish Paul <snehpaul@in.ibm.com> - Eclipse help public API services
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.remote;
12
package org.eclipse.ua.tests.help.remote;
12
13
Lines 146-152 Link Here
146
		}
147
		}
147
	}
148
	}
148
149
149
	private Node getIndexContributions( String locale)
150
	protected Node getIndexContributions( String locale)
150
			throws Exception {
151
			throws Exception {
151
		int port = WebappManager.getPort();
152
		int port = WebappManager.getPort();
152
		URL url = new URL("http", "localhost", port, "/help/index?lang=" + locale);
153
		URL url = new URL("http", "localhost", port, "/help/index?lang=" + locale);
(-)help/org/eclipse/ua/tests/help/remote/SearchServletTest.java (-3 / +4 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Snehasish Paul <snehpaul@in.ibm.com> - Eclipse help public API services
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.remote;
12
package org.eclipse.ua.tests.help.remote;
12
13
Lines 97-110 Link Here
97
		assertEquals(0, hits.length);
98
		assertEquals(0, hits.length);
98
	}
99
	}
99
100
100
	private Node[] getSearchHitsFromServlet(String phrase)
101
	protected Node[] getSearchHitsFromServlet(String phrase)
101
			throws Exception {
102
			throws Exception {
102
		int port = WebappManager.getPort();
103
		int port = WebappManager.getPort();
103
		URL url = new URL("http", "localhost", port, "/help/search?phrase=" + URLEncoder.encode(phrase, "UTF-8"));
104
		URL url = new URL("http", "localhost", port, "/help/search?phrase=" + URLEncoder.encode(phrase, "UTF-8"));
104
		return makeServletCall(url);
105
		return makeServletCall(url);
105
	}
106
	}
106
	
107
	
107
	private Node[] getSearchHitsUsingLocale(String phrase, String locale)
108
	protected Node[] getSearchHitsUsingLocale(String phrase, String locale)
108
			throws Exception {
109
			throws Exception {
109
		int port = WebappManager.getPort();
110
		int port = WebappManager.getPort();
110
		URL url = new URL("http", "localhost", port, "/help/search?phrase="
111
		URL url = new URL("http", "localhost", port, "/help/search?phrase="
Lines 112-118 Link Here
112
		return makeServletCall(url);
113
		return makeServletCall(url);
113
	}
114
	}
114
115
115
	private Node[] makeServletCall(URL url) throws IOException,
116
	protected Node[] makeServletCall(URL url) throws IOException,
116
			ParserConfigurationException, FactoryConfigurationError,
117
			ParserConfigurationException, FactoryConfigurationError,
117
			SAXException {
118
			SAXException {
118
		InputStream is = url.openStream();
119
		InputStream is = url.openStream();
(-)help/org/eclipse/ua/tests/help/remote/TocServletTest.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Snehasish Paul <snehpaul@in.ibm.com> - Eclipse help public API services
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.remote;
12
package org.eclipse.ua.tests.help.remote;
12
13
Lines 110-116 Link Here
110
	}
111
	}
111
	 
112
	 
112
113
113
	private Node getTocContributions( String locale)
114
	protected Node getTocContributions( String locale)
114
			throws Exception {
115
			throws Exception {
115
		int port = WebappManager.getPort();
116
		int port = WebappManager.getPort();
116
		URL url = new URL("http", "localhost", port, "/help/toc?lang=" + locale);
117
		URL url = new URL("http", "localhost", port, "/help/toc?lang=" + locale);
(-)help/org/eclipse/ua/tests/help/webapp/service/AdvancedSearchServiceTest.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
14
import java.net.URL;
15
import java.net.URLEncoder;
16
17
import org.eclipse.help.internal.server.WebappManager;
18
import org.eclipse.ua.tests.help.remote.SearchServletTest;
19
import org.w3c.dom.Node;
20
21
public class AdvancedSearchServiceTest extends SearchServletTest {
22
23
	protected Node[] getSearchHitsFromServlet(String searchWord)
24
			throws Exception {
25
		int port = WebappManager.getPort();
26
		URL url = new URL("http", "localhost", port, "/help/vs/service/advancedsearch?searchWord=" + URLEncoder.encode(searchWord, "UTF-8"));
27
		return makeServletCall(url);
28
	}
29
	
30
	protected Node[] getSearchHitsUsingLocale(String searchWord, String locale)
31
			throws Exception {
32
		int port = WebappManager.getPort();
33
		URL url = new URL("http", "localhost", port, "/help/vs/service/advancedsearch?searchWord="
34
				+ URLEncoder.encode(searchWord, "UTF-8") + "&lang=" + locale);
35
		return makeServletCall(url);
36
	}
37
38
	public void testRemoteSearchXMLSchema() 
39
			throws Exception {
40
		int port = WebappManager.getPort();
41
		URL url = new URL("http", "localhost", port, 
42
				"/help/vs/service/advancedsearch?searchWord=" + URLEncoder.encode("jehcyqpfjs vkrhjewiwh", "UTF-8"));
43
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/advancedsearch.xsd");
44
		String schema = schemaUrl.toString();
45
		String uri = url.toString();
46
		String result = SchemaValidator.testXMLSchema(uri, schema);
47
		
48
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
49
	}
50
51
	public void testRemoteSearchXMLSchemaExactMatchFound() 
52
			throws Exception {
53
		int port = WebappManager.getPort();
54
		URL url = new URL("http", "localhost", port, 
55
				"/help/vs/service/advancedsearch?searchWord=" + URLEncoder.encode("\"jehcyqpfjs vkrhjewiwh\"", "UTF-8"));
56
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/advancedsearch.xsd");
57
		String schema = schemaUrl.toString();
58
		String uri = url.toString();
59
		String result = SchemaValidator.testXMLSchema(uri, schema);
60
		
61
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
62
	}
63
64
	public void testRemoteSearchJSONSchema() 
65
			throws Exception {
66
//		fail("Not yet implemented.");
67
	}
68
69
}
(-)help/org/eclipse/ua/tests/help/webapp/service/AllWebappServiceTests.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
/*
17
 * Tests utility classes and servlets used in Web Application
18
 */
19
public class AllWebappServiceTests extends TestSuite {
20
21
	/*
22
	 * Returns the entire test suite.
23
	 */
24
	public static Test suite() {
25
		TestSuite suite = new TestSuite(
26
				"org.eclipse.ua.tests.help.AllWebappServiceTests");
27
		//$JUnit-BEGIN$
28
		suite.addTestSuite(AdvancedSearchServiceTest.class);
29
		suite.addTestSuite(ContentServiceTest.class);
30
		suite.addTestSuite(ContextServiceTest.class);
31
		suite.addTestSuite(ExtensionServiceTest.class);
32
		suite.addTestSuite(IndexFragmentServiceTest.class);
33
		suite.addTestSuite(IndexServiceTest.class);
34
		suite.addTestSuite(SearchServiceTest.class);
35
		suite.addTestSuite(TocFragmentServiceTest.class);
36
		suite.addTestSuite(TocServiceTest.class);
37
		//$JUnit-END$
38
		return suite;
39
	}
40
41
}
(-)help/org/eclipse/ua/tests/help/webapp/service/ContentServiceTest.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.IOException;
14
15
import org.eclipse.ua.tests.help.remote.ContentServletTest;
16
17
public class ContentServiceTest extends ContentServletTest {
18
19
	private static final String UA_TESTS = "org.eclipse.ua.tests";
20
21
	public void testSimpleContent() throws Exception {
22
		final String path = "/data/help/index/topic1.html";
23
		String remoteContent = ServicesTestUtils.getRemoteContent(UA_TESTS, path, "en");
24
		String localContent = ServicesTestUtils.getLocalContent(UA_TESTS, path);
25
	    assertEquals(remoteContent, localContent);
26
	}
27
28
	public void testFilteredContent() throws Exception {
29
		final String path = "/data/help/manual/filter.xhtml";
30
		String remoteContent = ServicesTestUtils.getRemoteContent(UA_TESTS, path, "en");
31
		String localContent = ServicesTestUtils.getLocalContent(UA_TESTS, path);
32
	    assertEquals(remoteContent, localContent);
33
	}
34
35
	public void testContentInEnLocale() throws Exception {
36
		final String path = "/data/help/search/testnl1.xhtml";
37
		String remoteContent = ServicesTestUtils.getRemoteContent(UA_TESTS, path, "en");
38
		String localContent = ServicesTestUtils.getLocalContent(UA_TESTS, path);
39
	    assertEquals(remoteContent, localContent);
40
	}
41
	
42
	public void testContentInDeLocale() throws Exception {
43
		final String path = "/data/help/search/testnl1.xhtml";
44
		String remoteContent = ServicesTestUtils.getRemoteContent(UA_TESTS, path, "de");
45
		String enLocalContent = ServicesTestUtils.getLocalContent(UA_TESTS, path);
46
		String deLocalContent = ServicesTestUtils.getLocalContent(UA_TESTS, "/nl/de" + path);
47
	    assertEquals(remoteContent, deLocalContent);
48
	    assertFalse(remoteContent.equals(enLocalContent));
49
	}
50
	
51
	public void testRemoteContentNotFound() throws Exception {
52
		try {
53
			ServicesTestUtils.getRemoteContent(UA_TESTS, "/no/such/path.html", "en");
54
			fail("No exception thrown");
55
		} catch (IOException e) {
56
			// Exception caught as expected
57
		}
58
	}
59
60
}
(-)help/org/eclipse/ua/tests/help/webapp/service/ContextServiceTest.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.net.URL;
14
import java.net.URLEncoder;
15
16
import org.eclipse.help.internal.server.WebappManager;
17
import org.eclipse.ua.tests.help.remote.ContextServletTest;
18
import org.w3c.dom.Element;
19
20
public class ContextServiceTest extends ContextServletTest {
21
22
	protected Element[] getContextsFromServlet(String phrase)
23
			throws Exception {
24
		int port = WebappManager.getPort();
25
		URL url = new URL("http", "localhost", port, "/help/vs/service/context?id=" 
26
				+ URLEncoder.encode(phrase, "UTF-8"));
27
		return makeServletCall(url);
28
	}
29
	
30
	protected Element[] getContextsUsingLocale(String phrase, String locale)
31
			throws Exception {
32
		int port = WebappManager.getPort();
33
		URL url = new URL("http", "localhost", port, "/help/vs/service/context?id="
34
				+ URLEncoder.encode(phrase, "UTF-8") + "&lang=" + locale);
35
		return makeServletCall(url);
36
	}
37
38
	public void testContextServiceXMLSchema() 
39
			throws Exception {
40
		int port = WebappManager.getPort();
41
		URL url = new URL("http", "localhost", port, "/help/vs/service/context?id=org.eclipse.ua.tests.test_cheatsheets&lang=en");
42
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/context.xsd");
43
		String schema = schemaUrl.toString();
44
		String uri = url.toString();
45
		String result = SchemaValidator.testXMLSchema(uri, schema);
46
		
47
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
48
	}
49
50
	public void testContextServiceJSONSchema() 
51
			throws Exception {
52
//		fail("Not yet implemented.");
53
	}
54
55
}
(-)help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java (+161 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import javax.xml.parsers.DocumentBuilder;
20
import javax.xml.parsers.DocumentBuilderFactory;
21
22
import junit.framework.TestCase;
23
24
import org.eclipse.help.internal.base.BaseHelpSystem;
25
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
26
import org.eclipse.help.internal.server.WebappManager;
27
import org.w3c.dom.Document;
28
import org.w3c.dom.Element;
29
import org.w3c.dom.Node;
30
import org.w3c.dom.NodeList;
31
import org.xml.sax.InputSource;
32
33
public class ExtensionServiceTest extends TestCase {
34
35
	private int mode;
36
37
	protected void setUp() throws Exception {
38
		BaseHelpSystem.ensureWebappRunning();
39
		mode = BaseHelpSystem.getMode();
40
		BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
41
	}
42
	
43
	protected void tearDown() throws Exception {
44
		BaseHelpSystem.setMode(mode);
45
	}
46
47
	public void testExtensionServiceContributionExactMatch1() throws Exception {
48
		Node root = getContentExtensions("en");
49
		Element[] UARoot = findContributionByContent(root, 
50
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.1");
51
	    assertEquals(1, UARoot.length);
52
	}
53
54
	public void testExtensionServiceContributionExactMatch3() throws Exception {
55
		Node root = getContentExtensions("en");
56
		Element[] UARoot = findContributionByContent(root, 
57
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.3");
58
	    assertEquals(1, UARoot.length);
59
	}
60
	
61
	public void testExtensionServiceContributionNoMatch() throws Exception {
62
		Node root = getContentExtensions("en");
63
		Element[] UARoot = findContributionByContent(root, 
64
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.4");
65
	    assertEquals(0, UARoot.length);
66
	}
67
	
68
	public void testExtensionServiceContributionByPath() throws Exception {
69
		Node root = getContentExtensions("en");
70
		Element[] UARoot = findContributionByPath(root, 
71
				"/org.eclipse.ua.tests/data/help/dynamic/extension.xml#anchor.invalidcontribution");
72
		assertEquals(2, UARoot.length);
73
	}
74
75
	public void testExtensionServiceReplacementExactMatch() throws Exception {
76
		Node root = getContentExtensions("en");
77
		Element[] UARoot = findReplacementByContent(root, 
78
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.1");
79
	    assertEquals(1, UARoot.length);
80
	}
81
	
82
	public void testExtensionServiceReplacementNoMatch() throws Exception {
83
		Node root = getContentExtensions("en");
84
		Element[] UARoot = findReplacementByContent(root, 
85
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.3");
86
		assertEquals(0, UARoot.length);
87
	}
88
	
89
	public void testExtensionServiceReplacementByPath() throws Exception {
90
		Node root = getContentExtensions("en");
91
		Element[] UARoot = findReplacementByPath(root, 
92
				"/org.eclipse.ua.tests/data/help/dynamic/shared/doc1.xml#element.2");
93
		assertEquals(1, UARoot.length);
94
	}
95
	
96
	private Element[] findContributionByContent(Node root, String content) {
97
		return findChildren(root, "contribution", "content", content);
98
	}
99
	
100
	private Element[] findContributionByPath(Node root, String path) {
101
		return findChildren(root, "contribution", "path", path);
102
	}
103
	
104
	private Element[] findReplacementByContent(Node root, String content) {
105
		return findChildren(root, "replacement", "content", content);
106
	}
107
	
108
	private Element[] findReplacementByPath(Node root, String path) {
109
		return findChildren(root, "replacement", "path", path);
110
	}
111
	
112
	private Element[] findChildren(Node parent, String childKind, 
113
			String attributeName, String attributeValue) {
114
		NodeList contributions = parent.getChildNodes();
115
		List<Node> results = new ArrayList<Node>();
116
		for (int i = 0; i < contributions.getLength(); i++) {
117
			Node next = contributions.item(i);
118
			if (next instanceof Element) {
119
				Element nextElement = (Element)next;
120
				if ( childKind.equals(nextElement.getTagName()) && attributeValue.equals(nextElement.getAttribute(attributeName))) {
121
		
122
				    results.add(next);	
123
				}
124
			}
125
		}
126
		return results.toArray(new Element[results.size()]);
127
	}
128
129
	private Node getContentExtensions(String locale)
130
			throws Exception {
131
		int port = WebappManager.getPort();
132
		URL url = new URL("http", "localhost", port, "/help/vs/service/extension?lang=" + locale);
133
		InputStream is = url.openStream();
134
		InputSource inputSource = new InputSource(is);
135
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
136
		documentBuilder.setEntityResolver(new LocalEntityResolver());
137
		Document document = documentBuilder.parse(inputSource);
138
		Node root = document.getFirstChild();
139
		is.close();
140
		assertEquals("contentExtensions", root.getNodeName());
141
		return root;
142
	}
143
144
	public void testExtensionFragmentServiceXMLSchema() 
145
			throws Exception {
146
		int port = WebappManager.getPort();
147
		URL url = new URL("http", "localhost", port, "/help/vs/service/extension?lang=en");
148
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/extension.xsd");
149
		String schema = schemaUrl.toString();
150
		String uri = url.toString();
151
		String result = SchemaValidator.testXMLSchema(uri, schema);
152
		
153
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
154
	}
155
156
	public void testExtensionFragmentServiceJSONSchema() 
157
			throws Exception {
158
//		fail("Not yet implemented.");
159
	}
160
161
}
(-)help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
14
import java.io.InputStream;
15
import java.net.URL;
16
17
import javax.xml.parsers.DocumentBuilder;
18
import javax.xml.parsers.DocumentBuilderFactory;
19
20
import junit.framework.TestCase;
21
22
import org.eclipse.help.internal.base.BaseHelpSystem;
23
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
24
import org.eclipse.help.internal.server.WebappManager;
25
import org.w3c.dom.Document;
26
import org.w3c.dom.Node;
27
import org.xml.sax.InputSource;
28
29
public class IndexFragmentServiceTest extends TestCase {
30
31
	private int mode;
32
33
	protected void setUp() throws Exception {
34
		BaseHelpSystem.ensureWebappRunning();
35
		mode = BaseHelpSystem.getMode();
36
		BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
37
	}
38
	
39
	protected void tearDown() throws Exception {
40
		BaseHelpSystem.setMode(mode);
41
	}
42
43
	public void testIndexServletEn() throws Exception {
44
		getTreeData("en");
45
	}
46
47
	public void testIndexServletDe() throws Exception {
48
		getTreeData("de");
49
	}
50
51
	private void getTreeData(String locale)
52
			throws Exception {
53
		int port = WebappManager.getPort();
54
		URL url = new URL("http", "localhost", port, "/help/vs/service/indexfragment?lang=" + locale);
55
		InputStream is = url.openStream();
56
		InputSource inputSource = new InputSource(is);
57
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
58
		documentBuilder.setEntityResolver(new LocalEntityResolver());
59
		Document document = documentBuilder.parse(inputSource);
60
		Node root = document.getFirstChild();
61
		is.close();
62
		assertEquals("tree_data", root.getNodeName());
63
	}
64
65
	public void testIndexFragmentServiceXMLSchema() 
66
			throws Exception {
67
		int port = WebappManager.getPort();
68
		URL url = new URL("http", "localhost", port, "/help/vs/service/indexfragment?lang=en");
69
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/indexfragment.xsd");
70
		String schema = schemaUrl.toString();
71
		String uri = url.toString();
72
		String result = SchemaValidator.testXMLSchema(uri, schema);
73
		
74
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
75
	}
76
77
	public void testIndexFragmentServiceJSONSchema() 
78
			throws Exception {
79
//		fail("Not yet implemented.");
80
	}
81
82
}
(-)help/org/eclipse/ua/tests/help/webapp/service/IndexServiceTest.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.InputStream;
14
import java.net.URL;
15
16
import javax.xml.parsers.DocumentBuilder;
17
import javax.xml.parsers.DocumentBuilderFactory;
18
19
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
20
import org.eclipse.help.internal.server.WebappManager;
21
import org.eclipse.ua.tests.help.remote.IndexServletTest;
22
import org.w3c.dom.Document;
23
import org.w3c.dom.Node;
24
import org.xml.sax.InputSource;
25
26
public class IndexServiceTest extends IndexServletTest {
27
28
	protected Node getIndexContributions( String locale)
29
			throws Exception {
30
		int port = WebappManager.getPort();
31
		URL url = new URL("http", "localhost", port, "/help/vs/service/index?lang=" + locale);
32
		InputStream is = url.openStream();
33
		InputSource inputSource = new InputSource(is);
34
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
35
		documentBuilder.setEntityResolver(new LocalEntityResolver());
36
		Document document = documentBuilder.parse(inputSource);
37
		Node root = document.getFirstChild();
38
		is.close();
39
		assertEquals("indexContributions", root.getNodeName());
40
		return root;
41
	}
42
43
	public void testIndexServiceXMLSchema() 
44
			throws Exception {
45
		int port = WebappManager.getPort();
46
		URL url = new URL("http", "localhost", port, "/help/vs/service/index?lang=en");
47
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/index.xsd");
48
		String schema = schemaUrl.toString();
49
		String uri = url.toString();
50
		String result = SchemaValidator.testXMLSchema(uri, schema);
51
		
52
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
53
	}
54
55
	public void testIndexServiceJSONSchema() 
56
			throws Exception {
57
//		fail("Not yet implemented.");
58
	}
59
60
}
(-)help/org/eclipse/ua/tests/help/webapp/service/SchemaValidator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.File;
14
import java.net.URL;
15
16
import javax.xml.transform.Source;
17
import javax.xml.transform.stream.StreamSource;
18
import javax.xml.validation.Schema;
19
import javax.xml.validation.SchemaFactory;
20
import javax.xml.validation.Validator;
21
22
import org.xml.sax.SAXException;
23
24
public class SchemaValidator {
25
26
	public static String testXMLSchema(String uri, String schemaFile) {
27
		String msg = ""; //$NON-NLS-1$
28
		try {
29
			SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$
30
			Schema schema = null;
31
			if (schemaFile.startsWith("http") || schemaFile.startsWith("ftp"))
32
				schema = factory.newSchema(new URL(schemaFile));
33
			else
34
				schema = factory.newSchema(new File(schemaFile));
35
			
36
			Validator validator = schema.newValidator();
37
			Source source = new StreamSource(uri);
38
			try {
39
				validator.validate(source);
40
				msg = "valid"; //$NON-NLS-1$
41
			} catch (SAXException ex) {
42
				msg = "not valid. Details: " + ex.getMessage(); //$NON-NLS-1$
43
			}
44
		} catch(Exception e) {
45
			msg = "Exception e: " + e; //$NON-NLS-1$
46
		}
47
		
48
		System.out.println(msg);
49
		return msg;
50
	}
51
	
52
	public static String testJSONSchema(String uri, String schemaFile) {
53
		// TODO: Not yet implemented
54
		return ""; //$NON-NLS-1$
55
	}
56
}
(-)help/org/eclipse/ua/tests/help/webapp/service/SearchServiceTest.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
14
import java.net.URL;
15
import java.net.URLEncoder;
16
17
import org.eclipse.help.internal.server.WebappManager;
18
import org.eclipse.ua.tests.help.remote.SearchServletTest;
19
import org.w3c.dom.Node;
20
21
public class SearchServiceTest extends SearchServletTest {
22
23
	protected Node[] getSearchHitsFromServlet(String phrase)
24
			throws Exception {
25
		int port = WebappManager.getPort();
26
		URL url = new URL("http", "localhost", port, "/help/vs/service/search?phrase=" + URLEncoder.encode(phrase, "UTF-8"));
27
		return makeServletCall(url);
28
	}
29
	
30
	protected Node[] getSearchHitsUsingLocale(String phrase, String locale)
31
			throws Exception {
32
		int port = WebappManager.getPort();
33
		URL url = new URL("http", "localhost", port, "/help/vs/service/search?phrase="
34
				+ URLEncoder.encode(phrase, "UTF-8") + "&lang=" + locale);
35
		return makeServletCall(url);
36
	}
37
38
	public void testRemoteSearchXMLSchema() 
39
			throws Exception {
40
		int port = WebappManager.getPort();
41
		URL url = new URL("http", "localhost", port, 
42
				"/help/vs/service/search?phrase=" + URLEncoder.encode("jehcyqpfjs vkrhjewiwh", "UTF-8"));
43
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/search.xsd");
44
		String schema = schemaUrl.toString();
45
		String uri = url.toString();
46
		String result = SchemaValidator.testXMLSchema(uri, schema);
47
		
48
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
49
	}
50
51
	public void testRemoteSearchXMLSchemaExactMatchFound() 
52
			throws Exception {
53
		int port = WebappManager.getPort();
54
		URL url = new URL("http", "localhost", port, 
55
				"/help/vs/service/search?phrase=" + URLEncoder.encode("\"jehcyqpfjs vkrhjewiwh\"", "UTF-8"));
56
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/search.xsd");
57
		String schema = schemaUrl.toString();
58
		String uri = url.toString();
59
		String result = SchemaValidator.testXMLSchema(uri, schema);
60
		
61
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
62
	}
63
64
	public void testRemoteSearchJSONSchema() 
65
			throws Exception {
66
//		fail("Not yet implemented.");
67
	}
68
69
}
(-)help/org/eclipse/ua/tests/help/webapp/service/ServicesTestUtils.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.IOException;
14
import java.net.URL;
15
16
import org.eclipse.help.internal.server.WebappManager;
17
import org.eclipse.help.internal.webapp.utils.Utils;
18
import org.eclipse.ua.tests.help.remote.RemoteTestUtils;
19
20
public class ServicesTestUtils extends RemoteTestUtils {
21
22
	public static String getRemoteContent(String plugin, String path,
23
			String locale) throws Exception {
24
		int port = WebappManager.getPort();
25
		URL url = new URL("http", "localhost", port, "/help/vs/service/rtopic/" + plugin
26
				+ path + "?lang=" + locale);
27
		return readFromURL(url);
28
	}
29
	
30
	public static String getLocalContent(String plugin, String path)
31
			throws IOException {
32
		String localContent = RemoteTestUtils.getLocalContent(plugin, path);
33
		try {
34
			localContent = Utils.updateResponse(localContent);
35
		} catch (Exception e) {
36
			e.printStackTrace();
37
		}
38
		return localContent;
39
	}
40
41
}
(-)help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java (+163 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.InputStream;
14
import java.net.URL;
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import javax.xml.parsers.DocumentBuilder;
19
import javax.xml.parsers.DocumentBuilderFactory;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.help.internal.base.BaseHelpSystem;
24
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
25
import org.eclipse.help.internal.server.WebappManager;
26
import org.w3c.dom.Document;
27
import org.w3c.dom.Element;
28
import org.w3c.dom.Node;
29
import org.w3c.dom.NodeList;
30
import org.xml.sax.InputSource;
31
32
public class TocFragmentServiceTest extends TestCase {
33
34
	private int mode;
35
36
	protected void setUp() throws Exception {
37
		BaseHelpSystem.ensureWebappRunning();
38
		mode = BaseHelpSystem.getMode();
39
		BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
40
	}
41
	
42
	protected void tearDown() throws Exception {
43
		BaseHelpSystem.setMode(mode);
44
	}
45
46
	public void testTocFragmentServiceContainsUAToc() throws Exception {
47
		int port = WebappManager.getPort();
48
		URL url = new URL("http", "localhost", port, 
49
				"/help/vs/service/tocfragment?lang=en");
50
		Node root = getTreeData(url);
51
		Element[] UARoot = findNodeById(root, 
52
				"/org.eclipse.ua.tests/data/help/toc/root.xml");
53
	    assertEquals(1, UARoot.length);
54
	}
55
56
	public void testTocFragmentServiceContainsFilteredToc() throws Exception {
57
		int port = WebappManager.getPort();
58
		URL url = new URL("http", "localhost", port, 
59
				"/help/vs/service/tocfragment?lang=en&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=2");
60
		Node root = getTreeData(url);
61
		Element[] UARoot = findNodeById(root, 
62
				"/org.eclipse.ua.tests/data/help/toc/root.xml");
63
		assertEquals(1, UARoot.length);
64
		Element[] filterNode = findNodeById(UARoot[0], "2");
65
		assertEquals(1, filterNode.length);
66
		Element[] results = findChildren(filterNode[0], "node", "href", 
67
				"../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/simple_page.html");
68
		assertEquals(24, results.length);
69
		
70
		results = findChildren(filterNode[0], "node", "href", 
71
		"../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html");
72
		assertEquals(1, results.length);
73
	}
74
	
75
	public void testReadEnToc() throws Exception {
76
		int port = WebappManager.getPort();
77
		URL url = new URL("http", "localhost", port, 
78
				"/help/vs/service/tocfragment?lang=en&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=7");
79
		Node root = getTreeData(url);
80
		Element[] UARoot = findNodeById(root, 
81
				"/org.eclipse.ua.tests/data/help/toc/root.xml");
82
		assertEquals(1, UARoot.length);
83
		Element[] searchNode = findNodeById(UARoot[0], "7");
84
		assertEquals(1, searchNode.length);
85
		Element[] topicEn = findChildren(searchNode[0], "node", "href", 
86
				"../topic/org.eclipse.ua.tests/data/help/search/test_en.html");
87
		assertEquals(1, topicEn.length);
88
		Element[] topicDe = findChildren(searchNode[0], "node", "href", 
89
				"../topic/org.eclipse.ua.tests/data/help/search/test_de.html");
90
		assertEquals(0, topicDe.length);
91
	}	
92
	
93
	public void testReadDeToc() throws Exception {
94
		int port = WebappManager.getPort();
95
		URL url = new URL("http", "localhost", port, 
96
				"/help/vs/service/tocfragment?lang=de&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=7");
97
		Node root = getTreeData(url);
98
		Element[] UARoot = findNodeById(root, 
99
				"/org.eclipse.ua.tests/data/help/toc/root.xml");
100
		assertEquals(1, UARoot.length);
101
		Element[] searchNode = findNodeById(UARoot[0], "7");
102
		Element[] topicEn = findChildren(searchNode[0], "node", "href", 
103
				"../topic/org.eclipse.ua.tests/data/help/search/test_en.html");
104
		assertEquals(0, topicEn.length);
105
		Element[] topicDe = findChildren(searchNode[0], "node", "href", 
106
				"../topic/org.eclipse.ua.tests/data/help/search/test_de.html");
107
		assertEquals(1, topicDe.length);
108
	}
109
	
110
	private Element[] findNodeById(Node root, String id) {
111
		return findChildren(root, "node", "id", id);
112
	}
113
	
114
	private Element[] findChildren(Node parent, String childKind, 
115
			String attributeName, String attributeValue) {
116
		NodeList nodes = parent.getChildNodes();
117
		List<Node> results = new ArrayList<Node>();
118
		for (int i = 0; i < nodes.getLength(); i++) {
119
			Node next = nodes.item(i);
120
			if (next instanceof Element) {
121
				Element nextElement = (Element)next;
122
				if ( childKind.equals(nextElement.getTagName()) 
123
						&& attributeValue.equals(nextElement.getAttribute(attributeName))) {
124
		
125
				    results.add(next);	
126
				}
127
			}
128
		}
129
		return (Element[]) results.toArray(new Element[results.size()]);
130
	}
131
	 
132
133
	private Node getTreeData(URL url)
134
			throws Exception {
135
		InputStream is = url.openStream();
136
		InputSource inputSource = new InputSource(is);
137
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
138
		documentBuilder.setEntityResolver(new LocalEntityResolver());
139
		Document document = documentBuilder.parse(inputSource);
140
		Node root = document.getFirstChild();
141
		is.close();
142
		assertEquals("tree_data", root.getNodeName());
143
		return root;
144
	}
145
146
	public void testTocFragmentServiceXMLSchema() 
147
			throws Exception {
148
		int port = WebappManager.getPort();
149
		URL url = new URL("http", "localhost", port, "/help/vs/service/tocfragment?lang=en");
150
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/tocfragment.xsd");
151
		String schema = schemaUrl.toString();
152
		String uri = url.toString();
153
		String result = SchemaValidator.testXMLSchema(uri, schema);
154
		
155
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
156
	}
157
	
158
	public void testTocFragmentServiceJSONSchema() 
159
			throws Exception {
160
//		fail("Not yet implemented.");
161
	}
162
163
}
(-)help/org/eclipse/ua/tests/help/webapp/service/TocServiceTest.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.help.webapp.service;
12
13
import java.io.InputStream;
14
import java.net.URL;
15
16
import javax.xml.parsers.DocumentBuilder;
17
import javax.xml.parsers.DocumentBuilderFactory;
18
19
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
20
import org.eclipse.help.internal.server.WebappManager;
21
import org.eclipse.ua.tests.help.remote.TocServletTest;
22
import org.w3c.dom.Document;
23
import org.w3c.dom.Node;
24
import org.xml.sax.InputSource;
25
26
public class TocServiceTest extends TocServletTest {
27
28
	protected Node getTocContributions( String locale)
29
			throws Exception {
30
		int port = WebappManager.getPort();
31
		URL url = new URL("http", "localhost", port, "/help/vs/service/toc?lang=" + locale);
32
		InputStream is = url.openStream();
33
		InputSource inputSource = new InputSource(is);
34
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
35
		documentBuilder.setEntityResolver(new LocalEntityResolver());
36
		Document document = documentBuilder.parse(inputSource);
37
		Node root = document.getFirstChild();
38
		is.close();
39
		assertEquals("tocContributions", root.getNodeName());
40
		return root;
41
	}
42
43
	public void testTocServiceXMLSchema() 
44
			throws Exception {
45
		int port = WebappManager.getPort();
46
		URL url = new URL("http", "localhost", port, "/help/vs/service/toc?lang=en");
47
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/xml/toc.xsd");
48
		String schema = schemaUrl.toString();
49
		String uri = url.toString();
50
		String result = SchemaValidator.testXMLSchema(uri, schema);
51
		
52
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);
53
	}
54
	
55
	public void testTocServiceJSONSchema() 
56
			throws Exception {
57
		/*int port = WebappManager.getPort();
58
		URL url = new URL("http", "localhost", port, "/help/vs/service/toc?lang=en");
59
		URL schemaUrl = new URL("http", "localhost", port, "/help/test/schema/json/toc.json");
60
		String schema = schemaUrl.toString();
61
		String uri = url.toString();
62
		String result = SchemaValidator.testJSONSchema(uri, schema);
63
		
64
		assertEquals("URL: \"" + uri + "\" is ", "valid", result);*/
65
//		fail("Not yet implemented.");
66
	}
67
68
}
(-)plugin.xml (+4 lines)
Lines 545-550 Link Here
545
            alias="/titlesearch/script"
545
            alias="/titlesearch/script"
546
            base-name="/script">
546
            base-name="/script">
547
      </resource>
547
      </resource>
548
      <resource
549
            alias="/test"
550
            base-name="/service">
551
      </resource>
548
      <serviceSelector
552
      <serviceSelector
549
            filter="(other.info=org.eclipse.help)">
553
            filter="(other.info=org.eclipse.help)">
550
      </serviceSelector>
554
      </serviceSelector>
(-)service/schema/xml/advancedsearch.xsd (+34 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
	<xs:element name="searchHits">
6
		<xs:complexType mixed="false">
7
			<xs:sequence>
8
				<xs:element ref="hit" minOccurs="0" maxOccurs="unbounded" />   <!-- hits result could be zero -->
9
			</xs:sequence>
10
		</xs:complexType>
11
	</xs:element>
12
13
	<xs:element name="hit" abstract="false" nillable="false">
14
		<xs:complexType mixed="false">
15
			<xs:sequence>
16
				<xs:element name="category" minOccurs="1" maxOccurs="1">  <!-- at least and at most one category element -->
17
					<xs:complexType>
18
						<xs:simpleContent>
19
							<xs:extension base="xs:string">
20
								<xs:attribute name="href" type="xs:string" use="required" />
21
							</xs:extension>
22
						</xs:simpleContent>
23
					</xs:complexType>
24
				</xs:element>
25
				<xs:element name="summary" type="xs:string" minOccurs="1" maxOccurs="1" />
26
			</xs:sequence>
27
			<xs:attribute name="href" type="xs:string" use="required" /> <!-- attribute for hit -->
28
			<xs:attribute name="label" type="xs:string" use="required" /> <!-- attribute for hit -->
29
			<xs:attribute name="isPotentialHit" type="xs:boolean" />  <!-- optional attribute for hit -->
30
			<xs:attribute name="score" type="xs:double" use="required" /> <!-- attribute for hit -->
31
		</xs:complexType>
32
	</xs:element>
33
34
</xs:schema>
(-)service/schema/xml/context.xsd (+22 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
6
	<xs:element name="context">
7
		<xs:complexType mixed="false">
8
			<xs:sequence>
9
				<xs:element name="description" type="xs:string" minOccurs="1" maxOccurs="1" /> <!-- at least and at most one description element -->
10
				<xs:element ref="topic" minOccurs="0" maxOccurs="unbounded" />	
11
			</xs:sequence>
12
			<xs:attribute name="title" type="xs:string" /> <!-- optional attribute for context -->
13
		</xs:complexType>
14
	</xs:element>
15
	
16
	<xs:element name="topic">
17
		<xs:complexType mixed="true">
18
			<xs:attribute name="label" type="xs:string" /> <!-- optional attribute for topic -->
19
			<xs:attribute name="href" type="xs:string" /> <!-- optional attribute for topic -->
20
		</xs:complexType>
21
	</xs:element>
22
</xs:schema>
(-)service/schema/xml/extension.xsd (+31 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
6
	<xs:element name="contentExtensions">
7
		<xs:complexType mixed="false">
8
			<xs:sequence>
9
				<xs:element ref="contribution" minOccurs="0"
10
					maxOccurs="unbounded" />
11
				<xs:element ref="replacement" minOccurs="0"
12
					maxOccurs="unbounded" />
13
			</xs:sequence>
14
		</xs:complexType>
15
	</xs:element>
16
	
17
	<xs:element name="contribution">
18
		<xs:complexType mixed="true">
19
			<xs:attribute name="content" type="xs:string"/> <!-- optional attribute for contribution -->
20
			<xs:attribute name="path" type="xs:string"/> <!-- optional attribute for contribution -->
21
		</xs:complexType>
22
	</xs:element>
23
	
24
	<xs:element name="replacement">
25
		<xs:complexType mixed="true">
26
			<xs:attribute name="content" type="xs:string"/> <!-- optional attribute for replacement -->
27
			<xs:attribute name="path" type="xs:string"/> <!-- optional attribute for replacement -->
28
		</xs:complexType>
29
	</xs:element>
30
	
31
</xs:schema>
(-)service/schema/xml/index.xsd (+68 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
6
<xs:element name="indexContributions">
7
		<xs:complexType mixed="false">
8
			<xs:sequence>
9
				<xs:element ref="indexContribution" minOccurs="0"
10
					maxOccurs="unbounded" />
11
			</xs:sequence>
12
		</xs:complexType>
13
	</xs:element>
14
	
15
	
16
	<xs:element name="indexContribution">
17
		<xs:complexType mixed="false">
18
			<xs:sequence>
19
				<xs:element ref="index" minOccurs="1"	maxOccurs="1" />
20
			</xs:sequence>
21
			<xs:attribute name="id" type="xs:string" use="required"/> <!-- attribute for indexContribution -->
22
			<xs:attribute name="locale" type="xs:string" use="required"/> <!-- attribute for indexContribution -->
23
		</xs:complexType>
24
	</xs:element>
25
	
26
	<xs:element name="index">
27
		<xs:complexType mixed="false">
28
			<xs:sequence>
29
				<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded" />
30
			</xs:sequence>
31
			<xs:attribute name="version" type="xs:string"/> <!-- optional attribute for index -->
32
		</xs:complexType>
33
	</xs:element>
34
	
35
	<xs:element name="entry">
36
		<xs:complexType mixed="false">
37
			<xs:sequence>
38
				<xs:element ref="topic" minOccurs="0" maxOccurs="unbounded" /> <!-- optional attribute for entry -->
39
				<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded" /> <!-- optional attribute for entry -->
40
				<xs:element ref="see" minOccurs="0" maxOccurs="unbounded" /> <!-- optional attribute for entry -->
41
			</xs:sequence>
42
			<xs:attribute name="keyword" type="xs:string" use="required"/> <!-- attribute for entry -->
43
		</xs:complexType>
44
	</xs:element>
45
	
46
	<xs:element name="topic">
47
		<xs:complexType mixed="false">
48
			<xs:attribute name="href" type="xs:string" /> <!-- optional attribute for topic -->
49
			<xs:attribute name="title" type="xs:string" /> <!-- optional attribute for topic -->
50
			<xs:attribute name="label" type="xs:string" /> <!-- optional attribute for topic -->			
51
		</xs:complexType>
52
	</xs:element>
53
	
54
	<xs:element name="see">
55
		<xs:complexType mixed="false">
56
			<xs:sequence>
57
				<xs:element ref="subpath" minOccurs="0" maxOccurs="unbounded" />
58
			</xs:sequence>
59
			<xs:attribute name="keyword" type="xs:string" use="required"/> <!-- attribute for see -->
60
		</xs:complexType>
61
	</xs:element>
62
	
63
	<xs:element name="subpath">
64
		<xs:complexType mixed="false">
65
			<xs:attribute name="keyword" type="xs:string" use="required"/> <!-- attribute for subpath -->
66
		</xs:complexType>
67
	</xs:element>
68
</xs:schema>
(-)service/schema/xml/indexfragment.xsd (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
	<xs:element name="tree_data">
6
		<xs:complexType mixed="false">
7
			<xs:sequence>
8
				<xs:element ref="node" minOccurs="0" maxOccurs="unbounded" />
9
			</xs:sequence>
10
			<xs:attribute name="enableNext" type="xs:boolean" use="required" /> <!-- attribute for tree_data -->
11
			<xs:attribute name="enablePrevious" type="xs:boolean" use="required" /> <!-- attribute for tree_data -->
12
13
		</xs:complexType>
14
	</xs:element>
15
16
	<xs:element name="node" abstract="false" nillable="false">
17
		<xs:complexType mixed="false">
18
			<xs:sequence>
19
				<xs:element ref="node" minOccurs="0" maxOccurs="unbounded" />
20
			</xs:sequence>
21
22
			<xs:attribute name="title" type="xs:string" /> <!-- optional attribute for node -->
23
			<xs:attribute name="id" type="xs:ID" use="required" /> <!-- attribute for node -->
24
			<xs:attribute name="href" type="xs:string"/> <!-- optional attribute for node -->
25
		</xs:complexType>
26
	</xs:element>
27
28
</xs:schema>
(-)service/schema/xml/search.xsd (+25 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
	<xs:element name="searchHits">
6
		<xs:complexType mixed="false">
7
			<xs:sequence>
8
				<xs:element ref="hit" minOccurs="0" maxOccurs="unbounded" />   <!-- hits result could be zero -->
9
			</xs:sequence>
10
		</xs:complexType>
11
	</xs:element>
12
13
	<xs:element name="hit" abstract="false" nillable="false">
14
		<xs:complexType mixed="false">
15
			<xs:sequence>
16
				<xs:element name="summary" type="xs:string" minOccurs="1" maxOccurs="1" />
17
			</xs:sequence>
18
			<xs:attribute name="href" type="xs:string" use="required" /> <!-- attribute for hit -->
19
			<xs:attribute name="label" type="xs:string" use="required" /> <!-- attribute for hit -->
20
			<xs:attribute name="isPotentialHit" type="xs:boolean" />  <!-- optional attribute for hit -->
21
			<xs:attribute name="score" type="xs:double" use="required" /> <!-- attribute for hit -->
22
		</xs:complexType>
23
	</xs:element>
24
25
</xs:schema>
(-)service/schema/xml/toc.xsd (+169 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
6
	<xs:element name="tocContributions">
7
		<xs:complexType mixed="true">
8
			<xs:sequence>
9
				<xs:element ref="tocContribution" minOccurs="0"
10
					maxOccurs="unbounded" />
11
			</xs:sequence>
12
		</xs:complexType>
13
	</xs:element>
14
15
	<xs:element name="tocContribution " abstract="false"
16
		nillable="false">
17
		<xs:complexType mixed="true">
18
			<xs:sequence>
19
				<xs:element ref="toc" minOccurs="0" maxOccurs="unbounded" />
20
				<xs:element ref="extraDocument" minOccurs="0" maxOccurs="unbounded" />
21
			</xs:sequence>
22
			<xs:attribute name="categoryId" type="xs:string" /> <!-- optional attribute for tree_data -->
23
			<xs:attribute name="contributorId" type="xs:string" /> <!-- optional attribute for tree_data -->
24
			<xs:attribute name="id" type="xs:string" use="required" /> <!-- attribute for tree_data -->
25
			<xs:attribute name="locale" type="xs:string" use="required" /> <!-- attribute for tree_data -->
26
			<xs:attribute name="isPrimary" type="xs:boolean" use="required" /> <!-- attribute for tree_data -->
27
		</xs:complexType>
28
	</xs:element>
29
30
	<xs:element name="toc" abstract="false">
31
		<xs:complexType mixed="true">
32
			<xs:sequence>
33
34
35
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" />
36
37
			</xs:sequence>
38
			<xs:attribute name="href" type="xs:string" /> <!-- optional attribute for node -->
39
			<xs:attribute name="label" type="xs:string" use="required" /> <!-- optional attribute for node -->
40
			<xs:attribute name="link_to" type="xs:string" /> <!-- attribute for node -->
41
			<xs:attribute name="topic" type="xs:string" /> <!-- optional attribute for node -->
42
			<xs:attribute name="unknownAttribute" type="xs:string" /> <!-- optional attribute for node -->
43
			<xs:attribute name="sort" type="xs:string" /> <!-- optional attribute for node -->
44
		</xs:complexType>
45
		
46
	</xs:element>
47
48
	<xs:element name="extraDocument" abstract="false" nillable="false">
49
		<xs:complexType mixed="true">
50
			<xs:attribute name="href" type="xs:string"/>
51
		</xs:complexType>
52
	</xs:element>
53
54
	<xs:element name="topic" abstract="false" nillable="false">
55
		<xs:complexType mixed="true">
56
			<xs:sequence>
57
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" />
58
			</xs:sequence>
59
60
			<xs:attribute name="label" type="xs:string" /> <!-- optional attribute for node -->
61
			<xs:attribute name="href" type="xs:string" /> <!-- optional attribute for node -->
62
			<xs:attribute name="unknownAttribute2" type="xs:string" /> <!-- optional attribute for node -->
63
			<xs:attribute name="aegraerg" type="xs:string" /> <!-- optional attribute for node -->
64
			<xs:attribute name="filter" type="xs:string" /> <!-- optional attribute for node -->
65
			<xs:attribute name="sort" type="xs:string" /> <!-- optional attribute for node -->
66
			<xs:attribute name="icon" type="xs:string" /> <!-- optional attribute for node -->
67
		</xs:complexType>
68
	</xs:element>
69
70
	<xs:element name="anchor" abstract="false" nillable="false">
71
		<xs:complexType mixed="true">
72
			<xs:attribute name="id" type="xs:string" /> <!-- optional attribute for node -->
73
		</xs:complexType>
74
	</xs:element>
75
76
	<xs:element name="link" abstract="false" nillable="false">
77
		<xs:complexType mixed="true">
78
			<xs:attribute name="toc" type="xs:string" /> <!-- optional attribute for node -->
79
		</xs:complexType>
80
	</xs:element>
81
82
	<xs:element name="enablement" abstract="false" nillable="false">
83
		<xs:complexType mixed="true">
84
			<xs:sequence>
85
				<xs:element ref="with" minOccurs="0" maxOccurs="unbounded" />
86
				<xs:element ref="test" minOccurs="0" maxOccurs="unbounded" />
87
				<xs:element ref="systemTest" minOccurs="0" maxOccurs="unbounded" />
88
			</xs:sequence>
89
		</xs:complexType>
90
	</xs:element>
91
92
	<xs:element name="test" abstract="false" nillable="false">
93
		<xs:complexType mixed="true">
94
95
			<xs:sequence>
96
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" /> <!-- accept any data -->
97
			</xs:sequence>
98
99
			<xs:attribute name="args" type="xs:string" /> <!-- optional attribute for node -->
100
			<xs:attribute name="property" type="xs:string" /> <!-- attribute for node -->
101
		</xs:complexType>
102
	</xs:element>
103
104
	<xs:element name="with" abstract="false" nillable="false">
105
		<xs:complexType mixed="true">
106
			<xs:sequence>
107
				<xs:element ref="test" minOccurs="0" maxOccurs="unbounded" />
108
			</xs:sequence>
109
			<xs:attribute name="variable" type="xs:string" /> <!-- optional attribute for node -->
110
		</xs:complexType>
111
	</xs:element>
112
113
	<xs:element name="systemTest" abstract="false" nillable="false">
114
		<xs:complexType mixed="true">
115
			<xs:attribute name="property" type="xs:string" /> <!-- optional attribute for node -->
116
			<xs:attribute name="value" type="xs:string" /> <!-- attribute for node -->
117
		</xs:complexType>
118
	</xs:element>
119
120
	<xs:element name="criteria" abstract="false" nillable="false">
121
		<xs:complexType mixed="true">
122
			<xs:attribute name="name" type="xs:string" /> <!-- optional attribute for node -->
123
			<xs:attribute name="value" type="xs:string" /> <!-- attribute for node -->
124
		</xs:complexType>
125
	</xs:element>
126
127
	<xs:element name="blah" abstract="false" nillable="false">
128
		<xs:complexType mixed="true">
129
			<xs:attribute name="value" type="xs:string" /> <!-- attribute for node -->
130
		</xs:complexType>
131
	</xs:element>
132
133
134
	<xs:element name="test2" abstract="false" nillable="false">
135
		<xs:complexType mixed="true">
136
			<xs:sequence>
137
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" />  <!-- accept any data -->
138
			</xs:sequence>
139
			<xs:attribute name="attr" type="xs:string" /> <!-- optional attribute for node -->
140
141
		</xs:complexType>
142
	</xs:element>
143
	
144
	<xs:element name="aergaer" abstract="false" nillable="false">
145
		<xs:complexType mixed="true">
146
			<xs:sequence>
147
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" /> <!-- accept any data -->
148
			</xs:sequence>
149
		</xs:complexType>
150
	</xs:element>
151
	
152
	<xs:element name="gaergr" abstract="false" nillable="false">
153
		<xs:complexType mixed="true">
154
			<xs:sequence>
155
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" /> <!-- accept any data -->
156
			</xs:sequence>
157
		</xs:complexType>
158
	</xs:element>
159
	
160
	<xs:element name="filter" abstract="false" nillable="false">
161
		<xs:complexType mixed="true">
162
			<xs:sequence>
163
				<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" /> <!-- accept any data -->
164
			</xs:sequence>
165
			<xs:attribute name="name" type="xs:string" /> <!-- optional attribute for node -->
166
			<xs:attribute name="value" type="xs:string" /> <!-- optional attribute for node -->
167
		</xs:complexType>
168
	</xs:element>
169
</xs:schema>
(-)service/schema/xml/tocfragment.xsd (+65 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
	elementFormDefault="qualified">
5
	<xs:element name="tree_data">
6
		<xs:complexType mixed="false">
7
			<xs:sequence>
8
				<xs:element name="error" minOccurs="0" />
9
				<xs:element ref="numeric_path" minOccurs="0" maxOccurs="1" />
10
				<xs:element name="node"  minOccurs="0" maxOccurs="unbounded">
11
					<!--
12
						toc node, only difference b/w toc and topic level node is of
13
						is_leaf attrb and order of attrb
14
					-->
15
					<xs:complexType mixed="false">
16
						<xs:sequence>
17
							<xs:element name="node" type="TopicNode" minOccurs="0" maxOccurs="unbounded" />
18
						</xs:sequence>
19
						<xs:attribute name="title" type="xs:string" /> <!-- optional attribute for node -->
20
						<xs:attribute name="id" type="xs:string" use="required" /> <!-- attribute for node -->
21
						<xs:attribute name="href" type="xs:string" use="required" /> <!-- attribute for node -->
22
						<xs:attribute name="openImage" type="xs:string" /> <!-- optional attribute for node -->
23
						<xs:attribute name="closedImage" type="xs:string" />  <!-- optional attribute for node -->
24
						<xs:attribute name="imageAlt" type="xs:string" />  <!-- optional attribute for node -->
25
						<xs:attribute name="image" type="xs:string" default="toc_closed" />  <!-- optional attribute for node -->
26
						<xs:attribute name="is_selected" type="xs:boolean"
27
							default="true" /> <!-- attribute for node -->
28
						<xs:attribute name="is_highlighted" type="xs:boolean"
29
							default="true" /> <!-- attribute for node -->
30
31
					</xs:complexType>
32
				</xs:element>
33
			</xs:sequence>
34
		</xs:complexType>
35
	</xs:element>
36
37
	<xs:element name="numeric_path">
38
		<xs:complexType>
39
			<xs:attribute name="path" type="xs:string" />
40
		</xs:complexType>
41
	</xs:element>
42
43
	
44
		<xs:complexType name="TopicNode" mixed="false">
45
			<xs:sequence>
46
				<xs:element name="node" type="TopicNode" minOccurs="0" maxOccurs="unbounded" />
47
			</xs:sequence>
48
49
			<xs:attribute name="title" type="xs:string" /> <!-- optional attribute for node -->
50
			<xs:attribute name="id" type="xs:string" use="required" /> <!-- attribute for node -->
51
			<xs:attribute name="href" type="xs:string" use="required" /> <!-- attribute for node -->
52
			<xs:attribute name="is_leaf" type="xs:boolean" default="true" /> <!-- attribute for node -->
53
			<xs:attribute name="is_selected" type="xs:boolean"
54
				default="true" /> <!-- attribute for node -->
55
			<xs:attribute name="is_highlighted" type="xs:boolean"
56
				default="true" /> <!-- attribute for node -->
57
			<xs:attribute name="openImage" type="xs:string" /> <!-- optional attribute for node -->
58
			<xs:attribute name="closedImage" type="xs:string" />  <!-- optional attribute for node -->
59
			<xs:attribute name="imageAlt" type="xs:string" />  <!-- optional attribute for node -->
60
			<xs:attribute name="image" type="xs:string" default="toc_closed" />  <!-- optional attribute for node -->
61
62
		</xs:complexType>
63
	
64
65
</xs:schema>

Return to bug 319907