KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > search > JavadocSearchType


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javadoc.search;
21
22 import java.util.*;
23 import java.util.regex.*;
24
25 import org.openide.filesystems.FileObject;
26 import org.openide.ServiceType;
27 import org.openide.util.NbBundle;
28 import org.openide.ErrorManager;
29
30 /**
31  * Service that knows how to parse doclet output and can
32  * search in it.
33  *
34  * @author Petr Suchomel
35  * @version 1.1
36  */

37 public abstract class JavadocSearchType extends ServiceType {
38
39     /** generated Serialized Version UID */
40     static final long serialVersionUID =-7643543247564581246L;
41
42     /** Tries to find javadoc index files in given directory
43      * @param apidocRoot Folder where to look for index files where to find index files
44      * @return File object containing index-files e.g index-files directory
45      * or index-all.html.
46      */

47     public abstract FileObject getDocFileObject( FileObject apidocRoot );
48     
49     private Pattern[] overviewLabelFilters;
50
51     private synchronized void prepareOverviewFilter() {
52         if (overviewLabelFilters != null)
53             return;
54         String JavaDoc filter = NbBundle.getMessage(JavadocSearchType.class, "FILTER_OverviewIndiceLabel"); // NOI18N
55
StringTokenizer tok = new StringTokenizer(filter, "\n"); // NOI18N
56
LinkedList ll = new LinkedList();
57         while (tok.hasMoreTokens()) {
58             try {
59                 String JavaDoc expr = tok.nextToken();
60                 Pattern re = Pattern.compile(expr);
61                 ll.add(re);
62             } catch (PatternSyntaxException e) {
63                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
64             }
65         }
66         overviewLabelFilters = (Pattern[])ll.toArray(new Pattern[ll.size()]);
67     }
68     
69     /**
70      * This method is supposed to strip generic parts ("Overview (...)" or "... - Overview")
71      * from the overview page's title. The default implementation does nothing,
72      * returns the title unfiltered.
73      *
74      * @since
75      */

76     public String JavaDoc getOverviewTitleBase(String JavaDoc overviewTitle) {
77         prepareOverviewFilter();
78         Matcher match;
79         String JavaDoc t = overviewTitle.trim();
80         
81         for (int i = 0; i < overviewLabelFilters.length; i++) {
82             match = overviewLabelFilters[i].matcher(t);
83             if (match.matches()) {
84                 return match.group(1);
85             }
86         }
87         return overviewTitle;
88     }
89
90     /** Returns Java doc search thread for doument
91      * @param toFind String to find
92      * @param fo File object containing index-files
93      * @param diiConsumer consumer for parse events
94      * @return IndexSearchThread
95      */

96     public abstract IndexSearchThread getSearchThread( String JavaDoc toFind, FileObject fo, IndexSearchThread.DocIndexItemConsumer diiConsumer );
97     
98
99     /**
100      * Returns true if the JavadocSearchType accepts the given apidocRoot.
101      * @param apidocRoot root of the javadoc
102      * @param encoding of the javadoc, may be null if the javadoc has no encoding
103      */

104     public abstract boolean accepts (FileObject apidocRoot, String JavaDoc encoding);
105
106 }
107
Popular Tags