From c696cb09b610bc91e3f2e0fcec18e2bc96fe71d5 Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Fri, 1 Jan 2016 14:10:39 -0500 Subject: [PATCH] NIFI-1212 Treating text/csv files as plain text so they may also be displayed. This closes #154. Signed-off-by: joewitt --- .../nifi/web/StandardContentViewerController.java | 13 +++++++------ .../src/main/webapp/META-INF/nifi-content-viewer | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java index a85c450e57..cc87e6f0dd 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java @@ -49,20 +49,21 @@ public class StandardContentViewerController extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final ViewableContent content = (ViewableContent) request.getAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE); - // handle json/xml - if ("application/json".equals(content.getContentType()) || "application/xml".equals(content.getContentType()) || "text/plain".equals(content.getContentType())) { + // handle json/xml specifically, treat others as plain text + final String contentType = content.getContentType(); + if ("application/json".equals(contentType) || "application/xml".equals(contentType) || "text/plain".equals(contentType) || "text/csv".equals(contentType)) { final String formatted; // leave the content alone if specified if (DisplayMode.Original.equals(content.getDisplayMode())) { formatted = content.getContent(); } else { - if ("application/json".equals(content.getContentType())) { + if ("application/json".equals(contentType)) { // format json final ObjectMapper mapper = new ObjectMapper(); final Object objectJson = mapper.readValue(content.getContentStream(), Object.class); formatted = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectJson); - } else if ("application/xml".equals(content.getContentType())) { + } else if ("application/xml".equals(contentType)) { // format xml final StringWriter writer = new StringWriter(); @@ -89,12 +90,12 @@ public class StandardContentViewerController extends HttpServlet { } // defer to the jsp - request.setAttribute("mode", content.getContentType()); + request.setAttribute("mode", contentType); request.setAttribute("content", formatted); request.getRequestDispatcher("/WEB-INF/jsp/codemirror.jsp").include(request, response); } else { final PrintWriter out = response.getWriter(); - out.println("Unexpected content type: " + content.getContentType()); + out.println("Unexpected content type: " + contentType); } } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/META-INF/nifi-content-viewer b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/META-INF/nifi-content-viewer index c6a78f1fde..302c44afce 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/META-INF/nifi-content-viewer +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/META-INF/nifi-content-viewer @@ -14,4 +14,5 @@ # limitations under the License. application/xml application/json -text/plain \ No newline at end of file +text/plain +text/csv \ No newline at end of file