From d75c7b54e8d6ab9374d6cf6afd1638270388c0f8 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Fri, 18 Sep 2015 18:17:12 -0400 Subject: [PATCH] NIFI-934: - Added a content viewer for image files. --- .../nifi-image-bundle/nifi-image-nar/pom.xml | 6 +++ .../nifi-image-viewer/pom.xml | 48 +++++++++++++++++ .../nifi/web/ImageViewerController.java | 52 +++++++++++++++++++ .../main/webapp/META-INF/nifi-content-viewer | 17 ++++++ .../src/main/webapp/WEB-INF/jsp/image.jsp | 39 ++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 29 +++++++++++ nifi-nar-bundles/nifi-image-bundle/pom.xml | 1 + 7 files changed, 192 insertions(+) create mode 100755 nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/pom.xml create mode 100755 nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/java/org/apache/nifi/web/ImageViewerController.java create mode 100755 nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/META-INF/nifi-content-viewer create mode 100755 nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/jsp/image.jsp create mode 100755 nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/web.xml diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-nar/pom.xml b/nifi-nar-bundles/nifi-image-bundle/nifi-image-nar/pom.xml index 1c60968c1e..5527bfd289 100644 --- a/nifi-nar-bundles/nifi-image-bundle/nifi-image-nar/pom.xml +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-nar/pom.xml @@ -32,6 +32,12 @@ nifi-image-processors 0.3.1-SNAPSHOT + + org.apache.nifi + nifi-image-viewer + 0.3.1-SNAPSHOT + war + diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/pom.xml b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/pom.xml new file mode 100755 index 0000000000..d8b20daee3 --- /dev/null +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/pom.xml @@ -0,0 +1,48 @@ + + + + 4.0.0 + + org.apache.nifi + nifi-image-bundle + 0.3.1-SNAPSHOT + + nifi-image-viewer + NiFi image viewer + war + + + org.apache.nifi + nifi-api + + + javax.servlet.jsp + javax.servlet.jsp-api + + + javax.el + javax.el-api + + + javax.servlet.jsp.jstl + javax.servlet.jsp.jstl-api + + + javax.servlet + javax.servlet-api + + + diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/java/org/apache/nifi/web/ImageViewerController.java b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/java/org/apache/nifi/web/ImageViewerController.java new file mode 100755 index 0000000000..a3ba1cd61d --- /dev/null +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/java/org/apache/nifi/web/ImageViewerController.java @@ -0,0 +1,52 @@ +/* + * 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.nifi.web; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name = "ImageViewer", urlPatterns = {"/view-content"}) +public class ImageViewerController extends HttpServlet { + + /** + * Handles generating markup for viewing an image. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + final ViewableContent content = (ViewableContent) request.getAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE); + + // handle images + if ("image/png".equals(content.getContentType()) || "image/jpeg".equals(content.getContentType()) || "image/gif".equals(content.getContentType())) { + // defer to the jsp + request.getRequestDispatcher("/WEB-INF/jsp/image.jsp").include(request, response); + } else { + final PrintWriter out = response.getWriter(); + out.println("Unexpected content type: " + content.getContentType()); + } + } +} diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/META-INF/nifi-content-viewer b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/META-INF/nifi-content-viewer new file mode 100755 index 0000000000..71cf2a29e7 --- /dev/null +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/META-INF/nifi-content-viewer @@ -0,0 +1,17 @@ +# 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. +image/png +image/jpeg +image/gif \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/jsp/image.jsp b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/jsp/image.jsp new file mode 100755 index 0000000000..9dc5e3c4a8 --- /dev/null +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/jsp/image.jsp @@ -0,0 +1,39 @@ +<%-- + 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. +--%> +<%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> + + +
+ \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/web.xml b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/web.xml new file mode 100755 index 0000000000..bccf333a82 --- /dev/null +++ b/nifi-nar-bundles/nifi-image-bundle/nifi-image-viewer/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + + nifi-image-viewer + + ImageViewer + org.apache.nifi.web.ImageViewerController + + + ImageViewer + /view-content + + + view-content + + diff --git a/nifi-nar-bundles/nifi-image-bundle/pom.xml b/nifi-nar-bundles/nifi-image-bundle/pom.xml index a254fd7910..2a5836f6bc 100644 --- a/nifi-nar-bundles/nifi-image-bundle/pom.xml +++ b/nifi-nar-bundles/nifi-image-bundle/pom.xml @@ -29,6 +29,7 @@ nifi-image-processors nifi-image-nar + nifi-image-viewer