Repository: incubator-unomi Updated Branches: refs/heads/master 1f350d08c -> 64b8fe833
UNOMI-135 : Allow yaml as text for profile download Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/64b8fe83 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/64b8fe83 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/64b8fe83 Branch: refs/heads/master Commit: 64b8fe8334c9935c127bd316c351b635e00f698d Parents: 1f350d0 Author: Abdelkader Midani <amid...@apache.org> Authored: Mon Nov 6 14:42:42 2017 +0100 Committer: Abdelkader Midani <amid...@apache.org> Committed: Mon Nov 6 14:42:42 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/unomi/web/ClientServlet.java | 17 ++++++++++------- wab/src/main/resources/org.apache.unomi.web.cfg | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/64b8fe83/wab/src/main/java/org/apache/unomi/web/ClientServlet.java ---------------------------------------------------------------------- diff --git a/wab/src/main/java/org/apache/unomi/web/ClientServlet.java b/wab/src/main/java/org/apache/unomi/web/ClientServlet.java index d5dc90b..4f994cf 100644 --- a/wab/src/main/java/org/apache/unomi/web/ClientServlet.java +++ b/wab/src/main/java/org/apache/unomi/web/ClientServlet.java @@ -104,7 +104,7 @@ public class ClientServlet extends HttpServlet { if (currentProfile != null) { switch (downloadFileType) { case "yaml": - prepareYamlFileToDownload(response, currentProfile); + prepareYamlFileToDownload(response, currentProfile, false); break; case "json": prepareJsonFileToDownload(response, currentProfile); @@ -112,6 +112,9 @@ public class ClientServlet extends HttpServlet { case "csv": prepareCsvFileToDownload(response, currentProfile, request.getParameter("vertical") != null); break; + case "text": + prepareYamlFileToDownload(response, currentProfile, true); + break; default: return; @@ -131,9 +134,9 @@ public class ClientServlet extends HttpServlet { CSVWriter csvWriter = new CSVWriter(writer); OutputStream outputStream = response.getOutputStream(); if (vertical) { - csvWriter.writeNext(new String[] {"name", "value"}); - for (Map.Entry<String,Object> entry : currentProfile.getProperties().entrySet()) { - csvWriter.writeNext(new String[] { entry.getKey(), entry.getValue().toString().trim().replace("\n", "")}); + csvWriter.writeNext(new String[]{"name", "value"}); + for (Map.Entry<String, Object> entry : currentProfile.getProperties().entrySet()) { + csvWriter.writeNext(new String[]{entry.getKey(), entry.getValue().toString().trim().replace("\n", "")}); } } else { Set<String> keySet = currentProfile.getProperties().keySet(); @@ -167,9 +170,9 @@ public class ClientServlet extends HttpServlet { } } - private void prepareYamlFileToDownload(HttpServletResponse response, Profile currentProfile) { - response.setContentType("text/yaml"); - response.setHeader("Content-Disposition", "attachment; filename=\"" + currentProfile.getItemId() + ".yml\""); + private void prepareYamlFileToDownload(HttpServletResponse response, Profile currentProfile, boolean asTextFile) { + response.setContentType("text/" + (asTextFile ? "plain" : "yaml")); + response.setHeader("Content-Disposition", "attachment; filename=\"" + currentProfile.getItemId() + (asTextFile ? ".txt" : ".yml") + "\""); try { YAMLFactory yf = new YAMLFactory(); ObjectMapper mapper = new ObjectMapper(yf); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/64b8fe83/wab/src/main/resources/org.apache.unomi.web.cfg ---------------------------------------------------------------------- diff --git a/wab/src/main/resources/org.apache.unomi.web.cfg b/wab/src/main/resources/org.apache.unomi.web.cfg index 6282886..0a3c518 100644 --- a/wab/src/main/resources/org.apache.unomi.web.cfg +++ b/wab/src/main/resources/org.apache.unomi.web.cfg @@ -22,5 +22,5 @@ #contextserver.profileIdCookieName=context-profile-id # This setting controls the maximum age of the profile cookie. By default it is set to a year. #contextserver.profileIdCookieMaxAgeInSeconds=31536000 -#Allowed profile download formats, actually only yaml, json and csv are allowed. -allowed.profile.download.formats=yaml,json,csv \ No newline at end of file +#Allowed profile download formats, actually only csv (horizontal and vertical), json, text and yaml are allowed. +allowed.profile.download.formats=csv,yaml,json,text \ No newline at end of file