You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/10/21 09:48:50 UTC
[16/29] incubator-taverna-workbench git commit: Added
MediaTypeDetector interface
Added MediaTypeDetector interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/commit/1ff3b51d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/tree/1ff3b51d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/diff/1ff3b51d
Branch: refs/heads/master
Commit: 1ff3b51d2cc4a9f29951207c63eadd3ba28524d0
Parents: f3a2ba9
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Aug 19 12:29:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 21 09:17:18 2016 +0200
----------------------------------------------------------------------
.../taverna/renderers/MediaTypeDetector.java | 102 +++++++++++++++++++
.../taverna/renderers/RendererRegistry.java | 12 +++
.../renderers/impl/MediaTypeDetectorImpl.java | 58 +++++++++++
.../renderers/impl/RendererRegistryImpl.java | 7 ++
4 files changed, 179 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/1ff3b51d/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/MediaTypeDetector.java
----------------------------------------------------------------------
diff --git a/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/MediaTypeDetector.java b/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/MediaTypeDetector.java
new file mode 100644
index 0000000..585d351
--- /dev/null
+++ b/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/MediaTypeDetector.java
@@ -0,0 +1,102 @@
+/*
+ * 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.taverna.renderers;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Path;
+import java.util.List;
+
+public interface MediaTypeDetector {
+
+ /**
+ * Guess the media types of a given {@link Path}.
+ * <p>
+ * The media types in the list are ordered by decreasing likelyhood, e.g.
+ * the first item in the list is the most likely (in many cases most
+ * specific) media type.
+ * <p>
+ * The returned list will never be empty, as it will always contain either
+ * <code>text/plain</code> or <code>application/octet-stream</code>
+ *
+ * @param path
+ * A {@link Path} to be guessed. The file extension of the path
+ * MAY be taken into consideration.
+ * @return A list of guessed media types
+ * @throws IOException If the path can't be accessed (e.g. lacking file permissions)
+ */
+ public List<String> guessMediaTypes(Path path) throws IOException ;
+
+ /**
+ * Guess the media types of a given {@link String}.
+ * <p>
+ * The media types in the list are ordered by decreasing likelihood, e.g.
+ * the first item in the list is the most likely (in many cases most
+ * specific) media type.
+ * <p>
+ * The returned list will never be empty, as it will always contain either
+ * <code>text/plain</code>.
+ *
+ * @param path
+ * A {@link Path} to be guessed. The file extension of the path
+ * MAY be taken into consideration.
+ * @return A list of guessed media types
+ */
+ public List<String> guessMediaTypes(String string);
+
+ /**
+ * Guess the media types of a given {@link Path}.
+ * <p>
+ * The media types in the list are ordered by decreasing likelihood, e.g.
+ * the first item in the list is the most likely (in many cases most
+ * specific) media type.
+ * <p>
+ * The returned list will never be empty, as it will always contain
+ * <code>application/octet-stream</code>
+ *
+ * @param path
+ * A {@link Path} to be guessed. The file extension of the path
+ * MAY be taken into consideration.
+ * @return A list of guessed media types
+ */
+ public List<String> guessMediaTypes(byte[] bytes);
+
+ /**
+ * Guess the media types of a given {@link URI}.
+ * <p>
+ * The detector MAY try to retrieve the given URI, e.g. issuing a
+ * HTTP <code>HEAD</code> request.
+ * <p>
+ * The media types in the list are ordered by decreasing likelihood, e.g.
+ * the first item in the list is the most likely (in many cases most
+ * specific) media type.
+ * <p>
+ * The returned list will never be empty, as it will always contain either
+ * <code>text/plain</code> or <code>application/octet-stream</code>
+ *
+ * @param path
+ * A {@link Path} to be guessed. Any file extension of the URL
+ * MAY be taken into consideration.
+ * @return A list of guessed media types
+ * @throws IOException If the URL can't be accessed (e.g. a network issue)
+ */
+ public List<String> guessMediaTypes(URI uri) throws IOException;
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/1ff3b51d/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/RendererRegistry.java
----------------------------------------------------------------------
diff --git a/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/RendererRegistry.java b/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/RendererRegistry.java
index a63a06a..1dec5df 100644
--- a/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/RendererRegistry.java
+++ b/taverna-renderers-api/src/main/java/org/apache/taverna/renderers/RendererRegistry.java
@@ -43,4 +43,16 @@ public interface RendererRegistry {
* @return all the renderers
*/
List<Renderer> getRenderers();
+
+ /**
+ * Return a mime type detector.
+ * <p>
+ * The detector can help guess the mime type of a given binary or String.
+ * <p>
+ * Note that the detector might also detect media types that do not have
+ * a corresponding renderer in {@link #getRenderersForMimeType(String)}.
+ *
+ * @return A mime type detector
+ */
+ MediaTypeDetector getMimeTypeDetector();
}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/1ff3b51d/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/MediaTypeDetectorImpl.java
----------------------------------------------------------------------
diff --git a/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/MediaTypeDetectorImpl.java b/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/MediaTypeDetectorImpl.java
new file mode 100644
index 0000000..c8b6fb7
--- /dev/null
+++ b/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/MediaTypeDetectorImpl.java
@@ -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.taverna.renderers.impl;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.taverna.renderers.MediaTypeDetector;
+
+/**
+ * Media Type detector that uses Apache Tika
+ *
+ */
+public class MediaTypeDetectorImpl implements MediaTypeDetector {
+
+ @Override
+ public List<String> guessMediaTypes(Path path) throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> guessMediaTypes(String string) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> guessMediaTypes(byte[] bytes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> guessMediaTypes(URI uri) throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/1ff3b51d/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/RendererRegistryImpl.java
----------------------------------------------------------------------
diff --git a/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/RendererRegistryImpl.java b/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/RendererRegistryImpl.java
index d83a7bb..8de768e 100644
--- a/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/RendererRegistryImpl.java
+++ b/taverna-renderers-impl/src/main/java/org/apache/taverna/renderers/impl/RendererRegistryImpl.java
@@ -21,6 +21,7 @@ package org.apache.taverna.renderers.impl;
import java.util.ArrayList;
import java.util.List;
+import org.apache.taverna.renderers.MediaTypeDetector;
import org.apache.taverna.renderers.Renderer;
import org.apache.taverna.renderers.RendererRegistry;
@@ -49,4 +50,10 @@ public class RendererRegistryImpl implements RendererRegistry {
public void setRenderers(List<Renderer> renderers) {
this.renderers = renderers;
}
+
+ @Override
+ public MediaTypeDetector getMimeTypeDetector() {
+ // TODO: Should the below have any configuration loaded?
+ return new MediaTypeDetectorImpl();
+ }
}