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/10/04 14:36:11 UTC
[tika] branch TIKA-3871 created (now 507931f4d)
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a change to branch TIKA-3871
in repository https://gitbox.apache.org/repos/asf/tika.git
at 507931f4d TIKA-3871 -- make checkstyle checks stricter
This branch includes the following new commits:
new 507931f4d TIKA-3871 -- make checkstyle checks stricter
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[tika] 01/01: TIKA-3871 -- make checkstyle checks stricter
Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch TIKA-3871
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 507931f4db8680ceaa78eb40af1a7218f78dedd6
Author: tallison <ta...@apache.org>
AuthorDate: Tue Oct 4 10:35:55 2022 -0400
TIKA-3871 -- make checkstyle checks stricter
---
.../tika/cli/TikaCLIBatchIntegrationTest.java | 2 +-
tika-bundles/tika-bundle-standard/pom.xml | 7 +-
.../test/java/org/apache/tika/bundle/BundleIT.java | 43 +--
.../src/test/resources/log4j.properties | 5 +-
.../tika/pipes/kafka/tests/TikaPipesKafkaTest.java | 66 ++--
.../resources/pipes-fork-server-custom-log4j2.xml | 4 +-
.../src/test/resources/tika-config-kafka.xml | 194 ++++++------
.../opensearch/tests/TikaPipesOpenSearchTest.java | 1 -
.../pipes/xsearch/tests/TikaPipesXSearchBase.java | 4 +-
.../pipes/solr/tests/TikaPipesSolr6ZkTest.java | 7 +-
.../pipes/solr/tests/TikaPipesSolr7ZkTest.java | 7 +-
.../pipes/solr/tests/TikaPipesSolr8ZkTest.java | 8 +-
.../pipes/solr/tests/TikaPipesSolr9ZkTest.java | 7 +-
.../pipes/solr/tests/TikaPipesSolrTestBase.java | 102 +++---
tika-java7/pom.xml | 5 +-
.../filetypedetector/TikaFileTypeDetector.java | 15 +-
.../apache/tika/filetypedetector/package-info.java | 2 +-
.../filetypedetector/TikaFileTypeDetectorTest.java | 30 +-
.../src/test/resources/test-documents/test.html | 7 +-
tika-parent/checkstyle.xml | 5 +
tika-parent/pom.xml | 3 +-
.../translate/impl/AbstractTranslator.java | 2 +-
.../language/translate/impl/CachedTranslator.java | 79 ++---
.../translate/impl/ExternalTranslator.java | 26 +-
.../language/translate/impl/GoogleTranslator.java | 40 ++-
.../translate/impl/JoshuaNetworkTranslator.java | 341 +++++++++++----------
.../language/translate/impl/Lingo24Translator.java | 42 +--
.../language/translate/impl/MarianTranslator.java | 139 +++++----
.../translate/impl/MicrosoftTranslator.java | 73 +++--
.../language/translate/impl/MosesTranslator.java | 39 +--
.../language/translate/impl/RTGTranslator.java | 53 ++--
.../language/translate/impl/YandexTranslator.java | 59 ++--
.../translate/impl/translator.google.properties | 1 +
.../translate/impl/translator.joshua.properties | 3 +-
.../translate/impl/translator.lingo24.properties | 1 +
.../translate/impl/translator.marian.properties | 1 +
.../translate/impl/translator.microsoft.properties | 1 +
.../translate/impl/translator.moses.properties | 3 +-
.../translate/impl/translator.yandex.properties | 1 +
.../translate/impl/CachedTranslatorTest.java | 20 +-
.../translate/impl/GoogleTranslatorTest.java | 105 +++----
.../translate/impl/Lingo24TranslatorTest.java | 9 +-
.../translate/impl/MarianTranslatorTest.java | 7 +-
.../translate/impl/MicrosoftTranslatorTest.java | 39 ++-
.../translate/impl/MosesTranslatorTest.java | 7 +-
.../language/translate/impl/RTGTranslatorTest.java | 11 +-
.../translate/impl/YandexTranslatorTest.java | 5 +-
.../main/java/org/apache/tika/xmp/XMPMetadata.java | 325 ++++++++++----------
.../apache/tika/xmp/convert/AbstractConverter.java | 130 ++++----
.../apache/tika/xmp/convert/GenericConverter.java | 58 ++--
.../tika/xmp/convert/ITikaToXMPConverter.java | 10 +-
.../tika/xmp/convert/MSOfficeBinaryConverter.java | 74 ++---
.../tika/xmp/convert/MSOfficeXMLConverter.java | 107 +++----
.../tika/xmp/convert/OpenDocumentConverter.java | 64 ++--
.../org/apache/tika/xmp/convert/RTFConverter.java | 49 +--
.../org/apache/tika/xmp/convert/TikaToXMP.java | 83 +++--
.../java/org/apache/tika/xmp/TikaToXMPTest.java | 168 +++++-----
.../java/org/apache/tika/xmp/XMPMetadataTest.java | 143 +++++----
58 files changed, 1424 insertions(+), 1418 deletions(-)
diff --git a/tika-app/src/test/java/org/apache/tika/cli/TikaCLIBatchIntegrationTest.java b/tika-app/src/test/java/org/apache/tika/cli/TikaCLIBatchIntegrationTest.java
index ee7749d88..b482db13e 100644
--- a/tika-app/src/test/java/org/apache/tika/cli/TikaCLIBatchIntegrationTest.java
+++ b/tika-app/src/test/java/org/apache/tika/cli/TikaCLIBatchIntegrationTest.java
@@ -98,7 +98,7 @@ public class TikaCLIBatchIntegrationTest {
String[] params = {
"-i", testInputDirForCommandLine,
"-o", tempOutputDirForCommandLine,
- "--config="+configFile.toAbsolutePath().toString()};
+ "--config=" + configFile.toAbsolutePath().toString() };
TikaCLI.main(params);
assertFileExists(tempOutputDir.resolve("bad_xml.xml.xml"));
assertFileExists(tempOutputDir.resolve("coffee.xls.xml"));
diff --git a/tika-bundles/tika-bundle-standard/pom.xml b/tika-bundles/tika-bundle-standard/pom.xml
index 81fb66a17..0529eab67 100644
--- a/tika-bundles/tika-bundle-standard/pom.xml
+++ b/tika-bundles/tika-bundle-standard/pom.xml
@@ -18,7 +18,8 @@
under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -40,6 +41,10 @@
from the tika-parsers component.
</description>
<url>https://tika.apache.org/</url>
+ <!-- pax doesn't yet work with junit4; checkstyle forbids junit4. -->
+ <properties>
+ <checkstyle.skip>true</checkstyle.skip>
+ </properties>
<dependencies>
<dependency>
diff --git a/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java b/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java
index 2d04ac1f9..340b1ba17 100644
--- a/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java
+++ b/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java
@@ -41,9 +41,22 @@ import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
-
import javax.inject.Inject;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
import org.apache.tika.Tika;
import org.apache.tika.detect.DefaultDetector;
import org.apache.tika.detect.Detector;
@@ -62,19 +75,6 @@ import org.apache.tika.parser.Parser;
import org.apache.tika.parser.internal.Activator;
import org.apache.tika.parser.ocr.TesseractOCRParser;
import org.apache.tika.sax.BodyContentHandler;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
@@ -94,8 +94,7 @@ public class BundleIT {
@Configuration
public Option[] configuration() throws IOException, URISyntaxException, ClassNotFoundException {
File base = new File(TARGET, "test-bundles");
- return options(
- systemPackages("javax.xml.bind"),
+ return options(systemPackages("javax.xml.bind"),
bundle(new File(base, "tika-core.jar").toURI().toURL().toString()),
//I couldn't find a way to get the build of bundle to work via imports
//for this one
@@ -105,8 +104,7 @@ public class BundleIT {
mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.8.5"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.8.5"),
junitBundles(),
- bundle(new File(base, "tika-bundle-standard.jar").toURI().toURL().toString())
- );
+ bundle(new File(base, "tika-bundle-standard.jar").toURI().toURL().toString()));
}
@Test
@@ -276,7 +274,8 @@ public class BundleIT {
ParseContext context = new ParseContext();
context.set(Parser.class, parser);
- try (InputStream stream = TikaInputStream.get(Paths.get("src/test/resources/test-documents.zip"))) {
+ try (InputStream stream = TikaInputStream.get(
+ Paths.get("src/test/resources/test-documents.zip"))) {
parser.parse(stream, handler, new Metadata(), context);
}
@@ -311,7 +310,8 @@ public class BundleIT {
ParseContext context = new ParseContext();
context.set(Parser.class, parser);
- try (InputStream stream = TikaInputStream.get(Paths.get("src/test/resources/testPPT.pptx"))) {
+ try (InputStream stream = TikaInputStream.get(
+ Paths.get("src/test/resources/testPPT.pptx"))) {
parser.parse(stream, handler, new Metadata(), context);
}
@@ -350,7 +350,8 @@ public class BundleIT {
System.err.println("tika Exception " + f.getName());
e.printStackTrace();
}
- System.out.println(Arrays.asList(metadata.getValues(TikaCoreProperties.TIKA_PARSED_BY)));
+ System.out.println(
+ Arrays.asList(metadata.getValues(TikaCoreProperties.TIKA_PARSED_BY)));
}
}
diff --git a/tika-bundles/tika-bundle-standard/src/test/resources/log4j.properties b/tika-bundles/tika-bundle-standard/src/test/resources/log4j.properties
index 7d3b372cc..e695468ee 100644
--- a/tika-bundles/tika-bundle-standard/src/test/resources/log4j.properties
+++ b/tika-bundles/tika-bundle-standard/src/test/resources/log4j.properties
@@ -12,13 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
#info,debug, error,fatal ...
log4j.rootLogger=info,stderr
-
#console
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.Target=System.err
-
-log4j.appender.stderr.layout.ConversionPattern= %-5p %m%n
+log4j.appender.stderr.layout.ConversionPattern=%-5p %m%n
diff --git a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/java/org/apache/tika/pipes/kafka/tests/TikaPipesKafkaTest.java b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/java/org/apache/tika/pipes/kafka/tests/TikaPipesKafkaTest.java
index 6be1eb24f..c2edb8ac5 100644
--- a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/java/org/apache/tika/pipes/kafka/tests/TikaPipesKafkaTest.java
+++ b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/java/org/apache/tika/pipes/kafka/tests/TikaPipesKafkaTest.java
@@ -48,8 +48,6 @@ import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;
-import org.apache.tika.cli.TikaCLI;
-import org.apache.tika.pipes.HandlerConfig;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -61,6 +59,9 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testcontainers.utility.DockerImageName;
+import org.apache.tika.cli.TikaCLI;
+import org.apache.tika.pipes.HandlerConfig;
+
/**
* Test will emit some documents into a Kafka "pipe_iterator_topic", then kafka pipe iterator will
* poll those documents and send them to tika pipes. Tika pipes will then use a file fetcher to fetch/parse, then
@@ -69,8 +70,6 @@ import org.testcontainers.utility.DockerImageName;
*/
@Testcontainers(disabledWithoutDocker = true)
public class TikaPipesKafkaTest {
- private static final Logger LOG = LoggerFactory.getLogger(TikaPipesKafkaTest.class);
-
public static final String PIPE_ITERATOR_TOPIC = "pipe_iterator_topic";
public static final String EMITTER_TOPIC = "emitter_topic";
/**
@@ -78,6 +77,7 @@ public class TikaPipesKafkaTest {
* emitter_topic and fail the test.
*/
public static final int WAIT_FOR_EMITTED_DOCS_TIMEOUT_MINUTES = 2;
+ private static final Logger LOG = LoggerFactory.getLogger(TikaPipesKafkaTest.class);
private final int numDocs = 42;
private final ObjectMapper objectMapper = new ObjectMapper();
@@ -85,6 +85,7 @@ public class TikaPipesKafkaTest {
private final File testFileFolder = new File("target", "test-files");
private final Set<String> waitingFor = new HashSet<>();
+ KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"));
private void createTestFiles() throws Exception {
if (testFileFolder.mkdirs()) {
@@ -98,8 +99,6 @@ public class TikaPipesKafkaTest {
}
}
- KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"));
-
@BeforeEach
public void before() {
kafka.start();
@@ -111,8 +110,7 @@ public class TikaPipesKafkaTest {
}
@Test
- public void testKafkaPipeIteratorAndEmitter()
- throws Exception {
+ public void testKafkaPipeIteratorAndEmitter() throws Exception {
createTestFiles();
File tikaConfigFile = new File("target", "ta.xml");
File log4jPropFile = new File("target", "tmp-log4j2.xml");
@@ -122,8 +120,7 @@ public class TikaPipesKafkaTest {
FileUtils.copyInputStreamToFile(is, log4jPropFile);
}
String tikaConfigTemplateXml;
- try (InputStream is = this.getClass()
- .getResourceAsStream("/tika-config-kafka.xml")) {
+ try (InputStream is = this.getClass().getResourceAsStream("/tika-config-kafka.xml")) {
assert is != null;
tikaConfigTemplateXml = IOUtils.toString(is, StandardCharsets.UTF_8);
}
@@ -131,14 +128,18 @@ public class TikaPipesKafkaTest {
Properties consumerProps = new Properties();
consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
consumerProps.put("group.id", UUID.randomUUID().toString());
- consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
- consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
+ consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
+ StringDeserializer.class.getName());
+ consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
+ StringDeserializer.class.getName());
consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
Properties producerProps = new Properties();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers());
- producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
- producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
+ producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
+ StringSerializer.class.getName());
+ producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+ StringSerializer.class.getName());
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProps);
LOG.info("Listening to EMITTER_TOPIC={}", EMITTER_TOPIC);
@@ -155,9 +156,9 @@ public class TikaPipesKafkaTest {
meta.put("path", nextFile.getAbsolutePath());
meta.put("totalSpace", nextFile.getTotalSpace());
try {
- producer.send(new ProducerRecord<>(PIPE_ITERATOR_TOPIC,
- nextFile.getAbsolutePath(),
- objectMapper.writeValueAsString(meta))).get();
+ producer.send(
+ new ProducerRecord<>(PIPE_ITERATOR_TOPIC, nextFile.getAbsolutePath(),
+ objectMapper.writeValueAsString(meta))).get();
LOG.info("Sent fetch request : {}", nextFile.getAbsolutePath());
++numSent;
} catch (Exception e) {
@@ -170,28 +171,31 @@ public class TikaPipesKafkaTest {
es.execute(() -> {
try {
String tikaConfigXml =
- createTikaConfigXml(tikaConfigFile, log4jPropFile, tikaConfigTemplateXml
- );
+ createTikaConfigXml(tikaConfigFile, log4jPropFile, tikaConfigTemplateXml);
FileUtils.writeStringToFile(tikaConfigFile, tikaConfigXml, StandardCharsets.UTF_8);
- TikaCLI.main(new String[] {"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
+ TikaCLI.main(new String[]{"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
} catch (Exception e) {
throw new RuntimeException(e);
}
});
- LOG.info("Tika pipes have been started. See if we can pull the response messages from the EMITTER_TOPIC={}", EMITTER_TOPIC);
+ LOG.info(
+ "Tika pipes have been started. See if we can pull the response messages from the EMITTER_TOPIC={}",
+ EMITTER_TOPIC);
Stopwatch stopwatch = Stopwatch.createStarted();
while (!waitingFor.isEmpty()) {
- assertFalse(
- stopwatch.elapsed(TimeUnit.MINUTES) > WAIT_FOR_EMITTED_DOCS_TIMEOUT_MINUTES,
- "Timed out after " + WAIT_FOR_EMITTED_DOCS_TIMEOUT_MINUTES + " minutes waiting for the emitted docs");
+ assertFalse(stopwatch.elapsed(TimeUnit.MINUTES) > WAIT_FOR_EMITTED_DOCS_TIMEOUT_MINUTES,
+ "Timed out after " + WAIT_FOR_EMITTED_DOCS_TIMEOUT_MINUTES +
+ " minutes waiting for the emitted docs");
try {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(1));
for (ConsumerRecord<String, String> record : records) {
String val = record.value();
- Map<String, Object> valMap = objectMapper.readValue(val, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> valMap =
+ objectMapper.readValue(val, new TypeReference<Map<String, Object>>() {
+ });
waitingFor.remove(FilenameUtils.getName(record.key()));
assertNotNull(valMap.get("content_s"));
assertNotNull(valMap.get("mime_s"));
@@ -210,11 +214,11 @@ public class TikaPipesKafkaTest {
private String createTikaConfigXml(File tikaConfigFile, File log4jPropFile,
String tikaConfigTemplateXml) {
return tikaConfigTemplateXml.replace("{TIKA_CONFIG}", tikaConfigFile.getAbsolutePath())
- .replace("{LOG4J_PROPERTIES_FILE}", log4jPropFile.getAbsolutePath())
- .replace("{PATH_TO_DOCS}", testFileFolder.getAbsolutePath())
- .replace("{PARSE_MODE}", HandlerConfig.PARSE_MODE.RMETA.name())
- .replace("{PIPE_ITERATOR_TOPIC}", PIPE_ITERATOR_TOPIC)
- .replace("{EMITTER_TOPIC}", EMITTER_TOPIC)
- .replace("{BOOTSTRAP_SERVERS}", kafka.getBootstrapServers());
+ .replace("{LOG4J_PROPERTIES_FILE}", log4jPropFile.getAbsolutePath())
+ .replace("{PATH_TO_DOCS}", testFileFolder.getAbsolutePath())
+ .replace("{PARSE_MODE}", HandlerConfig.PARSE_MODE.RMETA.name())
+ .replace("{PIPE_ITERATOR_TOPIC}", PIPE_ITERATOR_TOPIC)
+ .replace("{EMITTER_TOPIC}", EMITTER_TOPIC)
+ .replace("{BOOTSTRAP_SERVERS}", kafka.getBootstrapServers());
}
}
diff --git a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/pipes-fork-server-custom-log4j2.xml b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/pipes-fork-server-custom-log4j2.xml
index 5f946e6e5..f5e70eedb 100644
--- a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/pipes-fork-server-custom-log4j2.xml
+++ b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/pipes-fork-server-custom-log4j2.xml
@@ -21,12 +21,12 @@
<Appenders>
<Console name="console" target="SYSTEM_ERR">
<PatternLayout
- pattern="%-5p [%t] %d{HH:mm:ss,SSS} %c %m%n" />
+ pattern="%-5p [%t] %d{HH:mm:ss,SSS} %c %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
- <AppenderRef ref="console" />
+ <AppenderRef ref="console"/>
</Root>
</Loggers>
</Configuration>
diff --git a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/tika-config-kafka.xml b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/tika-config-kafka.xml
index f15faf262..68d517cbb 100644
--- a/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/tika-config-kafka.xml
+++ b/tika-integration-tests/tika-pipes-kafka-integration-tests/src/test/resources/tika-config-kafka.xml
@@ -18,101 +18,101 @@
under the License.
-->
<properties>
- <parsers>
- <parser class="org.apache.tika.parser.DefaultParser">
- <parser-exclude class="org.apache.tika.parser.ocr.TesseractOCRParser"/>
- <parser-exclude class="org.apache.tika.parser.pdf.PDFParser"/>
- <parser-exclude class="org.apache.tika.parser.microsoft.ooxml.OOXMLParser"/>
- <parser-exclude class="org.apache.tika.parser.microsoft.OfficeParser"/>
- </parser>
- <parser class="org.apache.tika.parser.pdf.PDFParser">
- <params>
- <param name="extractActions" type="bool">true</param>
- <param name="checkExtractAccessPermissions" type="bool">true</param>
- </params>
- </parser>
- <parser class="org.apache.tika.parser.microsoft.ooxml.OOXMLParser">
- <params>
- <param name="includeDeletedContent" type="bool">true</param>
- <param name="includeMoveFromContent" type="bool">true</param>
- <param name="extractMacros" type="bool">true</param>
- </params>
- </parser>
- <parser class="org.apache.tika.parser.microsoft.OfficeParser">
- <params>
- <param name="extractMacros" type="bool">true</param>
- </params>
- </parser>
- </parsers>
- <metadataFilters>
- <!-- depending on the file format, some dates do not have a timezone. This
- filter arbitrarily assumes dates have a UTC timezone and will format all
- dates as yyyy-MM-dd'T'HH:mm:ss'Z' whether or not they actually have a timezone.
- -->
- <metadataFilter class="org.apache.tika.metadata.filter.DateNormalizingMetadataFilter"/>
- <metadataFilter class="org.apache.tika.metadata.filter.FieldNameMappingFilter">
- <params>
- <excludeUnmapped>true</excludeUnmapped>
- <mappings>
- <mapping from="X-TIKA:content" to="content_s"/>
- <mapping from="Content-Length" to="length_i"/>
- <mapping from="dc:creator" to="creators_ss"/>
- <mapping from="dc:title" to="title_s"/>
- <mapping from="Content-Type" to="mime_s"/>
- <mapping from="X-TIKA:EXCEPTION:container_exception" to="tika_exception_s"/>
- </mappings>
- </params>
- </metadataFilter>
- </metadataFilters>
- <async>
- <params>
- <maxForEmitBatchBytes>10000</maxForEmitBatchBytes>
- <emitMaxEstimatedBytes>100000</emitMaxEstimatedBytes>
- <emitWithinMillis>10</emitWithinMillis>
- <numEmitters>1</numEmitters>
- <numClients>1</numClients>
- <tikaConfig>{TIKA_CONFIG}</tikaConfig>
- <forkedJvmArgs>
- <arg>-Xmx1g</arg>
- <arg>-XX:ParallelGCThreads=2</arg>
- <arg>-XX:+ExitOnOutOfMemoryError</arg>
- <arg>-Dlog4j.configurationFile={LOG4J_PROPERTIES_FILE}</arg>
- </forkedJvmArgs>
- <timeoutMillis>60000</timeoutMillis>
- </params>
- </async>
- <fetchers>
- <fetcher class="org.apache.tika.pipes.fetcher.fs.FileSystemFetcher">
- <params>
- <name>fsf</name>
- <basePath>{PATH_TO_DOCS}</basePath>
- </params>
- </fetcher>
- </fetchers>
- <emitters>
- <emitter class="org.apache.tika.pipes.emitter.kafka.KafkaEmitter">
- <params>
- <name>ke</name>
- <topic>{EMITTER_TOPIC}</topic>
- <bootstrapServers>{BOOTSTRAP_SERVERS}</bootstrapServers>
- </params>
- </emitter>
- <emitter class="org.apache.tika.pipes.emitter.fs.FileSystemEmitter">
- <params>
- <name>fse</name>
- <basePath>/path/to/extracts</basePath>
- </params>
- </emitter>
- </emitters>
- <pipesIterator class="org.apache.tika.pipes.pipesiterator.kafka.KafkaPipesIterator">
- <params>
- <topic>{PIPE_ITERATOR_TOPIC}</topic>
- <bootstrapServers>{BOOTSTRAP_SERVERS}</bootstrapServers>
- <groupId>grpid</groupId>
- <autoOffsetReset>earliest</autoOffsetReset>
- <pollDelayMs>1000</pollDelayMs>
- <fetcherName>fsf</fetcherName>
- <emitterName>ke</emitterName>
- </params>
- </pipesIterator>
+ <parsers>
+ <parser class="org.apache.tika.parser.DefaultParser">
+ <parser-exclude class="org.apache.tika.parser.ocr.TesseractOCRParser"/>
+ <parser-exclude class="org.apache.tika.parser.pdf.PDFParser"/>
+ <parser-exclude class="org.apache.tika.parser.microsoft.ooxml.OOXMLParser"/>
+ <parser-exclude class="org.apache.tika.parser.microsoft.OfficeParser"/>
+ </parser>
+ <parser class="org.apache.tika.parser.pdf.PDFParser">
+ <params>
+ <param name="extractActions" type="bool">true</param>
+ <param name="checkExtractAccessPermissions" type="bool">true</param>
+ </params>
+ </parser>
+ <parser class="org.apache.tika.parser.microsoft.ooxml.OOXMLParser">
+ <params>
+ <param name="includeDeletedContent" type="bool">true</param>
+ <param name="includeMoveFromContent" type="bool">true</param>
+ <param name="extractMacros" type="bool">true</param>
+ </params>
+ </parser>
+ <parser class="org.apache.tika.parser.microsoft.OfficeParser">
+ <params>
+ <param name="extractMacros" type="bool">true</param>
+ </params>
+ </parser>
+ </parsers>
+ <metadataFilters>
+ <!-- depending on the file format, some dates do not have a timezone. This
+ filter arbitrarily assumes dates have a UTC timezone and will format all
+ dates as yyyy-MM-dd'T'HH:mm:ss'Z' whether or not they actually have a timezone.
+ -->
+ <metadataFilter class="org.apache.tika.metadata.filter.DateNormalizingMetadataFilter"/>
+ <metadataFilter class="org.apache.tika.metadata.filter.FieldNameMappingFilter">
+ <params>
+ <excludeUnmapped>true</excludeUnmapped>
+ <mappings>
+ <mapping from="X-TIKA:content" to="content_s"/>
+ <mapping from="Content-Length" to="length_i"/>
+ <mapping from="dc:creator" to="creators_ss"/>
+ <mapping from="dc:title" to="title_s"/>
+ <mapping from="Content-Type" to="mime_s"/>
+ <mapping from="X-TIKA:EXCEPTION:container_exception" to="tika_exception_s"/>
+ </mappings>
+ </params>
+ </metadataFilter>
+ </metadataFilters>
+ <async>
+ <params>
+ <maxForEmitBatchBytes>10000</maxForEmitBatchBytes>
+ <emitMaxEstimatedBytes>100000</emitMaxEstimatedBytes>
+ <emitWithinMillis>10</emitWithinMillis>
+ <numEmitters>1</numEmitters>
+ <numClients>1</numClients>
+ <tikaConfig>{TIKA_CONFIG}</tikaConfig>
+ <forkedJvmArgs>
+ <arg>-Xmx1g</arg>
+ <arg>-XX:ParallelGCThreads=2</arg>
+ <arg>-XX:+ExitOnOutOfMemoryError</arg>
+ <arg>-Dlog4j.configurationFile={LOG4J_PROPERTIES_FILE}</arg>
+ </forkedJvmArgs>
+ <timeoutMillis>60000</timeoutMillis>
+ </params>
+ </async>
+ <fetchers>
+ <fetcher class="org.apache.tika.pipes.fetcher.fs.FileSystemFetcher">
+ <params>
+ <name>fsf</name>
+ <basePath>{PATH_TO_DOCS}</basePath>
+ </params>
+ </fetcher>
+ </fetchers>
+ <emitters>
+ <emitter class="org.apache.tika.pipes.emitter.kafka.KafkaEmitter">
+ <params>
+ <name>ke</name>
+ <topic>{EMITTER_TOPIC}</topic>
+ <bootstrapServers>{BOOTSTRAP_SERVERS}</bootstrapServers>
+ </params>
+ </emitter>
+ <emitter class="org.apache.tika.pipes.emitter.fs.FileSystemEmitter">
+ <params>
+ <name>fse</name>
+ <basePath>/path/to/extracts</basePath>
+ </params>
+ </emitter>
+ </emitters>
+ <pipesIterator class="org.apache.tika.pipes.pipesiterator.kafka.KafkaPipesIterator">
+ <params>
+ <topic>{PIPE_ITERATOR_TOPIC}</topic>
+ <bootstrapServers>{BOOTSTRAP_SERVERS}</bootstrapServers>
+ <groupId>grpid</groupId>
+ <autoOffsetReset>earliest</autoOffsetReset>
+ <pollDelayMs>1000</pollDelayMs>
+ <fetcherName>fsf</fetcherName>
+ <emitterName>ke</emitterName>
+ </params>
+ </pipesIterator>
</properties>
\ No newline at end of file
diff --git a/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests/TikaPipesOpenSearchTest.java b/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests/TikaPipesOpenSearchTest.java
index 6c36c11c7..f7771be07 100644
--- a/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests/TikaPipesOpenSearchTest.java
+++ b/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests/TikaPipesOpenSearchTest.java
@@ -20,7 +20,6 @@ package org.apache.tika.pipes.opensearch.tests;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
diff --git a/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/xsearch/tests/TikaPipesXSearchBase.java b/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/xsearch/tests/TikaPipesXSearchBase.java
index 7e5873b14..75b091943 100644
--- a/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/xsearch/tests/TikaPipesXSearchBase.java
+++ b/tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/xsearch/tests/TikaPipesXSearchBase.java
@@ -37,7 +37,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
@@ -149,8 +148,7 @@ public abstract class TikaPipesXSearchBase {
JsonResponse results = CLIENT.postJson(endpoint + "/_search", query);
assertEquals(200, results.getStatus());
- assertEquals(numHtmlDocs + 1,
- results.getJson().get("hits").get("total").get("value").asInt());
+ assertEquals(numHtmlDocs + 1, results.getJson().get("hits").get("total").get("value").asInt());
//now try match all
query = "{ " +
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr6ZkTest.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr6ZkTest.java
index 91cb6cd2d..221d1e277 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr6ZkTest.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr6ZkTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.tika.pipes.solr.tests;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -28,8 +28,9 @@ public class TikaPipesSolr6ZkTest extends TikaPipesSolr6Test {
@BeforeAll
public static void setUp() {
- assumeTrue("zk test only works on linux (and not mac os x)",
- SystemUtils.IS_OS_UNIX && ! SystemUtils.IS_OS_MAC_OSX);
+ assumeTrue(
+ SystemUtils.IS_OS_UNIX && !SystemUtils.IS_OS_MAC_OSX,
+ "zk test only works on linux (and not mac os x)");
}
@Override
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr7ZkTest.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr7ZkTest.java
index 2ffea2221..875afe223 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr7ZkTest.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr7ZkTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.tika.pipes.solr.tests;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -28,8 +28,9 @@ public class TikaPipesSolr7ZkTest extends TikaPipesSolr7Test {
@BeforeAll
public static void setUp() {
- assumeTrue("zk test only works on linux (and not mac os x)",
- SystemUtils.IS_OS_UNIX && ! SystemUtils.IS_OS_MAC_OSX);
+ assumeTrue(
+ SystemUtils.IS_OS_UNIX && !SystemUtils.IS_OS_MAC_OSX,
+ "zk test only works on linux (and not mac os x)");
}
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr8ZkTest.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr8ZkTest.java
index f689fbb2e..91293fe78 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr8ZkTest.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr8ZkTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.tika.pipes.solr.tests;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -28,8 +28,10 @@ public class TikaPipesSolr8ZkTest extends TikaPipesSolr8Test {
@BeforeAll
public static void setUp() {
- assumeTrue("zk test only works on linux (and not mac os x)",
- SystemUtils.IS_OS_UNIX && ! SystemUtils.IS_OS_MAC_OSX);
+ assumeTrue(
+ SystemUtils.IS_OS_UNIX && !SystemUtils.IS_OS_MAC_OSX,
+ "zk test only works on linux (and not mac os x)");
+
}
@Override
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr9ZkTest.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr9ZkTest.java
index 402a13e01..fa6571f39 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr9ZkTest.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolr9ZkTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.tika.pipes.solr.tests;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
@@ -30,8 +30,9 @@ public class TikaPipesSolr9ZkTest extends TikaPipesSolr9Test {
@BeforeAll
public static void setUp() {
- assumeTrue("zk test only works on linux (and not mac os x)",
- SystemUtils.IS_OS_UNIX && ! SystemUtils.IS_OS_MAC_OSX);
+ assumeTrue(
+ SystemUtils.IS_OS_UNIX && !SystemUtils.IS_OS_MAC_OSX,
+ "zk test only works on linux (and not mac os x)");
}
@Override
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
index c4c8be31d..640cfc45a 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -32,12 +33,7 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
-import org.apache.tika.cli.TikaCLI;
-import org.apache.tika.pipes.HandlerConfig;
-import org.apache.tika.pipes.emitter.solr.SolrEmitter;
-import org.apache.tika.utils.SystemUtils;
import org.jetbrains.annotations.NotNull;
-
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -47,6 +43,11 @@ import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testcontainers.utility.DockerImageName;
+import org.apache.tika.cli.TikaCLI;
+import org.apache.tika.pipes.HandlerConfig;
+import org.apache.tika.pipes.emitter.solr.SolrEmitter;
+import org.apache.tika.utils.SystemUtils;
+
public abstract class TikaPipesSolrTestBase {
@@ -61,37 +62,33 @@ public abstract class TikaPipesSolrTestBase {
private int zkPort;
private String solrEndpoint;
+ public TikaPipesSolrTestBase() {
+ try {
+ init();
+ } catch (InterruptedException e) {
+ //swallow
+ }
+ }
+
public abstract boolean useZk();
public abstract String getSolrImageName();
-
public boolean handlesParentChild() {
return true;
}
- public TikaPipesSolrTestBase() {
- try {
- init();
- } catch (InterruptedException e) {
-
- }
- }
-
private void init() throws InterruptedException {
if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_VERSION_WSL) {
// Networking on these operating systems needs fixed ports and localhost to be passed for the SolrCloud
// with Zookeeper tests to succeed. This means stopping and starting needs
- solr =
- new FixedHostPortGenericContainer<>(DockerImageName.parse(getSolrImageName()).toString())
- .withFixedExposedPort(8983,8983)
- .withFixedExposedPort(9983,9983)
- .withCommand("-DzkRun -Dhost=localhost");
+ solr = new FixedHostPortGenericContainer<>(
+ DockerImageName.parse(getSolrImageName()).toString()).withFixedExposedPort(8983,
+ 8983).withFixedExposedPort(9983, 9983).withCommand("-DzkRun -Dhost=localhost");
} else {
- solr =
- new GenericContainer<>(DockerImageName.parse(getSolrImageName())).withExposedPorts(8983,
- 9983)
- .withCommand("-DzkRun");
+ solr = new GenericContainer<>(
+ DockerImageName.parse(getSolrImageName())).withExposedPorts(8983, 9983)
+ .withCommand("-DzkRun");
}
solr.start();
@@ -132,7 +129,8 @@ public abstract class TikaPipesSolrTestBase {
FileUtils.writeStringToFile(new File(testFileFolder, "test-" + i + ".html"),
"<html><body>" + bodyContent + "</body></html>", StandardCharsets.UTF_8);
}
- FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/embedded/embedded.docx"),
+ FileUtils.copyInputStreamToFile(
+ this.getClass().getResourceAsStream("/embedded/embedded.docx"),
new File(testFileFolder, "test-embedded.docx"));
}
@@ -170,32 +168,25 @@ public abstract class TikaPipesSolrTestBase {
try (CloseableHttpClient client = HttpClients.createMinimal()) {
HttpPost postAddRoot = new HttpPost(solrUrl + "/schema");
postAddRoot.setHeader("Content-Type", "application/json");
- postAddRoot.setEntity(new StringEntity("{\n" +
- " \"add-field\":{\n" +
- " \"name\":\"path\",\n" +
- " \"type\":\"string\",\n" +
- " \"indexed\":true,\n" +
- " \"stored\":true, \n" +
- " \"docValues\":false \n" +
- " }\n" +
- "}"));
+ postAddRoot.setEntity(new StringEntity(
+ "{\n" + " \"add-field\":{\n" + " \"name\":\"path\",\n" +
+ " \"type\":\"string\",\n" + " \"indexed\":true,\n" +
+ " \"stored\":true, \n" + " \"docValues\":false \n" + " }\n" +
+ "}"));
CloseableHttpResponse resp = client.execute(postAddRoot);
assertEquals(200, resp.getStatusLine().getStatusCode());
}
}
+
private void addSchemaFieldsForNestedDocs(String solrUrl) throws IOException {
try (CloseableHttpClient client = HttpClients.createMinimal()) {
HttpPost postAddRoot = new HttpPost(solrUrl + "/schema");
postAddRoot.setHeader("Content-Type", "application/json");
- postAddRoot.setEntity(new StringEntity("{\n" +
- " \"replace-field\":{\n" +
- " \"name\":\"_root_\",\n" +
- " \"type\":\"string\",\n" +
- " \"indexed\":true,\n" +
- " \"stored\":true, \n" +
- " \"docValues\":false \n" +
- " }\n" +
- "}"));
+ postAddRoot.setEntity(new StringEntity(
+ "{\n" + " \"replace-field\":{\n" + " \"name\":\"_root_\",\n" +
+ " \"type\":\"string\",\n" + " \"indexed\":true,\n" +
+ " \"stored\":true, \n" + " \"docValues\":false \n" + " }\n" +
+ "}"));
CloseableHttpResponse resp = client.execute(postAddRoot);
assertEquals(200, resp.getStatusLine().getStatusCode());
}
@@ -204,8 +195,7 @@ public abstract class TikaPipesSolrTestBase {
/**
* Runs a test using Solr Pipe Iterator, File Fetcher and Solr Emitter.
*/
- protected void runTikaAsyncSolrPipeIteratorFileFetcherSolrEmitter()
- throws Exception {
+ protected void runTikaAsyncSolrPipeIteratorFileFetcherSolrEmitter() throws Exception {
File tikaConfigFile = new File("target", "ta.xml");
File log4jPropFile = new File("target", "tmp-log4j2.xml");
try (InputStream is = this.getClass()
@@ -213,29 +203,27 @@ public abstract class TikaPipesSolrTestBase {
FileUtils.copyInputStreamToFile(is, log4jPropFile);
}
String tikaConfigTemplateXml;
- try (InputStream is = this.getClass()
- .getResourceAsStream("/tika-config-solr-urls.xml")) {
+ try (InputStream is = this.getClass().getResourceAsStream("/tika-config-solr-urls.xml")) {
tikaConfigTemplateXml = IOUtils.toString(is, StandardCharsets.UTF_8);
}
String tikaConfigXml =
createTikaConfigXml(useZk(), tikaConfigFile, log4jPropFile, tikaConfigTemplateXml,
- SolrEmitter.UpdateStrategy.ADD,
- SolrEmitter.AttachmentStrategy.PARENT_CHILD,
+ SolrEmitter.UpdateStrategy.ADD, SolrEmitter.AttachmentStrategy.PARENT_CHILD,
HandlerConfig.PARSE_MODE.RMETA);
FileUtils.writeStringToFile(tikaConfigFile, tikaConfigXml, StandardCharsets.UTF_8);
- TikaCLI.main(new String[] {"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
+ TikaCLI.main(new String[]{"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
try (SolrClient solrClient = new LBHttpSolrClient.Builder().withBaseSolrUrls(solrEndpoint)
.build()) {
solrClient.commit(collection, true, true);
- assertEquals(numDocs, solrClient
- .query(collection, new SolrQuery("mime_s:\"text/html; charset=ISO-8859-1\""))
- .getResults().getNumFound());
+ assertEquals(numDocs, solrClient.query(collection,
+ new SolrQuery("mime_s:\"text/html; charset=ISO-8859-1\"")).getResults()
+ .getNumFound());
assertEquals(numDocs,
solrClient.query(collection, new SolrQuery("content_s:*initial*")).getResults()
.getNumFound());
- if(handlesParentChild()) {
+ if (handlesParentChild()) {
assertEquals(3,
solrClient.query(collection, new SolrQuery("_root_:\"test-embedded.docx\""))
.getResults().getNumFound());
@@ -259,14 +247,14 @@ public abstract class TikaPipesSolrTestBase {
HandlerConfig.PARSE_MODE.RMETA);
FileUtils.writeStringToFile(tikaConfigFile, tikaConfigXml, StandardCharsets.UTF_8);
- TikaCLI.main(new String[] {"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
+ TikaCLI.main(new String[]{"-a", "--config=" + tikaConfigFile.getAbsolutePath()});
try (SolrClient solrClient = new LBHttpSolrClient.Builder().withBaseSolrUrls(solrEndpoint)
.build()) {
solrClient.commit(collection, true, true);
- assertEquals(numDocs, solrClient
- .query(collection, new SolrQuery("mime_s:\"text/html; charset=ISO-8859-1\""))
- .getResults().getNumFound());
+ assertEquals(numDocs, solrClient.query(collection,
+ new SolrQuery("mime_s:\"text/html; charset=ISO-8859-1\"")).getResults()
+ .getNumFound());
assertEquals(numDocs,
solrClient.query(collection, new SolrQuery("content_s:*updated*")).getResults()
.getNumFound());
diff --git a/tika-java7/pom.xml b/tika-java7/pom.xml
index 65dede2a1..c8f5af62d 100644
--- a/tika-java7/pom.xml
+++ b/tika-java7/pom.xml
@@ -19,7 +19,8 @@
under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -57,7 +58,7 @@
<Export-Package>
org.apache.tika.filetypedetector
</Export-Package>
- <Private-Package />
+ <Private-Package/>
</instructions>
</configuration>
</plugin>
diff --git a/tika-java7/src/main/java/org/apache/tika/filetypedetector/TikaFileTypeDetector.java b/tika-java7/src/main/java/org/apache/tika/filetypedetector/TikaFileTypeDetector.java
index c479ade03..8d31459b2 100644
--- a/tika-java7/src/main/java/org/apache/tika/filetypedetector/TikaFileTypeDetector.java
+++ b/tika-java7/src/main/java/org/apache/tika/filetypedetector/TikaFileTypeDetector.java
@@ -26,28 +26,29 @@ import org.apache.tika.mime.MimeTypes;
public class TikaFileTypeDetector extends FileTypeDetector {
private final Tika tika = new Tika();
-
+
public TikaFileTypeDetector() {
super();
}
-
+
@Override
public String probeContentType(Path path) throws IOException {
// Try to detect based on the file name only for efficiency
String fileNameDetect = tika.detect(path.toString());
- if(!fileNameDetect.equals(MimeTypes.OCTET_STREAM)) {
+ if (!fileNameDetect.equals(MimeTypes.OCTET_STREAM)) {
return fileNameDetect;
}
-
+
// Then check the file content if necessary
String fileContentDetect = tika.detect(path);
- if(!fileContentDetect.equals(MimeTypes.OCTET_STREAM)) {
+ if (!fileContentDetect.equals(MimeTypes.OCTET_STREAM)) {
return fileContentDetect;
}
-
+
// Specification says to return null if we could not
// conclusively determine the file type
return null;
}
-
+
}
+
diff --git a/tika-java7/src/main/java/org/apache/tika/filetypedetector/package-info.java b/tika-java7/src/main/java/org/apache/tika/filetypedetector/package-info.java
index 7a680f3b6..a7a82cd5a 100644
--- a/tika-java7/src/main/java/org/apache/tika/filetypedetector/package-info.java
+++ b/tika-java7/src/main/java/org/apache/tika/filetypedetector/package-info.java
@@ -19,4 +19,4 @@
* Tika Java-7 FileTypeDetector implementations.
*/
@aQute.bnd.annotation.Version("1.0.0")
-package org.apache.tika.filetypedetector;
\ No newline at end of file
+package org.apache.tika.filetypedetector;
diff --git a/tika-java7/src/test/java/org/apache/tika/filetypedetector/TikaFileTypeDetectorTest.java b/tika-java7/src/test/java/org/apache/tika/filetypedetector/TikaFileTypeDetectorTest.java
index b21b7b358..718894520 100644
--- a/tika-java7/src/test/java/org/apache/tika/filetypedetector/TikaFileTypeDetectorTest.java
+++ b/tika-java7/src/test/java/org/apache/tika/filetypedetector/TikaFileTypeDetectorTest.java
@@ -32,16 +32,14 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
public class TikaFileTypeDetectorTest {
-
- @TempDir
- public Path tempDir;
-
- private Path testDirectory = null;
-
+
private static final String TEST_CLASSPATH = "/test-documents/test.html";
private static final String TEST_HTML = "test.html";
private static final String TEST_UNRECOGNISED_EXTENSION = "test.unrecognisedextension";
-
+ @TempDir
+ public Path tempDir;
+ private Path testDirectory = null;
+
@BeforeEach
public void setUp() throws Exception {
testDirectory = tempDir;
@@ -53,36 +51,38 @@ public class TikaFileTypeDetectorTest {
Files.copy(is, testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION));
}
}
-
+
@Test
public final void testDirectAccess() throws Exception {
- String contentType = new TikaFileTypeDetector().probeContentType(testDirectory.resolve(TEST_HTML));
+ String contentType =
+ new TikaFileTypeDetector().probeContentType(testDirectory.resolve(TEST_HTML));
assertNotNull(contentType);
assertEquals("text/html", contentType);
}
-
+
@Test
public final void testFilesProbeContentTypePathExtension() throws Exception {
String contentType = Files.probeContentType(testDirectory.resolve(TEST_HTML));
assertNotNull(contentType);
assertEquals("text/html", contentType);
}
-
+
@Test
public final void testFilesProbeContentTypePathUnrecognised() throws Exception {
- String contentType = Files.probeContentType(testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION));
+ String contentType =
+ Files.probeContentType(testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION));
assertNotNull(contentType);
assertEquals("text/html", contentType);
}
-
+
@Test
public final void testMetaInfServicesLoad() throws Exception {
ServiceLoader<FileTypeDetector> serviceLoader = ServiceLoader.load(FileTypeDetector.class);
-
+
Iterator<FileTypeDetector> iterator = serviceLoader.iterator();
assertTrue(iterator.hasNext());
boolean foundTika = false;
- while(iterator.hasNext()) {
+ while (iterator.hasNext()) {
FileTypeDetector fileTypeDetector = iterator.next();
assertNotNull(fileTypeDetector);
if (fileTypeDetector instanceof TikaFileTypeDetector) {
diff --git a/tika-java7/src/test/resources/test-documents/test.html b/tika-java7/src/test/resources/test-documents/test.html
index 763e23720..b0036e3d9 100644
--- a/tika-java7/src/test/resources/test-documents/test.html
+++ b/tika-java7/src/test/resources/test-documents/test.html
@@ -1,10 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>Hello World</title>
+ <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
+ <title>Hello World</title>
</head>
<body>
- <p>Hello World!<p/>
+<p>Hello World!
+<p/>
</body>
</html>
\ No newline at end of file
diff --git a/tika-parent/checkstyle.xml b/tika-parent/checkstyle.xml
index 94cc85507..f0d55ac9b 100644
--- a/tika-parent/checkstyle.xml
+++ b/tika-parent/checkstyle.xml
@@ -63,6 +63,11 @@
<module name="TreeWalker">
<!--<module name="FileContentsHolder"/>-->
+ <module name="IllegalImport">
+ <property name="regexp" value="true"/>
+ <!-- Reject any org.junit import that's not also org.junit.jupiter: -->
+ <property name="illegalClasses" value="^org\.junit\.(?!jupiter\.).+"/>
+ </module>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
diff --git a/tika-parent/pom.xml b/tika-parent/pom.xml
index bb3c99ded..502969d10 100644
--- a/tika-parent/pom.xml
+++ b/tika-parent/pom.xml
@@ -997,6 +997,7 @@
</executions>
</plugin>
<plugin>
+ <!-- mvn validate -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
@@ -1013,12 +1014,12 @@
<phase>validate</phase>
<configuration>
<configLocation>checkstyle.xml</configLocation>
- <encoding>UTF-8</encoding>
<consoleOutput>false</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<testSourceDirectories>${project.basedir}/src/test/java</testSourceDirectories>
<violationSeverity>warn</violationSeverity>
<failOnViolation>true</failOnViolation>
+ <failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/AbstractTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/AbstractTranslator.java
index 4ed9908cf..e441ec3a3 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/AbstractTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/AbstractTranslator.java
@@ -29,5 +29,5 @@ public abstract class AbstractTranslator implements Translator {
protected LanguageResult detectLanguage(String text) throws IOException {
LanguageDetector detector = new OptimaizeLangDetector().loadModels();
return detector.detect(text);
- }
+ }
}
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/CachedTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/CachedTranslator.java
index 3e20e6c39..1356e5f55 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/CachedTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/CachedTranslator.java
@@ -20,12 +20,12 @@ package org.apache.tika.language.translate.impl;
import java.io.IOException;
import java.util.HashMap;
+import com.fasterxml.jackson.databind.util.LRUMap;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.language.detect.LanguageResult;
import org.apache.tika.language.translate.Translator;
-import com.fasterxml.jackson.databind.util.LRUMap;
-
/**
* CachedTranslator. Saves a map of previous translations in order to prevent repetitive translation requests.
*/
@@ -37,12 +37,13 @@ public class CachedTranslator extends AbstractTranslator {
// Old entries are removed from the cache when it reaches its limit.
// For example, {en:fr -> {hello -> salut}}.
private HashMap<String, LRUMap<String, String>> cache;
-
+
/**
- * Create a new CachedTranslator (must set the {@link Translator} with {@link #setTranslator(Translator)} before use!)
+ * Create a new CachedTranslator (must set the {@link Translator} with
+ * {@link #setTranslator(Translator)} before use!)
*/
- public CachedTranslator(){
- this(null);
+ public CachedTranslator() {
+ this(null);
}
/**
@@ -57,25 +58,27 @@ public class CachedTranslator extends AbstractTranslator {
}
/**
- * @return the translator
- */
- public Translator getTranslator() {
- return translator;
- }
-
- /**
- * @param translator the translator to set
- */
- public void setTranslator(Translator translator) {
- this.translator = translator;
- }
-
- @Override
- public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException {
+ * @return the translator
+ */
+ public Translator getTranslator() {
+ return translator;
+ }
+
+ /**
+ * @param translator the translator to set
+ */
+ public void setTranslator(Translator translator) {
+ this.translator = translator;
+ }
+
+ @Override
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
if (translator == null) {
return text;
}
- LRUMap<String, String> translationCache = getTranslationCache(sourceLanguage, targetLanguage);
+ LRUMap<String, String> translationCache =
+ getTranslationCache(sourceLanguage, targetLanguage);
String translatedText = translationCache.get(text);
if (translatedText == null) {
translatedText = translator.translate(text, sourceLanguage, targetLanguage);
@@ -117,7 +120,8 @@ public class CachedTranslator extends AbstractTranslator {
* @since Tika 1.6
*/
public int getNumTranslationsFor(String sourceLanguage, String targetLanguage) {
- LRUMap<String, String> translationCache = cache.get(buildCacheKeyString(sourceLanguage, targetLanguage));
+ LRUMap<String, String> translationCache =
+ cache.get(buildCacheKeyString(sourceLanguage, targetLanguage));
if (translationCache == null) {
return 0;
} else {
@@ -129,13 +133,14 @@ public class CachedTranslator extends AbstractTranslator {
* Check whether this CachedTranslator's cache contains a translation of the text from the
* source language to the target language.
*
- * @param text What string to check for.
+ * @param text What string to check for.
* @param sourceLanguage The source language of translation.
* @param targetLanguage The target language of translation.
* @return true if the cache contains a translation of the text, false otherwise.
*/
public boolean contains(String text, String sourceLanguage, String targetLanguage) {
- LRUMap<String, String> translationCache = getTranslationCache(sourceLanguage, targetLanguage);
+ LRUMap<String, String> translationCache =
+ getTranslationCache(sourceLanguage, targetLanguage);
return translationCache.get(text) != null;
}
@@ -143,19 +148,19 @@ public class CachedTranslator extends AbstractTranslator {
* Check whether this CachedTranslator's cache contains a translation of the text to the target language,
* attempting to auto-detect the source language.
*
- * @param text What string to check for.
+ * @param text What string to check for.
* @param targetLanguage The target language of translation.
* @return true if the cache contains a translation of the text, false otherwise.
*/
public boolean contains(String text, String targetLanguage) {
- try {
- LanguageResult language = detectLanguage(text);
- String sourceLanguage = language.getLanguage();
- return contains(text, sourceLanguage, targetLanguage);
- } catch (IOException e) {
- // TODO what to do if we get an error?
- return false;
- }
+ try {
+ LanguageResult language = detectLanguage(text);
+ String sourceLanguage = language.getLanguage();
+ return contains(text, sourceLanguage, targetLanguage);
+ } catch (IOException e) {
+ // TODO what to do if we get an error?
+ return false;
+ }
}
/**
@@ -176,8 +181,10 @@ public class CachedTranslator extends AbstractTranslator {
* @param targetLanguage The target language of translation.
* @return The LRUMap representing the translation cache.
*/
- private LRUMap<String, String> getTranslationCache(String sourceLanguage, String targetLanguage) {
- LRUMap<String, String> translationCache = cache.get(buildCacheKeyString(sourceLanguage, targetLanguage));
+ private LRUMap<String, String> getTranslationCache(String sourceLanguage,
+ String targetLanguage) {
+ LRUMap<String, String> translationCache =
+ cache.get(buildCacheKeyString(sourceLanguage, targetLanguage));
if (translationCache == null) {
translationCache = new LRUMap<>(INITIAL_ENTRIES, MAX_ENTRIES);
cache.put(buildCacheKeyString(sourceLanguage, targetLanguage), translationCache);
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/ExternalTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/ExternalTranslator.java
index 57e697854..ba9d376a9 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/ExternalTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/ExternalTranslator.java
@@ -30,7 +30,6 @@ import org.apache.tika.exception.TikaException;
* Abstract class used to interact with command line/external Translators.
*
* @see MosesTranslator for an example of extending this class.
- *
* @since Tika 1.7
*/
public abstract class ExternalTranslator extends AbstractTranslator {
@@ -38,16 +37,18 @@ public abstract class ExternalTranslator extends AbstractTranslator {
/**
* Run the given command and return the output written to standard out.
*
- * @param command The complete command to run.
- * @param env The environment to pass along to the Runtime.
+ * @param command The complete command to run.
+ * @param env The environment to pass along to the Runtime.
* @param workingDirectory The directory from which to run the command.
* @return The output of the command written to standard out.
* @throws IOException
* @throws InterruptedException
*/
- public Reader runAndGetOutput(String command, String[] env, File workingDirectory) throws IOException, InterruptedException {
+ public Reader runAndGetOutput(String command, String[] env, File workingDirectory)
+ throws IOException, InterruptedException {
Process process = Runtime.getRuntime().exec(command, env, workingDirectory);
- InputStreamReader reader = new InputStreamReader(process.getInputStream(), Charset.defaultCharset());
+ InputStreamReader reader =
+ new InputStreamReader(process.getInputStream(), Charset.defaultCharset());
BufferedReader bufferedReader = new BufferedReader(reader);
process.waitFor();
return bufferedReader;
@@ -55,11 +56,11 @@ public abstract class ExternalTranslator extends AbstractTranslator {
/**
* Checks to see if the command can be run. Typically used with
- * something like "myapp --version" to check to see if "myapp"
- * is installed and on the path.
+ * something like "myapp --version" to check to see if "myapp"
+ * is installed and on the path.
*
* @param checkCommandString The command to run and check the return code of.
- * @param successCodes Return codes that signify success.
+ * @param successCodes Return codes that signify success.
*/
public boolean checkCommand(String checkCommandString, int... successCodes) {
try {
@@ -67,10 +68,12 @@ public abstract class ExternalTranslator extends AbstractTranslator {
process.waitFor();
int result = process.waitFor();
for (int code : successCodes) {
- if (code == result) return true;
+ if (code == result) {
+ return true;
+ }
}
return false;
- } catch(IOException e) {
+ } catch (IOException e) {
// Some problem, command is there or is broken
System.err.println("Broken pipe");
return false;
@@ -83,7 +86,8 @@ public abstract class ExternalTranslator extends AbstractTranslator {
/**
* Default translate method which uses built Tika language identification.
- * @param text The text to translate.
+ *
+ * @param text The text to translate.
* @param targetLanguage The desired language to translate to (for example, "hi").
* @return The translated text.
* @throws Exception
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/GoogleTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/GoogleTranslator.java
index 0ad75dc96..6f5ea198b 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/GoogleTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/GoogleTranslator.java
@@ -27,14 +27,14 @@ import java.util.Properties;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.tika.exception.TikaException;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.cxf.jaxrs.client.WebClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.tika.exception.TikaException;
+
/**
* An implementation of a REST client to the <a
* href="https://www.googleapis.com/language/translate/v2">Google Translate v2
@@ -42,14 +42,13 @@ import org.slf4j.LoggerFactory;
* href="http://hayageek.com/google-translate-api-tutorial/">great tutorial</a>
* from <a href="http://hayageek.com">hayageek.com</a>. Set your API key in
* translator.google.properties.
- *
- *
*/
public class GoogleTranslator extends AbstractTranslator {
private static final Logger LOG = LoggerFactory.getLogger(GoogleTranslator.class);
- private static final String GOOGLE_TRANSLATE_URL_BASE = "https://www.googleapis.com/language/translate/v2";
+ private static final String GOOGLE_TRANSLATE_URL_BASE =
+ "https://www.googleapis.com/language/translate/v2";
private static final String DEFAULT_KEY = "dummy-secret";
@@ -64,12 +63,11 @@ public class GoogleTranslator extends AbstractTranslator {
this.isAvailable = true;
Properties config = new Properties();
try {
- config.load(GoogleTranslator.class
- .getResourceAsStream(
- "translator.google.properties"));
+ config.load(GoogleTranslator.class.getResourceAsStream("translator.google.properties"));
this.apiKey = config.getProperty("translator.client-secret");
- if (this.apiKey.equals(DEFAULT_KEY))
+ if (this.apiKey.equals(DEFAULT_KEY)) {
this.isAvailable = false;
+ }
} catch (Exception e) {
LOG.warn("Exception reading config file", e);
isAvailable = false;
@@ -77,19 +75,19 @@ public class GoogleTranslator extends AbstractTranslator {
}
@Override
- public String translate(String text, String sourceLanguage,
- String targetLanguage) throws TikaException, IOException {
- if (!this.isAvailable)
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ if (!this.isAvailable) {
return text;
- Response response = client.accept(MediaType.APPLICATION_JSON)
- .query("key", apiKey).query("source", sourceLanguage)
- .query("target", targetLanguage).query("q", text).get();
+ }
+ Response response = client.accept(MediaType.APPLICATION_JSON).query("key", apiKey)
+ .query("source", sourceLanguage).query("target", targetLanguage).query("q", text)
+ .get();
StringBuilder responseText = new StringBuilder();
try (InputStreamReader inputStreamReader = new InputStreamReader(
(InputStream) response.getEntity(), UTF_8);
- BufferedReader reader = new BufferedReader(inputStreamReader);
- ) {
+ BufferedReader reader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = reader.readLine()) != null) {
responseText.append(line);
@@ -102,10 +100,10 @@ public class GoogleTranslator extends AbstractTranslator {
}
@Override
- public String translate(String text, String targetLanguage)
- throws TikaException, IOException {
- if (!this.isAvailable)
+ public String translate(String text, String targetLanguage) throws TikaException, IOException {
+ if (!this.isAvailable) {
return text;
+ }
String sourceLanguage = detectLanguage(text).getLanguage();
return translate(text, sourceLanguage, targetLanguage);
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/JoshuaNetworkTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/JoshuaNetworkTranslator.java
index cfa8fba7b..bf391df51 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/JoshuaNetworkTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/JoshuaNetworkTranslator.java
@@ -28,30 +28,29 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.tika.exception.TikaException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.tika.exception.TikaException;
/**
* <p>This translator is designed to work with a TCP-IP available
* Joshua translation server, specifically the
* <a href="https://github.com/joshua-decoder/joshua_translation_engine">
* REST-based Joshua server</a>.</p>
- *
+ *
* <p>If you were to interact with the server via curl a request
* would look as follows</p>
- *
+ *
* <pre>
* {code
* curl http://localhost:5000/joshua/translate/english \
@@ -59,177 +58,185 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
* -X POST -d '{"inputLanguage": "Spanish", "inputText": "vuelo"}' -v
* }
* </pre>
- *
+ * <p>
* Joshua requires input to be pre-formatted into sentences, one per line,
* so this translation implementation takes care of that.
*/
public class JoshuaNetworkTranslator extends AbstractTranslator {
- private static final Logger LOG = LoggerFactory.getLogger(JoshuaNetworkTranslator.class);
-
- private static final String PROPERTIES_FILE = "translator.joshua.properties";
-
- private static final String JOSHUA_SERVER = "joshua.server.url";
-
- private String networkServer;
-
- private String networkURI;
-
- /**
- * Default constructor which first checks for the presence of
- * the <code>translator.joshua.properties</code> file.
- * We check if the remote server is available on each
- * translation process. This check is not a remote call, but instead
- * a check for null value within of a local variable represetning the
- * value for <code>joshua.server.url</code>, which should be populated
- * within the <code>translator.joshua.properties</code> file.
- */
- public JoshuaNetworkTranslator() {
- Properties props = new Properties();
- InputStream stream;
- stream = JoshuaNetworkTranslator.class.getResourceAsStream(PROPERTIES_FILE);
- try {
- if(stream != null) {
- props.load(stream);
- networkServer = props.getProperty(JOSHUA_SERVER);
- }
- } catch (IOException e) {
- LOG.error("An error occured whilst reading translator.joshua.properties file", e);
- }
- }
-
- /**
- * <p>Initially then check if the source language has been provided.
- * If no source language (or a null value) has been provided then
- * we make an attempt to guess the source using Tika's
- * {@link org.apache.tika.langdetect.OptimaizeLangDetector}. If we
- * are still unable to guess the language then we return the source
- * text.</p>
- *
- * <p>We then process the input text into a new string consisting of
- * sentences, one per line e.g. insert \n between the presence of '.'</p>
- *
- * @see org.apache.tika.language.translate.Translator#translate
- * (java.lang.String, java.lang.String, java.lang.String)
- */
- @Override
- public String translate(String text, String sourceLanguage,
- String targetLanguage) throws TikaException, IOException {
- //create networkURI
- if (!networkServer.endsWith("/")) {
- networkURI = networkServer + "/" + targetLanguage;
- } else {
- networkURI = networkServer + targetLanguage;
- }
- if (!this.isAvailable())
- return text;
-
- //make an attempt to guess language if one is not provided.
- if (sourceLanguage == null)
- sourceLanguage = detectLanguage(text).getLanguage();
-
- //process input text into sentences, one per line
- // e.g. insert \n between the presence of '.'
- StringBuilder sb = new StringBuilder(text);
- int i = 0;
- while ((i = sb.indexOf(".", i + 1)) != -1) {
- sb.replace(i, i + 1, "\n");
+ private static final Logger LOG = LoggerFactory.getLogger(JoshuaNetworkTranslator.class);
+
+ private static final String PROPERTIES_FILE = "translator.joshua.properties";
+
+ private static final String JOSHUA_SERVER = "joshua.server.url";
+
+ private String networkServer;
+
+ private String networkURI;
+
+ /**
+ * Default constructor which first checks for the presence of
+ * the <code>translator.joshua.properties</code> file.
+ * We check if the remote server is available on each
+ * translation process. This check is not a remote call, but instead
+ * a check for null value within of a local variable represetning the
+ * value for <code>joshua.server.url</code>, which should be populated
+ * within the <code>translator.joshua.properties</code> file.
+ */
+ public JoshuaNetworkTranslator() {
+ Properties props = new Properties();
+ InputStream stream;
+ stream = JoshuaNetworkTranslator.class.getResourceAsStream(PROPERTIES_FILE);
+ try {
+ if (stream != null) {
+ props.load(stream);
+ networkServer = props.getProperty(JOSHUA_SERVER);
+ }
+ } catch (IOException e) {
+ LOG.error("An error occured whilst reading translator.joshua.properties file", e);
+ }
}
- String inputText = sb.toString();
- WebClient client;
- final List<Object> providers = new ArrayList<>();
- JacksonJsonProvider jacksonJsonProvider = new JacksonJsonProvider();
- providers.add(jacksonJsonProvider);
-
- client = WebClient.create(networkURI, providers);
-
- ObjectMapper requestMapper = new ObjectMapper();
- ObjectNode jsonNode = requestMapper.createObjectNode();
- jsonNode.put("inputLanguage", sourceLanguage);
- jsonNode.put("inputText", inputText);
- //make the request
- Response response = client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(jsonNode);
- StringBuilder responseText = new StringBuilder();
- try (InputStreamReader inputStreamReader = new InputStreamReader(
- (InputStream) response.getEntity(), UTF_8);
- BufferedReader reader = new BufferedReader(inputStreamReader);
- ) {
- String line;
- while ((line = reader.readLine()) != null) {
- responseText.append(line);
- }
+ /**
+ * <p>Initially then check if the source language has been provided.
+ * If no source language (or a null value) has been provided then
+ * we make an attempt to guess the source using Tika's
+ * {@link org.apache.tika.langdetect.OptimaizeLangDetector}. If we
+ * are still unable to guess the language then we return the source
+ * text.</p>
+ *
+ * <p>We then process the input text into a new string consisting of
+ * sentences, one per line e.g. insert \n between the presence of '.'</p>
+ *
+ * @see org.apache.tika.language.translate.Translator#translate
+ * (java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ //create networkURI
+ if (!networkServer.endsWith("/")) {
+ networkURI = networkServer + "/" + targetLanguage;
+ } else {
+ networkURI = networkServer + targetLanguage;
+ }
+ if (!this.isAvailable()) {
+ return text;
+ }
+
+ //make an attempt to guess language if one is not provided.
+ if (sourceLanguage == null) {
+ sourceLanguage = detectLanguage(text).getLanguage();
+ }
+
+ //process input text into sentences, one per line
+ // e.g. insert \n between the presence of '.'
+ StringBuilder sb = new StringBuilder(text);
+ int i = 0;
+ while ((i = sb.indexOf(".", i + 1)) != -1) {
+ sb.replace(i, i + 1, "\n");
+ }
+
+ String inputText = sb.toString();
+ WebClient client;
+ final List<Object> providers = new ArrayList<>();
+ JacksonJsonProvider jacksonJsonProvider = new JacksonJsonProvider();
+ providers.add(jacksonJsonProvider);
+
+ client = WebClient.create(networkURI, providers);
+
+ ObjectMapper requestMapper = new ObjectMapper();
+ ObjectNode jsonNode = requestMapper.createObjectNode();
+ jsonNode.put("inputLanguage", sourceLanguage);
+ jsonNode.put("inputText", inputText);
+ //make the request
+ Response response =
+ client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
+ .post(jsonNode);
+ StringBuilder responseText = new StringBuilder();
+ try (InputStreamReader inputStreamReader = new InputStreamReader(
+ (InputStream) response.getEntity(), UTF_8);
+ BufferedReader reader = new BufferedReader(inputStreamReader)) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ responseText.append(line);
+ }
+ }
+
+ try {
+ ObjectMapper responseMapper = new ObjectMapper();
+ JsonNode jsonResp = responseMapper.readTree(responseText.toString());
+
+ if (jsonResp.findValuesAsText("outputText") != null) {
+ return jsonResp.findValuesAsText("outputText").get(0);
+ } else {
+ throw new TikaException(jsonResp.findValue("message").get(0).asText());
+ }
+ } catch (JsonParseException e) {
+ throw new TikaException(
+ "Error requesting translation from '" + sourceLanguage + "' to '" +
+ targetLanguage + "', JSON response " +
+ "from Joshua REST Server is not well formatted: " +
+ responseText.toString());
+ }
}
- try {
- ObjectMapper responseMapper = new ObjectMapper();
- JsonNode jsonResp = responseMapper.readTree(responseText.toString());
-
- if (jsonResp.findValuesAsText("outputText") != null) {
- return jsonResp.findValuesAsText("outputText").get(0);
- } else {
- throw new TikaException(jsonResp.findValue("message").get(0).asText());
- }
- } catch (JsonParseException e) {
- throw new TikaException("Error requesting translation from '" +
- sourceLanguage + "' to '" + targetLanguage + "', JSON response "
- + "from Joshua REST Server is not well formatted: " + responseText.toString());
+ /**
+ * Make an attempt to guess the source language via
+ * {@link org.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)}
+ * before making the call to
+ * {@link JoshuaNetworkTranslator#translate(String, String, String)}
+ *
+ * @see org.apache.tika.language.translate.Translator#translate(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String translate(String text, String targetLanguage) throws TikaException, IOException {
+ if (isAvailable()) {
+ return text;
+ }
+ String sourceLanguage = detectLanguage(text).getLanguage();
+ return translate(text, sourceLanguage, targetLanguage);
}
- }
-
- /**
- * Make an attempt to guess the source language via
- * {@link org.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)}
- * before making the call to
- * {@link JoshuaNetworkTranslator#translate(String, String, String)}
- * @see org.apache.tika.language.translate.Translator#translate(java.lang.String, java.lang.String)
- */
- @Override
- public String translate(String text, String targetLanguage)
- throws TikaException, IOException {
- if (isAvailable())
- return text;
- String sourceLanguage = detectLanguage(text).getLanguage();
- return translate(text, sourceLanguage, targetLanguage);
- }
-
- /**
- * @see org.apache.tika.language.translate.Translator#isAvailable()
- */
- @Override
- public boolean isAvailable() {
- if (this.networkServer!=null) {
- URL url = null;
- try {
- url = new URL(networkURI);
- } catch (MalformedURLException mue) {
- LOG.error("Error reading {} property from {}. {}", JOSHUA_SERVER, PROPERTIES_FILE, mue);
- }
- HttpURLConnection connection = null;
- try {
- if (url!=null) {
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestProperty("Connection", "close");
- connection.setConnectTimeout(2000); // Timeout 2 seconds
- connection.connect();
- return tryResponseCode(connection);
+
+ /**
+ * @see org.apache.tika.language.translate.Translator#isAvailable()
+ */
+ @Override
+ public boolean isAvailable() {
+ if (this.networkServer != null) {
+ URL url = null;
+ try {
+ url = new URL(networkURI);
+ } catch (MalformedURLException mue) {
+ LOG.error("Error reading {} property from {}. {}", JOSHUA_SERVER, PROPERTIES_FILE,
+ mue);
+ }
+ HttpURLConnection connection = null;
+ try {
+ if (url != null) {
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestProperty("Connection", "close");
+ connection.setConnectTimeout(2000); // Timeout 2 seconds
+ connection.connect();
+ return tryResponseCode(connection);
+ }
+ } catch (IOException ioe) {
+ LOG.error("Error whilst checking availability of {}. {}", JOSHUA_SERVER, ioe);
+ }
}
- } catch (IOException ioe) {
- LOG.error("Error whilst checking availability of {}. {}", JOSHUA_SERVER, ioe);
- }
+ return false;
}
- return false;
- }
-
- private boolean tryResponseCode(HttpURLConnection connection) {
- // If the web service is available
- try {
- if (connection.getResponseCode() == 200)
- return true;
- } catch (IOException ioe) {
- LOG.error("Error retrieving response code from Joshua Network Translator.", ioe);
+
+ private boolean tryResponseCode(HttpURLConnection connection) {
+ // If the web service is available
+ try {
+ if (connection.getResponseCode() == 200) {
+ return true;
+ }
+ } catch (IOException ioe) {
+ LOG.error("Error retrieving response code from Joshua Network Translator.", ioe);
+ }
+ return false;
}
- return false;
- }
}
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/Lingo24Translator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/Lingo24Translator.java
index 1107e4e15..fcb32c87a 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/Lingo24Translator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/Lingo24Translator.java
@@ -24,18 +24,17 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
-
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.tika.exception.TikaException;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.cxf.jaxrs.client.WebClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.tika.exception.TikaException;
+
/**
* An implementation of a REST client for the
* <a href="https://developer.lingo24.com/premium-machine-translation-api">Premium MT API v1</a>.
@@ -46,7 +45,8 @@ public class Lingo24Translator extends AbstractTranslator {
private static final Logger LOG = LoggerFactory.getLogger(Lingo24Translator.class);
- private static final String LINGO24_TRANSLATE_URL_BASE = "https://api.lingo24.com/mt/v1/translate";
+ private static final String LINGO24_TRANSLATE_URL_BASE =
+ "https://api.lingo24.com/mt/v1/translate";
private static final String DEFAULT_KEY = "dummy-key";
@@ -61,12 +61,12 @@ public class Lingo24Translator extends AbstractTranslator {
this.isAvailable = true;
Properties config = new Properties();
try {
- config.load(Lingo24Translator.class
- .getResourceAsStream(
- "translator.lingo24.properties"));
+ config.load(
+ Lingo24Translator.class.getResourceAsStream("translator.lingo24.properties"));
this.userKey = config.getProperty("translator.user-key");
- if (this.userKey.equals(DEFAULT_KEY))
+ if (this.userKey.equals(DEFAULT_KEY)) {
this.isAvailable = false;
+ }
} catch (Exception e) {
LOG.warn("Couldn't read config file", e);
isAvailable = false;
@@ -74,18 +74,18 @@ public class Lingo24Translator extends AbstractTranslator {
}
@Override
- public String translate(String text, String sourceLanguage,
- String targetLanguage) throws TikaException, IOException {
- if (!this.isAvailable)
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ if (!this.isAvailable) {
return text;
- Response response = client.accept(MediaType.APPLICATION_JSON)
- .query("user_key", userKey).query("source", sourceLanguage)
- .query("target", targetLanguage).query("q", text).get();
+ }
+ Response response = client.accept(MediaType.APPLICATION_JSON).query("user_key", userKey)
+ .query("source", sourceLanguage).query("target", targetLanguage).query("q", text)
+ .get();
StringBuilder responseText = new StringBuilder();
try (InputStreamReader inputStreamReader = new InputStreamReader(
(InputStream) response.getEntity(), UTF_8);
- BufferedReader reader = new BufferedReader(inputStreamReader);
- ) {
+ BufferedReader reader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = reader.readLine()) != null) {
responseText.append(line);
@@ -102,11 +102,11 @@ public class Lingo24Translator extends AbstractTranslator {
}
@Override
- public String translate(String text, String targetLanguage)
- throws TikaException, IOException {
- if (!this.isAvailable)
+ public String translate(String text, String targetLanguage) throws TikaException, IOException {
+ if (!this.isAvailable) {
return text;
-
+ }
+
String sourceLanguage = detectLanguage(text).getLanguage();
return translate(text, sourceLanguage, targetLanguage);
}
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MarianTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MarianTranslator.java
index 143b6d467..88484b71d 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MarianTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MarianTranslator.java
@@ -18,20 +18,6 @@
package org.apache.tika.language.translate.impl;
-import jakarta.websocket.ClientEndpoint;
-import jakarta.websocket.ContainerProvider;
-import jakarta.websocket.DeploymentException;
-import jakarta.websocket.OnClose;
-import jakarta.websocket.OnMessage;
-import jakarta.websocket.OnOpen;
-import jakarta.websocket.Session;
-import jakarta.websocket.WebSocketContainer;
-import org.apache.commons.io.FileUtils;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -49,10 +35,26 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import jakarta.websocket.ClientEndpoint;
+import jakarta.websocket.ContainerProvider;
+import jakarta.websocket.DeploymentException;
+import jakarta.websocket.OnClose;
+import jakarta.websocket.OnMessage;
+import jakarta.websocket.OnOpen;
+import jakarta.websocket.Session;
+import jakarta.websocket.WebSocketContainer;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.utils.StringUtils;
+
/**
* Translator that uses the Marian NMT decoder for translation.
- *
+ * <p>
* Users must install Marian NMT and configure model locations before using this Translator.
+ *
* @link https://marian-nmt.github.io/.
*/
public class MarianTranslator extends AbstractTranslator {
@@ -61,11 +63,10 @@ public class MarianTranslator extends AbstractTranslator {
private static final String DEFAULT_PATH = "dummy-path";
private static final String INPUT_TMP_NAME = "tika.marian.input";
private static final String OUTPUT_TMP_NAME = "tika.marian.translation";
- private long maxWaitForMarianServerResponse = 120000;
- private long pulseCheckMarianServerResponse = 1000;
-
private final String marianPath;
private final Properties config;
+ private long maxWaitForMarianServerResponse = 120000;
+ private long pulseCheckMarianServerResponse = 1000;
/**
* Default constructor.
@@ -76,12 +77,12 @@ public class MarianTranslator extends AbstractTranslator {
config.load(MarianTranslator.class.getResourceAsStream("translator.marian.properties"));
marianPath = config.getProperty("translator.marian.path", DEFAULT_PATH);
if (config.containsKey("translator.marian.server.responseTimeout")) {
- maxWaitForMarianServerResponse =
- Long.parseLong(config.getProperty("translator.marian.server.responseTimeout"));
+ maxWaitForMarianServerResponse = Long.parseLong(
+ config.getProperty("translator.marian.server.responseTimeout"));
}
if (config.containsKey("translator.marian.server.responsePulse")) {
- pulseCheckMarianServerResponse =
- Long.parseLong(config.getProperty("translator.marian.server.responsePulse"));
+ pulseCheckMarianServerResponse = Long.parseLong(
+ config.getProperty("translator.marian.server.responsePulse"));
}
} catch (IOException e) {
throw new AssertionError("Failed to read translator.marian.properties.");
@@ -91,11 +92,11 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Default translate method which uses built Tika language identification.
*
- * @param text The text to translate.
+ * @param text The text to translate.
* @param targetLanguage The desired language to translate to (for example, "hi").
* @return The translated text.
* @throws TikaException on any error performing translation.
- * @throws IOException on any I/O error performing translation.
+ * @throws IOException on any I/O error performing translation.
*/
public String translate(String text, String targetLanguage) throws TikaException, IOException {
String sourceLanguage = detectLanguage(text).getLanguage();
@@ -105,30 +106,34 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Translate method with specific source and target languages.
*
- * @param text The text to translate.
+ * @param text The text to translate.
* @param sourceLanguage The language to translate from (for example, "en").
* @param targetLanguage The desired language to translate to (for example, "hi").
* @return The translated text.
* @throws TikaException on any error performing translation.
- * @throws IOException on any I/O error performing translation.
+ * @throws IOException on any I/O error performing translation.
*/
- public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException {
- String configPath =
- config.getProperty("translator.marian." + sourceLanguage + "_" + targetLanguage + ".config");
- String serverSocket =
- config.getProperty("translator.marian." + sourceLanguage + "_" + targetLanguage + ".server");
-
- if (!isAvailable(sourceLanguage, targetLanguage)) return text;
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ String configPath = config.getProperty(
+ "translator.marian." + sourceLanguage + "_" + targetLanguage + ".config");
+ String serverSocket = config.getProperty(
+ "translator.marian." + sourceLanguage + "_" + targetLanguage + ".server");
+
+ if (!isAvailable(sourceLanguage, targetLanguage)) {
+ return text;
+ }
if (!StringUtils.isEmpty(configPath) && !StringUtils.isEmpty(serverSocket)) {
- LOG.info("Both local and server configurations exist for " + sourceLanguage + " to " + targetLanguage
- + "\nDefaulting to use local engine.");
+ LOG.info("Both local and server configurations exist for " + sourceLanguage + " to " +
+ targetLanguage + "\nDefaulting to use local engine.");
}
StringBuilder translation = new StringBuilder();
File tmpFile = Files.createTempFile(INPUT_TMP_NAME, ".tmp").toFile();
tmpFile.deleteOnExit();
- try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile), Charset.defaultCharset())) {
+ try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile),
+ Charset.defaultCharset())) {
out.append(text).append('\n').close();
}
File tmpTranslatedFile = Files.createTempFile(OUTPUT_TMP_NAME, ".tmp").toFile();
@@ -147,9 +152,9 @@ public class MarianTranslator extends AbstractTranslator {
String postProcessScript = config.getProperty("translator.marian.postprocess");
executeScript(postProcessScript, tmpTranslatedFile);
- BufferedReader fileReader
- = new BufferedReader(new InputStreamReader(
- new FileInputStream(tmpTranslatedFile), Charset.defaultCharset()));
+ BufferedReader fileReader = new BufferedReader(
+ new InputStreamReader(new FileInputStream(tmpTranslatedFile),
+ Charset.defaultCharset()));
fileReader.lines().forEach(translation::append);
fileReader.close();
@@ -157,7 +162,7 @@ public class MarianTranslator extends AbstractTranslator {
throw new TikaException("Failed perform translation", e);
}
- if (!tmpFile.delete() || !tmpTranslatedFile.delete()){
+ if (!tmpFile.delete() || !tmpTranslatedFile.delete()) {
throw new IOException("Failed to delete temporary files.");
}
@@ -167,10 +172,11 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Process the translation request using a local instance of Marian - i.e. either </i>marian-decoder</i>
* or <i>marian</i> command line applications.
+ *
* @param configPath the path of the configuaration to use.
* @param sourceFile the file containing the source text to read from.
* @param targetFile the file to write the translated text to.
- * @throws IOException on any I/O error.
+ * @throws IOException on any I/O error.
* @throws InterruptedException on any process error.
*/
private void processWithLocalMarian(String configPath, File sourceFile, File targetFile)
@@ -183,8 +189,8 @@ public class MarianTranslator extends AbstractTranslator {
Process process = builder.start();
process.waitFor();
- BufferedReader stdOutReader =
- new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.defaultCharset()));
+ BufferedReader stdOutReader = new BufferedReader(
+ new InputStreamReader(process.getInputStream(), Charset.defaultCharset()));
stdOutReader.lines().forEach(LOG::debug);
stdOutReader.close();
}
@@ -192,15 +198,19 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Process the translation request using a Marian-Server instance. Marian Server is Marian NMT's WebSocket
* based server application (<i>marian-server</i>.
- * @param serverURI the Web Socket URI of the Marian Server instance.
+ *
+ * @param serverURI the Web Socket URI of the Marian Server instance.
* @param sourceFile the file containing the source text to read from.
* @param targetFile the file to write the translated text to.
* @throws TikaException on any error translating via the server.
*/
- private void processWithMarianServer(String serverURI, File sourceFile, File targetFile) throws TikaException {
+ private void processWithMarianServer(String serverURI, File sourceFile, File targetFile)
+ throws TikaException {
try {
- MarianServerClient clientEndpoint = new MarianServerClient(new URI(serverURI), targetFile);
- clientEndpoint.translate(FileUtils.readFileToString(sourceFile, Charset.defaultCharset()));
+ MarianServerClient clientEndpoint =
+ new MarianServerClient(new URI(serverURI), targetFile);
+ clientEndpoint.translate(
+ FileUtils.readFileToString(sourceFile, Charset.defaultCharset()));
long start = System.currentTimeMillis();
long elapsed = System.currentTimeMillis() - start;
while (!clientEndpoint.receivedResponse && elapsed < maxWaitForMarianServerResponse) {
@@ -221,8 +231,8 @@ public class MarianTranslator extends AbstractTranslator {
* Executes a script taking the passed file as it's first argument.
*
* @param script the path to the script to execute
- * @param file the file to process
- * @throws IOException on any IO errors
+ * @param file the file to process
+ * @throws IOException on any IO errors
* @throws InterruptedException if the process fails.
*/
private void executeScript(String script, File file) throws IOException, InterruptedException {
@@ -244,12 +254,13 @@ public class MarianTranslator extends AbstractTranslator {
* Builds the Marian NMT Command for the configuration.
*
* @param configPath the path to the configuration file
- * @param input the input file location
- * @param output the output file location
- * @param device the device for inference (i.e. cpu or gpu)
+ * @param input the input file location
+ * @param output the output file location
+ * @param device the device for inference (i.e. cpu or gpu)
* @return the command to be executed.
*/
- private List<String> buildMarianCommand(String configPath, File input, File output, String device) {
+ private List<String> buildMarianCommand(String configPath, File input, File output,
+ String device) {
List<String> command = new ArrayList<>();
command.add(Paths.get(marianPath).toString());
command.add("-c");
@@ -272,17 +283,18 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Checks if the approproate Marian engine is available.
+ *
* @param sourceLanguage The language to translate from (for example, "en").
* @param targetLanguage The desired language to translate to (for example, "hi").
* @return
*/
public boolean isAvailable(String sourceLanguage, String targetLanguage) {
- String configPath =
- config.getProperty("translator.marian." + sourceLanguage + "_" + targetLanguage + ".config");
- String serverSocket =
- config.getProperty("translator.marian." + sourceLanguage + "_" + targetLanguage + ".server");
- return (!marianPath.equals(DEFAULT_PATH) && !StringUtils.isEmpty(configPath))
- || !StringUtils.isEmpty(serverSocket);
+ String configPath = config.getProperty(
+ "translator.marian." + sourceLanguage + "_" + targetLanguage + ".config");
+ String serverSocket = config.getProperty(
+ "translator.marian." + sourceLanguage + "_" + targetLanguage + ".server");
+ return (!marianPath.equals(DEFAULT_PATH) && !StringUtils.isEmpty(configPath)) ||
+ !StringUtils.isEmpty(serverSocket);
}
/**
@@ -297,8 +309,9 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Marian Server Web Socket Client.
+ *
* @param endpointURI the endpoint URI for the Marian Server instance.
- * @param file the location of the file to write the translation response to.
+ * @param file the location of the file to write the translation response to.
*/
public MarianServerClient(URI endpointURI, File file) throws TikaException {
try {
@@ -311,7 +324,7 @@ public class MarianTranslator extends AbstractTranslator {
}
@OnOpen
- public void onOpen(Session session){
+ public void onOpen(Session session) {
LOG.debug("Opened connection, Session ID: " + session.getId());
this.session = session;
}
@@ -324,13 +337,14 @@ public class MarianTranslator extends AbstractTranslator {
}
@OnClose
- public void onClose(Session session){
+ public void onClose(Session session) {
LOG.debug("Closed connection, Session ID: " + session.getId());
receivedResponse = true;
}
/**
* Translate the passed text using the Marian Server.
+ *
* @param sourceText the source text to translate.
* @throws IOException on any I/O error calling the server.
*/
@@ -340,6 +354,7 @@ public class MarianTranslator extends AbstractTranslator {
/**
* Close the connection to the Marian Server.
+ *
* @throws IOException on any I/O error calling the server.
*/
public void close() throws IOException {
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MicrosoftTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MicrosoftTranslator.java
index c8d92f60a..f6c9add8e 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MicrosoftTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MicrosoftTranslator.java
@@ -17,41 +17,41 @@
package org.apache.tika.language.translate.impl;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.language.translate.Translator;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.language.translate.Translator;
/**
* Wrapper class to access the Windows translation service. This class uses the com.memetix.mst
* package as a wrapper for the API calls.
+ *
* @since Tika 1.6
*/
public class MicrosoftTranslator implements Translator {
- private static final Logger LOG = LoggerFactory.getLogger(MicrosoftTranslator.class);
-
- boolean available; // Flag for whether or not translation is available.
- String clientId, clientSecret; // Keys used for the API calls.
-
public static final String PROPERTIES_FILE = "translator.microsoft.properties";
public static final String ID_PROPERTY = "translator.client-id";
public static final String SECRET_PROPERTY = "translator.client-secret";
public static final String DEFAULT_ID = "dummy-id";
public static final String DEFAULT_SECRET = "dummy-secret";
+ private static final Logger LOG = LoggerFactory.getLogger(MicrosoftTranslator.class);
+ boolean available; // Flag for whether or not translation is available.
+ String clientId, clientSecret; // Keys used for the API calls.
/**
* Create a new MicrosoftTranslator with the client keys specified in
* resources/org/apache/tika/language/translate/translator.microsoft.properties. Silently becomes unavailable
* when client keys are unavailable. translator.microsoft.client-id and translator.client-secret must be set
* in translator.microsoft.properties for translation to work.
+ *
* @since Tika 1.6
*/
public MicrosoftTranslator() {
@@ -59,11 +59,11 @@ public class MicrosoftTranslator implements Translator {
InputStream stream;
stream = MicrosoftTranslator.class.getResourceAsStream(PROPERTIES_FILE);
try {
- if(stream != null) {
+ if (stream != null) {
props.load(stream);
clientId = props.getProperty(ID_PROPERTY);
clientSecret = props.getProperty(SECRET_PROPERTY);
- this.available = checkAvailable();
+ this.available = checkAvailable();
}
} catch (IOException e) {
LOG.warn("Error loading props file", e);
@@ -76,7 +76,7 @@ public class MicrosoftTranslator implements Translator {
* Use the Microsoft service to translate the given text from the given source language to the given target.
* You must set the client keys in translator.microsoft.properties.
*
- * @param text The text to translate.
+ * @param text The text to translate.
* @param sourceLanguage The input text language (for example, "en").
* @param targetLanguage The desired language to translate to (for example, "fr").
* @return The translated text. If translation is unavailable, returns the unchanged text.
@@ -84,8 +84,11 @@ public class MicrosoftTranslator implements Translator {
* @see org.apache.tika.language.translate.Translator
* @since Tika 1.6
*/
- public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException {
- if (!available) return text;
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ if (!available) {
+ return text;
+ }
Language source = Language.fromString(sourceLanguage);
Language target = Language.fromString(targetLanguage);
Translate.setClientId(clientId);
@@ -100,7 +103,8 @@ public class MicrosoftTranslator implements Translator {
/**
* Use the Microsoft service to translate the given text to the given target language. The source language
* is automatically detected by Microsoft. You must set the client keys in translator.microsoft.properties.
- * @param text The text to translate.
+ *
+ * @param text The text to translate.
* @param targetLanguage The desired language to translate to (for example, "hi").
* @return The translated text. If translation is unavailable, returns the unchanged text.
* @throws Exception
@@ -108,7 +112,9 @@ public class MicrosoftTranslator implements Translator {
* @since Tika 1.6
*/
public String translate(String text, String targetLanguage) throws TikaException, IOException {
- if (!available) return text;
+ if (!available) {
+ return text;
+ }
Language target = Language.fromString(targetLanguage);
Translate.setClientId(clientId);
Translate.setClientSecret(clientSecret);
@@ -122,34 +128,35 @@ public class MicrosoftTranslator implements Translator {
/**
* Check whether this instance has a working property file and its keys are not the defaults.
* This is not guaranteed to work, since keys may be incorrect or the webservice may be down.
+ *
* @return whether translation will probably work.
*/
- public boolean isAvailable(){
+ public boolean isAvailable() {
return available;
}
-
+
/**
* Sets the client Id for the translator API.
+ *
* @param id The ID to set.
*/
- public void setId(String id){
- this.clientId = id;
- this.available = checkAvailable();
+ public void setId(String id) {
+ this.clientId = id;
+ this.available = checkAvailable();
}
-
+
/**
* Sets the client secret for the translator API.
+ *
* @param secret The secret to set.
*/
- public void setSecret(String secret){
- this.clientSecret = secret;
- this.available = checkAvailable();
+ public void setSecret(String secret) {
+ this.clientSecret = secret;
+ this.available = checkAvailable();
}
-
- private boolean checkAvailable(){
- return clientId != null &&
- !clientId.equals(DEFAULT_ID) &&
- clientSecret != null &&
- !clientSecret.equals(DEFAULT_SECRET);
+
+ private boolean checkAvailable() {
+ return clientId != null && !clientId.equals(DEFAULT_ID) && clientSecret != null &&
+ !clientSecret.equals(DEFAULT_SECRET);
}
}
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MosesTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MosesTranslator.java
index cafd72589..4cc1aae6b 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MosesTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/MosesTranslator.java
@@ -50,10 +50,8 @@ public class MosesTranslator extends ExternalTranslator {
public MosesTranslator() {
Properties config = new Properties();
try {
- config.load(MosesTranslator.class
- .getResourceAsStream("translator.moses.properties"));
- new MosesTranslator(
- config.getProperty("translator.smt_path"),
+ config.load(MosesTranslator.class.getResourceAsStream("translator.moses.properties"));
+ new MosesTranslator(config.getProperty("translator.smt_path"),
config.getProperty("translator.script_path"));
} catch (IOException e) {
throw new AssertionError("Failed to read translator.moses.properties.");
@@ -63,7 +61,7 @@ public class MosesTranslator extends ExternalTranslator {
/**
* Create a Moses Translator with the specified smt jar and script paths.
*
- * @param smtPath Full path to the jar to run.
+ * @param smtPath Full path to the jar to run.
* @param scriptPath Full path to the script to pass to the smt jar.
*/
public MosesTranslator(String smtPath, String scriptPath) {
@@ -73,27 +71,31 @@ public class MosesTranslator extends ExternalTranslator {
}
@Override
- public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException {
- if (!isAvailable() || !checkCommand(buildCheckCommand(smtPath), 1)) return text;
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
+ if (!isAvailable() || !checkCommand(buildCheckCommand(smtPath), 1)) {
+ return text;
+ }
File tmpFile = new File(TMP_FILE_NAME);
- try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile), Charset.defaultCharset())) {
+ try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile),
+ Charset.defaultCharset())) {
out.append(text).append('\n').close();
}
- Runtime.getRuntime().exec(buildCommand(smtPath, scriptPath), new String[]{}, buildWorkingDirectory(scriptPath));
+ Runtime.getRuntime().exec(buildCommand(smtPath, scriptPath), new String[]{},
+ buildWorkingDirectory(scriptPath));
File tmpTranslatedFile = new File(TMP_FILE_NAME + ".translated");
StringBuilder stringBuilder = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(
- new FileInputStream(tmpTranslatedFile),
- Charset.defaultCharset()
- ))) {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(new FileInputStream(tmpTranslatedFile),
+ Charset.defaultCharset()))) {
String line;
while ((line = reader.readLine()) != null) stringBuilder.append(line);
}
- if (!tmpFile.delete() || !tmpTranslatedFile.delete()){
+ if (!tmpFile.delete() || !tmpTranslatedFile.delete()) {
throw new IOException("Failed to delete temporary files.");
}
return stringBuilder.toString();
@@ -106,19 +108,19 @@ public class MosesTranslator extends ExternalTranslator {
/**
* Build the command String to be executed.
- * @param smtPath Full path to the jar to run.
+ *
+ * @param smtPath Full path to the jar to run.
* @param scriptPath Full path to the script to pass to the smt jar.
* @return String to run on the command line.
*/
private String buildCommand(String smtPath, String scriptPath) {
- return "java -jar " + smtPath +
- " -c NONE " +
- scriptPath + " " +
+ return "java -jar " + smtPath + " -c NONE " + scriptPath + " " +
System.getProperty("user.dir") + "/" + TMP_FILE_NAME;
}
/**
* Build the command String to check if we can execute the smt jar.
+ *
* @param smtPath Full path to the jar to run.
* @return String to run on the command line.
*/
@@ -129,6 +131,7 @@ public class MosesTranslator extends ExternalTranslator {
/**
* Build the File that represents the desired working directory. In this case,
* the directory the script is in.
+ *
* @param scriptPath Full path to the script passed to the smt jar.
* @return File of the directory with the script in it.
*/
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/RTGTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/RTGTranslator.java
index 3ecf60908..2016a4062 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/RTGTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/RTGTranslator.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,27 +18,28 @@
package org.apache.tika.language.translate.impl;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.tika.exception.TikaException;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.Charset;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.tika.exception.TikaException;
/**
@@ -82,8 +83,8 @@ public class RTGTranslator extends AbstractTranslator {
public RTGTranslator() {
String rtgBaseUrl = RTG_TRANSLATE_URL_BASE;
Properties config = new Properties();
- try (InputStream stream = getClass().getClassLoader().getResourceAsStream(RTG_PROPS)){
- if (stream != null){
+ try (InputStream stream = getClass().getClassLoader().getResourceAsStream(RTG_PROPS)) {
+ if (stream != null) {
config.load(stream);
}
rtgBaseUrl = config.getProperty("rtg.base.url", rtgBaseUrl);
@@ -96,12 +97,13 @@ public class RTGTranslator extends AbstractTranslator {
try {
this.client = WebClient.create(rtgBaseUrl, providers);
this.isAvailable = client.head().getStatus() == 200;
- } catch (Exception e){
+ } catch (Exception e) {
LOG.warn(e.getMessage(), e);
isAvailable = false;
}
}
+
@Override
public String translate(String text, String sourceLanguage, String targetLanguage)
throws TikaException, IOException {
@@ -109,8 +111,7 @@ public class RTGTranslator extends AbstractTranslator {
}
@Override
- public String translate(String text, String targetLanguage)
- throws TikaException, IOException {
+ public String translate(String text, String targetLanguage) throws TikaException, IOException {
return this.translate(text);
}
@@ -120,17 +121,15 @@ public class RTGTranslator extends AbstractTranslator {
}
Map<String, List<Object>> input = new HashMap<>();
input.put("source", Arrays.asList(text.split("(?<=(?<![A-Z])\\. )|\\n")));
- Response response = client.path("translate")
- .type(MediaType.APPLICATION_JSON)
- .accept(MediaType.APPLICATION_JSON)
- .post(input);
- try (InputStreamReader reader = new InputStreamReader(
- (InputStream) response.getEntity(), Charset.defaultCharset())) {
+ Response response = client.path("translate").type(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON).post(input);
+ try (InputStreamReader reader = new InputStreamReader((InputStream) response.getEntity(),
+ Charset.defaultCharset())) {
JSONParser parser = new JSONParser();
JSONObject obj = (JSONObject) parser.parse(reader);
List<String> sentences = (List<String>) obj.get("translation");
return String.join("\n", sentences);
- } catch (ParseException e){
+ } catch (ParseException e) {
throw new IOException(e.getMessage(), e);
}
}
diff --git a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/YandexTranslator.java b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/YandexTranslator.java
index 841d709c4..91687e0ea 100644
--- a/tika-translate/src/main/java/org/apache/tika/language/translate/impl/YandexTranslator.java
+++ b/tika-translate/src/main/java/org/apache/tika/language/translate/impl/YandexTranslator.java
@@ -17,25 +17,25 @@
package org.apache.tika.language.translate.impl;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.language.translate.Translator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.language.translate.Translator;
/**
* An implementation of a REST client for the YANDEX <a href="https://tech.yandex.com/translate/">Translate API</a>.
@@ -49,7 +49,8 @@ public class YandexTranslator implements Translator {
/**
* Yandex Translate API service end-point URL
*/
- private static final String YANDEX_TRANSLATE_URL_BASE = "https://translate.yandex.net/api/v1.5/tr.json/translate";
+ private static final String YANDEX_TRANSLATE_URL_BASE =
+ "https://translate.yandex.net/api/v1.5/tr.json/translate";
/**
* Default USer-Key, a real User-Key must be provided before the Lingo24 can successfully request translations
@@ -57,10 +58,10 @@ public class YandexTranslator implements Translator {
private static final String DEFAULT_KEY = "dummy-key";
/**
- * Identifies the client of the request, used for authentication
+ * Identifies the client of the request, used for authentication
*/
private String apiKey;
-
+
/**
* The Yandex Translate API can handle text in <b>plain</b> and/or <b>html</b> format, the default
* format is <b>plain</b>
@@ -70,9 +71,7 @@ public class YandexTranslator implements Translator {
public YandexTranslator() {
Properties config = new Properties();
try {
- config.load(YandexTranslator.class
- .getResourceAsStream(
- "translator.yandex.properties"));
+ config.load(YandexTranslator.class.getResourceAsStream("translator.yandex.properties"));
this.apiKey = config.getProperty("translator.api-key");
this.format = config.getProperty("translator.text.format");
} catch (Exception e) {
@@ -81,16 +80,16 @@ public class YandexTranslator implements Translator {
}
@Override
- public String translate(String text, String sourceLanguage,
- String targetLanguage) throws TikaException, IOException {
+ public String translate(String text, String sourceLanguage, String targetLanguage)
+ throws TikaException, IOException {
if (!this.isAvailable()) {
return text;
}
-
+
WebClient client = WebClient.create(YANDEX_TRANSLATE_URL_BASE);
-
+
String langCode;
-
+
if (sourceLanguage == null) {
//Translate Service will identify source language
langCode = targetLanguage;
@@ -100,14 +99,12 @@ public class YandexTranslator implements Translator {
}
//TODO Add support for text over 10k characters
- Response response = client.accept(MediaType.APPLICATION_JSON)
- .query("key", this.apiKey).query("lang", langCode)
- .query("text", text).get();
+ Response response = client.accept(MediaType.APPLICATION_JSON).query("key", this.apiKey)
+ .query("lang", langCode).query("text", text).get();
StringBuilder responseText = new StringBuilder();
try (InputStreamReader inputStreamReader = new InputStreamReader(
(InputStream) response.getEntity(), UTF_8);
- BufferedReader reader = new BufferedReader(inputStreamReader);
- ) {
+ BufferedReader reader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = reader.readLine()) != null) {
responseText.append(line);
@@ -117,7 +114,7 @@ public class YandexTranslator implements Translator {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonResp = mapper.readTree(responseText.toString());
-
+
if (!jsonResp.findValuesAsText("code").isEmpty()) {
String code = jsonResp.findValuesAsText("code").get(0);
if (code.equals("200")) {
@@ -126,16 +123,22 @@ public class YandexTranslator implements Translator {
throw new TikaException(jsonResp.findValue("message").get(0).asText());
}
} else {
- throw new TikaException("Return message not recognized: " + responseText.toString().substring(0, Math.min(responseText.length(), 100)));
+ throw new TikaException("Return message not recognized: " +
+ responseText.toString().substring(0, Math.min(responseText.length(), 100)));
}
} catch (JsonParseException e) {
- throw new TikaException("Error requesting translation from '" + sourceLanguage + "' to '" + targetLanguage + "', JSON response from Lingo24 is not well formatted: " + responseText.toString());
+ throw new TikaException(
+ "Error requesting translation from '" + sourceLanguage + "' to '" +
+ targetLanguage +
+ "', JSON response from Lingo24 is not well formatted: " +
+ responseText.toString());
}
}
/**
* Get the API Key in use for client authentication
+ *
* @return API Key
*/
public String getApiKey() {
@@ -144,6 +147,7 @@ public class YandexTranslator implements Translator {
/**
* Set the API Key for client authentication
+ *
* @param apiKey API Key
*/
public void setApiKey(String apiKey) {
@@ -154,6 +158,7 @@ public class YandexTranslator implements Translator {
* Retrieve the current text format setting.
* The Yandex Translate API can handle text in <b>plain</b> and/or <b>html</b> format, the default
* format is <b>plain</b>
+ *
* @return
*/
public String getFormat() {
@@ -162,6 +167,7 @@ public class YandexTranslator implements Translator {
/**
* Set the text format to use (plain/html)
+ *
* @param format Text format setting, either plain or html
*/
public void setFormat(String format) {
@@ -169,14 +175,13 @@ public class YandexTranslator implements Translator {
}
@Override
- public String translate(String text, String targetLanguage)
- throws TikaException, IOException {
+ public String translate(String text, String targetLanguage) throws TikaException, IOException {
return this.translate(text, null, targetLanguage);
}
@Override
public boolean isAvailable() {
- return this.apiKey!=null && !this.apiKey.equals(DEFAULT_KEY);
+ return this.apiKey != null && !this.apiKey.equals(DEFAULT_KEY);
}
}
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.google.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.google.properties
index 4e622ce9d..da0cf1638 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.google.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.google.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.joshua.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.joshua.properties
index 53bd773b2..fbb91b279 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.joshua.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.joshua.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -19,4 +20,4 @@
# if left as null, then translation will not occur and the source text
# will be returned.
# An example would be http://localhost:5000/joshua/translate/
-joshua.server.url=http://localhost:5000/joshua/translate/
\ No newline at end of file
+joshua.server.url=http://localhost:5000/joshua/translate/
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.lingo24.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.lingo24.properties
index 24756ac74..88759a842 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.lingo24.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.lingo24.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.marian.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.marian.properties
index 1399ceb78..bf4bf8232 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.marian.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.marian.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.microsoft.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.microsoft.properties
index 6656fd386..9acf06c7f 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.microsoft.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.microsoft.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.moses.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.moses.properties
index 55f917686..9ed3aebca 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.moses.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.moses.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -17,4 +18,4 @@
# script_path is the full path to the script to pass to the smt jar.
translator.smt_path=dummy-path
-translator.script_path=dummy-path
\ No newline at end of file
+translator.script_path=dummy-path
diff --git a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.yandex.properties b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.yandex.properties
index a3dcf8d96..c56a44038 100644
--- a/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.yandex.properties
+++ b/tika-translate/src/main/resources/org/apache/tika/language/translate/impl/translator.yandex.properties
@@ -1,3 +1,4 @@
+#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/CachedTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/CachedTranslatorTest.java
index 65dc44627..8bc6c4f20 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/CachedTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/CachedTranslatorTest.java
@@ -33,7 +33,7 @@ public class CachedTranslatorTest {
private CachedTranslator cachedTranslator;
@BeforeEach
- public void setUp(){
+ public void setUp() {
cachedTranslator = new CachedTranslator(new GoogleTranslator());
}
@@ -42,8 +42,10 @@ public class CachedTranslatorTest {
for (int i = 0; i < 20; i++) {
cachedTranslator.translate("This is a test string to translate!", "en", "sv");
}
- assertEquals(cachedTranslator.getNumTranslationPairs(), 1, "Cache doesn't have a single translation pair!");
- assertEquals(cachedTranslator.getNumTranslationsFor("en", "sv"), 1, "Cache has more than one element!");
+ assertEquals(cachedTranslator.getNumTranslationPairs(), 1,
+ "Cache doesn't have a single translation pair!");
+ assertEquals(cachedTranslator.getNumTranslationsFor("en", "sv"), 1,
+ "Cache has more than one element!");
}
@Test
@@ -52,9 +54,12 @@ public class CachedTranslatorTest {
cachedTranslator.translate("This is a test string to translate!", "en", "no");
cachedTranslator.translate("This is a different string...", "en", "fr");
}
- assertEquals(cachedTranslator.getNumTranslationPairs(), 2, "Cache doesn't have two translation pairs!");
- assertEquals(cachedTranslator.getNumTranslationsFor("en", "no"), 1, "Cache has more than en to no translation!");
- assertEquals(cachedTranslator.getNumTranslationsFor("en", "fr"), 1, "Cache has more than en to fr translation!");
+ assertEquals(cachedTranslator.getNumTranslationPairs(), 2,
+ "Cache doesn't have two translation pairs!");
+ assertEquals(cachedTranslator.getNumTranslationsFor("en", "no"), 1,
+ "Cache has more than en to no translation!");
+ assertEquals(cachedTranslator.getNumTranslationsFor("en", "fr"), 1,
+ "Cache has more than en to fr translation!");
}
@Test
@@ -65,8 +70,7 @@ public class CachedTranslatorTest {
if (cachedTranslator.isAvailable()) {
String result = cachedTranslator.translate(source, "es", "en");
assertNotNull(result);
- assertEquals("Result: [" + result
- + "]: not equal to expected: [" + expected + "]",
+ assertEquals("Result: [" + result + "]: not equal to expected: [" + expected + "]",
expected, result);
}
}
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/GoogleTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/GoogleTranslatorTest.java
index dcb6a9b8a..dae288ef7 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/GoogleTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/GoogleTranslatorTest.java
@@ -25,63 +25,60 @@ import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.apache.tika.language.translate.impl.GoogleTranslator;
-
/**
* Test harness for the {@link GoogleTranslator}.
- *
*/
-public class GoogleTranslatorTest {
-
- private GoogleTranslator translator;
-
- public GoogleTranslatorTest() {
-
- }
-
- @BeforeEach
- public void setUp() {
- translator = new GoogleTranslator();
- }
-
- @Test
- public void testSimpleTranslate() {
- String source = "hola senor";
- String expected = "hello sir";
-
- String result = null;
- if (translator.isAvailable()) {
- try {
- result = translator.translate(source, "es", "en");
- assertNotNull(result);
- assertEquals(expected, result, "Result: [" + result
- + "]: not equal to expected: [" + expected + "]");
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void testTranslateGuessLanguage() {
- String source = "bonjour comment vas-tu";
- String expected = "hello how are you";
-
- String result = null;
- if (translator.isAvailable()) {
- try {
- result = translator.translate(source, "en");
- assertNotNull(result);
- assertEquals(expected, result, "Result: [" + result
- + "]: not equal to expected: [" + expected + "]");
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- }
+public class GoogleTranslatorTest {
+
+ private GoogleTranslator translator;
+
+ public GoogleTranslatorTest() {
+
+ }
+
+ @BeforeEach
+ public void setUp() {
+ translator = new GoogleTranslator();
+ }
+
+ @Test
+ public void testSimpleTranslate() {
+ String source = "hola senor";
+ String expected = "hello sir";
+
+ String result = null;
+ if (translator.isAvailable()) {
+ try {
+ result = translator.translate(source, "es", "en");
+ assertNotNull(result);
+ assertEquals(expected, result,
+ "Result: [" + result + "]: not equal to expected: [" + expected + "]");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ }
+
+ @Test
+ public void testTranslateGuessLanguage() {
+ String source = "bonjour comment vas-tu";
+ String expected = "hello how are you";
+
+ String result = null;
+ if (translator.isAvailable()) {
+ try {
+ result = translator.translate(source, "en");
+ assertNotNull(result);
+ assertEquals(expected, result,
+ "Result: [" + result + "]: not equal to expected: [" + expected + "]");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ }
}
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/Lingo24TranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/Lingo24TranslatorTest.java
index 08114b69b..a94b6ea66 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/Lingo24TranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/Lingo24TranslatorTest.java
@@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test;
/**
* Test harness for the {@link Lingo24Translator}.
- *
*/
public class Lingo24TranslatorTest {
@@ -46,9 +45,8 @@ public class Lingo24TranslatorTest {
try {
result = translator.translate(source, "es", "en");
assertNotNull(result);
- assertEquals(
- expected, result, "Result: [" + result
- + "]: not equal to expected: [" + expected + "]");
+ assertEquals(expected, result,
+ "Result: [" + result + "]: not equal to expected: [" + expected + "]");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
@@ -67,8 +65,7 @@ public class Lingo24TranslatorTest {
result = translator.translate(source, "en");
assertNotNull(result);
assertEquals(expected, result,
- "Result: [" + result
- + "]: not equal to expected: [" + expected + "]");
+ "Result: [" + result + "]: not equal to expected: [" + expected + "]");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MarianTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MarianTranslatorTest.java
index 42bbf68fb..16aacc4fe 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MarianTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MarianTranslatorTest.java
@@ -38,8 +38,8 @@ public class MarianTranslatorTest {
String source = "Apache Tika is a wonderful tool";
String expected = "Apache Tika este un instrument minunat";
String translated = translator.translate(source, "en", "ro");
- assertTrue(expected.equalsIgnoreCase(translated),
- "Translate " + source + " to " + expected + " (was " + translated + ")");
+ assertTrue(expected.equalsIgnoreCase(translated),
+ "Translate " + source + " to " + expected + " (was " + translated + ")");
}
@Test
@@ -55,7 +55,8 @@ public class MarianTranslatorTest {
@Test
public void testNoConfig() throws Exception {
String source = "Apache Tika is a wonderful tool";
- String expected = "Apache Tika is a wonderful tool"; // Pattern from other Translators is to return source
+ String expected =
+ "Apache Tika is a wonderful tool"; // Pattern from other Translators is to return source
String translated = translator.translate(source, "en", "zz");
assertTrue(expected.equalsIgnoreCase(translated),
"Translate " + source + " to " + expected + " (was " + translated + ")");
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MicrosoftTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MicrosoftTranslatorTest.java
index 5231ee158..fb8036cd6 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MicrosoftTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MicrosoftTranslatorTest.java
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
*/
public class MicrosoftTranslatorTest {
MicrosoftTranslator translator;
+
@BeforeEach
public void setUp() {
translator = new MicrosoftTranslator();
@@ -52,27 +53,25 @@ public class MicrosoftTranslatorTest {
assertTrue(expected.equalsIgnoreCase(translated),
"Translate " + source + " to " + expected + " (was " + translated + ")");
}
-
+
@Test
- public void testSettersAndIsAvailable(){
- try{
- translator.setId("foo");
- translator.setSecret("bar");
- }
- catch(Exception e){
- e.printStackTrace();
- fail(e.getMessage());
- }
- //reset
- translator = new MicrosoftTranslator();
- try{
- translator.setSecret("bar");
- translator.setId("foo");
- }
- catch(Exception e){
- e.printStackTrace();
- fail(e.getMessage());
- }
+ public void testSettersAndIsAvailable() {
+ try {
+ translator.setId("foo");
+ translator.setSecret("bar");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ //reset
+ translator = new MicrosoftTranslator();
+ try {
+ translator.setSecret("bar");
+ translator.setId("foo");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
}
}
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MosesTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MosesTranslatorTest.java
index 40aca5a84..6ad95f18f 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MosesTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/MosesTranslatorTest.java
@@ -16,14 +16,15 @@
*/
package org.apache.tika.language.translate.impl;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
public class MosesTranslatorTest {
MosesTranslator translator;
+
@BeforeEach
public void setUp() {
translator = new MosesTranslator();
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/RTGTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/RTGTranslatorTest.java
index 8d5f458e7..ac1067bad 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/RTGTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/RTGTranslatorTest.java
@@ -17,22 +17,19 @@
package org.apache.tika.language.translate.impl;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Locale;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import org.apache.tika.language.translate.impl.RTGTranslator;
+import java.util.Locale;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test harness for the {@link RTGTranslator}.
- *
*/
public class RTGTranslatorTest {
diff --git a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/YandexTranslatorTest.java b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/YandexTranslatorTest.java
index b8802d961..9d8171350 100644
--- a/tika-translate/src/test/java/org/apache/tika/language/translate/impl/YandexTranslatorTest.java
+++ b/tika-translate/src/test/java/org/apache/tika/language/translate/impl/YandexTranslatorTest.java
@@ -21,13 +21,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.language.translate.impl.YandexTranslator;
+import java.io.IOException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import java.io.IOException;
+import org.apache.tika.exception.TikaException;
/**
* Generic Tests to ensure that the RSS library behaves as expected
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/XMPMetadata.java b/tika-xmp/src/main/java/org/apache/tika/xmp/XMPMetadata.java
index 124a4b0b0..cd12cc117 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/XMPMetadata.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/XMPMetadata.java
@@ -24,16 +24,9 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.Property;
-import org.apache.tika.metadata.Property.PropertyType;
-import org.apache.tika.metadata.PropertyTypeException;
-import org.apache.tika.metadata.TikaCoreProperties;
-import org.apache.tika.xmp.convert.TikaToXMP;
-
import com.adobe.internal.xmp.XMPDateTime;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPIterator;
@@ -46,21 +39,33 @@ import com.adobe.internal.xmp.options.PropertyOptions;
import com.adobe.internal.xmp.options.SerializeOptions;
import com.adobe.internal.xmp.properties.XMPProperty;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.Property.PropertyType;
+import org.apache.tika.metadata.PropertyTypeException;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.xmp.convert.TikaToXMP;
+
/**
* Provides a conversion of the Metadata map from Tika to the XMP data model by also providing the
* Metadata API for clients to ease transition. But clients can also work directly on the XMP data
* model, by getting the XMPMeta reference from this class. Usually the instance would be
* initialized by providing the Metadata object that had been returned from Tika-core which
* populates the XMP data model with all properties that can be converted.
- *
+ * <p>
* This class is not serializable!
*/
@SuppressWarnings("serial")
public class XMPMetadata extends Metadata {
- /** The XMP data */
- private XMPMeta xmpData;
- /** Use the XMP namespace registry implementation */
+ /**
+ * Use the XMP namespace registry implementation
+ */
private static final XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
+ /**
+ * The XMP data
+ */
+ private XMPMeta xmpData;
/**
* Initializes with an empty XMP packet
@@ -74,7 +79,7 @@ public class XMPMetadata extends Metadata {
* But the mimetype is retrieved from the metadata map.
*/
public XMPMetadata(Metadata meta) throws TikaException {
- this.xmpData = TikaToXMP.convert( meta );
+ this.xmpData = TikaToXMP.convert(meta);
}
/**
@@ -84,104 +89,61 @@ public class XMPMetadata extends Metadata {
* will convert only those properties that are in known namespaces and are using the correct
* prefixes
*
- * @param meta
- * the Metadata information from Tika-core
- * @param mimetype
- * mimetype information
- * @throws TikaException
- * case an error occured during conversion
+ * @param meta the Metadata information from Tika-core
+ * @param mimetype mimetype information
+ * @throws TikaException case an error occurred during conversion
*/
public XMPMetadata(Metadata meta, String mimetype) throws TikaException {
- this.xmpData = TikaToXMP.convert( meta, mimetype );
- }
-
- /**
- * @see org.apache.tika.xmp.XMPMetadata#process(org.apache.tika.metadata.Metadata,
- * java.lang.String)
- * But the mimetype is retrieved from the metadata map.
- */
- public void process(Metadata meta) throws TikaException {
- this.xmpData = TikaToXMP.convert( meta );
- }
-
- /**
- * Converts the Metadata information to XMP. If a mimetype is provided, a specific converter can
- * be used, that converts all available metadata. If there is no mimetype provided or no
- * specific converter available a generic conversion is done which will convert only those
- * properties that are in known namespaces and are using the correct prefixes
- *
- * @param meta
- * the Metadata information from Tika-core
- * @param mimetype
- * mimetype information
- * @throws TikaException
- * case an error occured during conversion
- */
- public void process(Metadata meta, String mimetype) throws TikaException {
- this.xmpData = TikaToXMP.convert( meta, mimetype );
- }
-
- /**
- * Provides direct access to the XMP data model, in case a client prefers to work directly on it
- * instead of using the Metadata API
- *
- * @return the "internal" XMP data object
- */
- public XMPMeta getXMPData() {
- return xmpData;
+ this.xmpData = TikaToXMP.convert(meta, mimetype);
}
- // === Namespace Registry API === //
/**
* Register a namespace URI with a suggested prefix. It is not an error if the URI is already
* registered, no matter what the prefix is. If the URI is not registered but the suggested
- * prefix is in use, a unique prefix is created from the suggested one. The actual registeed
+ * prefix is in use, a unique prefix is created from the suggested one. The actual registered
* prefix is always returned. The function result tells if the registered prefix is the
* suggested one.
* Note: No checking is presently done on either the URI or the prefix.
*
- * @param namespaceURI
- * The URI for the namespace. Must be a valid XML URI.
- * @param suggestedPrefix
- * The suggested prefix to be used if the URI is not yet registered. Must be a valid
- * XML name.
+ * @param namespaceURI The URI for the namespace. Must be a valid XML URI.
+ * @param suggestedPrefix The suggested prefix to be used if the URI is not yet registered. Must be a valid
+ * XML name.
* @return Returns the registered prefix for this URI, is equal to the suggestedPrefix if the
- * namespace hasn't been registered before, otherwise the existing prefix.
- * @throws XMPException
- * If the parameters are not accordingly set
+ * namespace hasn't been registered before, otherwise the existing prefix.
+ * @throws XMPException If the parameters are not accordingly set
*/
public static String registerNamespace(String namespaceURI, String suggestedPrefix)
throws XMPException {
- return registry.registerNamespace( namespaceURI, suggestedPrefix );
+ return registry.registerNamespace(namespaceURI, suggestedPrefix);
}
/**
* Obtain the prefix for a registered namespace URI.
* It is not an error if the namespace URI is not registered.
*
- * @param namespaceURI
- * The URI for the namespace. Must not be null or the empty string.
+ * @param namespaceURI The URI for the namespace. Must not be null or the empty string.
* @return Returns the prefix registered for this namespace URI or null.
*/
public static String getNamespacePrefix(String namespaceURI) {
- return registry.getNamespacePrefix( namespaceURI );
+ return registry.getNamespacePrefix(namespaceURI);
}
/**
* Obtain the URI for a registered namespace prefix.
* It is not an error if the namespace prefix is not registered.
*
- * @param namespacePrefix
- * The prefix for the namespace. Must not be null or the empty string.
+ * @param namespacePrefix The prefix for the namespace. Must not be null or the empty string.
* @return Returns the URI registered for this prefix or null.
*/
public static String getNamespaceURI(String namespacePrefix) {
- return registry.getNamespaceURI( namespacePrefix );
+ return registry.getNamespaceURI(namespacePrefix);
}
+ // === Namespace Registry API === //
+
/**
* @return Returns the registered prefix/namespace-pairs as map, where the keys are the
- * namespaces and the values are the prefixes.
+ * namespaces and the values are the prefixes.
*/
@SuppressWarnings("unchecked")
public static Map<String, String> getNamespaces() {
@@ -190,7 +152,7 @@ public class XMPMetadata extends Metadata {
/**
* @return Returns the registered namespace/prefix-pairs as map, where the keys are the prefixes
- * and the values are the namespaces.
+ * and the values are the namespaces.
*/
@SuppressWarnings("unchecked")
public static Map<String, String> getPrefixes() {
@@ -205,20 +167,53 @@ public class XMPMetadata extends Metadata {
* <p>
* Note: Not yet implemented.
*
- * @param namespaceURI
- * The URI for the namespace.
+ * @param namespaceURI The URI for the namespace.
*/
public static void deleteNamespace(String namespaceURI) {
- registry.deleteNamespace( namespaceURI );
+ registry.deleteNamespace(namespaceURI);
+ }
+
+ /**
+ * @see org.apache.tika.xmp.XMPMetadata#process(org.apache.tika.metadata.Metadata,
+ * java.lang.String)
+ * But the mimetype is retrieved from the metadata map.
+ */
+ public void process(Metadata meta) throws TikaException {
+ this.xmpData = TikaToXMP.convert(meta);
+ }
+
+ /**
+ * Converts the Metadata information to XMP. If a mimetype is provided, a specific converter can
+ * be used, that converts all available metadata. If there is no mimetype provided or no
+ * specific converter available a generic conversion is done which will convert only those
+ * properties that are in known namespaces and are using the correct prefixes
+ *
+ * @param meta the Metadata information from Tika-core
+ * @param mimetype mimetype information
+ * @throws TikaException case an error occurred during conversion
+ */
+ public void process(Metadata meta, String mimetype) throws TikaException {
+ this.xmpData = TikaToXMP.convert(meta, mimetype);
+ }
+
+ /**
+ * Provides direct access to the XMP data model, in case a client prefers to work directly on it
+ * instead of using the Metadata API
+ *
+ * @return the "internal" XMP data object
+ */
+ public XMPMeta getXMPData() {
+ return xmpData;
}
// === Metadata API === //
+
/**
* @see org.apache.tika.xmp.XMPMetadata#isMultiValued(java.lang.String)
*/
@Override
public boolean isMultiValued(Property property) {
- return this.isMultiValued( property.getName() );
+ return this.isMultiValued(property.getName());
}
/**
@@ -228,18 +223,17 @@ public class XMPMetadata extends Metadata {
*/
@Override
public boolean isMultiValued(String name) {
- checkKey( name );
+ checkKey(name);
- String[] keyParts = splitKey( name );
+ String[] keyParts = splitKey(name);
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
try {
- XMPProperty prop = xmpData.getProperty( ns, keyParts[1] );
+ XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
return prop.getOptions().isArray();
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
}
@@ -252,7 +246,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public String[] names() {
- throw new UnsupportedOperationException( "Not implemented" );
+ throw new UnsupportedOperationException("Not implemented");
}
/**
@@ -263,26 +257,24 @@ public class XMPMetadata extends Metadata {
*/
@Override
public String get(String name) {
- checkKey( name );
+ checkKey(name);
String value = null;
- String[] keyParts = splitKey( name );
+ String[] keyParts = splitKey(name);
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
try {
- XMPProperty prop = xmpData.getProperty( ns, keyParts[1] );
+ XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
if (prop != null && prop.getOptions().isSimple()) {
value = prop.getValue();
- }
- else if (prop != null && prop.getOptions().isArray()) {
- prop = xmpData.getArrayItem( ns, keyParts[1], 1 );
+ } else if (prop != null && prop.getOptions().isArray()) {
+ prop = xmpData.getArrayItem(ns, keyParts[1], 1);
value = prop.getValue();
}
// in all other cases, null is returned
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
}
@@ -295,7 +287,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public String get(Property property) {
- return this.get( property.getName() );
+ return this.get(property.getName());
}
/**
@@ -307,8 +299,7 @@ public class XMPMetadata extends Metadata {
try {
result = XMPUtils.convertToInteger(this.get(property.getName()));
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
@@ -323,15 +314,14 @@ public class XMPMetadata extends Metadata {
Date result = null;
try {
- XMPDateTime xmpDate = XMPUtils.convertToDate( this.get( property.getName() ) );
+ XMPDateTime xmpDate = XMPUtils.convertToDate(this.get(property.getName()));
if (xmpDate != null) {
Calendar cal = xmpDate.getCalendar();
// TODO Timezone is currently lost
// need another solution that preserves the timezone
result = cal.getTime();
}
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
@@ -343,7 +333,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public String[] getValues(Property property) {
- return this.getValues( property.getName() );
+ return this.getValues(property.getName());
}
/**
@@ -354,31 +344,29 @@ public class XMPMetadata extends Metadata {
*/
@Override
public String[] getValues(String name) {
- checkKey( name );
+ checkKey(name);
String[] value = null;
- String[] keyParts = splitKey( name );
+ String[] keyParts = splitKey(name);
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
try {
- XMPProperty prop = xmpData.getProperty( ns, keyParts[1] );
+ XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
if (prop != null && prop.getOptions().isSimple()) {
value = new String[1];
value[0] = prop.getValue();
- }
- else if (prop != null && prop.getOptions().isArray()) {
- int size = xmpData.countArrayItems( ns, keyParts[1] );
+ } else if (prop != null && prop.getOptions().isArray()) {
+ int size = xmpData.countArrayItems(ns, keyParts[1]);
value = new String[size];
boolean onlySimpleChildren = true;
for (int i = 0; i < size && onlySimpleChildren; i++) {
- prop = xmpData.getArrayItem( ns, keyParts[1], i + 1 );
+ prop = xmpData.getArrayItem(ns, keyParts[1], i + 1);
if (prop.getOptions().isSimple()) {
value[i] = prop.getValue();
- }
- else {
+ } else {
onlySimpleChildren = false;
}
}
@@ -388,8 +376,7 @@ public class XMPMetadata extends Metadata {
}
}
// in all other cases, null is returned
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
}
@@ -405,7 +392,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void add(String name, String value) {
- set( name, value );
+ set(name, value);
}
/**
@@ -416,16 +403,15 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void set(String name, String value) {
- checkKey( name );
+ checkKey(name);
- String[] keyParts = splitKey( name );
+ String[] keyParts = splitKey(name);
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
try {
- xmpData.setProperty( ns, keyParts[1], value );
- }
- catch (XMPException e) {
+ xmpData.setProperty(ns, keyParts[1], value);
+ } catch (XMPException e) {
// Ignore
}
}
@@ -436,7 +422,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void set(Property property, String value) {
- this.set( property.getName(), value );
+ this.set(property.getName(), value);
}
/**
@@ -446,7 +432,7 @@ public class XMPMetadata extends Metadata {
public void set(Property property, int value) {
// Can reuse the checks from the base class implementation which will call
// the set(String, String) method in the end
- super.set( property, value );
+ super.set(property, value);
}
/**
@@ -454,7 +440,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void set(Property property, double value) {
- super.set( property, value );
+ super.set(property, value);
}
/**
@@ -462,7 +448,7 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void set(Property property, Date date) {
- super.set( property, date );
+ super.set(property, date);
}
/**
@@ -470,29 +456,28 @@ public class XMPMetadata extends Metadata {
* properties that use a registered prefix are stored in the XMP.
*
* @see org.apache.tika.metadata.Metadata#set(org.apache.tika.metadata.Property,
- * java.lang.String[])
+ * java.lang.String[])
*/
@Override
public void set(Property property, String[] values) {
- checkKey( property.getName() );
+ checkKey(property.getName());
if (!property.isMultiValuePermitted()) {
- throw new PropertyTypeException( "Property is not of an array type" );
+ throw new PropertyTypeException("Property is not of an array type");
}
- String[] keyParts = splitKey( property.getName() );
+ String[] keyParts = splitKey(property.getName());
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
try {
- int arrayType = tikaToXMPArrayType( property.getPrimaryProperty().getPropertyType() );
- xmpData.setProperty( ns, keyParts[1], null, new PropertyOptions( arrayType ) );
+ int arrayType = tikaToXMPArrayType(property.getPrimaryProperty().getPropertyType());
+ xmpData.setProperty(ns, keyParts[1], null, new PropertyOptions(arrayType));
for (String value : values) {
- xmpData.appendArrayItem( ns, keyParts[1], value );
+ xmpData.appendArrayItem(ns, keyParts[1], value);
}
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// Ignore
}
}
@@ -505,23 +490,22 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void setAll(Properties properties) {
- @SuppressWarnings("unchecked")
- Enumeration<String> names = (Enumeration<String>) properties.propertyNames();
+ @SuppressWarnings("unchecked") Enumeration<String> names =
+ (Enumeration<String>) properties.propertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
- Property property = Property.get( name );
+ Property property = Property.get(name);
if (property == null) {
- throw new PropertyTypeException( "Unknown property: " + name );
+ throw new PropertyTypeException("Unknown property: " + name);
}
- String value = properties.getProperty( name );
+ String value = properties.getProperty(name);
if (property.isMultiValuePermitted()) {
- this.set( property, new String[] { value } );
- }
- else {
- this.set( property, value );
+ this.set(property, new String[]{value});
+ } else {
+ this.set(property, value);
}
}
}
@@ -530,7 +514,7 @@ public class XMPMetadata extends Metadata {
* @see org.apache.tika.xmp.XMPMetadata#remove(java.lang.String)
*/
public void remove(Property property) {
- this.remove( property.getName() );
+ this.remove(property.getName());
}
/**
@@ -541,13 +525,13 @@ public class XMPMetadata extends Metadata {
*/
@Override
public void remove(String name) {
- checkKey( name );
+ checkKey(name);
- String[] keyParts = splitKey( name );
+ String[] keyParts = splitKey(name);
- String ns = registry.getNamespaceURI( keyParts[0] );
+ String ns = registry.getNamespaceURI(keyParts[0]);
if (ns != null) {
- xmpData.deleteProperty( ns, keyParts[1] );
+ xmpData.deleteProperty(ns, keyParts[1]);
}
}
@@ -560,15 +544,14 @@ public class XMPMetadata extends Metadata {
try {
// Get an iterator for the XMP packet, starting at the top level schema nodes
- XMPIterator nsIter = xmpData.iterator( new IteratorOptions().setJustChildren( true )
- .setOmitQualifiers( true ) );
+ XMPIterator nsIter = xmpData.iterator(
+ new IteratorOptions().setJustChildren(true).setOmitQualifiers(true));
// iterate all top level namespaces
while (nsIter.hasNext()) {
nsIter.next();
size++;
}
- }
- catch (XMPException e) {
+ } catch (XMPException e) {
// ignore
}
@@ -581,7 +564,12 @@ public class XMPMetadata extends Metadata {
*/
@Override
public boolean equals(Object o) {
- throw new UnsupportedOperationException( "Not implemented" );
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), xmpData);
}
/**
@@ -593,10 +581,9 @@ public class XMPMetadata extends Metadata {
public String toString() {
String result = null;
try {
- result = XMPMetaFactory.serializeToString( xmpData, new SerializeOptions()
- .setOmitPacketWrapper( true ).setUseCompactFormat( true ) );
- }
- catch (XMPException e) {
+ result = XMPMetaFactory.serializeToString(xmpData,
+ new SerializeOptions().setOmitPacketWrapper(true).setUseCompactFormat(true));
+ } catch (XMPException e) {
// ignore
}
return result;
@@ -615,41 +602,39 @@ public class XMPMetadata extends Metadata {
/**
* Checks if the given key is a valid QName with a known standard namespace prefix
*
- * @param key
- * the key to check
+ * @param key the key to check
* @return true if the key is valid otherwise false
*/
private void checkKey(String key) throws PropertyTypeException {
if (key == null || key.length() == 0) {
- throw new PropertyTypeException( "Key must not be null" );
+ throw new PropertyTypeException("Key must not be null");
}
- String[] keyParts = splitKey( key );
+ String[] keyParts = splitKey(key);
if (keyParts == null) {
- throw new PropertyTypeException( "Key must be a QName in the form prefix:localName" );
+ throw new PropertyTypeException("Key must be a QName in the form prefix:localName");
}
- if (registry.getNamespaceURI( keyParts[0] ) == null) {
- throw new PropertyTypeException( "Key does not use a registered Namespace prefix" );
+ if (registry.getNamespaceURI(keyParts[0]) == null) {
+ throw new PropertyTypeException("Key does not use a registered Namespace prefix");
}
}
/**
* Split the given key at the namespace prefix delimiter
*
- * @param key
- * the key to split
+ * @param key the key to split
* @return prefix and local name of the property or null if the key did not contain a delimiter
- * or too much of them
+ * or too much of them
*/
private String[] splitKey(String key) {
- String[] keyParts = key.split( TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER );
+ String[] keyParts = key.split(TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER);
if (keyParts.length > 0 && keyParts.length <= 2) {
return keyParts;
}
return null;
- }// checkKeyPrefix
+ } // checkKeyPrefix
/**
* Convert Tika array types to XMP array types
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/AbstractConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/AbstractConverter.java
index bd1ffa9a1..ed03e2a0e 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/AbstractConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/AbstractConverter.java
@@ -18,10 +18,6 @@ package org.apache.tika.xmp.convert;
import java.util.Set;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.Property;
-
import com.adobe.internal.xmp.XMPConst;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
@@ -30,12 +26,22 @@ import com.adobe.internal.xmp.XMPSchemaRegistry;
import com.adobe.internal.xmp.XMPUtils;
import com.adobe.internal.xmp.options.PropertyOptions;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+
/**
* Base class for Tika Metadata to XMP converter which provides some needed common functionality.
*/
public abstract class AbstractConverter implements ITikaToXMPConverter {
- private Metadata metadata;
protected XMPMeta meta;
+ private Metadata metadata;
+
+ public AbstractConverter() throws TikaException {
+ meta = XMPMetaFactory.create();
+ metadata = new Metadata();
+ registerNamespaces(getAdditionalNamespaces());
+ }
abstract public XMPMeta process(Metadata metadata) throws XMPException;
@@ -47,12 +53,6 @@ public abstract class AbstractConverter implements ITikaToXMPConverter {
*/
abstract protected Set<Namespace> getAdditionalNamespaces();
- public AbstractConverter() throws TikaException {
- meta = XMPMetaFactory.create();
- metadata = new Metadata();
- registerNamespaces( getAdditionalNamespaces() );
- }
-
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@@ -67,10 +67,8 @@ public abstract class AbstractConverter implements ITikaToXMPConverter {
* Registers a number <code>Namespace</code> information with XMPCore. Any already registered
* namespace is not registered again.
*
- * @param namespaces
- * the list of namespaces to be registered
- * @throws TikaException
- * in case a namespace oculd not be registered
+ * @param namespaces the list of namespaces to be registered
+ * @throws TikaException in case a namespace oculd not be registered
*/
protected void registerNamespaces(Set<Namespace> namespaces) throws TikaException {
XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
@@ -78,11 +76,10 @@ public abstract class AbstractConverter implements ITikaToXMPConverter {
for (Namespace namespace : namespaces) {
// Any already registered namespace is not registered again
try {
- registry.registerNamespace( namespace.uri, namespace.prefix );
- }
- catch (XMPException e) {
+ registry.registerNamespace(namespace.uri, namespace.prefix);
+ } catch (XMPException e) {
throw new TikaException(
- "Namespace needed by converter could not be registiered with XMPCore", e );
+ "Namespace needed by converter could not be registiered with XMPCore", e);
}
}
}
@@ -92,26 +89,22 @@ public abstract class AbstractConverter implements ITikaToXMPConverter {
*/
protected void createProperty(Property metadataProperty, String ns, String propertyName)
throws XMPException {
- createProperty( metadataProperty.getName(), ns, propertyName );
+ createProperty(metadataProperty.getName(), ns, propertyName);
}
/**
* Creates a simple property.
*
- * @param tikaKey
- * Key in the Tika metadata map
- * @param ns
- * namespace the property should be created in
- * @param propertyName
- * name of the property
- * @throws XMPException
- * if the property could not be created
+ * @param tikaKey Key in the Tika metadata map
+ * @param ns namespace the property should be created in
+ * @param propertyName name of the property
+ * @throws XMPException if the property could not be created
*/
protected void createProperty(String tikaKey, String ns, String propertyName)
throws XMPException {
- String value = metadata.get( tikaKey );
+ String value = metadata.get(tikaKey);
if (value != null && value.length() > 0) {
- meta.setProperty( ns, propertyName, value );
+ meta.setProperty(ns, propertyName, value);
}
}
@@ -120,84 +113,71 @@ public abstract class AbstractConverter implements ITikaToXMPConverter {
*/
protected void createLangAltProperty(Property metadataProperty, String ns, String propertyName)
throws XMPException {
- createLangAltProperty( metadataProperty.getName(), ns, propertyName );
+ createLangAltProperty(metadataProperty.getName(), ns, propertyName);
}
/**
* Creates a language alternative property in the x-default language
*
- * @param tikaKey
- * Key in the Tika metadata map
- * @param ns
- * namespace the property should be created in
- * @param propertyName
- * name of the property
- * @throws XMPException
- * if the property could not be created
+ * @param tikaKey Key in the Tika metadata map
+ * @param ns namespace the property should be created in
+ * @param propertyName name of the property
+ * @throws XMPException if the property could not be created
*/
protected void createLangAltProperty(String tikaKey, String ns, String propertyName)
throws XMPException {
- String value = metadata.get( tikaKey );
+ String value = metadata.get(tikaKey);
if (value != null && value.length() > 0) {
- meta.setLocalizedText( ns, propertyName, null, XMPConst.X_DEFAULT, value );
+ meta.setLocalizedText(ns, propertyName, null, XMPConst.X_DEFAULT, value);
}
}
- protected void createArrayProperty(Property metadataProperty, String nsDc,
- String arrayProperty, int arrayType) throws XMPException {
- createArrayProperty( metadataProperty.getName(), nsDc, arrayProperty, arrayType );
+ protected void createArrayProperty(Property metadataProperty, String nsDc, String arrayProperty,
+ int arrayType) throws XMPException {
+ createArrayProperty(metadataProperty.getName(), nsDc, arrayProperty, arrayType);
}
/**
* Creates an array property from a list of values.
*
- * @param tikaKey
- * Key in the Tika metadata map
- * @param ns
- * namespace the property should be created in
- * @param propertyName
- * name of the property
- * @param arrayType
- * depicts which kind of array shall be created
- * @throws XMPException
- * if the property could not be created
+ * @param tikaKey Key in the Tika metadata map
+ * @param ns namespace the property should be created in
+ * @param propertyName name of the property
+ * @param arrayType depicts which kind of array shall be created
+ * @throws XMPException if the property could not be created
*/
- protected void createArrayProperty(String tikaKey, String ns, String propertyName, int arrayType)
- throws XMPException {
- String[] values = metadata.getValues( tikaKey );
+ protected void createArrayProperty(String tikaKey, String ns, String propertyName,
+ int arrayType) throws XMPException {
+ String[] values = metadata.getValues(tikaKey);
if (values != null) {
- meta.setProperty( ns, propertyName, null, new PropertyOptions( arrayType ) );
+ meta.setProperty(ns, propertyName, null, new PropertyOptions(arrayType));
for (String value : values) {
- meta.appendArrayItem( ns, propertyName, value );
+ meta.appendArrayItem(ns, propertyName, value);
}
}
}
protected void createCommaSeparatedArray(Property metadataProperty, String nsDc,
- String arrayProperty, int arrayType) throws XMPException {
- createCommaSeparatedArray( metadataProperty.getName(), nsDc, arrayProperty, arrayType );
+ String arrayProperty, int arrayType)
+ throws XMPException {
+ createCommaSeparatedArray(metadataProperty.getName(), nsDc, arrayProperty, arrayType);
}
/**
* Creates an array property from a comma separated list.
*
- * @param tikaKey
- * Key in the Tika metadata map
- * @param ns
- * namespace the property should be created in
- * @param propertyName
- * name of the property
- * @param arrayType
- * depicts which kind of array shall be created
- * @throws XMPException
- * if the property could not be created
+ * @param tikaKey Key in the Tika metadata map
+ * @param ns namespace the property should be created in
+ * @param propertyName name of the property
+ * @param arrayType depicts which kind of array shall be created
+ * @throws XMPException if the property could not be created
*/
protected void createCommaSeparatedArray(String tikaKey, String ns, String propertyName,
- int arrayType) throws XMPException {
- String value = metadata.get( tikaKey );
+ int arrayType) throws XMPException {
+ String value = metadata.get(tikaKey);
if (value != null && value.length() > 0) {
- XMPUtils.separateArrayItems( meta, ns, propertyName, value, new PropertyOptions(
- arrayType ), false );
+ XMPUtils.separateArrayItems(meta, ns, propertyName, value,
+ new PropertyOptions(arrayType), false);
}
}
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/GenericConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/GenericConverter.java
index 3059e0e2f..981626515 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/GenericConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/GenericConverter.java
@@ -20,19 +20,19 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.XMPMetaFactory;
+import com.adobe.internal.xmp.XMPSchemaRegistry;
+import com.adobe.internal.xmp.options.PropertyOptions;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.DublinCore;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.Property.PropertyType;
import org.apache.tika.metadata.TikaCoreProperties;
import org.apache.tika.metadata.XMPRights;
-import org.apache.tika.metadata.Property.PropertyType;
-
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.XMPMetaFactory;
-import com.adobe.internal.xmp.XMPSchemaRegistry;
-import com.adobe.internal.xmp.options.PropertyOptions;
/**
* Trys to convert as much of the properties in the <code>Metadata</code> map to XMP namespaces.
@@ -47,46 +47,44 @@ public class GenericConverter extends AbstractConverter {
@Override
public XMPMeta process(Metadata metadata) throws XMPException {
- setMetadata( metadata );
+ setMetadata(metadata);
XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
String[] keys = metadata.names();
for (String key : keys) {
- String[] keyParts = key.split( TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER );
+ String[] keyParts = key.split(TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER);
if (keyParts.length > 0 && keyParts.length <= 2) {
- String uri = registry.getNamespaceURI( keyParts[0] );
+ String uri = registry.getNamespaceURI(keyParts[0]);
if (uri != null) {
// Tika properties where the type differs from the XMP specification
- if (key.equals( DublinCore.TITLE.getName() )
- || key.equals( DublinCore.DESCRIPTION.getName() )
- || key.equals( XMPRights.USAGE_TERMS.getName() )) {
- createLangAltProperty( key, uri, keyParts[1] );
- }
- else if (key.equals( DublinCore.CREATOR.getName() )) {
- createArrayProperty( key, uri, keyParts[1], PropertyOptions.ARRAY_ORDERED );
- }
- else {
- PropertyType type = Property.getPropertyType( key );
+ if (key.equals(DublinCore.TITLE.getName()) ||
+ key.equals(DublinCore.DESCRIPTION.getName()) ||
+ key.equals(XMPRights.USAGE_TERMS.getName())) {
+ createLangAltProperty(key, uri, keyParts[1]);
+ } else if (key.equals(DublinCore.CREATOR.getName())) {
+ createArrayProperty(key, uri, keyParts[1], PropertyOptions.ARRAY_ORDERED);
+ } else {
+ PropertyType type = Property.getPropertyType(key);
if (type != null) {
switch (type) {
case SIMPLE:
- createProperty( key, uri, keyParts[1] );
+ createProperty(key, uri, keyParts[1]);
break;
case BAG:
- createArrayProperty( key, uri, keyParts[1],
- PropertyOptions.ARRAY );
+ createArrayProperty(key, uri, keyParts[1],
+ PropertyOptions.ARRAY);
break;
case SEQ:
- createArrayProperty( key, uri, keyParts[1],
- PropertyOptions.ARRAY_ORDERED );
+ createArrayProperty(key, uri, keyParts[1],
+ PropertyOptions.ARRAY_ORDERED);
break;
case ALT:
- createArrayProperty( key, uri, keyParts[1],
- PropertyOptions.ARRAY_ALTERNATE );
+ createArrayProperty(key, uri, keyParts[1],
+ PropertyOptions.ARRAY_ALTERNATE);
break;
- // TODO Add support for structs and lang-alts, but those types are
- // currently not used in Tika
+ // TODO Add support for structs and lang-alts, but those types are
+ // currently not used in Tika
}
}
}
@@ -100,6 +98,6 @@ public class GenericConverter extends AbstractConverter {
@Override
public Set<Namespace> getAdditionalNamespaces() {
// no additional namespaces needed
- return Collections.unmodifiableSet(new HashSet<>() );
+ return Collections.unmodifiableSet(new HashSet<>());
}
}
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/ITikaToXMPConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/ITikaToXMPConverter.java
index 0dc9eedd6..d131df012 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/ITikaToXMPConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/ITikaToXMPConverter.java
@@ -16,11 +16,11 @@
*/
package org.apache.tika.xmp.convert;
-import org.apache.tika.metadata.Metadata;
-
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
+import org.apache.tika.metadata.Metadata;
+
/**
* Interface for the specific <code>Metadata</code> to XMP converters
*/
@@ -29,11 +29,9 @@ public interface ITikaToXMPConverter {
* Converts a Tika {@link Metadata}-object into an {@link XMPMeta} containing the useful
* properties.
*
- * @param metadata
- * a Tika Metadata object
+ * @param metadata a Tika Metadata object
* @return Returns an XMPMeta object.
- * @throws XMPException
- * If an error occurs during the creation of the XMP object.
+ * @throws XMPException If an error occurs during the creation of the XMP object.
*/
XMPMeta process(Metadata metadata) throws XMPException;
}
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeBinaryConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeBinaryConverter.java
index 0338ded61..05ea4b034 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeBinaryConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeBinaryConverter.java
@@ -21,6 +21,11 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import com.adobe.internal.xmp.XMPConst;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.options.PropertyOptions;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.HttpHeaders;
import org.apache.tika.metadata.Metadata;
@@ -29,57 +34,52 @@ import org.apache.tika.metadata.OfficeOpenXMLCore;
import org.apache.tika.metadata.OfficeOpenXMLExtended;
import org.apache.tika.metadata.TikaCoreProperties;
-import com.adobe.internal.xmp.XMPConst;
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.options.PropertyOptions;
-
/**
* Tika to XMP mapping for the binary MS formats Word (.doc), Excel (.xls) and PowerPoint (.ppt).
*/
public class MSOfficeBinaryConverter extends AbstractConverter {
+ protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections.unmodifiableSet(
+ new HashSet<>(Arrays.asList(
+ new Namespace(OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX),
+ new Namespace(OfficeOpenXMLExtended.NAMESPACE_URI,
+ OfficeOpenXMLExtended.PREFIX))));
+
public MSOfficeBinaryConverter() throws TikaException {
super();
}
- protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections
- .unmodifiableSet(new HashSet<>(Arrays.asList(new Namespace(
- OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX), new Namespace(
- OfficeOpenXMLExtended.NAMESPACE_URI, OfficeOpenXMLExtended.PREFIX))) );
-
/**
- * @throws XMPException
- * Forwards XMP errors
+ * @throws XMPException Forwards XMP errors
* @see ITikaToXMPConverter#process(Metadata)
*/
public XMPMeta process(Metadata metadata) throws XMPException {
- super.setMetadata( metadata );
+ super.setMetadata(metadata);
// For all formats, Tika uses the same keys
- createProperty( HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format" );
- createProperty( OfficeOpenXMLExtended.APPLICATION, XMPConst.NS_XMP, "CreatorTool" );
- createCommaSeparatedArray( TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
- PropertyOptions.ARRAY_ORDERED );
- createProperty( OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre" );
- createProperty( TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate" );
- createProperty( Office.CHARACTER_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Characters" );
- createProperty( TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments" );
- createProperty( OfficeOpenXMLExtended.COMPANY, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Company" );
- createCommaSeparatedArray( TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
- PropertyOptions.ARRAY );
- createLangAltProperty( TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description" );
- createProperty( TikaCoreProperties.LANGUAGE, OfficeOpenXMLCore.NAMESPACE_URI, "language" );
- createProperty( TikaCoreProperties.PRINT_DATE, OfficeOpenXMLCore.NAMESPACE_URI,
- "lastPrinted" );
- createProperty( TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate" );
- createProperty( Office.PAGE_COUNT, XMPConst.TYPE_PAGEDFILE, "NPages" );
- createProperty( OfficeOpenXMLCore.REVISION, OfficeOpenXMLCore.NAMESPACE_URI, "revision" );
- createProperty( Office.SLIDE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Pages" );
- createProperty( OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Template" );
- createLangAltProperty( TikaCoreProperties.TITLE, XMPConst.NS_DC, "title" );
- createProperty( Office.WORD_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Words" );
+ createProperty(HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format");
+ createProperty(OfficeOpenXMLExtended.APPLICATION, XMPConst.NS_XMP, "CreatorTool");
+ createCommaSeparatedArray(TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
+ PropertyOptions.ARRAY_ORDERED);
+ createProperty(OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre");
+ createProperty(TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate");
+ createProperty(Office.CHARACTER_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Characters");
+ createProperty(TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments");
+ createProperty(OfficeOpenXMLExtended.COMPANY, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Company");
+ createCommaSeparatedArray(TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
+ PropertyOptions.ARRAY);
+ createLangAltProperty(TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description");
+ createProperty(TikaCoreProperties.LANGUAGE, OfficeOpenXMLCore.NAMESPACE_URI, "language");
+ createProperty(TikaCoreProperties.PRINT_DATE, OfficeOpenXMLCore.NAMESPACE_URI,
+ "lastPrinted");
+ createProperty(TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate");
+ createProperty(Office.PAGE_COUNT, XMPConst.TYPE_PAGEDFILE, "NPages");
+ createProperty(OfficeOpenXMLCore.REVISION, OfficeOpenXMLCore.NAMESPACE_URI, "revision");
+ createProperty(Office.SLIDE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Pages");
+ createProperty(OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Template");
+ createLangAltProperty(TikaCoreProperties.TITLE, XMPConst.NS_DC, "title");
+ createProperty(Office.WORD_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Words");
// Not mapped: (MSOffice) Edit-Time ???
// Not mapped: (MSOffice) Last-Author ???
// not mapped: (MSOffice) Security ???
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeXMLConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeXMLConverter.java
index 6d133c375..6d8d30bce 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeXMLConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/MSOfficeXMLConverter.java
@@ -21,6 +21,11 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import com.adobe.internal.xmp.XMPConst;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.options.PropertyOptions;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.HttpHeaders;
import org.apache.tika.metadata.Metadata;
@@ -29,20 +34,16 @@ import org.apache.tika.metadata.OfficeOpenXMLCore;
import org.apache.tika.metadata.OfficeOpenXMLExtended;
import org.apache.tika.metadata.TikaCoreProperties;
-import com.adobe.internal.xmp.XMPConst;
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.options.PropertyOptions;
-
/**
* Tika to XMP mapping for the Office Open XML formats Word (.docx), Excel (.xlsx) and PowerPoint
* (.pptx).
*/
public class MSOfficeXMLConverter extends AbstractConverter {
- protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections
- .unmodifiableSet(new HashSet<>(Arrays.asList(new Namespace(
- OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX), new Namespace(
- OfficeOpenXMLExtended.NAMESPACE_URI, OfficeOpenXMLExtended.PREFIX))) );
+ protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections.unmodifiableSet(
+ new HashSet<>(Arrays.asList(
+ new Namespace(OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX),
+ new Namespace(OfficeOpenXMLExtended.NAMESPACE_URI,
+ OfficeOpenXMLExtended.PREFIX))));
public MSOfficeXMLConverter() throws TikaException {
super();
@@ -50,69 +51,69 @@ public class MSOfficeXMLConverter extends AbstractConverter {
@Override
public XMPMeta process(Metadata metadata) throws XMPException {
- super.setMetadata( metadata );
+ super.setMetadata(metadata);
- createProperty( HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format" );
+ createProperty(HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format");
// Core Properties
- createProperty( OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre" );
- createProperty( OfficeOpenXMLCore.CONTENT_STATUS, OfficeOpenXMLCore.NAMESPACE_URI,
- "contentStatus" );
- createProperty( TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate" );
- createCommaSeparatedArray( TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
- PropertyOptions.ARRAY_ORDERED );
- createProperty( TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments" );
- createProperty( TikaCoreProperties.IDENTIFIER, XMPConst.NS_DC, "identifier" );
- createCommaSeparatedArray( TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
- PropertyOptions.ARRAY );
- createLangAltProperty( TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description" );
- createProperty( TikaCoreProperties.LANGUAGE, XMPConst.NS_DC, "language" );
- createProperty( TikaCoreProperties.MODIFIER, OfficeOpenXMLCore.NAMESPACE_URI,
- "lastModifiedBy" );
- createProperty( TikaCoreProperties.PRINT_DATE, OfficeOpenXMLCore.NAMESPACE_URI,
- "lastPrinted" );
- createProperty( TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate" );
- createProperty( OfficeOpenXMLCore.REVISION, OfficeOpenXMLCore.NAMESPACE_URI, "revision" );
- createLangAltProperty( TikaCoreProperties.TITLE, XMPConst.NS_DC, "title" );
- createProperty( OfficeOpenXMLCore.VERSION, OfficeOpenXMLCore.NAMESPACE_URI, "version" );
+ createProperty(OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre");
+ createProperty(OfficeOpenXMLCore.CONTENT_STATUS, OfficeOpenXMLCore.NAMESPACE_URI,
+ "contentStatus");
+ createProperty(TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate");
+ createCommaSeparatedArray(TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
+ PropertyOptions.ARRAY_ORDERED);
+ createProperty(TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments");
+ createProperty(TikaCoreProperties.IDENTIFIER, XMPConst.NS_DC, "identifier");
+ createCommaSeparatedArray(TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
+ PropertyOptions.ARRAY);
+ createLangAltProperty(TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description");
+ createProperty(TikaCoreProperties.LANGUAGE, XMPConst.NS_DC, "language");
+ createProperty(TikaCoreProperties.MODIFIER, OfficeOpenXMLCore.NAMESPACE_URI,
+ "lastModifiedBy");
+ createProperty(TikaCoreProperties.PRINT_DATE, OfficeOpenXMLCore.NAMESPACE_URI,
+ "lastPrinted");
+ createProperty(TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate");
+ createProperty(OfficeOpenXMLCore.REVISION, OfficeOpenXMLCore.NAMESPACE_URI, "revision");
+ createLangAltProperty(TikaCoreProperties.TITLE, XMPConst.NS_DC, "title");
+ createProperty(OfficeOpenXMLCore.VERSION, OfficeOpenXMLCore.NAMESPACE_URI, "version");
// Extended Properties
// Put both App name and version in xmp:CreatorTool
String creatorTool = "";
- String value = metadata.get( OfficeOpenXMLExtended.APPLICATION );
+ String value = metadata.get(OfficeOpenXMLExtended.APPLICATION);
if (value != null && value.length() > 0) {
creatorTool = value;
- value = metadata.get( OfficeOpenXMLExtended.APP_VERSION );
+ value = metadata.get(OfficeOpenXMLExtended.APP_VERSION);
if (value != null && value.length() > 0) {
creatorTool += " " + value;
}
}
if (creatorTool.length() > 0) {
- meta.setProperty( XMPConst.NS_XMP, "CreatorTool", creatorTool );
+ meta.setProperty(XMPConst.NS_XMP, "CreatorTool", creatorTool);
}
- createProperty( Office.CHARACTER_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Characters" );
- createProperty( Office.CHARACTER_COUNT_WITH_SPACES, OfficeOpenXMLExtended.NAMESPACE_URI,
- "CharactersWithSpaces" );
- createProperty( TikaCoreProperties.PUBLISHER, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Company" );
- createProperty( Office.LINE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Lines" );
- createProperty( OfficeOpenXMLExtended.MANAGER, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Manager" );
- createProperty( OfficeOpenXMLExtended.NOTES, OfficeOpenXMLExtended.NAMESPACE_URI, "Notes" );
- createProperty( Office.PAGE_COUNT, XMPConst.TYPE_PAGEDFILE, "NPages" );
- createProperty( Office.PARAGRAPH_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Paragraphs" );
- createProperty( OfficeOpenXMLExtended.PRESENTATION_FORMAT,
- OfficeOpenXMLExtended.NAMESPACE_URI, "PresentationFormat" );
- createProperty( Office.SLIDE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Slides" );
- createProperty( OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Template" );
- createProperty( OfficeOpenXMLExtended.TOTAL_TIME, OfficeOpenXMLExtended.NAMESPACE_URI,
- "TotalTime" );
- createProperty( Office.WORD_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Words" );
+ createProperty(Office.CHARACTER_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Characters");
+ createProperty(Office.CHARACTER_COUNT_WITH_SPACES, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "CharactersWithSpaces");
+ createProperty(TikaCoreProperties.PUBLISHER, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Company");
+ createProperty(Office.LINE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Lines");
+ createProperty(OfficeOpenXMLExtended.MANAGER, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Manager");
+ createProperty(OfficeOpenXMLExtended.NOTES, OfficeOpenXMLExtended.NAMESPACE_URI, "Notes");
+ createProperty(Office.PAGE_COUNT, XMPConst.TYPE_PAGEDFILE, "NPages");
+ createProperty(Office.PARAGRAPH_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Paragraphs");
+ createProperty(OfficeOpenXMLExtended.PRESENTATION_FORMAT,
+ OfficeOpenXMLExtended.NAMESPACE_URI, "PresentationFormat");
+ createProperty(Office.SLIDE_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Slides");
+ createProperty(OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Template");
+ createProperty(OfficeOpenXMLExtended.TOTAL_TIME, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "TotalTime");
+ createProperty(Office.WORD_COUNT, OfficeOpenXMLExtended.NAMESPACE_URI, "Words");
return super.getXMPMeta();
}
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/OpenDocumentConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/OpenDocumentConverter.java
index e6a16339c..559a18fcf 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/OpenDocumentConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/OpenDocumentConverter.java
@@ -20,6 +20,11 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import com.adobe.internal.xmp.XMPConst;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.options.PropertyOptions;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.HttpHeaders;
import org.apache.tika.metadata.Metadata;
@@ -28,55 +33,50 @@ import org.apache.tika.metadata.OfficeOpenXMLExtended;
import org.apache.tika.metadata.PagedText;
import org.apache.tika.metadata.TikaCoreProperties;
-import com.adobe.internal.xmp.XMPConst;
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.options.PropertyOptions;
-
/**
* Tika to XMP mapping for the Open Document formats: Text (.odt), Spreatsheet (.ods), Graphics
* (.odg) and Presentation (.odp).
*/
public class OpenDocumentConverter extends AbstractConverter {
- protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections
- .unmodifiableSet(new HashSet<>(Collections.singletonList(new Namespace(
- Office.NAMESPACE_URI_DOC_META, Office.PREFIX_DOC_META))) );
+ protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections.unmodifiableSet(
+ new HashSet<>(Collections.singletonList(
+ new Namespace(Office.NAMESPACE_URI_DOC_META, Office.PREFIX_DOC_META))));
public OpenDocumentConverter() throws TikaException {
super();
}
/**
- * @throws XMPException
- * Forwards XMP errors
+ * @throws XMPException Forwards XMP errors
* @see ITikaToXMPConverter#process(Metadata)
*/
@Override
public XMPMeta process(Metadata metadata) throws XMPException {
- super.setMetadata( metadata );
+ super.setMetadata(metadata);
- createProperty( HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format" );
+ createProperty(HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format");
- createProperty( Office.CHARACTER_COUNT, Office.NAMESPACE_URI_DOC_META, "character-count" );
- createProperty( TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate" );
- createCommaSeparatedArray( TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
- PropertyOptions.ARRAY_ORDERED );
- createProperty( TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate" );
- createProperty( TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments" );
- createCommaSeparatedArray( TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
- PropertyOptions.ARRAY );
- createLangAltProperty( TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description" );
- createProperty( OfficeOpenXMLExtended.TOTAL_TIME, Office.NAMESPACE_URI_DOC_META, "editing-duration" );
- createProperty( "editing-cycles", Office.NAMESPACE_URI_DOC_META, "editing-cycles" );
- createProperty( "generator", XMPConst.NS_XMP, "CreatorTool" );
- createProperty( Office.IMAGE_COUNT, Office.NAMESPACE_URI_DOC_META, "image-count" );
- createProperty( "initial-creator", Office.NAMESPACE_URI_DOC_META, "initial-creator" );
- createProperty( Office.OBJECT_COUNT, Office.NAMESPACE_URI_DOC_META, "object-count" );
- createProperty( PagedText.N_PAGES, XMPConst.TYPE_PAGEDFILE, "NPages" );
- createProperty( Office.PARAGRAPH_COUNT, Office.NAMESPACE_URI_DOC_META, "paragraph-count" );
- createProperty( Office.TABLE_COUNT, Office.NAMESPACE_URI_DOC_META, "table-count" );
- createLangAltProperty( TikaCoreProperties.TITLE, XMPConst.NS_DC, "title" );
- createProperty( Office.WORD_COUNT, Office.NAMESPACE_URI_DOC_META, "word-count" );
+ createProperty(Office.CHARACTER_COUNT, Office.NAMESPACE_URI_DOC_META, "character-count");
+ createProperty(TikaCoreProperties.CREATED, XMPConst.NS_XMP, "CreateDate");
+ createCommaSeparatedArray(TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
+ PropertyOptions.ARRAY_ORDERED);
+ createProperty(TikaCoreProperties.MODIFIED, XMPConst.NS_XMP, "ModifyDate");
+ createProperty(TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments");
+ createCommaSeparatedArray(TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
+ PropertyOptions.ARRAY);
+ createLangAltProperty(TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description");
+ createProperty(OfficeOpenXMLExtended.TOTAL_TIME, Office.NAMESPACE_URI_DOC_META,
+ "editing-duration");
+ createProperty("editing-cycles", Office.NAMESPACE_URI_DOC_META, "editing-cycles");
+ createProperty("generator", XMPConst.NS_XMP, "CreatorTool");
+ createProperty(Office.IMAGE_COUNT, Office.NAMESPACE_URI_DOC_META, "image-count");
+ createProperty("initial-creator", Office.NAMESPACE_URI_DOC_META, "initial-creator");
+ createProperty(Office.OBJECT_COUNT, Office.NAMESPACE_URI_DOC_META, "object-count");
+ createProperty(PagedText.N_PAGES, XMPConst.TYPE_PAGEDFILE, "NPages");
+ createProperty(Office.PARAGRAPH_COUNT, Office.NAMESPACE_URI_DOC_META, "paragraph-count");
+ createProperty(Office.TABLE_COUNT, Office.NAMESPACE_URI_DOC_META, "table-count");
+ createLangAltProperty(TikaCoreProperties.TITLE, XMPConst.NS_DC, "title");
+ createProperty(Office.WORD_COUNT, Office.NAMESPACE_URI_DOC_META, "word-count");
// duplicate properties not mapped:
// nbImg | 0
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/RTFConverter.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/RTFConverter.java
index f05e10f19..80d29d669 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/RTFConverter.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/RTFConverter.java
@@ -20,6 +20,11 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import com.adobe.internal.xmp.XMPConst;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.options.PropertyOptions;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.HttpHeaders;
import org.apache.tika.metadata.Metadata;
@@ -27,18 +32,14 @@ import org.apache.tika.metadata.OfficeOpenXMLCore;
import org.apache.tika.metadata.OfficeOpenXMLExtended;
import org.apache.tika.metadata.TikaCoreProperties;
-import com.adobe.internal.xmp.XMPConst;
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.options.PropertyOptions;
-
/**
* Tika to XMP mapping for the RTF format.
*/
public class RTFConverter extends AbstractConverter {
- protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections
- .unmodifiableSet(new HashSet<>(Collections.singletonList(new Namespace(
- OfficeOpenXMLExtended.NAMESPACE_URI, OfficeOpenXMLExtended.PREFIX))) );
+ protected static final Set<Namespace> ADDITIONAL_NAMESPACES = Collections.unmodifiableSet(
+ new HashSet<>(Collections.singletonList(
+ new Namespace(OfficeOpenXMLExtended.NAMESPACE_URI,
+ OfficeOpenXMLExtended.PREFIX))));
public RTFConverter() throws TikaException {
super();
@@ -46,24 +47,24 @@ public class RTFConverter extends AbstractConverter {
@Override
public XMPMeta process(Metadata metadata) throws XMPException {
- setMetadata( metadata );
+ setMetadata(metadata);
- createProperty( HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format" );
+ createProperty(HttpHeaders.CONTENT_TYPE, XMPConst.NS_DC, "format");
- createCommaSeparatedArray( TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
- PropertyOptions.ARRAY_ORDERED );
- createLangAltProperty( TikaCoreProperties.TITLE, XMPConst.NS_DC, "title" );
- createLangAltProperty( TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description" );
- createCommaSeparatedArray( TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
- PropertyOptions.ARRAY );
- createProperty( OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre" );
- createProperty( OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Template" );
- createProperty( TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments" );
- createProperty( OfficeOpenXMLExtended.COMPANY, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Company" );
- createProperty( OfficeOpenXMLExtended.MANAGER, OfficeOpenXMLExtended.NAMESPACE_URI,
- "Manager" );
+ createCommaSeparatedArray(TikaCoreProperties.CREATOR, XMPConst.NS_DC, "creator",
+ PropertyOptions.ARRAY_ORDERED);
+ createLangAltProperty(TikaCoreProperties.TITLE, XMPConst.NS_DC, "title");
+ createLangAltProperty(TikaCoreProperties.DESCRIPTION, XMPConst.NS_DC, "description");
+ createCommaSeparatedArray(TikaCoreProperties.SUBJECT, XMPConst.NS_DC, "subject",
+ PropertyOptions.ARRAY);
+ createProperty(OfficeOpenXMLCore.CATEGORY, XMPConst.NS_IPTCCORE, "intellectualGenre");
+ createProperty(OfficeOpenXMLExtended.TEMPLATE, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Template");
+ createProperty(TikaCoreProperties.COMMENTS, XMPConst.NS_PDFX, "Comments");
+ createProperty(OfficeOpenXMLExtended.COMPANY, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Company");
+ createProperty(OfficeOpenXMLExtended.MANAGER, OfficeOpenXMLExtended.NAMESPACE_URI,
+ "Manager");
return getXMPMeta();
}
diff --git a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/TikaToXMP.java b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/TikaToXMP.java
index 0475a3463..4c891d1a4 100644
--- a/tika-xmp/src/main/java/org/apache/tika/xmp/convert/TikaToXMP.java
+++ b/tika-xmp/src/main/java/org/apache/tika/xmp/convert/TikaToXMP.java
@@ -20,6 +20,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import com.adobe.internal.xmp.XMPException;
+import com.adobe.internal.xmp.XMPMeta;
+import com.adobe.internal.xmp.XMPMetaFactory;
+
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.TikaCoreProperties;
@@ -30,10 +34,6 @@ import org.apache.tika.parser.microsoft.ooxml.OOXMLParser;
import org.apache.tika.parser.microsoft.rtf.RTFParser;
import org.apache.tika.parser.odf.OpenDocumentParser;
-import com.adobe.internal.xmp.XMPException;
-import com.adobe.internal.xmp.XMPMeta;
-import com.adobe.internal.xmp.XMPMetaFactory;
-
public class TikaToXMP {
/**
* Map from mimetype to converter class Must only be accessed through
@@ -49,19 +49,19 @@ public class TikaToXMP {
/**
* @see TikaToXMP#convert(Metadata, String) But the mimetype is retrieved from the metadata
- * map.
+ * map.
*/
public static XMPMeta convert(Metadata tikaMetadata) throws TikaException {
if (tikaMetadata == null) {
- throw new IllegalArgumentException( "Metadata parameter must not be null" );
+ throw new IllegalArgumentException("Metadata parameter must not be null");
}
- String mimetype = tikaMetadata.get( Metadata.CONTENT_TYPE );
+ String mimetype = tikaMetadata.get(Metadata.CONTENT_TYPE);
if (mimetype == null) {
- mimetype = tikaMetadata.get( TikaCoreProperties.FORMAT );
+ mimetype = tikaMetadata.get(TikaCoreProperties.FORMAT);
}
- return convert( tikaMetadata, mimetype );
+ return convert(tikaMetadata, mimetype);
}
/**
@@ -71,24 +71,21 @@ public class TikaToXMP {
* convert only those properties that are in known namespaces and are using the correct
* prefixes.
*
- * @param tikaMetadata
- * the Metadata map from Tika
- * @param mimetype
- * depicts the format's converter to use
+ * @param tikaMetadata the Metadata map from Tika
+ * @param mimetype depicts the format's converter to use
* @return XMP object
* @throws TikaException
*/
public static XMPMeta convert(Metadata tikaMetadata, String mimetype) throws TikaException {
if (tikaMetadata == null) {
- throw new IllegalArgumentException( "Metadata parameter must not be null" );
+ throw new IllegalArgumentException("Metadata parameter must not be null");
}
ITikaToXMPConverter converter = null;
- if (isConverterAvailable( mimetype )) {
- converter = getConverter( mimetype );
- }
- else {
+ if (isConverterAvailable(mimetype)) {
+ converter = getConverter(mimetype);
+ } else {
converter = new GenericConverter();
}
@@ -96,13 +93,11 @@ public class TikaToXMP {
if (converter != null) {
try {
- xmp = converter.process( tikaMetadata );
+ xmp = converter.process(tikaMetadata);
+ } catch (XMPException e) {
+ throw new TikaException("Tika metadata could not be converted to XMP", e);
}
- catch (XMPException e) {
- throw new TikaException( "Tika metadata could not be converted to XMP", e );
- }
- }
- else {
+ } else {
xmp = XMPMetaFactory.create(); // empty packet
}
@@ -112,15 +107,14 @@ public class TikaToXMP {
/**
* Check if there is a converter available which allows to convert the Tika metadata to XMP
*
- * @param mimetype
- * the Mimetype
+ * @param mimetype the Mimetype
* @return true if the Metadata object can be converted or false if not
*/
public static boolean isConverterAvailable(String mimetype) {
- MediaType type = MediaType.parse( mimetype );
+ MediaType type = MediaType.parse(mimetype);
if (type != null) {
- return (getConverterMap().get( type ) != null);
+ return (getConverterMap().get(type) != null);
}
return false;
@@ -129,30 +123,28 @@ public class TikaToXMP {
/**
* Retrieve a specific converter according to the mimetype
*
- * @param mimetype
- * the Mimetype
+ * @param mimetype the Mimetype
* @return the converter or null, if none exists
* @throws TikaException
*/
public static ITikaToXMPConverter getConverter(String mimetype) throws TikaException {
if (mimetype == null) {
- throw new IllegalArgumentException( "mimetype must not be null" );
+ throw new IllegalArgumentException("mimetype must not be null");
}
ITikaToXMPConverter converter = null;
- MediaType type = MediaType.parse( mimetype );
+ MediaType type = MediaType.parse(mimetype);
if (type != null) {
- Class<? extends ITikaToXMPConverter> clazz = getConverterMap().get( type );
+ Class<? extends ITikaToXMPConverter> clazz = getConverterMap().get(type);
if (clazz != null) {
try {
converter = clazz.newInstance();
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new TikaException(
- "TikaToXMP converter class cannot be instantiated for mimetype: "
- + type.toString(), e );
+ "TikaToXMP converter class cannot be instantiated for mimetype: " +
+ type.toString(), e);
}
}
}
@@ -178,25 +170,24 @@ public class TikaToXMP {
ParseContext parseContext = new ParseContext();
// MS Office Binary File Format
- addConverter( new OfficeParser().getSupportedTypes( parseContext ),
- MSOfficeBinaryConverter.class );
+ addConverter(new OfficeParser().getSupportedTypes(parseContext),
+ MSOfficeBinaryConverter.class);
// Rich Text Format
- addConverter( new RTFParser().getSupportedTypes( parseContext ), RTFConverter.class );
+ addConverter(new RTFParser().getSupportedTypes(parseContext), RTFConverter.class);
// MS Open XML Format
- addConverter( new OOXMLParser().getSupportedTypes( parseContext ),
- MSOfficeXMLConverter.class );
+ addConverter(new OOXMLParser().getSupportedTypes(parseContext), MSOfficeXMLConverter.class);
// Open document format
- addConverter( new OpenDocumentParser().getSupportedTypes( parseContext ),
- OpenDocumentConverter.class );
+ addConverter(new OpenDocumentParser().getSupportedTypes(parseContext),
+ OpenDocumentConverter.class);
}
private static void addConverter(Set<MediaType> supportedTypes,
- Class<? extends ITikaToXMPConverter> converter) {
+ Class<? extends ITikaToXMPConverter> converter) {
for (MediaType type : supportedTypes) {
- getConverterMap().put( type, converter );
+ getConverterMap().put(type, converter);
}
}
}
diff --git a/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java b/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
index 7f92db295..b16358ee8 100644
--- a/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
+++ b/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
@@ -23,14 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.OfficeOpenXMLCore;
-import org.apache.tika.metadata.TikaCoreProperties;
-import org.apache.tika.xmp.convert.ITikaToXMPConverter;
-import org.apache.tika.xmp.convert.MSOfficeXMLConverter;
-import org.apache.tika.xmp.convert.TikaToXMP;
-
import com.adobe.internal.xmp.XMPConst;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPIterator;
@@ -40,14 +32,22 @@ import com.adobe.internal.xmp.properties.XMPProperty;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.OfficeOpenXMLCore;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.xmp.convert.ITikaToXMPConverter;
+import org.apache.tika.xmp.convert.MSOfficeXMLConverter;
+import org.apache.tika.xmp.convert.TikaToXMP;
+
/**
* Tests the Tika <code>Metadata</code> to XMP conversion functionatlity
*/
public class TikaToXMPTest {
- private Metadata tikaMetadata;
-
- private static final String OOXML_MIMETYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+ private static final String OOXML_MIMETYPE =
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
private static final String GENERIC_MIMETYPE = "generic/mimetype";
+ private Metadata tikaMetadata;
// --- Set up ---
@BeforeEach
@@ -57,166 +57,166 @@ public class TikaToXMPTest {
private void setupOOXMLMetadata(Metadata metadata) {
// simple property
- metadata.set( TikaCoreProperties.LANGUAGE, "language" );
+ metadata.set(TikaCoreProperties.LANGUAGE, "language");
// language alternative
- metadata.set( TikaCoreProperties.TITLE, "title" );
+ metadata.set(TikaCoreProperties.TITLE, "title");
// comma separated array
- metadata.set( TikaCoreProperties.SUBJECT, "keyword1,keyword2" );
+ metadata.set(TikaCoreProperties.SUBJECT, "keyword1,keyword2");
// OOXML specific simple prop
- metadata.set( TikaCoreProperties.MODIFIER, "lastModifiedBy" );
+ metadata.set(TikaCoreProperties.MODIFIER, "lastModifiedBy");
}
private void checkOOXMLMetadata(XMPMeta xmp) throws XMPException {
// check simple property
- XMPProperty prop = xmp.getProperty( XMPConst.NS_DC, "language" );
- assertNotNull( prop );
- assertEquals( "language", prop.getValue() );
+ XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "language");
+ assertNotNull(prop);
+ assertEquals("language", prop.getValue());
// check lang alt
- prop = xmp.getLocalizedText( XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT );
- assertNotNull( prop );
- assertEquals( "title", prop.getValue() );
+ prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
+ assertNotNull(prop);
+ assertEquals("title", prop.getValue());
// check array
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 1 );
- assertNotNull( prop );
- assertEquals( "keyword1", prop.getValue() );
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 2 );
- assertNotNull( prop );
- assertEquals( "keyword2", prop.getValue() );
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 1);
+ assertNotNull(prop);
+ assertEquals("keyword1", prop.getValue());
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 2);
+ assertNotNull(prop);
+ assertEquals("keyword2", prop.getValue());
// check OOXML specific simple property
- prop = xmp.getProperty( OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy" );
- assertNotNull( prop );
- assertEquals( "lastModifiedBy", prop.getValue() );
+ prop = xmp.getProperty(OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy");
+ assertNotNull(prop);
+ assertEquals("lastModifiedBy", prop.getValue());
}
// --- TESTS ---
@Test
- public void convert_OOXMLMetadataWithMimetype_everythingConverted() throws XMPException,
- TikaException {
- setupOOXMLMetadata( tikaMetadata );
- tikaMetadata.set( Metadata.CONTENT_TYPE, OOXML_MIMETYPE );
+ public void convert_OOXMLMetadataWithMimetype_everythingConverted()
+ throws XMPException, TikaException {
+ setupOOXMLMetadata(tikaMetadata);
+ tikaMetadata.set(Metadata.CONTENT_TYPE, OOXML_MIMETYPE);
- XMPMeta xmp = TikaToXMP.convert( tikaMetadata );
+ XMPMeta xmp = TikaToXMP.convert(tikaMetadata);
- checkOOXMLMetadata( xmp );
+ checkOOXMLMetadata(xmp);
}
@Test
- public void convert_OOXMLMetadataWithExtraMimetype_everythingConverted() throws XMPException,
- TikaException {
- setupOOXMLMetadata( tikaMetadata );
+ public void convert_OOXMLMetadataWithExtraMimetype_everythingConverted()
+ throws XMPException, TikaException {
+ setupOOXMLMetadata(tikaMetadata);
- XMPMeta xmp = TikaToXMP.convert( tikaMetadata, OOXML_MIMETYPE );
+ XMPMeta xmp = TikaToXMP.convert(tikaMetadata, OOXML_MIMETYPE);
- checkOOXMLMetadata( xmp );
+ checkOOXMLMetadata(xmp);
}
@Test
public void convert_OOXMLMetadataWithoutMimetype_onlyGeneralMetadataconverted()
throws XMPException, TikaException {
- setupOOXMLMetadata( tikaMetadata );
+ setupOOXMLMetadata(tikaMetadata);
- XMPMeta xmp = TikaToXMP.convert( tikaMetadata, null );
+ XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
// general metadata is converted
// check simple property
- XMPProperty prop = xmp.getProperty( XMPConst.NS_DC, "language" );
- assertNotNull( prop );
- assertEquals( "language", prop.getValue() );
+ XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "language");
+ assertNotNull(prop);
+ assertEquals("language", prop.getValue());
// check lang alt
- prop = xmp.getLocalizedText( XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT );
- assertNotNull( prop );
- assertEquals( "title", prop.getValue() );
+ prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
+ assertNotNull(prop);
+ assertEquals("title", prop.getValue());
// OOXML one is not, the namespace has also not been registiered as the converter has not
// been used
- XMPMetaFactory.getSchemaRegistry().registerNamespace( OfficeOpenXMLCore.NAMESPACE_URI,
- OfficeOpenXMLCore.PREFIX );
- prop = xmp.getProperty( OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy" );
- assertNull( prop );
+ XMPMetaFactory.getSchemaRegistry()
+ .registerNamespace(OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX);
+ prop = xmp.getProperty(OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy");
+ assertNull(prop);
}
@Test
- public void convert_genericMetadataAllQualified_allConverted() throws XMPException,
- TikaException {
+ public void convert_genericMetadataAllQualified_allConverted()
+ throws XMPException, TikaException {
// simple property
- tikaMetadata.set( TikaCoreProperties.FORMAT, GENERIC_MIMETYPE );
+ tikaMetadata.set(TikaCoreProperties.FORMAT, GENERIC_MIMETYPE);
// language alternative
- tikaMetadata.set( TikaCoreProperties.TITLE, "title" );
+ tikaMetadata.set(TikaCoreProperties.TITLE, "title");
// array
- tikaMetadata.set( TikaCoreProperties.SUBJECT, new String[] { "keyword1", "keyword2" } );
+ tikaMetadata.set(TikaCoreProperties.SUBJECT, new String[]{"keyword1", "keyword2"});
- XMPMeta xmp = TikaToXMP.convert( tikaMetadata, null );
+ XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
// check simple property
- XMPProperty prop = xmp.getProperty( XMPConst.NS_DC, "format" );
- assertNotNull( prop );
- assertEquals( GENERIC_MIMETYPE, prop.getValue() );
+ XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "format");
+ assertNotNull(prop);
+ assertEquals(GENERIC_MIMETYPE, prop.getValue());
// check lang alt
- prop = xmp.getLocalizedText( XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT );
- assertNotNull( prop );
- assertEquals( "title", prop.getValue() );
+ prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
+ assertNotNull(prop);
+ assertEquals("title", prop.getValue());
// check array
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 1 );
- assertNotNull( prop );
- assertEquals( "keyword1", prop.getValue() );
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 2 );
- assertNotNull( prop );
- assertEquals( "keyword2", prop.getValue() );
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 1);
+ assertNotNull(prop);
+ assertEquals("keyword1", prop.getValue());
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 2);
+ assertNotNull(prop);
+ assertEquals("keyword2", prop.getValue());
}
@Test
public void convert_wrongGenericMetadata_notConverted() throws XMPException, TikaException {
// unknown prefix
- tikaMetadata.set( "unknown:key", "unknownPrefixValue" );
+ tikaMetadata.set("unknown:key", "unknownPrefixValue");
// not qualified key
- tikaMetadata.set( "wrongKey", "wrongKeyValue" );
+ tikaMetadata.set("wrongKey", "wrongKeyValue");
- XMPMeta xmp = TikaToXMP.convert( tikaMetadata, null );
+ XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
// XMP is empty
XMPIterator iter = xmp.iterator();
- assertFalse( iter.hasNext() );
+ assertFalse(iter.hasNext());
}
@Test
public void convert_nullInput_throw() throws TikaException {
assertThrows(IllegalArgumentException.class, () -> {
- TikaToXMP.convert( null );
+ TikaToXMP.convert(null);
});
}
@Test
public void isConverterAvailable_availableMime_true() {
- assertTrue( TikaToXMP.isConverterAvailable( OOXML_MIMETYPE ) );
+ assertTrue(TikaToXMP.isConverterAvailable(OOXML_MIMETYPE));
}
@Test
public void isConverterAvailable_noAvailableMime_false() {
- assertFalse( TikaToXMP.isConverterAvailable( GENERIC_MIMETYPE ) );
+ assertFalse(TikaToXMP.isConverterAvailable(GENERIC_MIMETYPE));
}
@Test
public void isConverterAvailable_nullInput_false() {
- assertFalse( TikaToXMP.isConverterAvailable( null ) );
+ assertFalse(TikaToXMP.isConverterAvailable(null));
}
@Test
public void getConverter_ConverterAvailable_class() throws TikaException {
- ITikaToXMPConverter converter = TikaToXMP.getConverter( OOXML_MIMETYPE );
- assertNotNull( converter );
- assertTrue( converter instanceof MSOfficeXMLConverter );
+ ITikaToXMPConverter converter = TikaToXMP.getConverter(OOXML_MIMETYPE);
+ assertNotNull(converter);
+ assertTrue(converter instanceof MSOfficeXMLConverter);
}
@Test
public void getConverter_noConverterAvailable_null() throws TikaException {
- ITikaToXMPConverter converter = TikaToXMP.getConverter( GENERIC_MIMETYPE );
- assertNull( converter );
+ ITikaToXMPConverter converter = TikaToXMP.getConverter(GENERIC_MIMETYPE);
+ assertNull(converter);
}
@Test
diff --git a/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java b/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
index c2c0c1d31..0e4117e3c 100644
--- a/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
+++ b/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
@@ -26,14 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Date;
import java.util.Properties;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.DublinCore;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.Property;
-import org.apache.tika.metadata.PropertyTypeException;
-import org.apache.tika.metadata.TikaCoreProperties;
-import org.apache.tika.metadata.XMPRights;
-
import com.adobe.internal.xmp.XMPConst;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
@@ -42,40 +34,47 @@ import com.adobe.internal.xmp.properties.XMPProperty;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.DublinCore;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.PropertyTypeException;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.metadata.XMPRights;
+
public class XMPMetadataTest {
+ private static final String GENERIC_MIMETYPE = "generic/mimetype";
private Metadata tikaMetadata;
private XMPMetadata xmpMeta;
- private static final String GENERIC_MIMETYPE = "generic/mimetype";
-
// --- SETUP ---
@BeforeEach
public void setUp() throws Exception {
- XMPMetadata.registerNamespace( DublinCore.NAMESPACE_URI_DC_TERMS,
- DublinCore.PREFIX_DC_TERMS );
+ XMPMetadata.registerNamespace(DublinCore.NAMESPACE_URI_DC_TERMS,
+ DublinCore.PREFIX_DC_TERMS);
xmpMeta = new XMPMetadata();
tikaMetadata = new Metadata();
- setupMetadata( tikaMetadata );
+ setupMetadata(tikaMetadata);
}
private void setupMetadata(Metadata metadata) {
// simple property
- metadata.set( TikaCoreProperties.FORMAT, GENERIC_MIMETYPE );
+ metadata.set(TikaCoreProperties.FORMAT, GENERIC_MIMETYPE);
// language alternative
- metadata.set( TikaCoreProperties.TITLE, "title" );
+ metadata.set(TikaCoreProperties.TITLE, "title");
// array
- metadata.set( TikaCoreProperties.SUBJECT, new String[] { "keyword1", "keyword2" } );
+ metadata.set(TikaCoreProperties.SUBJECT, new String[]{"keyword1", "keyword2"});
// date
- metadata.set( TikaCoreProperties.MODIFIED, "2001-01-01T01:01" );
+ metadata.set(TikaCoreProperties.MODIFIED, "2001-01-01T01:01");
// int simple property
- metadata.set( Property.internalInteger( "xmp:Integer" ), "2" );
+ metadata.set(Property.internalInteger("xmp:Integer"), "2");
}
// --- HELPER ---
private void checkArrayValues(String[] values, String baseValue) {
int i = 1;
for (String value : values) {
- assertEquals( baseValue + i, value );
+ assertEquals(baseValue + i, value);
i++;
}
}
@@ -83,60 +82,60 @@ public class XMPMetadataTest {
// --- TESTS ---
@Test
public void process_genericConversion_ok() throws TikaException, XMPException {
- xmpMeta.process( tikaMetadata, GENERIC_MIMETYPE );
+ xmpMeta.process(tikaMetadata, GENERIC_MIMETYPE);
XMPMeta xmp = xmpMeta.getXMPData();
// check simple property
- XMPProperty prop = xmp.getProperty( XMPConst.NS_DC, "format" );
- assertNotNull( prop );
- assertEquals( GENERIC_MIMETYPE, prop.getValue() );
+ XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "format");
+ assertNotNull(prop);
+ assertEquals(GENERIC_MIMETYPE, prop.getValue());
// check lang alt
- prop = xmp.getLocalizedText( XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT );
- assertNotNull( prop );
- assertEquals( "title", prop.getValue() );
+ prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
+ assertNotNull(prop);
+ assertEquals("title", prop.getValue());
// check array
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 1 );
- assertNotNull( prop );
- assertEquals( "keyword1", prop.getValue() );
- prop = xmp.getArrayItem( XMPConst.NS_DC, "subject", 2 );
- assertNotNull( prop );
- assertEquals( "keyword2", prop.getValue() );
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 1);
+ assertNotNull(prop);
+ assertEquals("keyword1", prop.getValue());
+ prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 2);
+ assertNotNull(prop);
+ assertEquals("keyword2", prop.getValue());
}
@Test
public void isMultiValued_multiProp_true() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertTrue( xmpMeta.isMultiValued( TikaCoreProperties.SUBJECT) );
+ assertTrue(xmpMeta.isMultiValued(TikaCoreProperties.SUBJECT));
}
@Test
public void isMultiValued_simpleProp_false() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertFalse( xmpMeta.isMultiValued( TikaCoreProperties.FORMAT ) );
+ assertFalse(xmpMeta.isMultiValued(TikaCoreProperties.FORMAT));
}
@Test
public void get_simpleProp_valueReturned() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertEquals( GENERIC_MIMETYPE, xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertEquals(GENERIC_MIMETYPE, xmpMeta.get(TikaCoreProperties.FORMAT));
}
@Test
public void get_arrayProp_firstValueReturned() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertEquals( "keyword1", xmpMeta.get( TikaCoreProperties.SUBJECT) );
+ assertEquals("keyword1", xmpMeta.get(TikaCoreProperties.SUBJECT));
}
@Test
public void get_notExistingProp_null() throws TikaException {
- assertNull( xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertNull(xmpMeta.get(TikaCoreProperties.FORMAT));
}
@Test
@@ -150,7 +149,7 @@ public class XMPMetadataTest {
@Test
public void get_notQualifiedKey_throw() {
assertThrows(PropertyTypeException.class, () -> {
- xmpMeta.get( "wrongKey" );
+ xmpMeta.get("wrongKey");
});
}
@@ -163,50 +162,50 @@ public class XMPMetadataTest {
@Test
public void getInt_IntegerProperty_valueReturned() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertEquals( new Integer( 2 ), xmpMeta.getInt( Property.get( "xmp:Integer" ) ) );
+ assertEquals(new Integer(2), xmpMeta.getInt(Property.get("xmp:Integer")));
}
@Test
public void getDate_DateProperty_valueReturned() throws TikaException, XMPException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- Date date = XMPUtils.convertToDate( "2001-01-01T01:01" ).getCalendar().getTime();
- assertTrue( date.equals( xmpMeta.getDate( TikaCoreProperties.MODIFIED ) ) );
+ Date date = XMPUtils.convertToDate("2001-01-01T01:01").getCalendar().getTime();
+ assertTrue(date.equals(xmpMeta.getDate(TikaCoreProperties.MODIFIED)));
}
@Test
public void getValues_arrayProperty_allElementsReturned() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- String[] values = xmpMeta.getValues( TikaCoreProperties.SUBJECT);
- assertEquals( 2, values.length );
+ String[] values = xmpMeta.getValues(TikaCoreProperties.SUBJECT);
+ assertEquals(2, values.length);
- checkArrayValues( values, "keyword" );
+ checkArrayValues(values, "keyword");
}
@Test
public void testSetAll() {
Properties props = new Properties();
- props.put( TikaCoreProperties.FORMAT.getName(), "format" );
- props.put( TikaCoreProperties.SUBJECT.getName(), "keyword" );
+ props.put(TikaCoreProperties.FORMAT.getName(), "format");
+ props.put(TikaCoreProperties.SUBJECT.getName(), "keyword");
- xmpMeta.setAll( props );
+ xmpMeta.setAll(props);
- assertEquals( "format", xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertEquals("format", xmpMeta.get(TikaCoreProperties.FORMAT));
- String[] values = xmpMeta.getValues( TikaCoreProperties.SUBJECT);
- assertEquals( 1, values.length );
+ String[] values = xmpMeta.getValues(TikaCoreProperties.SUBJECT);
+ assertEquals(1, values.length);
- assertEquals( "keyword", values[0] );
+ assertEquals("keyword", values[0]);
}
@Test
public void set_simpleProp_ok() {
- xmpMeta.set( TikaCoreProperties.FORMAT, GENERIC_MIMETYPE );
+ xmpMeta.set(TikaCoreProperties.FORMAT, GENERIC_MIMETYPE);
- assertEquals( GENERIC_MIMETYPE, xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertEquals(GENERIC_MIMETYPE, xmpMeta.get(TikaCoreProperties.FORMAT));
}
@Test
@@ -233,12 +232,12 @@ public class XMPMetadataTest {
@Test
public void set_arrayProperty_ok() {
- xmpMeta.set( TikaCoreProperties.SUBJECT, new String[] { "keyword1", "keyword2" } );
+ xmpMeta.set(TikaCoreProperties.SUBJECT, new String[]{"keyword1", "keyword2"});
- String[] values = xmpMeta.getValues( TikaCoreProperties.SUBJECT);
- assertEquals( 2, values.length );
+ String[] values = xmpMeta.getValues(TikaCoreProperties.SUBJECT);
+ assertEquals(2, values.length);
- checkArrayValues( values, "keyword" );
+ checkArrayValues(values, "keyword");
}
@Test
@@ -250,24 +249,24 @@ public class XMPMetadataTest {
@Test
public void remove_existingProperty_propertyRemoved() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertNotNull( xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertNotNull(xmpMeta.get(TikaCoreProperties.FORMAT));
- xmpMeta.remove( TikaCoreProperties.FORMAT );
+ xmpMeta.remove(TikaCoreProperties.FORMAT);
- assertNull( xmpMeta.get( TikaCoreProperties.FORMAT ) );
+ assertNull(xmpMeta.get(TikaCoreProperties.FORMAT));
}
@Test
public void size_numberOfNamespacesReturned() throws TikaException {
- xmpMeta.process( tikaMetadata );
+ xmpMeta.process(tikaMetadata);
- assertEquals( 3, xmpMeta.size() );
+ assertEquals(3, xmpMeta.size());
- xmpMeta.set( XMPRights.OWNER, "owner" );
+ xmpMeta.set(XMPRights.OWNER, "owner");
- assertEquals( 4, xmpMeta.size() );
+ assertEquals(4, xmpMeta.size());
}
}