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 223475 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/help/internal/index/Index.java (-5 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 Intel Corporation and others.
2
 * Copyright (c) 2005, 2010 Intel 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 9-14 Link Here
9
 *     Intel Corporation - initial API and implementation
9
 *     Intel Corporation - initial API and implementation
10
 *     IBM Corporation - 122967 [Help] Remote help system
10
 *     IBM Corporation - 122967 [Help] Remote help system
11
 *     IBM Corporation - add support for see / see also
11
 *     IBM Corporation - add support for see / see also
12
 *     IBM Corporation - add support for filtering of the index view
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.help.internal.index;
14
package org.eclipse.help.internal.index;
14
15
Lines 42-59 Link Here
42
43
43
	/**
44
	/**
44
	 * @param see A see element
45
	 * @param see A see element
45
	 * @return true if the keyword of the see matches an entry in the index
46
	 * @return the entry with matching keyword or null 
46
	 */
47
	 */
47
	public boolean containsSeeTarget(IndexSee see) {
48
	public IndexEntry getSeeTarget(IndexSee see) {
48
		if (children == null) getChildren();
49
		if (children == null) getChildren();
49
		String keyword = see.getKeyword();
50
		String keyword = see.getKeyword();
50
		for (Iterator iter = children.iterator(); iter.hasNext();) {
51
		for (Iterator iter = children.iterator(); iter.hasNext();) {
51
			Object next = iter.next();
52
			Object next = iter.next();
52
			if (next instanceof IndexEntry && keyword.equals(((IndexEntry)next).getKeyword())) {
53
			if (next instanceof IndexEntry && keyword.equals(((IndexEntry)next).getKeyword())) {
53
				return true;
54
				return (IndexEntry)next;
54
			}
55
			}
55
		}
56
		}
56
		return false;
57
		return null;
57
	}
58
	}
58
	
59
	
59
}
60
}
(-)src/org/eclipse/help/internal/index/IndexAssembler.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 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 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
 *     IBM Corporation - add support for filtering of the index view
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.help.internal.index;
12
package org.eclipse.help.internal.index;
12
13
Lines 195-201 Link Here
195
			}
196
			}
196
			ancestor = ancestor.getParentElement();
197
			ancestor = ancestor.getParentElement();
197
		}
198
		}
198
		return ((Index)ancestor).containsSeeTarget(see);
199
		return ((Index)ancestor).getSeeTarget(see) != null;
199
	}
200
	}
200
	
201
	
201
	/*
202
	/*
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 7-12 Link Here
7
Bundle-Vendor: %providerName
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.apache.lucene.demo.html;x-internal:=true,
9
Export-Package: org.apache.lucene.demo.html;x-internal:=true,
10
 org.eclipse.help.base,
10
 org.eclipse.help.browser,
11
 org.eclipse.help.browser,
11
 org.eclipse.help.internal.base;
12
 org.eclipse.help.internal.base;
12
  x-friends:="org.eclipse.help.ui,
13
  x-friends:="org.eclipse.help.ui,
Lines 15-20 Link Here
15
   org.eclipse.ui.intro,
16
   org.eclipse.ui.intro,
16
   org.eclipse.ua.tests.doc",
17
   org.eclipse.ua.tests.doc",
17
 org.eclipse.help.internal.base.remote;x-friends:="org.eclipse.ua.tests,org.eclipse.help.webapp,org.eclipse.help.ui",
18
 org.eclipse.help.internal.base.remote;x-friends:="org.eclipse.ua.tests,org.eclipse.help.webapp,org.eclipse.help.ui",
19
 org.eclipse.help.internal.base.scope;x-friends:="org.eclipse.help.webapp,org.eclipse.ua.tests",
18
 org.eclipse.help.internal.base.util;x-friends:="org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.ua.tests",
20
 org.eclipse.help.internal.base.util;x-friends:="org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.ua.tests",
19
 org.eclipse.help.internal.browser;x-friends:="org.eclipse.help.ui,org.eclipse.ua.tests",
21
 org.eclipse.help.internal.browser;x-friends:="org.eclipse.help.ui,org.eclipse.ua.tests",
20
 org.eclipse.help.internal.browser.macosx;x-friends:="org.eclipse.ua.tests",
22
 org.eclipse.help.internal.browser.macosx;x-friends:="org.eclipse.ua.tests",
(-)plugin.xml (+1 lines)
Lines 19-24 Link Here
19
   <extension-point id="luceneSearchParticipants" name="%search_participant_extension_point_name" schema="schema/luceneSearchParticipants.exsd"/>
19
   <extension-point id="luceneSearchParticipants" name="%search_participant_extension_point_name" schema="schema/luceneSearchParticipants.exsd"/>
20
   <extension-point id="server" name="%server_extension_point_name" schema="schema/server.exsd"/>
20
   <extension-point id="server" name="%server_extension_point_name" schema="schema/server.exsd"/>
21
   <extension-point id="searchParticipant" name="Help Search Participant" schema="schema/searchParticipant.exsd"/>
21
   <extension-point id="searchParticipant" name="Help Search Participant" schema="schema/searchParticipant.exsd"/>
22
   <extension-point id="scope" name="Help Scope" schema="schema/scope.exsd"/>
22
23
23
<!-- Stand-alone infocenter application -->
24
<!-- Stand-alone infocenter application -->
24
   <extension
25
   <extension
(-)schema/scope.exsd (+109 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.help.base" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.help.base" id="scope" name="Help Scope"/>
7
      </appInfo>
8
      <documentation>
9
         Support for user defined scopes in the help table of contents, index and search results.
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="1" maxOccurs="unbounded">
21
            <element ref="scope"/>
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="scope">
51
      <annotation>
52
         <documentation>
53
            Defines a scope class which contains methods to determine which UA elements are in scope.
54
         </documentation>
55
      </annotation>
56
      <complexType>
57
         <attribute name="class" type="string" use="required">
58
            <annotation>
59
               <documentation>
60
                  
61
               </documentation>
62
               <appInfo>
63
                  <meta.attribute kind="java"/>
64
               </appInfo>
65
            </annotation>
66
         </attribute>
67
         <attribute name="id" type="string" use="required">
68
            <annotation>
69
               <documentation>
70
                  An id for this scope which must be unique among scope ids.
71
               </documentation>
72
            </annotation>
73
         </attribute>
74
      </complexType>
75
   </element>
76
77
   <annotation>
78
      <appInfo>
79
         <meta.section type="since"/>
80
      </appInfo>
81
      <documentation>
82
         3.5
83
      </documentation>
84
   </annotation>
85
86
87
   <annotation>
88
      <appInfo>
89
         <meta.section type="apiinfo"/>
90
      </appInfo>
91
      <documentation>
92
         A class which implements AbstractScope contains functions to determine which elemements should be displayed when the scope is active. The help UI allows the user to specify any of the predefiend scopes.
93
      </documentation>
94
   </annotation>
95
96
97
   <annotation>
98
      <appInfo>
99
         <meta.section type="copyright"/>
100
      </appInfo>
101
      <documentation>
102
         Copyright (c) 2010 IBM Corporation and others.&lt;br&gt;
103
All rights reserved. This program and the accompanying materials are made 
104
available under the terms of the Eclipse Public License v1.0 which accompanies 
105
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;
106
      </documentation>
107
   </annotation>
108
109
</schema>
(-)src/org/eclipse/help/base/AbstractHelpScope.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.base;
13
14
import java.util.Locale;
15
import org.eclipse.help.IIndexEntry;
16
import org.eclipse.help.IIndexSee;
17
import org.eclipse.help.IToc;
18
import org.eclipse.help.ITopic;
19
import org.eclipse.help.IUAElement;
20
import org.eclipse.help.internal.base.scope.ScopeUtils;
21
22
/**
23
 * Represents a scope which can be used to specify which topics are shown in the
24
 * table of contents and which entries will show in the index. The inScope() functions
25
 * are used by the help system to determine which elements to show. Both the table of
26
 * contents and index are trees and the help system reads these trees starting with the 
27
 * root and working down through the children. 
28
 * 
29
 * @since 3.5
30
 */
