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 2024/08/07 13:41:24 UTC
(tika) 01/01: TIKA-4295 --- allow user bypass for bytes' emitkey
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch TIKA-4295
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 85b273dfb60d5f1a67f741da26adf1db12c5ff24
Author: tallison <ta...@apache.org>
AuthorDate: Wed Aug 7 09:41:10 2024 -0400
TIKA-4295 --- allow user bypass for bytes' emitkey
---
.../AbstractEmbeddedDocumentBytesHandler.java | 18 +++++--
.../extractor/EmbeddedDocumentBytesConfig.java | 57 ++++++++++++----------
2 files changed, 43 insertions(+), 32 deletions(-)
diff --git a/tika-core/src/main/java/org/apache/tika/extractor/AbstractEmbeddedDocumentBytesHandler.java b/tika-core/src/main/java/org/apache/tika/extractor/AbstractEmbeddedDocumentBytesHandler.java
index 3f2f38f94..3e009f666 100644
--- a/tika-core/src/main/java/org/apache/tika/extractor/AbstractEmbeddedDocumentBytesHandler.java
+++ b/tika-core/src/main/java/org/apache/tika/extractor/AbstractEmbeddedDocumentBytesHandler.java
@@ -41,11 +41,19 @@ public abstract class AbstractEmbeddedDocumentBytesHandler implements EmbeddedDo
Integer.toString(embeddedId);
- StringBuilder emitKey = new StringBuilder(containerEmitKey)
- .append("/")
- .append(FilenameUtils.getName(containerEmitKey))
- .append(embeddedDocumentBytesConfig.getEmbeddedIdPrefix())
- .append(embeddedIdString);
+ StringBuilder emitKey = new StringBuilder();
+ if (StringUtils.isBlank(embeddedDocumentBytesConfig.getEmitKeyBase())) {
+ emitKey.append(containerEmitKey);
+ emitKey.append("/")
+ .append(FilenameUtils.getName(containerEmitKey));
+ } else {
+ emitKey.append(embeddedDocumentBytesConfig.getEmitKeyBase());
+ }
+ //at this point the emit key has the full "file" part, now we
+ //add the embedded id prefix, the embedded id string and then maybe
+ //the file extension
+ emitKey.append(embeddedDocumentBytesConfig.getEmbeddedIdPrefix())
+ .append(embeddedIdString);
if (embeddedDocumentBytesConfig.getSuffixStrategy().equals(
EmbeddedDocumentBytesConfig.SUFFIX_STRATEGY.EXISTING)) {
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/extractor/EmbeddedDocumentBytesConfig.java b/tika-core/src/main/java/org/apache/tika/pipes/extractor/EmbeddedDocumentBytesConfig.java
index 9ee99c068..542c1c8a3 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/extractor/EmbeddedDocumentBytesConfig.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/extractor/EmbeddedDocumentBytesConfig.java
@@ -56,6 +56,11 @@ public class EmbeddedDocumentBytesConfig implements Serializable {
private boolean includeOriginal = false;
+ //This should be set per file. This allows a custom
+ //emit key base that bypasses the algorithmic generation of the emitKey
+ //from the primary json emitKey
+ private String emitKeyBase = "";
+
/**
* Create an EmbeddedDocumentBytesConfig with
* {@link EmbeddedDocumentBytesConfig#extractEmbeddedDocumentBytes}
@@ -108,6 +113,7 @@ public class EmbeddedDocumentBytesConfig implements Serializable {
public void setSuffixStrategy(SUFFIX_STRATEGY suffixStrategy) {
this.suffixStrategy = suffixStrategy;
}
+
public void setSuffixStrategy(String suffixStrategy) {
setSuffixStrategy(SUFFIX_STRATEGY.valueOf(suffixStrategy));
}
@@ -124,13 +130,21 @@ public class EmbeddedDocumentBytesConfig implements Serializable {
this.includeOriginal = includeOriginal;
}
+ public void setEmitKeyBase(String emitKeyBase) {
+ this.emitKeyBase = emitKeyBase;
+ }
+
+ public String getEmitKeyBase() {
+ return emitKeyBase;
+ }
+
@Override
public String toString() {
- return "EmbeddedDocumentBytesConfig{" + "extractEmbeddedDocumentBytes=" +
- extractEmbeddedDocumentBytes + ", zeroPadName=" + zeroPadName +
- ", suffixStrategy=" + suffixStrategy + ", embeddedIdPrefix='" + embeddedIdPrefix +
- '\'' + ", emitter='" + emitter + '\'' + ", includeOriginal=" + includeOriginal +
- '}';
+ return "EmbeddedDocumentBytesConfig{" + "extractEmbeddedDocumentBytes=" + extractEmbeddedDocumentBytes + ", zeroPadName=" +
+ zeroPadName + ", suffixStrategy=" +
+ suffixStrategy + ", embeddedIdPrefix='" + embeddedIdPrefix + '\'' + ", emitter='" + emitter + '\'' +
+ ", includeOriginal=" + includeOriginal + ", emitKeyBase='" +
+ emitKeyBase + '\'' + '}';
}
@Override
@@ -143,33 +157,22 @@ public class EmbeddedDocumentBytesConfig implements Serializable {
}
EmbeddedDocumentBytesConfig that = (EmbeddedDocumentBytesConfig) o;
-
- if (extractEmbeddedDocumentBytes != that.extractEmbeddedDocumentBytes) {
- return false;
- }
- if (zeroPadName != that.zeroPadName) {
- return false;
- }
- if (includeOriginal != that.includeOriginal) {
- return false;
- }
- if (suffixStrategy != that.suffixStrategy) {
- return false;
- }
- if (!Objects.equals(embeddedIdPrefix, that.embeddedIdPrefix)) {
- return false;
- }
- return Objects.equals(emitter, that.emitter);
+ return extractEmbeddedDocumentBytes == that.extractEmbeddedDocumentBytes && zeroPadName == that.zeroPadName
+ && includeOriginal == that.includeOriginal &&
+ suffixStrategy == that.suffixStrategy && Objects.equals(embeddedIdPrefix, that.embeddedIdPrefix)
+ && Objects.equals(emitter, that.emitter) &&
+ Objects.equals(emitKeyBase, that.emitKeyBase);
}
@Override
public int hashCode() {
- int result = (extractEmbeddedDocumentBytes ? 1 : 0);
+ int result = Boolean.hashCode(extractEmbeddedDocumentBytes);
result = 31 * result + zeroPadName;
- result = 31 * result + (suffixStrategy != null ? suffixStrategy.hashCode() : 0);
- result = 31 * result + (embeddedIdPrefix != null ? embeddedIdPrefix.hashCode() : 0);
- result = 31 * result + (emitter != null ? emitter.hashCode() : 0);
- result = 31 * result + (includeOriginal ? 1 : 0);
+ result = 31 * result + Objects.hashCode(suffixStrategy);
+ result = 31 * result + Objects.hashCode(embeddedIdPrefix);
+ result = 31 * result + Objects.hashCode(emitter);
+ result = 31 * result + Boolean.hashCode(includeOriginal);
+ result = 31 * result + Objects.hashCode(emitKeyBase);
return result;
}
}