001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.javadoc.search;
043:
044: import java.util.*;
045: import java.util.regex.*;
046:
047: import org.openide.filesystems.FileObject;
048: import org.openide.util.NbBundle;
049: import org.openide.ErrorManager;
050:
051: /**
052: * Service that knows how to parse doclet output and can
053: * search in it.
054: *
055: * @author Petr Suchomel
056: * @version 1.1
057: */
058: public abstract class JavadocSearchType {
059:
060: /** Tries to find javadoc index files in given directory
061: * @param apidocRoot Folder where to look for index files where to find index files
062: * @return File object containing index-files e.g index-files directory
063: * or index-all.html.
064: */
065: public abstract FileObject getDocFileObject(FileObject apidocRoot);
066:
067: private Pattern[] overviewLabelFilters;
068:
069: private synchronized void prepareOverviewFilter() {
070: if (overviewLabelFilters != null)
071: return;
072: String filter = NbBundle.getMessage(JavadocSearchType.class,
073: "FILTER_OverviewIndiceLabel"); // NOI18N
074: StringTokenizer tok = new StringTokenizer(filter, "\n"); // NOI18N
075: LinkedList ll = new LinkedList();
076: while (tok.hasMoreTokens()) {
077: try {
078: String expr = tok.nextToken();
079: Pattern re = Pattern.compile(expr);
080: ll.add(re);
081: } catch (PatternSyntaxException e) {
082: ErrorManager.getDefault().notify(
083: ErrorManager.INFORMATIONAL, e);
084: }
085: }
086: overviewLabelFilters = (Pattern[]) ll.toArray(new Pattern[ll
087: .size()]);
088: }
089:
090: /**
091: * This method is supposed to strip generic parts ("Overview (...)" or "... - Overview")
092: * from the overview page's title. The default implementation does nothing,
093: * returns the title unfiltered.
094: *
095: * @since
096: */
097: public String getOverviewTitleBase(String overviewTitle) {
098: prepareOverviewFilter();
099: Matcher match;
100: String t = overviewTitle.trim();
101:
102: for (int i = 0; i < overviewLabelFilters.length; i++) {
103: match = overviewLabelFilters[i].matcher(t);
104: if (match.matches()) {
105: return match.group(1);
106: }
107: }
108: return overviewTitle;
109: }
110:
111: /** Returns Java doc search thread for doument
112: * @param toFind String to find
113: * @param fo File object containing index-files
114: * @param diiConsumer consumer for parse events
115: * @return IndexSearchThread
116: */
117: public abstract IndexSearchThread getSearchThread(String toFind,
118: FileObject fo,
119: IndexSearchThread.DocIndexItemConsumer diiConsumer);
120:
121: /**
122: * Returns true if the JavadocSearchType accepts the given apidocRoot.
123: * @param apidocRoot root of the javadoc
124: * @param encoding of the javadoc, may be null if the javadoc has no encoding
125: */
126: public abstract boolean accepts(FileObject apidocRoot,
127: String encoding);
128:
129: }
|