31
32
public abstract class AbstractHelpScope {
33
	
34
	/**
35
	 * Determine whether a table of contents is in scope
36
	 */
37
	public abstract boolean inScope(IToc toc);
38
	
39
	/**
40
	 * Determine whether a topic is in scope
41
	 */
42
	public abstract boolean inScope(ITopic topic);
43
44
	/**
45
	 * Determine whether an index entry is in scope
46
	 */
47
	public abstract boolean inScope(IIndexEntry entry);
48
	
49
	/**
50
	 * a single information center instance can display content in multiple locales.
51
	 * This function exists to provide a name for a specific locale.
52
	 * @param locale a string representing the locale used for the UI
53
	 * @return a name for this scope appropriate for the locale which 
54
	 * will be used in the scope selection dialog. It is recommended that 
55
	 * the name be no more than 20 characters long.
56
	 */
57
	public abstract String getName(Locale locale);
58
	
59
	/**
60
     * In the default implementation of this method an IndexSee element is in scope
61
     * if it's target is in scope. May be overridden to exclude more IndexSee elements 
62
     * from the scope
63
	 * @param see
64
	 * @return
65
	 */
66
	public boolean inScope(IIndexSee see) {
67
		return hasInScopeChildren(see);
68
	}
69
	
70
	/**
71
	 * The help system can build the trees faster if it knows that an out of
72
	 * scope element cannot have child elements which are in scope. This 
73
	 * is called a hierarchical scope. If an out of scope element can have
74
	 * in scope children this function should be overridden and the help 
75
	 * system will perform a deeper search.
76
	 */
77
	public boolean isHierarchicalScope() {
78
		return true;
79
	}
80
	
81
	/**
82
	 * Convenience method to make it easier to write subclasses
83
	 * In the case of an IIndexSee element this method tests 
84
	 * to see if the target is in scope. For all other elements
85
	 * it tests all children and if this is not a hierarchical scope 
86
	 * all descendants are tested.
87
	 * @param element An element which may have children
88
	 * @return true if at least one child is in scope
89
	 */
90
	public final boolean hasInScopeChildren(IUAElement element) {
91
		return ScopeUtils.hasInScopeChildren(element, this);
92
	}
93
		
94
}
95
(-)src/org/eclipse/help/internal/base/scope/EnablementScope.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.Locale;
15
16
import org.eclipse.help.IIndexEntry;
17
import org.eclipse.help.IIndexSee;
18
import org.eclipse.help.IToc;
19
import org.eclipse.help.ITopic;
20
import org.eclipse.help.base.AbstractHelpScope;
21
import org.eclipse.help.internal.base.HelpBasePlugin;
22
23
public class EnablementScope extends AbstractHelpScope {
24
25
	public boolean inScope(IToc toc) {
26
		return HelpBasePlugin.getActivitySupport().isEnabled(toc.getHref());
27
	}
28
29
	public boolean inScope(ITopic topic) {
30
		return true;
31
	}
32
33
	public boolean inScope(IIndexEntry entry) {
34
		return true;
35
	}
36
37
	public boolean inScope(IIndexSee see) {
38
		return true;
39
	}
40
	
41
	public String getName(Locale locale) {
42
		return null;
43
	}
44
45
}
(-)src/org/eclipse/help/internal/base/scope/FilterScope.java (+59 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.Locale;
15
16
import org.eclipse.help.IIndexEntry;
17
import org.eclipse.help.IIndexSee;
18
import org.eclipse.help.IToc;
19
import org.eclipse.help.ITopic;
20
import org.eclipse.help.base.AbstractHelpScope;
21
import org.eclipse.help.internal.base.HelpEvaluationContext;
22
23
/**
24
 * A scope which tests for content filtering
25
 */
26
27
public class FilterScope extends AbstractHelpScope {
28
29
	public boolean inScope(IToc toc) {
30
		if (!toc.isEnabled(HelpEvaluationContext.getContext())) {
31
			return false;
32
		}
33
		return hasInScopeChildren(toc);
34
	}
35
36
	public boolean inScope(ITopic topic) {
37
		if (!topic.isEnabled(HelpEvaluationContext.getContext())) {
38
			return false;
39
		}
40
		if (topic.getHref() != null) {
41
			return true;
42
		}
43
		return ScopeUtils.hasInScopeDescendent(topic, this);
44
	}
45
46
	public boolean inScope(IIndexEntry entry) {
47
		return entry.isEnabled(HelpEvaluationContext.getContext());
48
	}
49
50
	public boolean inScope(IIndexSee see) {
51
		return see.isEnabled(HelpEvaluationContext.getContext());
52
	}
53
54
	public String getName(Locale locale) {
55
		// TODO Auto-generated method stub
56
		return null;
57
	}
58
59
}
(-)src/org/eclipse/help/internal/base/scope/IntersectionScope.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.Locale;
15
16
import org.eclipse.help.IIndexEntry;
17
import org.eclipse.help.IIndexSee;
18
import org.eclipse.help.IToc;
19
import org.eclipse.help.ITopic;
20
import org.eclipse.help.base.AbstractHelpScope;
21
22
/**
23
 * A scope which represents the intersection of two or more other scopes
24
 * An element is in scope only if it is included in every scope passed to the constructor
25
 */
26
27
public class IntersectionScope extends AbstractHelpScope {
28
	
29
	AbstractHelpScope[] scopes;
30
	
31
	public IntersectionScope(AbstractHelpScope[] scopes) {
32
		this.scopes = scopes;
33
	}
34
35
	public boolean inScope(IToc toc) {
36
		for (int scope = 0; scope < scopes.length; scope ++) {
37
			if (!scopes[scope].inScope(toc)) {
38
				return false;
39
			}
40
		}
41
		return true;
42
	}
43
44
	public boolean inScope(ITopic topic) {
45
		for (int scope = 0; scope < scopes.length; scope ++) {
46
			if (!scopes[scope].inScope(topic)) {
47
				return false;
48
			}
49
		}
50
		return true;
51
	}
52
53
	public boolean inScope(IIndexEntry entry) {
54
		for (int scope = 0; scope < scopes.length; scope ++) {
55
			if (!scopes[scope].inScope(entry)) {
56
				return false;
57
			}
58
		}
59
		return true;
60
	}
61
62
	public boolean inScope(IIndexSee see) {
63
		for (int scope = 0; scope < scopes.length; scope ++) {
64
			if (!scopes[scope].inScope(see)) {
65
				return false;
66
			}
67
		}
68
		return true;
69
	}
70
71
	public String getName(Locale locale) {
72
		return null;
73
	}
74
	
75
	public boolean isHierarchicalScope() {
76
		for (int scope = 0; scope < scopes.length; scope ++) {
77
			if (!scopes[scope].isHierarchicalScope()) {
78
				return false;
79
			}
80
		}
81
		return true;
82
	}
83
84
}
(-)src/org/eclipse/help/internal/base/scope/ScopeHandle.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import org.eclipse.help.base.AbstractHelpScope;
15
16
public class ScopeHandle {
17
	
18
	private AbstractHelpScope scope;	
19
	private String id;
20
	
21
	public ScopeHandle( String id, AbstractHelpScope scope) {
22
		this.id = id;
23
		this.scope = scope;
24
	}
25
26
	public AbstractHelpScope getScope() {
27
		return scope;
28
	}
29
30
	public String getId() {
31
		return id;
32
	}
33
34
}
(-)src/org/eclipse/help/internal/base/scope/ScopeRegistry.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IExtensionRegistry;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.help.base.AbstractHelpScope;
23
import org.eclipse.help.internal.base.HelpBasePlugin;
24
25
public class ScopeRegistry {
26
27
	public static final String SCOPE_XP_NAME = "org.eclipse.help.base.scope"; //$NON-NLS-1$
28
29
	private static List scopes = null;
30
	
31
	private static ScopeRegistry instance;
32
33
	private boolean initialized = false;
34
	
35
36
	private ScopeRegistry() {
37
	}
38
	
39
	public static ScopeRegistry getInstance() {
40
		if (instance == null) {
41
			instance = new ScopeRegistry();
42
		}
43
		return instance;
44
	}
45
	
46
	public AbstractHelpScope getScope(String id) {
47
		if (id == null) {
48
			return new UniversalScope();
49
		}
50
		readScopes();
51
		// Lookup in scope registry
52
		for (Iterator iter = scopes.iterator(); iter.hasNext();) {
53
			ScopeHandle handle = (ScopeHandle) iter.next();
54
			if (id.equals(handle.getId())) {
55
				return handle.getScope();
56
			}
57
		}
58
		return null;
59
	}
60
61
	synchronized private void readScopes() {
62
		if (initialized ) {
63
			return;
64
		}	
65
		scopes = new ArrayList();
66
		IExtensionRegistry registry = Platform.getExtensionRegistry();
67
		IConfigurationElement[] elements = registry
68
				.getConfigurationElementsFor(SCOPE_XP_NAME);
69
		for (int i = 0; i < elements.length; i++) {
70
71
			Object obj = null;
72
			try {
73
				obj = elements[i].createExecutableExtension("class"); //$NON-NLS-1$
74
			} catch (CoreException e) {
75
				HelpBasePlugin.logError("Create extension failed:[" //$NON-NLS-1$
76
						+ SCOPE_XP_NAME + "].", e); //$NON-NLS-1$
77
			}
78
			if (obj instanceof AbstractHelpScope) {
79
				String id = elements[i].getAttribute("id"); //$NON-NLS-1$
80
				ScopeHandle filter = new ScopeHandle(id, (AbstractHelpScope) obj);
81
				scopes.add(filter);
82
			}
83
		}
84
		initialized = true;
85
	}
86
87
}
(-)src/org/eclipse/help/internal/base/scope/ScopeUtils.java (+188 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.help.IIndexEntry;
18
import org.eclipse.help.IIndexEntry2;
19
import org.eclipse.help.IIndexSee;
20
import org.eclipse.help.IToc;
21
import org.eclipse.help.ITopic;
22
import org.eclipse.help.IUAElement;
23
import org.eclipse.help.base.AbstractHelpScope;
24
import org.eclipse.help.internal.UAElement;
25
import org.eclipse.help.internal.index.Index;
26
import org.eclipse.help.internal.index.IndexSee;
27
28
/**
29
 * Utilities to test for enabled topics, index entries etc. 
30
 */
31
32
public class ScopeUtils {
33
	
34
35
	/*
36
	 * Function to determine whether a topic should be shown in the toc.
37
	 * For hierarchical scopes the element itself must be in scope.
38
	 * For non hierarchical scopes if any child is in scope the element should show.
39
	 */
40
	public static boolean showInTree(IToc toc, AbstractHelpScope scope) {
41
		return scope.inScope(toc) || 
42
		   (!scope.isHierarchicalScope() && hasInScopeDescendent(toc, scope));
43
	}
44
45
	/*
46
	 * Function to determine whether a topic should be shown in the toc.
47
	 * For hierarchical scopes the element itself must be in scope.
48
	 * For non hierarchical scopes if any child is in scope the element should show.
49
	 */
50
	public static boolean showInTree(ITopic topic, AbstractHelpScope scope) {
51
		return scope.inScope(topic) || 
52
		   (!scope.isHierarchicalScope() && hasInScopeDescendent(topic, scope));
53
	}
54
	
55
	/*
56
	 * Function to determine whether an entry should be shown in the index.
57
	 * For hierarchical scopes the element itself must be in scope.
58
	 * For non hierarchical scopes if any child is in scope the element should show.
59
	 */
60
	public static boolean showInTree(IIndexEntry entry, AbstractHelpScope scope) {
61
		return scope.inScope(entry) || 
62
		   (!scope.isHierarchicalScope() && hasInScopeDescendent(entry, scope));
63
	}
64
65
	public static boolean hasInScopeDescendent(ITopic topic, AbstractHelpScope scope) {
66
		ITopic[] subtopics = topic.getSubtopics();
67
		for (int i = 0; i < subtopics.length; i++) {
68
			if (showInTree(subtopics[i], scope)) {  
69
				return true;
70
			}
71
		}
72
		return false;
73
    }
74
	
75
	public static boolean hasInScopeDescendent(IToc toc, AbstractHelpScope scope) {
76
		ITopic[] topics = toc.getTopics();
77
		for (int i = 0; i < topics.length; i++) {
78
			if (showInTree(topics[i], scope)) {  
79
				return true;
80
			}
81
		}
82
		return false;
83
    }
84
	
85
	public static boolean hasInScopeDescendent(IIndexEntry entry,
86
			AbstractHelpScope scope) {
87
		ITopic[] topics = entry.getTopics();
88
		for (int t = 0; t < topics.length; t++) {
89
			if (showInTree(topics[t], scope)) {
90
				return true;
91
			}
92
		}
93
		IIndexEntry[] entries = entry.getSubentries();
94
		for (int e = 0; e < entries.length; e++) {
95
			if (showInTree(entries[e], scope)) {
96
				return true;
97
			}
98
		}
99
		if (entry instanceof IIndexEntry2) {
100
			IIndexSee[] sees = ((IIndexEntry2)entry).getSees();
101
			for (int s = 0; s < sees.length; s++) {
102
				if (scope.inScope(sees[s]) && hasInScopeTarget(sees[s], scope)) {
103
					return true;
104
				}
105
			}
106
		}
107
		return false;
108
	}
109
	
110
	public static boolean hasInScopeTarget(IIndexSee see, AbstractHelpScope scope) {
111
		if (see instanceof IndexSee) {
112
			IndexSee indexSee = (IndexSee)see;
113
			UAElement ancestor = indexSee.getParentElement();
114
			while (!(ancestor instanceof Index)) {
115
				if (ancestor == null) {
116
					return true;
117
				}
118
				ancestor = ancestor.getParentElement();
119
			}
120
			IIndexEntry target = ((Index)ancestor).getSeeTarget(indexSee);
121
			if (target == null) {
122
				return false;
123
			}
124
			return scope.inScope(target) || hasInScopeDescendent(target, scope);	
125
		}
126
		return false;
127
	}
128
129
	/**
130
	 * Filter out any disabled entries from an array
131
	 * @param entries an array of entries
132
	 * @param scope 
133
	 * @return an array containing only those entries which are enabled
134
	 */
135
	public static IIndexEntry[] inScopeEntries(IIndexEntry[] entries, AbstractHelpScope scope) {
136
		for (int i=0;i<entries.length;++i) {
137
			if (!scope.inScope(entries[i])) {
138
				List list = new ArrayList(entries.length);
139
				for (int j=0;j<entries.length;++j) {
140
					if (j < i || scope.inScope(entries[j])) {
141
						list.add(entries[j]);
142
					}
143
				}
144
				return (IIndexEntry[])list.toArray(new IIndexEntry[list.size()]);
145
			}
146
		}
147
		return entries;
148
	}
149
150
	/**
151
	 * Filter out any disabled topics from an array
152
	 * @param topics an array of topics
153
	 * @param scope 
154
	 * @return an array containing only those topics which are enabled
155
	 */
156
	public static ITopic[] inScopeTopics(ITopic[] topics, AbstractHelpScope scope) {
157
		for (int i=0;i<topics.length;++i) {
158
			if (!scope.inScope(topics[i])) {
159
				List list = new ArrayList(topics.length);
160
				for (int j=0;j<topics.length;++j) {
161
					if (j < i || scope.inScope(topics[j])) {
162
						list.add(topics[j]);
163
					}
164
				}
165
				return (ITopic[])list.toArray(new ITopic[list.size()]);
166
			}
167
		}
168
		return topics;
169
	}
170
171
	public static boolean hasInScopeChildren(IUAElement element,
172
			AbstractHelpScope scope) {
173
		if (element instanceof IToc) {
174
			return hasInScopeDescendent((IToc)element, scope);
175
		}
176
		if (element instanceof ITopic) {
177
			return hasInScopeDescendent((ITopic)element, scope);
178
		}
179
		if (element instanceof IIndexEntry) {
180
			return hasInScopeDescendent((IIndexEntry) element, scope);
181
		}
182
		if (element instanceof IIndexSee) {
183
			return hasInScopeTarget((IIndexSee) element, scope);
184
		}
185
		return false;
186
	}
187
188
}
(-)src/org/eclipse/help/internal/base/scope/UniversalScope.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.Locale;
15
16
import org.eclipse.help.IIndexEntry;
17
import org.eclipse.help.IIndexSee;
18
import org.eclipse.help.IToc;
19
import org.eclipse.help.ITopic;
20
import org.eclipse.help.base.AbstractHelpScope;
21
22
public class UniversalScope extends AbstractHelpScope {
23
24
	public boolean inScope(IToc toc) {
25
		return true;
26
	}
27
28
	public boolean inScope(ITopic topic) {
29
		return true;
30
	}
31
32
	public boolean inScope(IIndexEntry entry) {
33
		return true;
34
	}
35
36
	public boolean inScope(IIndexSee see) {
37
		return true;
38
	}
39
40
	public String getName(Locale locale) {
41
		// TODO Auto-generated method stub
42
		return null;
43
	}
44
45
}
(-)src/org/eclipse/help/internal/base/scope/WorkingSetScope.java (+119 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.base.scope;
13
14
import java.util.HashSet;
15
import java.util.Locale;
16
import java.util.Set;
17
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.help.IIndexEntry;
20
import org.eclipse.help.IIndexSee;
21
import org.eclipse.help.IToc;
22
import org.eclipse.help.ITopic;
23
import org.eclipse.help.base.AbstractHelpScope;
24
import org.eclipse.help.internal.UAElement;
25
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
26
import org.eclipse.help.internal.workingset.IHelpWorkingSetManager;
27
import org.eclipse.help.internal.workingset.WorkingSet;
28
29
public class WorkingSetScope extends AbstractHelpScope {
30
	
31
	IHelpWorkingSetManager wSetManager;
32
	private WorkingSet workingSet;
33
	AdaptableHelpResource[] elements;
34
	
35
	public WorkingSetScope(String scope, IHelpWorkingSetManager manager) {
36
		wSetManager = manager;
37
		workingSet = wSetManager.getWorkingSet(scope); 
38
		elements = workingSet.getElements();
39
		wSetManager = manager;
40
	}
41
42
	public boolean inScope(IToc toc) {
43
		for (int i = 0; i < elements.length; i++) {	
44
			for (AdaptableHelpResource adaptable = elements[i]; adaptable != null; ) {
45
				Object itoc = adaptable.getAdapter(IToc.class); 
46
				if (toc == itoc) {
47
					return true;	
48
				}
49
				IAdaptable parent= adaptable.getParent();
50
				if (parent instanceof AdaptableHelpResource) {
51
					adaptable = (AdaptableHelpResource) parent;
52
				} else {
53
				    adaptable = null;
54
				}
55
			}		
56
		}
57
		return false;
58
	}
59
60
	public boolean inScope(ITopic topic) {
61
		Set topics = new HashSet();
62
		IToc toc = null;
63
		topics.add(topic);
64
		if (topic instanceof UAElement) {
65
			for (UAElement uae = (UAElement) topic; uae != null; ) {
66
				if (uae instanceof IToc)  {
67
					toc = (IToc) uae;
68
					uae = null;
69
				} else if (uae instanceof IIndexEntry) {
70
					for (int i = 0; i < elements.length; i++) {
71
						AdaptableHelpResource adaptable = elements[i];
72
						if (adaptable.getTopic(topic.getHref()) != null) {
73
							return true;
74
						}
75
					}
76
					return false;
77
				} else {					
78
					if (uae instanceof ITopic) {
79
					    topics.add(uae);
80
					}
81
					uae = uae.getParentElement();
82
				}
83
			}
84
		}
85
		for (int i = 0; i < elements.length; i++) {
86
			AdaptableHelpResource adaptable = elements[i];
87
			if (toc != null) {
88
				Object itoc = adaptable.getAdapter(IToc.class);
89
				if (toc == itoc) {
90
					return true;
91
				}
92
			}
93
			Object itopic = adaptable.getAdapter(ITopic.class);
94
			if (topic != null && topics.contains(itopic)) {
95
				return true;
96
			}
97
			IAdaptable parent = adaptable.getParent();
98
			if (parent instanceof AdaptableHelpResource) {
99
				adaptable = (AdaptableHelpResource) parent;
100
			} else {
101
				adaptable = null;
102
			}
103
		}
104
		return false;
105
	}
106
107
	public boolean inScope(IIndexEntry entry) {
108
		return hasInScopeChildren(entry);
109
	}
110
111
	public boolean inScope(IIndexSee see) {
112
		return hasInScopeChildren(see);
113
	}
114
115
	public String getName(Locale locale) {
116
		return null;
117
	}
118
119
}
(-)src/org/eclipse/help/internal/search/SearchResults.java (-5 / +35 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 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 16-21 Link Here
16
16
17
import org.eclipse.help.IToc;
17
import org.eclipse.help.IToc;
18
import org.eclipse.help.ITopic;
18
import org.eclipse.help.ITopic;
19
import org.eclipse.help.base.AbstractHelpScope;
19
import org.eclipse.help.internal.HelpPlugin;
20
import org.eclipse.help.internal.HelpPlugin;
20
import org.eclipse.help.internal.util.URLCoder;
21
import org.eclipse.help.internal.util.URLCoder;
21
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
22
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
Lines 34-39 Link Here
34
	private ArrayList scopes;
35
	private ArrayList scopes;
35
	private int maxHits;
36
	private int maxHits;
36
	private String locale;
37
	private String locale;
38
	private AbstractHelpScope filter;
37
	protected SearchHit[] searchHits = new SearchHit[0];
39
	protected SearchHit[] searchHits = new SearchHit[0];
38
	/**
40
	/**
39
	 * Constructor
41
	 * Constructor
Lines 46-51 Link Here
46
		this.locale = locale;
48
		this.locale = locale;
47
		this.scopes = getScopes(workingSets);
49
		this.scopes = getScopes(workingSets);
48
	}
50
	}
51
	
52
	public void setFilter(AbstractHelpScope filter) {
53
		this.filter = filter;
54
	}
49
55
50
	/* (non-Javadoc)
56
	/* (non-Javadoc)
51
	 * @see org.eclipse.help.internal.search.ISearchHitCollector#addHits(List, String)
57
	 * @see org.eclipse.help.internal.search.ISearchHitCollector#addHits(List, String)
Lines 65-70 Link Here
65
			// the scope for the topic, if any
71
			// the scope for the topic, if any
66
			if (scopes == null) {
72
			if (scopes == null) {
67
				toc = getTocForTopic(href, locale);
73
				toc = getTocForTopic(href, locale);
74
				if (toc == null) {
75
					continue;
76
				}
68
			} else {
77
			} else {
69
				scope = getScopeForTopic(href);
78
				scope = getScopeForTopic(href);
70
				if (scope == null) {
79
				if (scope == null) {
Lines 123-130 Link Here
123
	private AdaptableHelpResource getScopeForTopic(String href) {
132
	private AdaptableHelpResource getScopeForTopic(String href) {
124
		for (int i = 0; i < scopes.size(); i++) {
133
		for (int i = 0; i < scopes.size(); i++) {
125
			AdaptableHelpResource scope = (AdaptableHelpResource) scopes.get(i);
134
			AdaptableHelpResource scope = (AdaptableHelpResource) scopes.get(i);
126
			if (scope.getTopic(href) != null)
135
			ITopic inScopeTopic = scope.getTopic(href);
127
				return scope;
136
			if (inScopeTopic != null)
137
				if (filter == null || filter.inScope(inScopeTopic)) {
138
				    return scope;
139
				}
128
		
140
		
129
			// add root toc's extradir topics to search scope
141
			// add root toc's extradir topics to search scope
130
			IToc tocRoot = getTocForScope(scope, locale);
142
			IToc tocRoot = getTocForScope(scope, locale);
Lines 133-138 Link Here
133
				if (toc != null) {
145
				if (toc != null) {
134
					String owningTocHref = toc.getHref();
146
					String owningTocHref = toc.getHref();
135
					if (owningTocHref == tocRoot.getHref()) {
147
					if (owningTocHref == tocRoot.getHref()) {
148
						if (filter == null || filter.inScope(inScopeTopic)) {
149
						    return scope;
150
						}
136
						return scope;
151
						return scope;
137
					}
152
					}
138
				}
153
				}
Lines 176-185 Link Here
176
	 */
191
	 */
177
	private IToc getTocForTopic(String href, String locale) {
192
	private IToc getTocForTopic(String href, String locale) {
178
		IToc[] tocs = HelpPlugin.getTocManager().getTocs(locale);
193
		IToc[] tocs = HelpPlugin.getTocManager().getTocs(locale);
194
		boolean foundInToc = false;
179
		for (int i = 0; i < tocs.length; i++) {
195
		for (int i = 0; i < tocs.length; i++) {
180
			ITopic topic = tocs[i].getTopic(href);
196
			ITopic topic = tocs[i].getTopic(href);
181
			if (topic != null)
197
			if (topic != null) {
182
				return tocs[i];
198
				foundInToc = true;
199
				if (filter == null || filter.inScope(topic)) {
200
				    return tocs[i];
201
				}
202
			} 
203
		}
204
		if (!foundInToc) {
205
			// test to pick up files in extradirs
206
			IToc toc = HelpPlugin.getTocManager().getOwningToc(href);
207
			if (toc != null) {
208
				foundInToc = true;
209
				if (filter == null || filter.inScope(toc)) {
210
				    return toc;
211
				}
212
			}
183
		}
213
		}
184
		return null;
214
		return null;
185
	}
215
	}
(-)advanced/index.jsp (-1 / +3 lines)
Lines 1-5 Link Here
1
<%--
1
<%--
2
 Copyright (c) 2000, 2009 IBM Corporation and others.
2
 Copyright (c) 2000, 2010 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 18-23 Link Here
18
		cookieTest.setMaxAge(365*24*60*60);
18
		cookieTest.setMaxAge(365*24*60*60);
19
		response.addCookie(cookieTest);
19
		response.addCookie(cookieTest);
20
	}
20
	}
21
	// Read the scope parameter
22
	RequestScope.getScopeParameter(request, response, false);
21
%>
23
%>
22
24
23
<html>
25
<html>
(-)advanced/indexView.js (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 Intel Corporation and others.
2
 * Copyright (c) 2005, 2010 Intel 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 9-14 Link Here
9
 *     Intel Corporation - initial API and implementation
9
 *     Intel Corporation - initial API and implementation
10
 *     IBM Corporation 2006, refactored index view into a single frame
10
 *     IBM Corporation 2006, refactored index view into a single frame
11
 *     IBM Corporation 2007, allow partial loading of index
11
 *     IBM Corporation 2007, allow partial loading of index
12
 *     IBM Corporation 2010, add filtering in toc and index view
12
 *******************************************************************************/
13
 *******************************************************************************/
13
 
14
 
14
var isMozilla = navigator.userAgent.indexOf("Mozilla") != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;
15
var isMozilla = navigator.userAgent.indexOf("Mozilla") != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;
Lines 204-210 Link Here
204
}
205
}
205
206
206
function makeNodeRequest(parameters) {
207
function makeNodeRequest(parameters) {
207
    var href = "../indexfragment" + parameters;
208
    var href = "indexfragment" + parameters;
208
    var callback = function(xml) { updateIndexTree(xml);}; 
209
    var callback = function(xml) { updateIndexTree(xml);}; 
209
    var errorCallback = function() { 
210
    var errorCallback = function() { 
210
        // alert("ajax error"); 
211
        // alert("ajax error"); 
(-)advanced/tocTree.js (-14 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 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 12-25 Link Here
12
// Tree code specific to the help toc
12
// Tree code specific to the help toc
13
13
14
var showExpanders = true;
14
var showExpanders = true;
15
var ajaxPrefix = "../tocfragment"; 
15
var ajaxPath = "tocfragment"; 
16
var pendingSynchTopic = null; // Should the toc be synchronized when the view becomes visible
16
var pendingSynchTopic = null; // Should the toc be synchronized when the view becomes visible
17
17
18
// The default value of ajaxPrefix works from jsp files but needs to be overridden to 
18
// The default value of ajaxPath works from jsp files but needs to be overridden to 
19
// a non relative path to work from scripts launched from any page
19
// a non relative path to work from scripts launched from any page
20
20
21
function setAjaxPrefix(prefix) {
21
function setAjaxPrefix(prefix) {
22
    ajaxPrefix = prefix;
22
    ajaxPath = prefix + "/tocfragment";
23
}
23
}
24
24
25
/*
25
/*
Lines 174-184 Link Here
174
174
175
function makeNodeRequest(parameters) {
175
function makeNodeRequest(parameters) {
176
    var href;
176
    var href;
177
    if (ajaxPrefix) {
177
    href = ajaxPath +parameters; 
178
        href = ajaxPrefix + "/tocfragment" +parameters; 
179
    } else {
180
        href = "../tocfragment" + parameters;
181
    }
182
    var callback = function(xml) { updateTocTree(xml);}; 
178
    var callback = function(xml) { updateTocTree(xml);}; 
183
    var errorCallback = function() { 
179
    var errorCallback = function() { 
184
        // alert("ajax error"); 
180
        // alert("ajax error"); 
Lines 188-198 Link Here
188
184
189
function makeShowInTocRequest(parameters) {
185
function makeShowInTocRequest(parameters) {
190
    var href;
186
    var href;
191
    if (ajaxPrefix) {
187
    href = ajaxPath +parameters; 
192
        href = ajaxPrefix + "/tocfragment" +parameters; 
193
    } else {
194
        href = "../tocfragment" + parameters;
195
    }
196
    var callback = function(xml) { showInToc(xml);}; 
188
    var callback = function(xml) { showInToc(xml);}; 
197
    var errorCallback = function() { 
189
    var errorCallback = function() { 
198
        // alert("ajax error"); 
190
        // alert("ajax error"); 
(-)advanced/tocView.jsp (-3 / +3 lines)
Lines 1-5 Link Here
1
<%--
1
<%--
2
 Copyright (c) 2000, 2009 IBM Corporation and others.
2
 Copyright (c) 2000, 2010 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 72-80 Link Here
72
    setRootAccessibility();
72
    setRootAccessibility();
73
	loadChildren(null);
73
	loadChildren(null);
74
	
74
	
75
	// Set prefix for AJAX calls by removing advanced/tocView.jsp from location
75
	// Set prefix for AJAX calls by removing tocView.jsp from location
76
	var locationHref = window.location.href;
76
	var locationHref = window.location.href;
77
    var slashAdvanced = locationHref.lastIndexOf('/advanced');
77
    var slashAdvanced = locationHref.lastIndexOf('/tocView.jsp');
78
    if(slashAdvanced > 0) {
78
    if(slashAdvanced > 0) {
79
	    setAjaxPrefix(locationHref.substr(0, slashAdvanced));
79
	    setAjaxPrefix(locationHref.substr(0, slashAdvanced));
80
	}
80
	}
(-)plugin.xml (-2 / +2 lines)
Lines 83-89 Link Here
83
            httpcontextId="help">
83
            httpcontextId="help">
84
      </servlet>
84
      </servlet>
85
      <servlet
85
      <servlet
86
            alias="/tocfragment"
86
            alias="/advanced/tocfragment"
87
            class="org.eclipse.help.internal.webapp.servlet.TocFragmentServlet"
87
            class="org.eclipse.help.internal.webapp.servlet.TocFragmentServlet"
88
            httpcontextId="help">
88
            httpcontextId="help">
89
      </servlet>
89
      </servlet>
Lines 93-99 Link Here
93
            httpcontextId="help">
93
            httpcontextId="help">
94
      </servlet>
94
      </servlet>
95
      <servlet
95
      <servlet
96
            alias="/indexfragment"
96
            alias="/advanced/indexfragment"
97
            class="org.eclipse.help.internal.webapp.servlet.IndexFragmentServlet"
97
            class="org.eclipse.help.internal.webapp.servlet.IndexFragmentServlet"
98
            httpcontextId="help">
98
            httpcontextId="help">
99
      </servlet>
99
      </servlet>
(-)src/org/eclipse/help/internal/webapp/data/PrintData.java (-5 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 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 33-40 Link Here
33
import org.eclipse.help.HelpSystem;
33
import org.eclipse.help.HelpSystem;
34
import org.eclipse.help.IToc;
34
import org.eclipse.help.IToc;
35
import org.eclipse.help.ITopic;
35
import org.eclipse.help.ITopic;
36
import org.eclipse.help.base.AbstractHelpScope;
36
import org.eclipse.help.internal.HelpPlugin;
37
import org.eclipse.help.internal.HelpPlugin;
37
import org.eclipse.help.internal.base.BaseHelpSystem;
38
import org.eclipse.help.internal.base.BaseHelpSystem;
39
import org.eclipse.help.internal.base.scope.ScopeUtils;
38
import org.eclipse.help.internal.search.HTMLDocParser;
40
import org.eclipse.help.internal.search.HTMLDocParser;
39
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
41
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
40
import org.eclipse.help.internal.xhtml.DynamicXHTMLProcessor;
42
import org.eclipse.help.internal.xhtml.DynamicXHTMLProcessor;
Lines 70-75 Link Here
70
	// flag right-to-left direction of text
72
	// flag right-to-left direction of text
71
	private boolean isRTL;
73
	private boolean isRTL;
72
74
75
	private AbstractHelpScope scope;
76
73
	/*
77
	/*
74
	 * Constructs the print data for the given request.
78
	 * Constructs the print data for the given request.
75
	 */
79
	 */
Lines 81-86 Link Here
81
		}
85
		}
82
86
83
		isRTL = UrlUtil.isRTL(request, response);
87
		isRTL = UrlUtil.isRTL(request, response);
88
		scope = RequestScope.getScopeFromRequest(request, response);
84
		
89
		
85
		String confirmString = request.getParameter("confirmed"); //$NON-NLS-1$
90
		String confirmString = request.getParameter("confirmed"); //$NON-NLS-1$
86
		if ((confirmString != null) && ("true".equals(confirmString))) { //$NON-NLS-1$
91
		if ((confirmString != null) && ("true".equals(confirmString))) { //$NON-NLS-1$
Lines 209-215 Link Here
209
			topicsRequested++;
214
			topicsRequested++;
210
		}
215
		}
211
216
212
		ITopic[] subtopics = EnabledTopicUtils.getEnabled(topic.getSubtopics());
217
		ITopic[] subtopics = ScopeUtils.inScopeTopics(topic.getSubtopics(), scope);
213
		for (int i = 0; i < subtopics.length; ++i) {
218
		for (int i = 0; i < subtopics.length; ++i) {
214
			topicsRequested += topicsRequested(subtopics[i]);
219
			topicsRequested += topicsRequested(subtopics[i]);
215
		}
220
		}
Lines 243-249 Link Here
243
		if (href != null && href.length() > 0) {
248
		if (href != null && href.length() > 0) {
244
			tocGenerated++;
249
			tocGenerated++;
245
		}
250
		}
246
		ITopic[] subtopics = EnabledTopicUtils.getEnabled(topic.getSubtopics());
251
		ITopic[] subtopics = ScopeUtils.inScopeTopics(topic.getSubtopics(), scope);
247
		for (int i = 0; i < subtopics.length; ++i) {
252
		for (int i = 0; i < subtopics.length; ++i) {
248
			tocGenerated = generateToc(subtopics[i], String.valueOf(i + 1), tocGenerated, out);
253
			tocGenerated = generateToc(subtopics[i], String.valueOf(i + 1), tocGenerated, out);
249
		}
254
		}
Lines 267-273 Link Here
267
				tocGenerated++;
272
				tocGenerated++;
268
			}
273
			}
269
274
270
			ITopic[] subtopics = EnabledTopicUtils.getEnabled(topic.getSubtopics());
275
			ITopic[] subtopics = ScopeUtils.inScopeTopics(topic.getSubtopics(), scope);
271
			for (int i = 0; i < subtopics.length; ++i) {
276
			for (int i = 0; i < subtopics.length; ++i) {
272
				String subsectionId = sectionId + "." + (i + 1); //$NON-NLS-1$
277
				String subsectionId = sectionId + "." + (i + 1); //$NON-NLS-1$
273
				tocGenerated = generateToc(subtopics[i], subsectionId, tocGenerated, out);
278
				tocGenerated = generateToc(subtopics[i], subsectionId, tocGenerated, out);
Lines 311-317 Link Here
311
					out.write(content);
316
					out.write(content);
312
				}
317
				}
313
			}
318
			}
