1 package org.simantics.help.base.internal;
\r
4 import java.io.IOException;
\r
6 import java.net.URLDecoder;
\r
8 import org.eclipse.core.runtime.FileLocator;
\r
9 import org.eclipse.core.runtime.IPath;
\r
10 import org.eclipse.core.runtime.IStatus;
\r
11 import org.eclipse.core.runtime.Path;
\r
12 import org.eclipse.core.runtime.Platform;
\r
13 import org.eclipse.core.runtime.Status;
\r
14 import org.eclipse.help.search.IHelpSearchIndex;
\r
15 import org.eclipse.help.search.ISearchDocument;
\r
16 import org.eclipse.help.search.SearchParticipant;
\r
17 import org.osgi.framework.Bundle;
\r
20 * An abstract search participants for adding XML documents to the search index. Subclass it
\r
21 * and implement or override protected methods to handle parsing of the document.
\r
25 public class PDFSearchParticipant extends SearchParticipant {
\r
28 public IStatus addDocument(IHelpSearchIndex index, String pluginId, String name, URL url, String id, ISearchDocument doc) {
\r
30 //System.out.println("PDFSearchParticipant.addDocument(" + index + ", " + pluginId + ", " + name + ", " + url + ", " + id + ", " + doc + ")");
\r
31 Bundle bundle = Platform.getBundle(pluginId);
\r
33 return new Status(IStatus.ERROR, pluginId, "Failed to find bundle " + bundle + " from the platform.");
\r
35 // Need to decode path because it will fail to resolve if it contains %20 (=' ').
\r
36 IPath path = new Path(URLDecoder.decode(name, "UTF-8"));
\r
37 path = path.removeFirstSegments(1);
\r
38 URL bundleUrl = FileLocator.find(bundle, path, null);
\r
39 if (bundleUrl == null)
\r
40 return new Status(IStatus.ERROR, pluginId, "Failed to find file " + name + " from bundle " + pluginId + ".");
\r
42 URL fileUrl = FileLocator.toFileURL(bundleUrl);
\r
43 if (!fileUrl.getProtocol().equals("file"))
\r
44 return new Status(IStatus.ERROR, pluginId, "Failed to make " + url + " available as a file");
\r
46 File f = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")).getCanonicalFile();
\r
47 PDFUtil.stripText(f, doc);
\r
48 return Status.OK_STATUS;
\r
49 } catch (IOException e) {
\r
50 return new Status(IStatus.ERROR, pluginId, "Failed to strip text from PDF document " + url + ".", e);
\r