KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > search > InfoCenterSearchScopeFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.internal.search;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Dictionary JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 import org.eclipse.help.internal.search.InfoCenter;
18 import org.eclipse.help.search.*;
19 import org.eclipse.help.ui.ISearchScopeFactory;
20 import org.eclipse.jface.preference.IPreferenceStore;
21
22 /**
23  * Creates the scope for local search using the help working sets
24  */

25 public class InfoCenterSearchScopeFactory implements ISearchScopeFactory {
26     public static final String JavaDoc P_URL = "url"; //$NON-NLS-1$
27
public static final String JavaDoc P_SEARCH_SELECTED = "searchSelected"; //$NON-NLS-1$
28
public static final String JavaDoc P_TOCS = "tocs"; //$NON-NLS-1$
29
public static final String JavaDoc TOC_SEPARATOR = ";"; //$NON-NLS-1$
30

31     /* (non-Javadoc)
32      * @see org.eclipse.help.ui.ISearchScopeFactory#createSearchScope(org.eclipse.jface.preference.IPreferenceStore)
33      */

34     public ISearchScope createSearchScope(IPreferenceStore store, String JavaDoc engineId, Dictionary JavaDoc parameters) {
35         String JavaDoc url = getProperty(P_URL, store, engineId, parameters);
36         String JavaDoc ssvalue = getProperty(P_SEARCH_SELECTED, store, engineId, parameters);
37         boolean searchSelected = ssvalue!=null && ssvalue.equalsIgnoreCase("true"); //$NON-NLS-1$
38
String JavaDoc [] tocs=null;
39         if (searchSelected) {
40             String JavaDoc tvalue = getProperty(P_TOCS, store, engineId, parameters);
41             if (tvalue!=null && tvalue.length()>0) {
42                 StringTokenizer JavaDoc stok = new StringTokenizer JavaDoc(tvalue, TOC_SEPARATOR);
43                 ArrayList JavaDoc list = new ArrayList JavaDoc();
44                 while (stok.hasMoreTokens()) {
45                     String JavaDoc toc = stok.nextToken();
46                     list.add(toc);
47                 }
48                 if (list.size()>0)
49                     tocs = (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]);
50             }
51         }
52         return new InfoCenter.Scope(url, searchSelected, tocs);
53     }
54     
55     private String JavaDoc getProperty(String JavaDoc key, IPreferenceStore store, String JavaDoc engineId, Dictionary JavaDoc parameters) {
56         // try the store first
57
String JavaDoc value = store.getString(engineId+"."+key); //$NON-NLS-1$
58
if (value!=null && value.length()>0) return value;
59         // try the parameters
60
return (String JavaDoc)parameters.get(key);
61     }
62 }
63
Popular Tags