314
			ITopic[] subtopics = EnabledTopicUtils.getEnabled(topic.getSubtopics());
319
			ITopic[] subtopics = ScopeUtils.inScopeTopics(topic.getSubtopics(), scope);
315
			for (int i = 0; i < subtopics.length; ++i) {
320
			for (int i = 0; i < subtopics.length; ++i) {
316
				String subsectionId = (sectionId != null ? sectionId + "." : "") + (i + 1); //$NON-NLS-1$ //$NON-NLS-2$
321
				String subsectionId = (sectionId != null ? sectionId + "." : "") + (i + 1); //$NON-NLS-1$ //$NON-NLS-2$
317
				topicsGenerated = generateContent(subtopics[i], subsectionId, topicsGenerated, generated, out);
322
				topicsGenerated = generateContent(subtopics[i], subsectionId, topicsGenerated, generated, out);
(-)src/org/eclipse/help/internal/webapp/data/RequestScope.java (+122 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.help.internal.webapp.data;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.StringTokenizer;
17
18
import javax.servlet.http.Cookie;
19
import javax.servlet.http.HttpServletRequest;
20
import javax.servlet.http.HttpServletResponse;
21
22
import org.eclipse.help.HelpSystem;
23
import org.eclipse.help.base.AbstractHelpScope;
24
import org.eclipse.help.internal.base.HelpBasePlugin;
25
import org.eclipse.help.internal.base.scope.EnablementScope;
26
import org.eclipse.help.internal.base.scope.FilterScope;
27
import org.eclipse.help.internal.base.scope.IntersectionScope;
28
import org.eclipse.help.internal.base.scope.ScopeRegistry;
29
import org.eclipse.help.internal.base.scope.UniversalScope;
30
import org.eclipse.help.internal.base.scope.WorkingSetScope;
31
import org.eclipse.help.internal.webapp.servlet.WebappWorkingSetManager;
32
33
public class RequestScope {
34
	
35
	private static final String SCOPE_PARAMETER_NAME = "subset"; //$NON-NLS-1$
36
	private static final String SCOPE_COOKIE_NAME = "filter"; //$NON-NLS-1$
37
38
	public static AbstractHelpScope getScopeFromRequest(HttpServletRequest req, HttpServletResponse resp ) {
39
		if (!HelpSystem.isShared()) {
40
			// Filtering by scope is currently only in information center mode
41
			if (HelpBasePlugin.getActivitySupport().isFilteringEnabled()) {
42
				AbstractHelpScope[] scopes = { new FilterScope(), new EnablementScope() };
43
				return new IntersectionScope(scopes);
44
			}
45
			return new FilterScope();
46
		}
47
48
		String scopesFromParameter= getScopeParameter(req, resp, true);
49
		List scopes = new ArrayList();
50
		if (scopesFromParameter != null) {
51
			StringTokenizer tokenizer = new StringTokenizer(scopesFromParameter, "/"); //$NON-NLS-1$
52
			while (tokenizer.hasMoreTokens()) {
53
				String nextScope = tokenizer.nextToken().trim();
54
				if (!nextScope.equals("")) { //$NON-NLS-1$
55
					AbstractHelpScope scope = ScopeRegistry.getInstance().getScope(nextScope);
56
					if (scope != null) {
57
						scopes.add(scope);
58
					} else {
59
						// Try for a working set
60
						try {
61
							WorkingSetScope workingSetScope = new WorkingSetScope(
62
									nextScope, new WebappWorkingSetManager(req,
63
											resp, UrlUtil.getLocale(req, resp)));
64
							scopes.add(workingSetScope);
65
						} catch (Exception e) {
66
						}
67
					}
68
69
				}
70
			}
71
		}
72
		switch (scopes.size()) {
73
		case 0:
74
			return new UniversalScope();
75
		case 1:
76
			return (AbstractHelpScope) scopes.get(0);
77
		default:
78
			return new IntersectionScope(
79
					(AbstractHelpScope[]) scopes.toArray(new AbstractHelpScope[scopes.size()]));
80
		}	
81
	}
82
	
83
	public static String getScopeParameter(HttpServletRequest request, HttpServletResponse response, boolean readCookie ) {
84
		// See if there is a scope parameter, if so save as cookie
85
		String[] scope = request.getParameterValues(SCOPE_PARAMETER_NAME); 
86
		String scopeString = null;
87
		if (scope != null) {
88
			// save scope (in session cookie) for later use in a user session
89
			// If there are multiple values separate them with an '&'
90
			if (scope != null && scope.length > 0 && response != null) {
91
				scopeString = scope[0];			
92
				for (int s = 1; s < scope.length; s++) {
93
					scopeString += '/';
94
					scopeString += scope[s];
95
				}
96
				Cookie scopeCookie = new Cookie(SCOPE_COOKIE_NAME, scopeString); 
97
				response.addCookie(scopeCookie);
98
				return scopeString;
99
			}
100
		} else {
101
			if (readCookie) {
102
				// check if scope was passed earlier in this session
103
				Cookie[] cookies = request.getCookies();
104
				if (cookies != null) {
105
					for (int c = 0; c < cookies.length; c++) {
106
						if (SCOPE_COOKIE_NAME.equals(cookies[c].getName())) { 
107
							scopeString = cookies[c].getValue();
108
							break;
109
						}
110
					}
111
				}
112
			} else if (response != null) {
113
				// No scope parameter and cookie is stale. Set the cookie to show all
114
				scopeString = "all"; //$NON-NLS-1$
115
				Cookie scopeCookie = new Cookie(SCOPE_COOKIE_NAME, scopeString); 
116
				response.addCookie(scopeCookie);
117
			}
118
		}
119
		return scopeString;
120
	}
121
122
}
(-)src/org/eclipse/help/internal/webapp/data/SearchData.java (-4 / +7 lines)
Lines 26-31 Link Here
26
import org.eclipse.help.IHelpResource;
26
import org.eclipse.help.IHelpResource;
27
import org.eclipse.help.IToc;
27
import org.eclipse.help.IToc;
28
import org.eclipse.help.ITopic;
28
import org.eclipse.help.ITopic;
29
import org.eclipse.help.base.AbstractHelpScope;
29
import org.eclipse.help.internal.HelpPlugin;
30
import org.eclipse.help.internal.HelpPlugin;
30
import org.eclipse.help.internal.base.BaseHelpSystem;
31
import org.eclipse.help.internal.base.BaseHelpSystem;
31
import org.eclipse.help.internal.base.HelpBasePlugin;
32
import org.eclipse.help.internal.base.HelpBasePlugin;
Lines 348-354 Link Here
348
					.getProgressMonitor(getLocale());
349
					.getProgressMonitor(getLocale());
349
			if (pm.isDone()) {
350
			if (pm.isDone()) {
350
				this.indexCompletion = 100;
351
				this.indexCompletion = 100;
351
				SearchResults results = createHitCollector();
352
				AbstractHelpScope filter = RequestScope.getScopeFromRequest(request, response);
353
				SearchResults results = createHitCollector(filter);
352
				BaseHelpSystem.getSearchManager().search(createSearchQuery(),
354
				BaseHelpSystem.getSearchManager().search(createSearchQuery(),
353
						results, pm);
355
						results, pm);
354
				hits = results.getSearchHits();
356
				hits = results.getSearchHits();
Lines 386-392 Link Here
386
				getLocale());
388
				getLocale());
387
	}
389
	}
388
390
389
	private SearchResults createHitCollector() {
391
	private SearchResults createHitCollector(AbstractHelpScope filter) {
390
		WorkingSet[] workingSets;
392
		WorkingSet[] workingSets;
391
		if (request.getParameterValues("scopedSearch") != null) { //$NON-NLS-1$
393
		if (request.getParameterValues("scopedSearch") != null) { //$NON-NLS-1$
392
			// scopes are books (advanced search)
394
			// scopes are books (advanced search)
Lines 414-420 Link Here
414
			} catch (NumberFormatException nfe) {
416
			} catch (NumberFormatException nfe) {
415
			}
417
			}
416
		}
418
		}
417
		return new SearchResultFilter(workingSets, maxHits, getLocale());
419
		return new SearchResultFilter(workingSets, maxHits, getLocale(), filter);
418
	}
