mirror of https://github.com/apache/nifi.git
NIFI-10044: Add content viewer support for YAML
This closes #6063 Signed-off-by: David Handermann <exceptionfactory@apache.org?
This commit is contained in:
parent
e74557f990
commit
41b3778d67
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html
|
||||
|
||||
(ASLv2) SnakeYAML
|
||||
The following NOTICE information applies:
|
||||
Copyright (c) 2008, https://www.snakeyaml.org
|
|
@ -19,4 +19,11 @@ text/plain
|
|||
text/csv
|
||||
avro/binary
|
||||
application/avro-binary
|
||||
application/avro+binary
|
||||
application/avro+binary
|
||||
text/x-yaml
|
||||
text/yaml
|
||||
text/yml
|
||||
application/x-yaml
|
||||
application/x-yml
|
||||
application/yaml
|
||||
application/yml
|
Loading…
Reference in New Issue