You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2022/08/05 21:22:22 UTC
[tika] branch main updated: add convenience methods to FetcherManager and EmitterManager to get the one fetcher/emitter if only one is specified.
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 1bee087c2 add convenience methods to FetcherManager and EmitterManager to get the one fetcher/emitter if only one is specified.
1bee087c2 is described below
commit 1bee087c230fe364d002c23394c600a3ee89c5c2
Author: tballison <ta...@apache.org>
AuthorDate: Fri Aug 5 17:22:14 2022 -0400
add convenience methods to FetcherManager and EmitterManager to get the one fetcher/emitter if only one is specified.
---
.../apache/tika/pipes/emitter/EmitterManager.java | 21 +++++++++++++++++++++
.../apache/tika/pipes/fetcher/FetcherManager.java | 21 +++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/emitter/EmitterManager.java b/tika-core/src/main/java/org/apache/tika/pipes/emitter/EmitterManager.java
index fee9df4e1..7d1aba1cf 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/emitter/EmitterManager.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/emitter/EmitterManager.java
@@ -74,4 +74,25 @@ public class EmitterManager extends ConfigBase {
}
return emitter;
}
+
+ /**
+ * Convenience method that returns an emitter if only one emitter
+ * is specified in the tika-config file. If 0 or > 1 emitters
+ * are specified, this throws an IllegalArgumentException.
+ * @return
+ */
+ public Emitter getEmitter() {
+ if (emitterMap.size() == 0) {
+ throw new IllegalArgumentException("emitters size must == 1 for the no arg call");
+ }
+ if (emitterMap.size() > 1) {
+ throw new IllegalArgumentException("need to specify 'emitterName' if > 1 emitters are" +
+ " available");
+ }
+ for (Emitter emitter : emitterMap.values()) {
+ return emitter;
+ }
+ //this should be unreachable?!
+ throw new IllegalArgumentException("emitters size must == 0");
+ }
}
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/FetcherManager.java b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/FetcherManager.java
index 2d9382541..40121f9a7 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/fetcher/FetcherManager.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/fetcher/FetcherManager.java
@@ -72,4 +72,25 @@ public class FetcherManager extends ConfigBase {
public Set<String> getSupported() {
return fetcherMap.keySet();
}
+
+ /**
+ * Convenience method that returns a fetcher if only one fetcher
+ * is specified in the tika-config file. If 0 or > 1 fetchers
+ * are specified, this throws an IllegalArgumentException.
+ * @return
+ */
+ public Fetcher getFetcher() {
+ if (fetcherMap.size() == 0) {
+ throw new IllegalArgumentException("fetchers size must == 1 for the no arg call");
+ }
+ if (fetcherMap.size() > 1) {
+ throw new IllegalArgumentException("need to specify 'fetcherName' if > 1 fetchers are" +
+ " available");
+ }
+ for (Fetcher fetcher : fetcherMap.values()) {
+ return fetcher;
+ }
+ //this should be unreachable?!
+ throw new IllegalArgumentException("fetchers size must == 0");
+ }
}