X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.help.base%2Fsrc%2Forg%2Fsimantics%2Fhelp%2Fbase%2Finternal%2FPDFSearchParticipant.java;h=e1c9045ce667046c8a8823a05e1d2b0331607c8b;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=d630e113eec31d0f8603c7fd7ede074c94bedb3e;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java index d630e113e..e1c9045ce 100644 --- a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java +++ b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFSearchParticipant.java @@ -1,54 +1,54 @@ -package org.simantics.help.base.internal; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLDecoder; - -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.help.search.IHelpSearchIndex; -import org.eclipse.help.search.ISearchDocument; -import org.eclipse.help.search.SearchParticipant; -import org.osgi.framework.Bundle; - -/** - * An abstract search participants for adding XML documents to the search index. Subclass it - * and implement or override protected methods to handle parsing of the document. - * - * @since 1.20.0 - */ -public class PDFSearchParticipant extends SearchParticipant { - - @Override - public IStatus addDocument(IHelpSearchIndex index, String pluginId, String name, URL url, String id, ISearchDocument doc) { - try { - //System.out.println("PDFSearchParticipant.addDocument(" + index + ", " + pluginId + ", " + name + ", " + url + ", " + id + ", " + doc + ")"); - Bundle bundle = Platform.getBundle(pluginId); - if (bundle == null) - return new Status(IStatus.ERROR, pluginId, "Failed to find bundle " + bundle + " from the platform."); - - // Need to decode path because it will fail to resolve if it contains %20 (=' '). - IPath path = new Path(URLDecoder.decode(name, "UTF-8")); - path = path.removeFirstSegments(1); - URL bundleUrl = FileLocator.find(bundle, path, null); - if (bundleUrl == null) - return new Status(IStatus.ERROR, pluginId, "Failed to find file " + name + " from bundle " + pluginId + "."); - - URL fileUrl = FileLocator.toFileURL(bundleUrl); - if (!fileUrl.getProtocol().equals("file")) - return new Status(IStatus.ERROR, pluginId, "Failed to make " + url + " available as a file"); - - File f = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")).getCanonicalFile(); - PDFUtil.stripText(f, doc); - return Status.OK_STATUS; - } catch (IOException e) { - return new Status(IStatus.ERROR, pluginId, "Failed to strip text from PDF document " + url + ".", e); - } - } - -} +package org.simantics.help.base.internal; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLDecoder; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.help.search.IHelpSearchIndex; +import org.eclipse.help.search.ISearchDocument; +import org.eclipse.help.search.SearchParticipant; +import org.osgi.framework.Bundle; + +/** + * An abstract search participants for adding XML documents to the search index. Subclass it + * and implement or override protected methods to handle parsing of the document. + * + * @since 1.20.0 + */ +public class PDFSearchParticipant extends SearchParticipant { + + @Override + public IStatus addDocument(IHelpSearchIndex index, String pluginId, String name, URL url, String id, ISearchDocument doc) { + try { + //System.out.println("PDFSearchParticipant.addDocument(" + index + ", " + pluginId + ", " + name + ", " + url + ", " + id + ", " + doc + ")"); + Bundle bundle = Platform.getBundle(pluginId); + if (bundle == null) + return new Status(IStatus.ERROR, pluginId, "Failed to find bundle " + bundle + " from the platform."); + + // Need to decode path because it will fail to resolve if it contains %20 (=' '). + IPath path = new Path(URLDecoder.decode(name, "UTF-8")); + path = path.removeFirstSegments(1); + URL bundleUrl = FileLocator.find(bundle, path, null); + if (bundleUrl == null) + return new Status(IStatus.ERROR, pluginId, "Failed to find file " + name + " from bundle " + pluginId + "."); + + URL fileUrl = FileLocator.toFileURL(bundleUrl); + if (!fileUrl.getProtocol().equals("file")) + return new Status(IStatus.ERROR, pluginId, "Failed to make " + url + " available as a file"); + + File f = new File(URLDecoder.decode(fileUrl.getPath(), "UTF-8")).getCanonicalFile(); + PDFUtil.stripText(f, doc); + return Status.OK_STATUS; + } catch (IOException e) { + return new Status(IStatus.ERROR, pluginId, "Failed to strip text from PDF document " + url + ".", e); + } + } + +}