--- /dev/null
+package org.simantics.help.base.internal;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.net.URL;\r
+import java.net.URLDecoder;\r
+\r
+import org.eclipse.core.runtime.FileLocator;\r
+import org.eclipse.core.runtime.IPath;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Path;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.help.search.IHelpSearchIndex;\r
+import org.eclipse.help.search.ISearchDocument;\r
+import org.eclipse.help.search.SearchParticipant;\r
+import org.osgi.framework.Bundle;\r
+\r
+/**\r
+ * An abstract search participants for adding XML documents to the search index. Subclass it\r
+ * and implement or override protected methods to handle parsing of the document.\r
+ *\r
+ * @since 1.20.0\r
+ */\r
+public class PDFSearchParticipant extends SearchParticipant {\r
+\r
+ @Override\r
+ public IStatus addDocument(IHelpSearchIndex index, String pluginId, String name, URL url, String id, ISearchDocument doc) {\r
+ try {\r
+ //System.out.println("PDFSearchParticipant.addDocument(" + index + ", " + pluginId + ", " + name + ", " + url + ", " + id + ", " + doc + ")");\r
+ Bundle bundle = Platform.getBundle(pluginId);\r
+ if (bundle == null)\r
+ return new Status(IStatus.ERROR, pluginId, "Failed to find bundle " + bundle + " from the platform.");\r
+\r
+ // Need to decode path because it will fail to resolve if it contains %20 (=' ').\r
+ IPath path = new Path(URLDecoder.decode(name, "UTF-8"));\r
+ path = path.removeFirstSegments(1);\r
+ URL bundleUrl = FileLocator.find(bundle, path, null);\r
+ if (bundleUrl == null)\r
+ return new Status(IStatus.ERROR, pluginId, "Failed to find file " + name + " from bundle " + pluginId + ".");\r
+\r
+ URL fileUrl = FileLocator.toFileURL(bundleUrl);\r
+ if (!fileUrl.getProtocol().equals("file"))\r
+ return new Status(IStatus.ERROR, pluginId, "Failed to make " + url + " available as a file");\r
+\r
+ File f = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")).getCanonicalFile();\r
+ PDFUtil.stripText(f, doc);\r
+ return Status.OK_STATUS;\r
+ } catch (IOException e) {\r
+ return new Status(IStatus.ERROR, pluginId, "Failed to strip text from PDF document " + url + ".", e);\r
+ }\r
+ }\r
+\r
+}\r