You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ni...@apache.org on 2022/03/08 00:41:08 UTC
[tika] branch main updated (eda4427 -> d583973)
This is an automated email from the ASF dual-hosted git repository.
nick pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git.
from eda4427 Merge branch 'TIKA-3689' into main
new 7768c87 TIKA-3694 Additional details in HTML on mime type, and per-type json
new c54dd20 TIKA-3694 Per-Type HTML page, and more info in the JSON
new d583973 TIKA-3694 Unit test for type-specific page
The 3 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.
Summary of changes:
.../tika/server/core/resource/TikaMimeTypes.java | 135 ++++++++++++++++++++-
.../apache/tika/server/core/TikaMimeTypesTest.java | 20 ++-
2 files changed, 147 insertions(+), 8 deletions(-)
[tika] 03/03: TIKA-3694 Unit test for type-specific page
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nick pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
commit d583973f829aa2b48b8a08cb8c46927a3446ca7a
Author: Nick Burch <ni...@gagravarr.org>
AuthorDate: Mon Mar 7 23:30:15 2022 +0000
TIKA-3694 Unit test for type-specific page
---
.../tika/server/core/resource/TikaMimeTypes.java | 4 +++-
.../org/apache/tika/server/core/TikaMimeTypesTest.java | 18 ++++++++++++++++--
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
index cfb42b4..1dc0462 100644
--- a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
+++ b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
@@ -277,7 +277,9 @@ public class TikaMimeTypes {
try {
details.mime = mimeTypes.getRegisteredMimeType(type.toString());
- } catch (MimeTypeException e) {}
+ } catch (MimeTypeException e) {
+ // Ignore if invalid
+ }
MediaType supertype = registry.getSupertype(type);
if (supertype != null && !MediaType.OCTET_STREAM.equals(supertype)) {
diff --git a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
index f373515..dc8a0c1 100644
--- a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
+++ b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
@@ -70,7 +70,8 @@ public class TikaMimeTypesTest extends CXFTestBase {
assertContains("application/xml", text);
assertContains("video/x-ogm", text);
- assertContains("<h2>text/plain", text);
+ assertContains("<h2>", text);
+ assertContains("/text/plain\">", text);
assertContains("name=\"text/plain", text);
assertContains("Super Type: <a href=\"#video/ogg\">video/ogg", text);
@@ -80,5 +81,18 @@ public class TikaMimeTypesTest extends CXFTestBase {
assertContains("Extension: .ogg", text);
}
-// TODO Type Specific
+ @Test
+ public void testGetHTMLDetails() throws Exception {
+ Response response =
+ WebClient.create(endPoint + MIMETYPES_PATH + "/application/cbor")
+ .type("text/html").accept("text/html").get();
+
+ String text = getStringFromInputStream((InputStream) response.getEntity());
+ assertNotFound("text/plain", text);
+ assertContains("application/cbor", text);
+
+ assertContains("Acronym: CBOR", text);
+ assertContains("Link: http://tools.ietf.org/html/rfc7049", text);
+ assertContains("Extension: .cbor", text);
+ }
}
[tika] 02/03: TIKA-3694 Per-Type HTML page, and more info in the JSON
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nick pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
commit c54dd2078ab8a48461847a27e91ac27efbfe10ed
Author: Nick Burch <ni...@gagravarr.org>
AuthorDate: Mon Mar 7 23:18:18 2022 +0000
TIKA-3694 Per-Type HTML page, and more info in the JSON
---
.../tika/server/core/resource/TikaMimeTypes.java | 76 ++++++++++++++++++++--
.../apache/tika/server/core/TikaMimeTypesTest.java | 4 +-
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
index 784660c..cfb42b4 100644
--- a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
+++ b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
@@ -17,6 +17,7 @@
package org.apache.tika.server.core.resource;
import java.io.IOException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -82,21 +83,22 @@ public class TikaMimeTypes {
h.append("<ul>");
for (String section : firstType.keySet()) {
h.append("<li><a href=\"#").append(firstType.get(section)).append("\">").append(section)
- .append("</a></li>\n");
+ .append("</a></li>\n");
}
h.append("</ul>");
// Output all of them
for (MediaTypeDetails type : types) {
h.append("<a name=\"").append(type.type).append("\"></a>\n");
- h.append("<h2>").append(type.type).append("</h2>\n");
+ h.append("<h2><a href=\"mime-types/").append(type.type)
+ .append("\">").append(type.type).append("</a></h2>\n");
for (MediaType alias : type.aliases) {
h.append("<div>Alias: ").append(alias).append("</div>\n");
}
if (type.supertype != null) {
h.append("<div>Super Type: <a href=\"#").append(type.supertype).append("\">")
- .append(type.supertype).append("</a></div>\n");
+ .append(type.supertype).append("</a></div>\n");
}
if (type.mime != null) {
if (!type.mime.getDescription().isEmpty()) {
@@ -120,6 +122,53 @@ public class TikaMimeTypes {
}
@GET
+ @Path("/{type}/{subtype}")
+ @Produces("text/html")
+ public String getMimeTypeDetailsHTML(@PathParam("type") String typePart,
+ @PathParam("subtype") String subtype) {
+ MediaTypeDetails type = getMediaType(typePart, subtype);
+
+ StringBuffer h = new StringBuffer();
+ html.generateHeader(h, "Apache Tika Details on Mime Type " + type.type);
+ h.append("<h2>").append(type.type).append("</h2>\n");
+
+ for (MediaType alias : type.aliases) {
+ h.append("<div>Alias: ").append(alias).append("</div>\n");
+ }
+ if (type.supertype != null) {
+ h.append("<div>Super Type: <a href=\"#").append(type.supertype).append("\">")
+ .append(type.supertype).append("</a></div>\n");
+ }
+ if (type.mime != null) {
+ if (!type.mime.getDescription().isEmpty()) {
+ h.append("<div>Description: ").append(type.mime.getDescription()).append("</div>\n");
+ }
+ if (!type.mime.getAcronym().isEmpty()) {
+ h.append("<div>Acronym: ").append(type.mime.getAcronym()).append("</div>\n");
+ }
+ if (!type.mime.getUniformTypeIdentifier().isEmpty()) {
+ h.append("<div>Uniform Type Identifier: ").append(type.mime.getUniformTypeIdentifier()).append("</div>\n");
+ }
+ for (URI uri : type.mime.getLinks()) {
+ h.append("<div>Link: ").append(uri).append("</div>\n");
+ }
+ if (!type.mime.getExtension().isEmpty()) {
+ h.append("<div>Default Extension: ").append(type.mime.getExtension()).append("</div>\n");
+ }
+ for (String ext : type.mime.getExtensions()) {
+ h.append("<div>Extension: ").append(ext).append("</div>\n");
+ }
+ }
+
+ if (type.parser != null) {
+ h.append("<div>Parser: ").append(type.parser).append("</div>\n");
+ }
+
+ html.generateFooter(h);
+ return h.toString();
+ }
+
+ @GET
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public String getMimeTypesJSON() throws IOException {
Map<String, Object> details = new HashMap<>();
@@ -157,7 +206,26 @@ public class TikaMimeTypes {
if (type.parser != null) {
details.put("parser", type.parser);
}
- // TODO Additional details from Mime
+ if (type.mime != null) {
+ if (! type.mime.getDescription().isEmpty()) {
+ details.put("description", type.mime.getDescription());
+ }
+ if (! type.mime.getAcronym().isEmpty()) {
+ details.put("acronym", type.mime.getAcronym());
+ }
+ if (! type.mime.getUniformTypeIdentifier().isEmpty()) {
+ details.put("uniformTypeIdentifier", type.mime.getUniformTypeIdentifier());
+ }
+ if (! type.mime.getLinks().isEmpty()) {
+ details.put("links", type.mime.getLinks());
+ }
+ if (! type.mime.getExtension().isEmpty()) {
+ details.put("defaultExtension", type.mime.getExtension());
+ }
+ if (! type.mime.getExtensions().isEmpty()) {
+ details.put("extensions", type.mime.getExtensions());
+ }
+ }
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(details);
}
diff --git a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
index 51f387d..f373515 100644
--- a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
+++ b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/TikaMimeTypesTest.java
@@ -76,7 +76,9 @@ public class TikaMimeTypesTest extends CXFTestBase {
assertContains("Super Type: <a href=\"#video/ogg\">video/ogg", text);
assertContains("Alias: image/x-ms-bmp", text);
+ assertContains("Description: Ogg Vorbis", text);
+ assertContains("Extension: .ogg", text);
}
-
+// TODO Type Specific
}
[tika] 01/03: TIKA-3694 Additional details in HTML on mime type, and per-type json
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nick pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 7768c87b467bb6cc9d01f6b92c45131af3d44fef
Author: Nick Burch <ni...@gagravarr.org>
AuthorDate: Mon Mar 7 22:49:22 2022 +0000
TIKA-3694 Additional details in HTML on mime type, and per-type json
---
.../tika/server/core/resource/TikaMimeTypes.java | 59 ++++++++++++++++++++--
1 file changed, 56 insertions(+), 3 deletions(-)
diff --git a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
index 7b1887f..784660c 100644
--- a/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
+++ b/tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaMimeTypes.java
@@ -24,13 +24,19 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.tika.config.TikaConfig;
import org.apache.tika.mime.MediaType;
import org.apache.tika.mime.MediaTypeRegistry;
+import org.apache.tika.mime.MimeType;
+import org.apache.tika.mime.MimeTypes;
+import org.apache.tika.mime.MimeTypeException;
import org.apache.tika.parser.CompositeParser;
import org.apache.tika.parser.Parser;
import org.apache.tika.server.core.HTMLHelper;
@@ -38,6 +44,7 @@ import org.apache.tika.server.core.HTMLHelper;
/**
* <p>Provides details of all the mimetypes known to Apache Tika,
* similar to <em>--list-supported-types</em> with the Tika CLI.
+ * <p>Can also provide full details on a single known type.
*/
@Path("/mime-types")
public class TikaMimeTypes {
@@ -91,6 +98,17 @@ public class TikaMimeTypes {
h.append("<div>Super Type: <a href=\"#").append(type.supertype).append("\">")
.append(type.supertype).append("</a></div>\n");
}
+ if (type.mime != null) {
+ if (!type.mime.getDescription().isEmpty()) {
+ h.append("<div>Description: ").append(type.mime.getDescription()).append("</div>\n");
+ }
+ if (!type.mime.getAcronym().isEmpty()) {
+ h.append("<div>Acronym: ").append(type.mime.getAcronym()).append("</div>\n");
+ }
+ if (!type.mime.getExtension().isEmpty()) {
+ h.append("<div>Default Extension: ").append(type.mime.getExtension()).append("</div>\n");
+ }
+ }
if (type.parser != null) {
h.append("<div>Parser: ").append(type.parser).append("</div>\n");
@@ -124,6 +142,27 @@ public class TikaMimeTypes {
}
@GET
+ @Path("/{type}/{subtype}")
+ @Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
+ public String getMimeTypeDetailsJSON(@PathParam("type") String typePart,
+ @PathParam("subtype") String subtype) throws IOException {
+ MediaTypeDetails type = getMediaType(typePart, subtype);
+ Map<String, Object> details = new HashMap<>();
+
+ details.put("type", type.type.toString());
+ details.put("alias", copyToStringArray(type.aliases));
+ if (type.supertype != null) {
+ details.put("supertype", type.supertype.toString());
+ }
+ if (type.parser != null) {
+ details.put("parser", type.parser);
+ }
+ // TODO Additional details from Mime
+
+ return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(details);
+ }
+
+ @GET
@Produces("text/plain")
public String getMimeTypesPlain() {
StringBuffer text = new StringBuffer();
@@ -147,10 +186,19 @@ public class TikaMimeTypes {
return text.toString();
}
+ protected MediaTypeDetails getMediaType(String type, String subtype) throws NotFoundException {
+ MediaType mt = MediaType.parse(type+"/"+subtype);
+ for (MediaTypeDetails mtd : getMediaTypes()) {
+ if (mtd.type.equals(mt)) return mtd;
+ }
+ throw new NotFoundException("No Media Type registered in Tika for " + mt);
+ }
protected List<MediaTypeDetails> getMediaTypes() {
- MediaTypeRegistry registry = TikaResource.getConfig().getMediaTypeRegistry();
- Map<MediaType, Parser> parsers =
- ((CompositeParser) TikaResource.getConfig().getParser()).getParsers();
+ TikaConfig config = TikaResource.getConfig();
+ MimeTypes mimeTypes = config.getMimeRepository();
+ MediaTypeRegistry registry = config.getMediaTypeRegistry();
+ Map<MediaType, Parser> parsers = ((CompositeParser)config.getParser()).getParsers();
+
List<MediaTypeDetails> types =
new ArrayList<>(registry.getTypes().size());
@@ -159,6 +207,10 @@ public class TikaMimeTypes {
details.type = type;
details.aliases = registry.getAliases(type).toArray(new MediaType[0]);
+ try {
+ details.mime = mimeTypes.getRegisteredMimeType(type.toString());
+ } catch (MimeTypeException e) {}
+
MediaType supertype = registry.getSupertype(type);
if (supertype != null && !MediaType.OCTET_STREAM.equals(supertype)) {
details.supertype = supertype;
@@ -182,6 +234,7 @@ public class TikaMimeTypes {
private MediaType type;
private MediaType[] aliases;
private MediaType supertype;
+ private MimeType mime;
private String parser;
}
}