You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2016/02/25 16:13:27 UTC

[1/2] nifi git commit: NIFI-1539 - Add normalization of content type for content viewing

Repository: nifi
Updated Branches:
  refs/heads/master 6af108c0c -> 0d13de0cf


NIFI-1539 - Add normalization of content type for content viewing

Add code to ContentViewerController to strip content type of any trailing parameters and lowercase the type and subtype.

Added function to ViewableContent to enable retrieving the original value of the content type if needed.

This closes #242

Signed-off-by: Matt Gilman <ma...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/fc924419
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/fc924419
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/fc924419

Branch: refs/heads/master
Commit: fc92441981ff6e5c7b625e6b77f477031bb62af7
Parents: 6af108c
Author: Sönke Liebau <so...@opencore.com>
Authored: Mon Feb 22 08:25:42 2016 +0100
Committer: Matt Gilman <ma...@gmail.com>
Committed: Thu Feb 25 10:12:45 2016 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/nifi/web/ViewableContent.java  |  8 +++++++-
 .../org/apache/nifi/web/ContentViewerController.java    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/fc924419/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java b/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
index 180385e..d506b5d 100644
--- a/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
+++ b/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
@@ -59,7 +59,13 @@ public interface ViewableContent {
     String getFileName();
 
     /**
-     * @return mime type of the content
+     * @return mime type of the content, value is lowercase and stripped of all parameters if there were any
      */
     String getContentType();
+
+    /**
+     * @return unchanged mime type of the content
+     */
+    String getRawContentType();
+
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/fc924419/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
index efc5db8..65f9353 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
@@ -150,6 +150,7 @@ public class ContentViewerController extends HttpServlet {
         // buffer the content to support reseting in case we need to detect the content type or char encoding
         try (final BufferedInputStream bis = new BufferedInputStream(downloadableContent.getContent());) {
             final String mimeType;
+            final String normalizedMimeType;
 
             // when standalone and we don't know the type is null as we were able to directly access the content bypassing the rest endpoint,
             // when clustered and we don't know the type set to octet stream since the content was retrieved from the node's rest endpoint
@@ -171,6 +172,10 @@ public class ContentViewerController extends HttpServlet {
                 mimeType = downloadableContent.getType();
             }
 
+            // Extract only mime type and subtype from content type (anything after the first ; are parameters)
+            // Lowercase so subsequent code does not need to implement case insensitivity
+            normalizedMimeType = mimeType.split(";",2)[0].toLowerCase();
+
             // add attributes needed for the header
             request.setAttribute("filename", downloadableContent.getFilename());
             request.setAttribute("contentType", mimeType);
@@ -202,7 +207,7 @@ public class ContentViewerController extends HttpServlet {
                 request.getRequestDispatcher("/WEB-INF/jsp/hexview.jsp").include(request, response);
             } else {
                 // lookup a viewer for the content
-                final String contentViewerUri = servletContext.getInitParameter(mimeType);
+                final String contentViewerUri = servletContext.getInitParameter(normalizedMimeType);
 
                 // handle no viewer for content type
                 if (contentViewerUri == null) {
@@ -244,6 +249,11 @@ public class ContentViewerController extends HttpServlet {
 
                         @Override
                         public String getContentType() {
+                            return normalizedMimeType;
+                        }
+
+                        @Override
+                        public String getRawContentType() {
                             return mimeType;
                         }
                     });


[2/2] nifi git commit: NIFI-1539: - Comparing octet stream content type by using starts with and ignores case.

Posted by mc...@apache.org.
NIFI-1539: - Comparing octet stream content type by using starts with and ignores case.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/0d13de0c
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/0d13de0c
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/0d13de0c

Branch: refs/heads/master
Commit: 0d13de0cf350cd6f5bef985303fe41fd8d769731
Parents: fc92441
Author: Matt Gilman <ma...@gmail.com>
Authored: Thu Feb 25 09:43:25 2016 -0500
Committer: Matt Gilman <ma...@gmail.com>
Committed: Thu Feb 25 10:13:07 2016 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/nifi/web/ContentViewerController.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/0d13de0c/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
index 65f9353..50ca101 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
@@ -154,7 +154,7 @@ public class ContentViewerController extends HttpServlet {
 
             // when standalone and we don't know the type is null as we were able to directly access the content bypassing the rest endpoint,
             // when clustered and we don't know the type set to octet stream since the content was retrieved from the node's rest endpoint
-            if (downloadableContent.getType() == null || downloadableContent.getType().equals(MediaType.OCTET_STREAM.toString())) {
+            if (downloadableContent.getType() == null || StringUtils.startsWithIgnoreCase(downloadableContent.getType(), MediaType.OCTET_STREAM.toString())) {
                 // attempt to detect the content stream if we don't know what it is ()
                 final DefaultDetector detector = new DefaultDetector();