diff options
author | John Arthorne | 2012-06-26 20:29:16 +0000 |
---|---|---|
committer | John Arthorne | 2012-07-24 17:19:12 +0000 |
commit | c3212ea5ec223c1145a8834ab2d7cb2b04b2cf32 (patch) | |
tree | e979007830f9b8969ceb75a76a0679935c1b49c8 | |
parent | c8c9769892778c5d79ace97596fef346e071c64a (diff) | |
download | eclipse.platform.ua-c3212ea5ec223c1145a8834ab2d7cb2b04b2cf32.tar.gz eclipse.platform.ua-c3212ea5ec223c1145a8834ab2d7cb2b04b2cf32.tar.xz eclipse.platform.ua-c3212ea5ec223c1145a8834ab2d7cb2b04b2cf32.zip |
Bug 383582 - Lucene analyzers no longer have a default constructor
4 files changed, 112 insertions, 47 deletions
diff --git a/org.eclipse.help.base/META-INF/MANIFEST.MF b/org.eclipse.help.base/META-INF/MANIFEST.MF index 919783c3f..ecdf79c28 100644 --- a/org.eclipse.help.base/META-INF/MANIFEST.MF +++ b/org.eclipse.help.base/META-INF/MANIFEST.MF @@ -42,17 +42,10 @@ Export-Package: org.apache.lucene.demo.html;x-internal:=true, Require-Bundle: org.eclipse.ant.core;bundle-version="3.2.200";resolution:=optional, org.eclipse.core.runtime;bundle-version="3.6.0", org.eclipse.help;bundle-version="[3.5.0,4.0.0)";visibility:=reexport, - org.eclipse.core.expressions;bundle-version="[3.4.200,4.0.0)" + org.eclipse.core.expressions;bundle-version="[3.4.200,4.0.0)", + org.apache.lucene.analysis;bundle-version="3.5.0", + org.apache.lucene.core;bundle-version="3.5.0" Import-Package: com.ibm.icu.text, - org.apache.lucene.analysis;version="3.5.0", - org.apache.lucene.analysis.standard;version="3.5.0", - org.apache.lucene.analysis.tokenattributes;version="3.5.0", - org.apache.lucene.collation;version="3.5.0", - org.apache.lucene.document;version="3.5.0", - org.apache.lucene.index;core=split;version="3.5.0", - org.apache.lucene.search;core=split;version="3.5.0", - org.apache.lucene.store;core=split;version="3.5.0", - org.apache.lucene.util;version="3.5.0", org.eclipse.equinox.http.jetty;resolution:=optional Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.help.base/plugin.xml b/org.eclipse.help.base/plugin.xml index 1f508fd64..07a5a22d4 100644 --- a/org.eclipse.help.base/plugin.xml +++ b/org.eclipse.help.base/plugin.xml @@ -71,15 +71,15 @@ </analyzer> <analyzer locale="pt" - class="org.apache.lucene.analysis.br.BrazilianAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:pt"> </analyzer> <analyzer locale="ja" - class="org.apache.lucene.analysis.cjk.CJKAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:ja"> </analyzer> <analyzer locale="ko" - class="org.apache.lucene.analysis.cjk.CJKAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:ko"> </analyzer> <analyzer locale="zh" @@ -87,27 +87,27 @@ </analyzer> <analyzer locale="cs" - class="org.apache.lucene.analysis.cz.CzechAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:cs"> </analyzer> <analyzer locale="de" - class="org.apache.lucene.analysis.de.GermanAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:de"> </analyzer> <analyzer locale="el" - class="org.apache.lucene.analysis.el.GreekAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:el"> </analyzer> <analyzer locale="fr" - class="org.apache.lucene.analysis.fr.FrenchAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:fr"> </analyzer> <analyzer locale="nl" - class="org.apache.lucene.analysis.nl.DutchAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:nl"> </analyzer> <analyzer locale="ru" - class="org.apache.lucene.analysis.ru.RussianAnalyzer"> + class="org.eclipse.help.internal.search.AnalyzerFactory:ru"> </analyzer> </extension> <!-- Web Browsers --> diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerDescriptor.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerDescriptor.java index 6552a0a6f..e6f678bee 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerDescriptor.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerDescriptor.java @@ -1,12 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the + * accompanying materials are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation + * + * Contributors: IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.help.internal.search; @@ -19,6 +17,7 @@ import org.osgi.framework.*; * Text Analyzer Descriptor. Encapsulates Lucene Analyzer */ public class AnalyzerDescriptor { + private Analyzer luceneAnalyzer; private String id; @@ -47,8 +46,8 @@ public class AnalyzerDescriptor { if (this.luceneAnalyzer == null) { this.id = HelpBasePlugin.PLUGIN_ID + "#" //$NON-NLS-1$ - + HelpBasePlugin.getDefault().getBundle().getHeaders().get( - Constants.BUNDLE_VERSION) + "?locale=" + locale; //$NON-NLS-1$ + + HelpBasePlugin.getDefault().getBundle().getHeaders().get(Constants.BUNDLE_VERSION) + + "?locale=" + locale; //$NON-NLS-1$ this.luceneAnalyzer = new DefaultAnalyzer(locale); this.lang = locale; } @@ -80,7 +79,7 @@ public class AnalyzerDescriptor { public String getLang() { return lang; } - + public String getAnalyzerClassName() { return luceneAnalyzer.getClass().getName(); } @@ -94,9 +93,8 @@ public class AnalyzerDescriptor { */ private Analyzer createAnalyzer(String locale) { // find extension point - IConfigurationElement configElements[] = Platform - .getExtensionRegistry().getConfigurationElementsFor( - HelpBasePlugin.PLUGIN_ID, "luceneAnalyzer"); //$NON-NLS-1$ + IConfigurationElement configElements[] = Platform.getExtensionRegistry().getConfigurationElementsFor( + HelpBasePlugin.PLUGIN_ID, "luceneAnalyzer"); //$NON-NLS-1$ for (int i = 0; i < configElements.length; i++) { if (!configElements[i].getName().equals("analyzer")) //$NON-NLS-1$ continue; @@ -104,15 +102,16 @@ public class AnalyzerDescriptor { if (analyzerLocale == null || !analyzerLocale.equals(locale)) continue; try { - Object analyzer = configElements[i] - .createExecutableExtension("class"); //$NON-NLS-1$ - if (!(analyzer instanceof Analyzer)) + Object analyzer = configElements[i].createExecutableExtension("class"); //$NON-NLS-1$ + if (analyzer instanceof AnalyzerFactory) + this.luceneAnalyzer = ((AnalyzerFactory) analyzer).create(); + else if (analyzer instanceof Analyzer) + this.luceneAnalyzer = (Analyzer) analyzer; + else continue; String pluginId = configElements[i].getContributor().getName(); - String pluginVersion = (String) Platform - .getBundle(pluginId).getHeaders().get( - Constants.BUNDLE_VERSION); - this.luceneAnalyzer = (Analyzer) analyzer; + String pluginVersion = (String) Platform.getBundle(pluginId).getHeaders() + .get(Constants.BUNDLE_VERSION); this.id = pluginId + "#" + pluginVersion + "?locale=" + locale; //$NON-NLS-1$ //$NON-NLS-2$ this.lang = locale; if (HelpBasePlugin.PLUGIN_ID.equals(pluginId)) { @@ -126,10 +125,9 @@ public class AnalyzerDescriptor { return this.luceneAnalyzer; } } catch (CoreException ce) { - HelpBasePlugin.logError( - "Exception occurred creating text analyzer " //$NON-NLS-1$ - + configElements[i].getAttribute("class") //$NON-NLS-1$ - + " for " + locale + " locale.", ce); //$NON-NLS-1$ //$NON-NLS-2$ + HelpBasePlugin.logError("Exception occurred creating text analyzer " //$NON-NLS-1$ + + configElements[i].getAttribute("class") //$NON-NLS-1$ + + " for " + locale + " locale.", ce); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -155,14 +153,14 @@ public class AnalyzerDescriptor { String pluginId = analyzerId.substring(0, numberSignIndex); String version = analyzerId.substring(numberSignIndex + 1, questionMarkIndex); String locale = analyzerId.substring(questionMarkIndex + 1 + "locale=".length()); //$NON-NLS-1$ - + // plugin compatible? // must both be org.eclipse.help.base String thisPluginId = id.substring(0, id.indexOf('#')); if (!HelpBasePlugin.PLUGIN_ID.equals(pluginId) || !HelpBasePlugin.PLUGIN_ID.equals(thisPluginId)) { return false; } - + // version compatible? // must both be >= 3.1 Version vA = getVersion(id); @@ -171,7 +169,7 @@ public class AnalyzerDescriptor { if (vA.compareTo(v3_1) < 0 && vB.compareTo(v3_1) < 0) { return false; } - + // locale compatible? // first part must be equal (first two chars) if (!lang.substring(0, 2).equals(locale.substring(0, 2))) { @@ -181,11 +179,11 @@ public class AnalyzerDescriptor { } return false; } - + private Version getVersion(String id) { int idStart = id.indexOf('#'); int idStop = id.indexOf('?'); - String value = idStop== -1?id.substring(idStart+1):id.substring(idStart+1, idStop); + String value = idStop == -1 ? id.substring(idStart + 1) : id.substring(idStart + 1, idStop); return new Version(value); } } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerFactory.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerFactory.java new file mode 100644 index 000000000..db7db9233 --- /dev/null +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerFactory.java @@ -0,0 +1,74 @@ +/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.help.internal.search;
+
+import org.apache.lucene.analysis.ru.RussianAnalyzer;
+
+import org.apache.lucene.analysis.nl.DutchAnalyzer;
+
+import org.apache.lucene.analysis.fr.FrenchAnalyzer;
+
+import org.apache.lucene.analysis.el.GreekAnalyzer;
+
+import org.apache.lucene.analysis.cz.CzechAnalyzer;
+
+import org.apache.lucene.analysis.cn.ChineseAnalyzer;
+
+import org.apache.lucene.analysis.cjk.CJKAnalyzer;
+
+import org.apache.lucene.analysis.br.BrazilianAnalyzer;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.de.GermanAnalyzer;
+import org.apache.lucene.util.Version;
+import org.eclipse.core.runtime.*;
+
+/**
+ * A factory responsible for instantiating a lucene {@link Analyzer}.
+ */
+public class AnalyzerFactory implements IExecutableExtension{
+ private String locale = null;
+ public Analyzer create() {
+ if (locale == null)
+ return null;
+ Version version = Version.LUCENE_35;
+ if ("pt".equals(locale)) //$NON-NLS-1$
+ return new BrazilianAnalyzer(version);
+ if ("ja".equals(locale)) //$NON-NLS-1$
+ return new CJKAnalyzer(version);
+ if ("ko".equals(locale)) //$NON-NLS-1$
+ return new CJKAnalyzer(version);
+ if ("pt".equals(locale)) //$NON-NLS-1$
+ return new BrazilianAnalyzer(version);
+ if ("cs".equals(locale)) //$NON-NLS-1$
+ return new CzechAnalyzer(version);
+ if ("de".equals(locale)) //$NON-NLS-1$
+ return new GermanAnalyzer(version);
+ if ("el".equals(locale)) //$NON-NLS-1$
+ return new GreekAnalyzer(version);
+ if ("fr".equals(locale)) //$NON-NLS-1$
+ return new FrenchAnalyzer(version);
+ if ("nl".equals(locale)) //$NON-NLS-1$
+ return new DutchAnalyzer(version);
+ if ("ru".equals(locale)) //$NON-NLS-1$
+ return new RussianAnalyzer(version);
+ //unknown language
+ return null;
+
+ }
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
+ throws CoreException {
+ if (data instanceof String)
+ locale = (String)data;
+ }
+
+}
|