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