420
	}
419
421
420
	/**
422
	/**
Lines 533-540 Link Here
533
	 * that implement ISearchEngineResult2 and canOpen() returns true.
535
	 * that implement ISearchEngineResult2 and canOpen() returns true.
534
	 */
536
	 */
535
	private static class SearchResultFilter extends SearchResults {
537
	private static class SearchResultFilter extends SearchResults {
536
		public SearchResultFilter(WorkingSet[] workingSets, int maxHits, String locale) {
538
		public SearchResultFilter(WorkingSet[] workingSets, int maxHits, String locale, AbstractHelpScope filter) {
537
			super(workingSets, maxHits, locale);
539
			super(workingSets, maxHits, locale);
540
			setFilter(filter);
538
		}
541
		}
539
		public void addHits(List hits, String highlightTerms) {
542
		public void addHits(List hits, String highlightTerms) {
540
			List filtered = new ArrayList();
543
			List filtered = new ArrayList();
(-)src/org/eclipse/help/internal/webapp/servlet/ChildLinkInserter.java (-4 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 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 19-27 Link Here
19
19
20
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.help.ITopic;
21
import org.eclipse.help.ITopic;
22
import org.eclipse.help.base.AbstractHelpScope;
22
import org.eclipse.help.internal.HelpPlugin;
23
import org.eclipse.help.internal.HelpPlugin;
24
import org.eclipse.help.internal.base.scope.ScopeUtils;
23
import org.eclipse.help.internal.toc.Toc;
25
import org.eclipse.help.internal.toc.Toc;
24
import org.eclipse.help.internal.webapp.data.EnabledTopicUtils;
26
import org.eclipse.help.internal.webapp.data.RequestScope;
25
import org.eclipse.help.internal.webapp.data.UrlUtil;
27
import org.eclipse.help.internal.webapp.data.UrlUtil;
26
28
27
public class ChildLinkInserter {
29
public class ChildLinkInserter {
Lines 31-40 Link Here
31
	private OutputStream out;
33
	private OutputStream out;
32
	private static final String NO_CHILDREN = "no_child_topics"; //$NON-NLS-1$
34
	private static final String NO_CHILDREN = "no_child_topics"; //$NON-NLS-1$
33
	private static final String HAS_CHILDREN = "has_child_topics"; //$NON-NLS-1$
35
	private static final String HAS_CHILDREN = "has_child_topics"; //$NON-NLS-1$
36
	private AbstractHelpScope scope;
34
37
35
	public ChildLinkInserter(HttpServletRequest req, OutputStream out) {
38
	public ChildLinkInserter(HttpServletRequest req, OutputStream out) {
36
		this.req = req;
39
		this.req = req;
37
		this.out = out;
40
		this.out = out;
41
		scope = RequestScope.getScopeFromRequest(req, null);
38
	}
42
	}
39
	
43
	
40
	public void addContents(String encoding) throws IOException {	
44
	public void addContents(String encoding) throws IOException {	
Lines 46-52 Link Here
46
	    }
50
	    }
47
	    StringBuffer links = new StringBuffer("\n<ul class=\"childlinks\">\n"); //$NON-NLS-1$
51
	    StringBuffer links = new StringBuffer("\n<ul class=\"childlinks\">\n"); //$NON-NLS-1$
48
		for (int i=0;i<subtopics.length;++i) {
52
		for (int i=0;i<subtopics.length;++i) {
49
			if (EnabledTopicUtils.isEnabled(subtopics[i])) {
53
			if (ScopeUtils.showInTree(subtopics[i], scope)) {
50
				links.append("\n<li><a href=\""); //$NON-NLS-1$
54
				links.append("\n<li><a href=\""); //$NON-NLS-1$
51
				String href = subtopics[i].getHref();
55
				String href = subtopics[i].getHref();
52
				if (href == null) {
56
				if (href == null) {
Lines 106-112 Link Here
106
		if (topic != null && topic.getHref() != null) {
110
		if (topic != null && topic.getHref() != null) {
107
			ITopic[] subtopics = topic.getSubtopics();
111
			ITopic[] subtopics = topic.getSubtopics();
108
			for (int i = 0; i < subtopics.length; ++i) {
112
			for (int i = 0; i < subtopics.length; ++i) {
109
				if (EnabledTopicUtils.isEnabled(subtopics[i])) {
113
				if (ScopeUtils.showInTree(subtopics[i], scope)) {
110
					out.write(HAS_CHILDREN.getBytes(UTF_8));
114
					out.write(HAS_CHILDREN.getBytes(UTF_8));
111
					return;
115
					return;
112
				}
116
				}
(-)src/org/eclipse/help/internal/webapp/servlet/CookieUtil.java (-1 / +1 lines)
Lines 69-75 Link Here
69
	 * Saves string in multiple browser cookies. Cookies can store limited
69
	 * Saves string in multiple browser cookies. Cookies can store limited
70
	 * length string. This method will attemt to split string among multiple
70
	 * length string. This method will attemt to split string among multiple
71
	 * cookies. The following cookies will be set name1=length <substing1
71
	 * cookies. The following cookies will be set name1=length <substing1
72
	 * name2=substrging2 ... namen=substringn
72
	 * name2=substring2 ... namen=substringn
73
	 * 
73
	 * 
74
	 * @param data
74
	 * @param data
75
	 *            a string containing legal characters for cookie value
75
	 *            a string containing legal characters for cookie value
(-)src/org/eclipse/help/internal/webapp/servlet/IndexFragmentServlet.java (-15 / +43 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 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 28-38 Link Here
28
import org.eclipse.help.IIndexSee;
28
import org.eclipse.help.IIndexSee;
29
import org.eclipse.help.IIndexSubpath;
29
import org.eclipse.help.IIndexSubpath;
30
import org.eclipse.help.ITopic;
30
import org.eclipse.help.ITopic;
31
import org.eclipse.help.base.AbstractHelpScope;
31
import org.eclipse.help.internal.HelpPlugin;
32
import org.eclipse.help.internal.HelpPlugin;
32
import org.eclipse.help.internal.base.BaseHelpSystem;
33
import org.eclipse.help.internal.base.BaseHelpSystem;
34
import org.eclipse.help.internal.base.scope.ScopeUtils;
33
import org.eclipse.help.internal.webapp.WebappResources;
35
import org.eclipse.help.internal.webapp.WebappResources;
34
import org.eclipse.help.internal.webapp.data.ActivitiesData;
36
import org.eclipse.help.internal.webapp.data.ActivitiesData;
35
import org.eclipse.help.internal.webapp.data.EnabledTopicUtils;
37
import org.eclipse.help.internal.webapp.data.RequestScope;
36
import org.eclipse.help.internal.webapp.data.UrlUtil;
38
import org.eclipse.help.internal.webapp.data.UrlUtil;
37
import org.eclipse.osgi.util.NLS;
39
import org.eclipse.osgi.util.NLS;
38
40
Lines 107-113 Link Here
107
		    resp.setHeader("Pragma","no-cache");  //$NON-NLS-1$ //$NON-NLS-2$
109
		    resp.setHeader("Pragma","no-cache");  //$NON-NLS-1$ //$NON-NLS-2$
108
		    resp.setDateHeader ("Expires", 0); 	 //$NON-NLS-1$	
110
		    resp.setDateHeader ("Expires", 0); 	 //$NON-NLS-1$	
109
		}
111
		}
110
		Serializer serializer = new Serializer(locale);
112
		AbstractHelpScope scope = RequestScope.getScopeFromRequest(req, resp);
113
		Serializer serializer = new Serializer(locale, scope);
111
		String response = serializer.generateIndexXml();	
114
		String response = serializer.generateIndexXml();	
112
		locale2Response.put(locale, response);
115
		locale2Response.put(locale, response);
113
		resp.getWriter().write(response);
116
		resp.getWriter().write(response);
Lines 126-134 Link Here
126
		private IIndexEntry[] entries;
129
		private IIndexEntry[] entries;
127
		private boolean enablePrevious = true;
130
		private boolean enablePrevious = true;
128
		private boolean enableNext = true;
131
		private boolean enableNext = true;
132
		private AbstractHelpScope scope;
129
133
130
		public Serializer(String locale) {
134
		public Serializer(String locale, AbstractHelpScope scope) {
131
			this.locale = locale;
135
			this.locale = locale;
136
			this.scope = scope;
132
			index = HelpPlugin.getIndexManager().getIndex(locale);
137
			index = HelpPlugin.getIndexManager().getIndex(locale);
133
			buf = new StringBuffer();
138
			buf = new StringBuffer();
134
		}
139
		}
Lines 265-286 Link Here
265
		}
270
		}
266
		
271
		
267
		private int enabledEntryCount(IIndexEntry entry) {
272
		private int enabledEntryCount(IIndexEntry entry) {
268
			if (!EnabledTopicUtils.isEnabled(entry)) return 0;
273
			if (!ScopeUtils.hasInScopeDescendent(entry, scope)) return 0;
269
			if (entry.getKeyword() == null || entry.getKeyword().length() == 0) {
274
			if (entry.getKeyword() == null || entry.getKeyword().length() == 0) {
270
				return 0;
275
				return 0;
271
			}
276
			}
272
			int count = 1;
277
			int count = 1;
273
		    ITopic[] topics = EnabledTopicUtils.getEnabled(entry.getTopics());
278
		    int topicCount = enabledTopicCount(entry);
274
			IIndexEntry[] subentries = EnabledTopicUtils.getEnabled(entry.getSubentries());
279
280
			IIndexEntry[] subentries = entry.getSubentries();
281
		    int subentryCount = 0;
282
			for (int i=0; i<subentries.length; ++i) {
283
				count += enabledEntryCount(subentries[i]);
284
			}
285
			
286
			int seeCount = 0;
275
			IIndexSee[] sees = entry instanceof IIndexEntry2 ? ((IIndexEntry2)entry).getSees() : new IIndexSee[0];
287
			IIndexSee[] sees = entry instanceof IIndexEntry2 ? ((IIndexEntry2)entry).getSees() : new IIndexSee[0];
276
			if (topics.length + subentries.length + sees.length > 1) {
288
			for (int s = 0; s < sees.length; s++) {
277
				count += topics.length;
289
				if (scope.inScope(sees[s])) {
290
					seeCount++;
291
				}
278
			}
292
			}
279
			for (int i=0;i<subentries.length;++i) {
293
			
280
				count += enabledEntryCount(subentries[i]);
294
			if (topicCount + subentryCount + seeCount > 1) {
295
				count += topicCount;
281
			}
296
			}
297
			count += subentryCount;
298
			count += seeCount;
282
            return count;
299
            return count;
283
		}
300
		}
301
302
		private int enabledTopicCount(IIndexEntry entry) {
303
			int topicCount = 0;
304
		    ITopic[] topics = entry.getTopics();
305
		    for (int i = 0; i < topics.length; i++) {
306
		    	if (scope.inScope(topics[i])) {
307
		    		topicCount++;
308
		    	}
309
		    }
310
			return topicCount;
311
		}
284
		
312
		
285
		private void generateEmptyIndexMessage() {
313
		private void generateEmptyIndexMessage() {
286
			buf.append("<node"); //$NON-NLS-1$			
314
			buf.append("<node"); //$NON-NLS-1$			
Lines 293-302 Link Here
293
		}
321
		}
294
		
322
		
295
		private void generateEntry(IIndexEntry entry, int level, String id) {
323
		private void generateEntry(IIndexEntry entry, int level, String id) {
296
			if (!EnabledTopicUtils.isEnabled(entry)) return;
324
			if (!ScopeUtils.hasInScopeDescendent(entry, scope)) return;
297
			if (entry.getKeyword() != null && entry.getKeyword().length() > 0) {
325
			if (entry.getKeyword() != null && entry.getKeyword().length() > 0) {
298
				ITopic[] topics = EnabledTopicUtils.getEnabled(entry.getTopics());
326
				ITopic[] topics = ScopeUtils.inScopeTopics(entry.getTopics(), scope);
299
				IIndexEntry[] subentries = EnabledTopicUtils.getEnabled(entry.getSubentries());
327
				IIndexEntry[] subentries = ScopeUtils.inScopeEntries(entry.getSubentries(), scope);
300
				IIndexSee[] sees; 
328
				IIndexSee[] sees; 
301
				if (entry instanceof IIndexEntry2) {
329
				if (entry instanceof IIndexEntry2) {
302
					sees = ((IIndexEntry2)entry).getSees();
330
					sees = ((IIndexEntry2)entry).getSees();
Lines 370-376 Link Here
370
		private void generateSees(IIndexSee[] sees) {
398
		private void generateSees(IIndexSee[] sees) {
371
	        for (int i = 0; i < sees.length; i++) {
399
	        for (int i = 0; i < sees.length; i++) {
372
	        	IIndexSee see = sees[i];
400
	        	IIndexSee see = sees[i];
373
				if (EnabledTopicUtils.isEnabled(see)) {
401
				if (scope.inScope(see)) {
374
					//
402
					//
375
					String key = see.isSeeAlso() ? "SeeAlso" : "See"; //$NON-NLS-1$ //$NON-NLS-2$
403
					String key = see.isSeeAlso() ? "SeeAlso" : "See"; //$NON-NLS-1$ //$NON-NLS-2$
376
					String seePrefix = WebappResources.getString(key, UrlUtil
404
					String seePrefix = WebappResources.getString(key, UrlUtil
(-)src/org/eclipse/help/internal/webapp/servlet/NavServlet.java (-5 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 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-31 Link Here
23
import javax.servlet.http.HttpServletResponse;
23
import javax.servlet.http.HttpServletResponse;
24
24
25
import org.eclipse.help.ITopic;
25
import org.eclipse.help.ITopic;
26
import org.eclipse.help.base.AbstractHelpScope;
26
import org.eclipse.help.internal.HelpPlugin;
27
import org.eclipse.help.internal.HelpPlugin;
27
import org.eclipse.help.internal.webapp.WebappResources;
28
import org.eclipse.help.internal.webapp.WebappResources;
28
import org.eclipse.help.internal.webapp.data.EnabledTopicUtils;
29
import org.eclipse.help.internal.webapp.data.RequestScope;
29
import org.eclipse.help.internal.webapp.data.UrlUtil;
30
import org.eclipse.help.internal.webapp.data.UrlUtil;
30
import org.eclipse.help.webapp.IFilter;
31
import org.eclipse.help.webapp.IFilter;
31
32
Lines 61-67 Link Here
61
		}
62
		}
62
63
63
		PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); //$NON-NLS-1$
64
		PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); //$NON-NLS-1$
64
		writeContent(topic, path, locale, writer, UrlUtil.isRTL(req, resp));
65
		AbstractHelpScope scope = RequestScope.getScopeFromRequest(req, resp);
66
		writeContent(topic, path, locale, writer, UrlUtil.isRTL(req, resp), scope);
65
		writer.close();
67
		writer.close();
66
	}
68
	}
67
	
69
	
Lines 93-99 Link Here
93
		return topic;
95
		return topic;
94
	}
96
	}
95
	
97
	
96
	private void writeContent(ITopic topic, String path, Locale locale, PrintWriter writer, boolean isRTL) {
98
	private void writeContent(ITopic topic, String path, Locale locale, PrintWriter writer, boolean isRTL, AbstractHelpScope scope) {
97
		writer.write(XHTML_1);
99
		writer.write(XHTML_1);
98
		writer.write(topic.getLabel());
100
		writer.write(topic.getLabel());
99
		if (isRTL) {
101
		if (isRTL) {
Lines 106-112 Link Here
106
		writer.write("<ul class=\"NavList\">\n"); //$NON-NLS-1$
108
		writer.write("<ul class=\"NavList\">\n"); //$NON-NLS-1$
107
		ITopic[] subtopics = topic.getSubtopics();
109
		ITopic[] subtopics = topic.getSubtopics();
108
		for (int i=0;i<subtopics.length;++i) {
110
		for (int i=0;i<subtopics.length;++i) {
109
			if (EnabledTopicUtils.isEnabled(subtopics[i])) {
111
			if (scope.inScope(subtopics[i])) {
110
				writer.write("<li><a href=\""); //$NON-NLS-1$
112
				writer.write("<li><a href=\""); //$NON-NLS-1$
111
				String href = subtopics[i].getHref();
113
				String href = subtopics[i].getHref();
112
				if (href == null) {
114
				if (href == null) {
(-)src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java (-10 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 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 22-32 Link Here
22
22
23
import org.eclipse.help.IToc;
23
import org.eclipse.help.IToc;
24
import org.eclipse.help.ITopic;
24
import org.eclipse.help.ITopic;
25
import org.eclipse.help.base.AbstractHelpScope;
25
import org.eclipse.help.internal.Topic;
26
import org.eclipse.help.internal.Topic;
27
import org.eclipse.help.internal.base.scope.ScopeUtils;
26
import org.eclipse.help.internal.toc.Toc;
28
import org.eclipse.help.internal.toc.Toc;
27
import org.eclipse.help.internal.webapp.WebappResources;
29
import org.eclipse.help.internal.webapp.WebappResources;
28
import org.eclipse.help.internal.webapp.data.EnabledTopicUtils;
29
import org.eclipse.help.internal.webapp.data.IconFinder;
30
import org.eclipse.help.internal.webapp.data.IconFinder;
31
import org.eclipse.help.internal.webapp.data.RequestScope;
30
import org.eclipse.help.internal.webapp.data.TocData;
32
import org.eclipse.help.internal.webapp.data.TocData;
31
import org.eclipse.help.internal.webapp.data.UrlUtil;
33
import org.eclipse.help.internal.webapp.data.UrlUtil;
32
34
Lines 54-60 Link Here
54
		
56
		
55
		readParameters(req);
57
		readParameters(req);
56
		
58
		
57
		Serializer serializer = new Serializer(data, req.getLocale());
59
		AbstractHelpScope scope = RequestScope.getScopeFromRequest(req, resp);
60
		Serializer serializer = new Serializer(data, req.getLocale(), scope);
58
		String response = serializer.generateTreeXml();	
61
		String response = serializer.generateTreeXml();	
59
		locale2Response.put(locale, response);
62
		locale2Response.put(locale, response);
60
		resp.getWriter().write(response);
63
		resp.getWriter().write(response);
Lines 74-88 Link Here
74
		private StringBuffer buf;
77
		private StringBuffer buf;
75
		private int requestKind;
78
		private int requestKind;
76
		private Locale locale;
79
		private Locale locale;
80
		private AbstractHelpScope scope;
77
		private static final int REQUEST_SHOW_IN_TOC = 1;      // Get the path to an element an element based on its href
81
		private static final int REQUEST_SHOW_IN_TOC = 1;      // Get the path to an element an element based on its href
78
		private static final int REQUEST_SHOW_TOCS = 2;        // Show all the tocs but not their children
82
		private static final int REQUEST_SHOW_TOCS = 2;        // Show all the tocs but not their children
79
		private static final int REQUEST_SHOW_CHILDREN = 3;    // Show the children of a node
83
		private static final int REQUEST_SHOW_CHILDREN = 3;    // Show the children of a node
80
		private static final int REQUEST_EXPAND_PATH = 4;      // Get all the nodes requires to expand a path in the tree
84
		private static final int REQUEST_EXPAND_PATH = 4;      // Get all the nodes requires to expand a path in the tree
81
85
82
		public Serializer(TocData data, Locale locale) {
86
		public Serializer(TocData data, Locale locale, AbstractHelpScope scope) {
83
			tocData = data;
87
			tocData = data;
84
			buf = new StringBuffer();
88
			buf = new StringBuffer();
85
			this.locale = locale;
89
			this.locale = locale;
90
			this.scope = scope;
86
			if (tocData.isExpandPath()) {
91
			if (tocData.isExpandPath()) {
87
				requestKind = REQUEST_EXPAND_PATH;
92
				requestKind = REQUEST_EXPAND_PATH;
88
			} else if (tocData.getTopicHref() != null) {
93
			} else if (tocData.getTopicHref() != null) {
Lines 119-125 Link Here
119
				// Count the number of enabled tocs
124
				// Count the number of enabled tocs
120
				int enabled = 0;
125
				int enabled = 0;
121
				for (int i = 0; i <= selectedToc; i++) {
126
				for (int i = 0; i <= selectedToc; i++) {
122
					if (EnabledTopicUtils.isEnabled(tocData.getTocs()[i])) {
127
					if (ScopeUtils.showInTree(tocData.getTocs()[i], scope)) {
123
						enabled++;
128
						enabled++;
124
					}
129
					}
125
				}
130
				}
Lines 165-172 Link Here
165
	
170
	
166
		private void serializeToc(IToc toc, int tocIndex, ITopic[] topicPath, boolean isSelected) {		
171
		private void serializeToc(IToc toc, int tocIndex, ITopic[] topicPath, boolean isSelected) {		
167
			
172
			
168
			if (!EnabledTopicUtils.isEnabled(toc)) {
173
			if (!ScopeUtils.showInTree(toc, scope)) {
169
				// do not generate toc when there are no leaf topics
174
				// do not generate toc when there are no leaf topics or if it is filtered out
170
				return;
175
				return;
171
			}
176
			}
172
			ITopic[] topics = toc.getTopics();
177
			ITopic[] topics = toc.getTopics();
Lines 205-211 Link Here
205
210
206
		private void serializeTopic(ITopic topic, ITopic[] topicPath, boolean isSelected, String parentPath)  {
211
		private void serializeTopic(ITopic topic, ITopic[] topicPath, boolean isSelected, String parentPath)  {
207
		    ITopic[] subtopics = topic.getSubtopics();
212
		    ITopic[] subtopics = topic.getSubtopics();
208
		     boolean isLeaf = !EnabledTopicUtils.hasEnabledSubtopic(topic);
213
		     boolean isLeaf = !ScopeUtils.hasInScopeDescendent(topic, scope);
209
		    buf.append("<node"); //$NON-NLS-1$
214
		    buf.append("<node"); //$NON-NLS-1$
210
			if (topic.getLabel() != null) { 
215
			if (topic.getLabel() != null) { 
211
				buf.append('\n'	+ "      title=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$
216
				buf.append('\n'	+ "      title=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$
Lines 293-306 Link Here
293
				// Show the children of this node
298
				// Show the children of this node
294
				for (int subtopic = 0; subtopic < childTopics.length; subtopic++) {
299
				for (int subtopic = 0; subtopic < childTopics.length; subtopic++) {
295
				    ITopic childTopic = childTopics[subtopic];
300
				    ITopic childTopic = childTopics[subtopic];
296
				    if (EnabledTopicUtils.isEnabled(childTopic)) {
301
				    if (ScopeUtils.showInTree(childTopic, scope)) {
297
					    serializeTopic(childTopic, null, false, addSuffix(parentPath, subtopic));
302
					    serializeTopic(childTopic, null, false, addSuffix(parentPath, subtopic));
298
				    }
303
				    }
299
				}
304
				}
300
			} else if (topicPath != null) {
305
			} else if (topicPath != null) {
301
				for (int subtopic = 0; subtopic < childTopics.length; subtopic++) {
306
				for (int subtopic = 0; subtopic < childTopics.length; subtopic++) {
302
					ITopic childTopic = childTopics[subtopic];
307
					ITopic childTopic = childTopics[subtopic];
303
					if (EnabledTopicUtils.isEnabled(childTopic)) {
308
				    if (ScopeUtils.showInTree(childTopic, scope)) {
304
						if (topicPath[0].getLabel().equals(childTopic.getLabel())) {
309
						if (topicPath[0].getLabel().equals(childTopic.getLabel())) {
305
							ITopic[] newPath = null;
310
							ITopic[] newPath = null;
306
							if (topicPath.length > 1) {
311
							if (topicPath.length > 1) {

Return to bug 223475