You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2022/05/23 16:57:47 UTC
[nifi] branch main updated: NIFI-10044: Add content viewer support for YAML
This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 41b3778d67 NIFI-10044: Add content viewer support for YAML
41b3778d67 is described below
commit 41b3778d67296245675f41e17825aceca49eee49
Author: Matthew Burgess <ma...@apache.org>
AuthorDate: Fri May 20 13:37:58 2022 -0400
NIFI-10044: Add content viewer support for YAML
This closes #6063
Signed-off-by: David Handermann <exceptionfactory@apache.org?
---
.../nifi-standard-content-viewer/pom.xml | 5 +++++
.../nifi/web/StandardContentViewerController.java | 23 ++++++++++++++++++++++
.../src/main/resources/META-INF/NOTICE | 6 +++++-
.../src/main/webapp/META-INF/nifi-content-viewer | 9 ++++++++-
4 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
index a0ecda0357..1c6e219add 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
@@ -79,5 +79,10 @@
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.30</version>
+ </dependency>
</dependencies>
</project>
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