From 41b3778d67296245675f41e17825aceca49eee49 Mon Sep 17 00:00:00 2001 From: Matthew Burgess Date: Fri, 20 May 2022 13:37:58 -0400 Subject: [PATCH] NIFI-10044: Add content viewer support for YAML This closes #6063 Signed-off-by: David Handermann org.xerial.snappy snappy-java + + org.yaml + snakeyaml + 1.30 + 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 a02300f91c..f89a74f4e2 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 @@ -30,6 +30,8 @@ import org.apache.nifi.xml.processing.transform.StandardTransformProvider; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalTime; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -57,6 +59,13 @@ public class StandardContentViewerController extends HttpServlet { supportedMimeTypes.add("application/avro-binary"); supportedMimeTypes.add("avro/binary"); supportedMimeTypes.add("application/avro+binary"); + supportedMimeTypes.add("text/x-yaml"); + supportedMimeTypes.add("text/yaml"); + supportedMimeTypes.add("text/yml"); + supportedMimeTypes.add("application/x-yaml"); + supportedMimeTypes.add("application/x-yml"); + supportedMimeTypes.add("application/yaml"); + supportedMimeTypes.add("application/yml"); } /** @@ -150,6 +159,20 @@ public class StandardContentViewerController extends HttpServlet { formatted = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectJson); contentType = "application/json"; + } else if ("text/x-yaml".equals(contentType) || "text/yaml".equals(contentType) || "text/yml".equals(contentType) + || "application/x-yaml".equals(contentType) || "application/x-yml".equals(contentType) + || "application/yaml".equals(contentType) || "application/yml".equals(contentType)) { + Yaml yaml = new Yaml(); + // Parse the YAML file + final Object yamlObject = yaml.load(content.getContentStream()); + DumperOptions options = new DumperOptions(); + options.setIndent(2); + options.setPrettyFlow(true); + // Fix below - additional configuration + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Yaml output = new Yaml(options); + formatted = output.dump(yamlObject); + } else { // leave plain text alone when formatting formatted = content.getContent(); diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/resources/META-INF/NOTICE index b12860cb3d..c61dc15981 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/resources/META-INF/NOTICE +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/resources/META-INF/NOTICE @@ -34,4 +34,8 @@ The following binary components are provided under the Apache Software License v This library containd statically linked libstdc++. This inclusion is allowed by "GCC RUntime Library Exception" - http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html \ No newline at end of file + http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html + + (ASLv2) SnakeYAML + The following NOTICE information applies: + Copyright (c) 2008, https://www.snakeyaml.org \ No newline at end of file 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 f105ca2f0b..3e17ff63a5 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 @@ -19,4 +19,11 @@ text/plain text/csv avro/binary application/avro-binary -application/avro+binary \ No newline at end of file +application/avro+binary +text/x-yaml +text/yaml +text/yml +application/x-yaml +application/x-yml +application/yaml +application/yml \ No newline at end of file