From 4e85e34c319c847632574c9589b3aa0fdbc355b6 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Wed, 4 Feb 2015 09:05:18 -0500 Subject: [PATCH] NIFI-317: - Adding support for exporting the lineage graph as SVG. - Removing support to convert to PNG. --- .../nifi-web/nifi-web-ui/pom.xml | 12 ------ .../{ConvertSvg.java => DownloadSvg.java} | 42 ++++--------------- .../src/main/webapp/WEB-INF/web.xml | 30 +++++++++++-- .../js/nf/provenance/nf-provenance-lineage.js | 15 ++++++- 4 files changed, 48 insertions(+), 51 deletions(-) rename nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/{ConvertSvg.java => DownloadSvg.java} (64%) diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml index 9eaa1b94e2..f01cbea3ab 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml @@ -609,18 +609,6 @@ commons-lang3 provided - - batik - batik-transcoder - 1.6-1 - - - fop - fop - - - - javax.servlet javax.servlet-api diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/ConvertSvg.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/DownloadSvg.java similarity index 64% rename from nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/ConvertSvg.java rename to nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/DownloadSvg.java index 6282f412bc..ab76d4e842 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/ConvertSvg.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/java/org/apache/nifi/web/servlet/DownloadSvg.java @@ -16,34 +16,24 @@ */ package org.apache.nifi.web.servlet; -import java.io.BufferedOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintWriter; -import java.io.StringReader; import java.net.URLDecoder; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.batik.dom.svg.SAXSVGDocumentFactory; -import org.apache.batik.transcoder.TranscoderInput; -import org.apache.batik.transcoder.TranscoderOutput; -import org.apache.batik.transcoder.image.PNGTranscoder; -import org.apache.batik.util.XMLResourceDescriptor; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.svg.SVGDocument; /** * */ -@WebServlet(name = "ConvertSvg", urlPatterns = {"/convert-svg"}) -public class ConvertSvg extends HttpServlet { +@WebServlet(name = "DownloadSvg", urlPatterns = {"/download-svg"}) +public class DownloadSvg extends HttpServlet { - private static final Logger logger = LoggerFactory.getLogger(ConvertSvg.class); + private static final Logger logger = LoggerFactory.getLogger(DownloadSvg.class); /** * @@ -54,7 +44,6 @@ public class ConvertSvg extends HttpServlet { */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - final String uri = request.getRequestURL().toString(); final String rawSvg = request.getParameter("svg"); // ensure the image markup has been included @@ -69,7 +58,6 @@ public class ConvertSvg extends HttpServlet { return; } - OutputStream bufferedOut = null; try { // get the svg and decode it, +'s need to be converted final String svg = URLDecoder.decode(rawSvg.replace("+", "%2B"), "UTF-8"); @@ -80,26 +68,16 @@ public class ConvertSvg extends HttpServlet { String filename = request.getParameter("filename"); if (filename == null) { - filename = "image.png"; - } else if (!filename.endsWith(".png")) { - filename += ".png"; + filename = "image.svg"; + } else if (!filename.endsWith(".svg")) { + filename += ".svg"; } - final StringReader reader = new StringReader(svg); - final String parser = XMLResourceDescriptor.getXMLParserClassName(); - final SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - final SVGDocument doc = f.createSVGDocument(uri, reader); - - response.setContentType("image/png"); + response.setContentType("image/svg+xml"); response.setHeader("Content-Disposition", "attachment; filename=" + filename); response.setStatus(HttpServletResponse.SC_OK); - bufferedOut = new BufferedOutputStream(response.getOutputStream()); - final TranscoderInput transcoderInput = new TranscoderInput(doc); - final TranscoderOutput transcoderOutput = new TranscoderOutput(bufferedOut); - - final PNGTranscoder transcoder = new PNGTranscoder(); - transcoder.transcode(transcoderInput, transcoderOutput); + response.getWriter().print(svg); } catch (final Exception e) { logger.error(e.getMessage(), e); @@ -109,9 +87,7 @@ public class ConvertSvg extends HttpServlet { // write the response message PrintWriter out = response.getWriter(); - out.println("Unable to export image as a PNG."); - } finally { - IOUtils.closeQuietly(bufferedOut); + out.println("Unable to export image as a SVG."); } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/web.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/web.xml index 8cae6e525c..eff7b8d37a 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/web.xml +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/web.xml @@ -15,7 +15,9 @@ --> nifi + + NiFiCanvas /WEB-INF/pages/canvas.jsp @@ -24,7 +26,9 @@ NiFiCanvas /canvas + + NiFiSummary /WEB-INF/pages/summary.jsp @@ -33,7 +37,9 @@ NiFiSummary /summary + + NiFiHistory /WEB-INF/pages/history.jsp @@ -42,7 +48,9 @@ NiFiHistory /history + + NiFiProvenance /WEB-INF/pages/provenance.jsp @@ -51,7 +59,9 @@ NiFiProvenance /provenance + + NiFiCounters /WEB-INF/pages/counters.jsp @@ -60,7 +70,9 @@ NiFiCounters /counters + + NiFiTemplates /WEB-INF/pages/templates.jsp @@ -69,7 +81,9 @@ NiFiTemplates /templates + + NiFiUsers /WEB-INF/pages/users.jsp @@ -78,7 +92,9 @@ NiFiUsers /users + + NiFiCluster /WEB-INF/pages/cluster.jsp @@ -87,7 +103,9 @@ NiFiCluster /cluster + + BulletinBoard /WEB-INF/pages/bulletin-board.jsp @@ -96,15 +114,18 @@ BulletinBoard /bulletin-board + + - ConvertSvg - org.apache.nifi.web.servlet.ConvertSvg + DownloadSvg + org.apache.nifi.web.servlet.DownloadSvg - ConvertSvg - /convert-svg + DownloadSvg + /download-svg + IeEdgeHeader org.apache.nifi.web.filter.IeEdgeHeader @@ -113,6 +134,7 @@ IeEdgeHeader /* + canvas.jsp /WEB-INF/pages/canvas.jsp diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-lineage.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-lineage.js index 1f05caa698..03b08f0078 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-lineage.js +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/provenance/nf-provenance-lineage.js @@ -531,6 +531,10 @@ nf.ProvenanceLineage = (function () { var svg = d3.select('#provenance-lineage-container').append('svg:svg') .attr('width', width) .attr('height', height) + .style({ + 'font-family': 'Verdana, Arial, sans-serif', + 'font-size': '10px' + }) .call(lineageZoom) .on('dblclick.zoom', null) .on('mousedown', function (d) { @@ -1210,7 +1214,7 @@ nf.ProvenanceLineage = (function () { // add the initial lineage addLineage(lineageResults.nodes, lineageResults.links); }; - + return { /** * Initializes the lineage graph. @@ -1276,7 +1280,14 @@ nf.ProvenanceLineage = (function () { return ''; }); - nf.Common.submit('POST', './convert-svg', { + // namespaces + svg = svg.replace(/^