Skip to content

Commit

Permalink
Tika support #799
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Jun 17, 2020
1 parent eb68674 commit 384fe34
Show file tree
Hide file tree
Showing 24 changed files with 988 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/test-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ misc:
- qute
- stream
- tarfile
- tika
- vertx
networking:
- ftp
Expand Down
52 changes: 52 additions & 0 deletions docs/modules/ROOT/pages/extensions/tika.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Do not edit directly!
// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page

[[tika]]
= Tika

[.badges]
[.badge-key]##Since Camel Quarkus##[.badge-version]##1.0.0-CR3## [.badge-key]##JVM##[.badge-supported]##supported## [.badge-key]##Native##[.badge-supported]##supported##

Parse documents and extract metadata and text using Apache Tika.

== What's inside

* https://camel.apache.org/components/latest/tika-component.html[Tika component], URI syntax: `tika:operation`

Please refer to the above link for usage and configuration details.

== Maven coordinates

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika</artifactId>
</dependency>
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Camel Quarkus limitations

Parameters `tikaConfig` and `tikaConfigUri` are not available in quarkus camel tika extension. Configuration
can be changed only via `application.properties`.

While you can use any of the available Tika parsers in JVM mode (https://tika.apache.org/[Apache Tika]),
only several Tika parses are supported in native mode. See https://quarkus.io/guides/tika[QUARKUS - USING APACHE TIKA].

In order to work in native mode, some properties should be set:

* `quarkus.tika.parsers`
* optionally `quarkus.tika.parser.*`

Example of `application.properties` follows :
[source,properties]
----
quarkus.tika.parsers = pdf,odf,office
quarkus.tika.parser.office = org.apache.tika.parser.microsoft.OfficeParser
----

For more information about selecting parsers see https://quarkus.io/guides/tika[QUARKUS - USING APACHE TIKA]


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list:
== Camel Components

// components: START
Number of Camel components: 149 in 114 JAR artifacts (0 deprecated)
Number of Camel components: 150 in 115 JAR artifacts (0 deprecated)

[width="100%",cols="4,1,1,1,5",options="header"]
|===
Expand Down Expand Up @@ -306,6 +306,8 @@ Number of Camel components: 149 in 114 JAR artifacts (0 deprecated)

| xref:extensions/telegram.adoc[Telegram] | camel-quarkus-telegram | Native + Stable | 1.0.0-M4 | Send and receive messages acting as a Telegram Bot Telegram Bot API.

| xref:extensions/tika.adoc[Tika] | camel-quarkus-tika | Native + Stable | 1.0.0-CR3 | Parse documents and extract metadata and text using Apache Tika.

| xref:extensions/timer.adoc[Timer] | camel-quarkus-timer | Native + Stable | 0.2.0 | Generate messages in specified intervals using java.util.Timer.

| xref:extensions/twitter.adoc[Twitter Direct Message] | camel-quarkus-twitter | Native + Stable | 0.2.0 | Send and receive Twitter direct messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;

import org.xml.sax.XMLFilter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,7 +37,7 @@
* A {@link TransformerFactory} delegating to a {@link TransformerFactory} created via
* {@code TransformerFactory.newInstance("org.apache.xalan.xsltc.trax.TransformerFactoryImpl", Thread.currentThread().getContextClassLoader())}
*/
public final class XalanTransformerFactory extends TransformerFactory {
public final class XalanTransformerFactory extends SAXTransformerFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(XalanTransformerFactory.class);

private final TransformerFactory delegate;
Expand Down Expand Up @@ -110,4 +115,42 @@ public void setErrorListener(ErrorListener listener) {
public ErrorListener getErrorListener() {
return delegate.getErrorListener();
}

private SAXTransformerFactory delegateAsSAXTransformerFactory() {
if (delegate instanceof SAXTransformerFactory) {
return (SAXTransformerFactory) delegate;
}
throw new IllegalArgumentException("Unsupported TransformerFactory feature " + SAXTransformerFactory.FEATURE);
}

@Override
public TransformerHandler newTransformerHandler(Source source) throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newTransformerHandler(source);
}

@Override
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newTransformerHandler(templates);
}

@Override
public TransformerHandler newTransformerHandler() throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newTransformerHandler();
}

@Override
public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newTemplatesHandler();
}

@Override
public XMLFilter newXMLFilter(Source source) throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newXMLFilter(source);
}

@Override
public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException {
return delegateAsSAXTransformerFactory().newXMLFilter(templates);
}

}
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<module>tagsoup</module>
<module>tarfile</module>
<module>telegram</module>
<module>tika</module>
<module>timer</module>
<module>twitter</module>
<module>validator</module>
Expand Down
83 changes: 83 additions & 0 deletions extensions/tika/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
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
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.
See the License for the specific language governing permissions and
limitations 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-tika-deployment</artifactId>
<name>Camel Quarkus :: Tika :: Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tika</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tika-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
* 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
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.tika.deployment;

import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import org.apache.camel.component.tika.TikaComponent;
import org.apache.camel.quarkus.component.tika.TikaRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem;
import org.jboss.logging.Logger;

class TikaProcessor {

private static final Logger LOG = Logger.getLogger(TikaProcessor.class);
private static final String FEATURE = "camel-tika";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/*
* The tika component is programmatically configured by the extension thus
* we can safely prevent camel to instantiate a default instance.
*/
@BuildStep
CamelServiceFilterBuildItem serviceFilter() {
return new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent("tika"));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelRuntimeBeanBuildItem tikaComponent(BeanContainerBuildItem beanContainer, TikaRecorder recorder) {
return new CamelRuntimeBeanBuildItem(
"tika",
TikaComponent.class.getName(),
recorder.createTikaComponent(beanContainer.getValue()));
}
}
39 changes: 39 additions & 0 deletions extensions/tika/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
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
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.
See the License for the specific language governing permissions and
limitations 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../poms/build-parent/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-tika-parent</artifactId>
<name>Camel Quarkus :: Tika</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>

0 comments on commit 384fe34

Please sign in to comment.