KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > XHTMLSearchParticipant


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.internal.search;
12
13 import java.io.InputStream JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.help.internal.base.HelpBasePlugin;
18 import org.eclipse.help.internal.xhtml.DynamicXHTMLProcessor;
19 import org.eclipse.help.search.XMLSearchParticipant;
20 import org.xml.sax.Attributes JavaDoc;
21
22 /**
23  * The search participant responsible for indexing XHTML documents.
24  */

25 public class XHTMLSearchParticipant extends XMLSearchParticipant {
26     
27     /* (non-Javadoc)
28      * @see org.eclipse.help.search.XMLSearchParticipant#handleEndElement(java.lang.String, org.eclipse.help.search.XMLSearchParticipant.IParsedXMLContent)
29      */

30     protected void handleEndElement(String JavaDoc name, IParsedXMLContent data) {
31     }
32     
33     /* (non-Javadoc)
34      * @see org.eclipse.help.search.XMLSearchParticipant#handleStartElement(java.lang.String, org.xml.sax.Attributes, org.eclipse.help.search.XMLSearchParticipant.IParsedXMLContent)
35      */

36     protected void handleStartElement(String JavaDoc name, Attributes JavaDoc attributes, IParsedXMLContent data) {
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.help.search.XMLSearchParticipant#handleText(java.lang.String, org.eclipse.help.search.XMLSearchParticipant.IParsedXMLContent)
41      */

42     protected void handleText(String JavaDoc text, IParsedXMLContent data) {
43         String JavaDoc stackPath = getElementStackPath();
44         IPath path = new Path(stackPath);
45         if (path.segment(1).equalsIgnoreCase("body")) { //$NON-NLS-1$
46
data.addText(text);
47             data.addToSummary(text);
48         } else if (path.segment(1).equalsIgnoreCase("head")) { //$NON-NLS-1$
49
data.setTitle(text);
50         }
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.help.search.XMLSearchParticipant#preprocess(java.io.InputStream, java.lang.String, java.lang.String)
55      */

56     protected InputStream JavaDoc preprocess(InputStream JavaDoc in, String JavaDoc name, String JavaDoc locale) {
57         try {
58             return DynamicXHTMLProcessor.process(name, in, locale, false);
59         }
60         catch (Throwable JavaDoc t) {
61             String JavaDoc msg = "An error occured while pre-processing help XHTML document \"" + name + "\" for search indexing"; //$NON-NLS-1$ //$NON-NLS-2$
62
HelpBasePlugin.logError(msg, t);
63             return in;
64         }
65     }
66 }
Popular Tags