Commit 352deb9e authored by Spiros Koulouzis's avatar Spiros Koulouzis

Moved method to utils

parent 174fdc54
...@@ -226,31 +226,7 @@ public class PlannerService { ...@@ -226,31 +226,7 @@ public class PlannerService {
} }
public String saveStringContents(String ymlContents, Integer level, String name) { public String saveStringContents(String ymlContents, Integer level, String name) {
//Remove '\' and 'n' if they are together and replace them with '\n' Map<String, Object> map = Converter.cleanStringContents(ymlContents);
char[] array = ymlContents.toCharArray();
StringBuilder sb = new StringBuilder();
int prevChar = -1;
for (int i = 0; i < array.length; i++) {
int currentChar = (int) array[i];
if (prevChar > 0 && prevChar == 92 && currentChar == 110) {
sb.delete(sb.length() - 1, sb.length());
sb.append('\n');
} else {
sb.append((char) currentChar);
}
prevChar = (int) array[i];
}
ymlContents = sb.toString();
ymlContents = ymlContents.replaceAll("(?m)^[ \t]*\r?\n", "");
for (int i = 0; i < Constants.BAD_CHARS.length; i++) {
int hex = Constants.BAD_CHARS[i];
ymlContents = ymlContents.replaceAll(String.valueOf((char) hex), "");
}
ymlContents = ymlContents.replaceAll("\\.", "\uff0E");
// ymlContents = ymlContents.replaceAll("\uff0E", ".");
Map<String, Object> map = Converter.ymlString2Map(ymlContents);
PlanResponse pr = new PlanResponse(); PlanResponse pr = new PlanResponse();
pr.setKvMap(map); pr.setKvMap(map);
pr.setLevel(level); pr.setLevel(level);
......
...@@ -116,31 +116,7 @@ public class PlaybookService { ...@@ -116,31 +116,7 @@ public class PlaybookService {
} }
public String saveStringContents(String playbookContents) throws IOException { public String saveStringContents(String playbookContents) throws IOException {
Map<String, Object> map = Converter.cleanStringContents(playbookContents);
//Remove '\' and 'n' if they are together and replace them with '\n'
char[] array = playbookContents.toCharArray();
StringBuilder sb = new StringBuilder();
int prevChar = -1;
for (int i = 0; i < array.length; i++) {
int currentChar = (int) array[i];
if (prevChar > 0 && prevChar == 92 && currentChar == 110) {
sb.delete(sb.length() - 1, sb.length());
sb.append('\n');
} else {
sb.append((char) currentChar);
}
prevChar = (int) array[i];
}
playbookContents = sb.toString();
playbookContents = playbookContents.replaceAll("(?m)^[ \t]*\r?\n", "");
for (int i = 0; i < Constants.BAD_CHARS.length; i++) {
int hex = Constants.BAD_CHARS[i];
playbookContents = playbookContents.replaceAll(String.valueOf((char) hex), "");
}
playbookContents = playbookContents.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(playbookContents);
PlaybookRepresentation t = new PlaybookRepresentation(); PlaybookRepresentation t = new PlaybookRepresentation();
t.setKvMap(map); t.setKvMap(map);
save(t); save(t);
......
...@@ -120,30 +120,8 @@ public class ToscaService { ...@@ -120,30 +120,8 @@ public class ToscaService {
public String saveStringContents(String toscaContents, String name) throws IOException { public String saveStringContents(String toscaContents, String name) throws IOException {
//Remove '\' and 'n' if they are together and replace them with '\n' Map<String, Object> map = Converter.cleanStringContents(toscaContents);
char[] array = toscaContents.toCharArray();
StringBuilder sb = new StringBuilder();
int prevChar = -1;
for (int i = 0; i < array.length; i++) {
int currentChar = (int) array[i];
if (prevChar > 0 && prevChar == 92 && currentChar == 110) {
sb.delete(sb.length() - 1, sb.length());
sb.append('\n');
} else {
sb.append((char) currentChar);
}
prevChar = (int) array[i];
}
toscaContents = sb.toString();
toscaContents = toscaContents.replaceAll("(?m)^[ \t]*\r?\n", "");
for (int i = 0; i < Constants.BAD_CHARS.length; i++) {
int hex = Constants.BAD_CHARS[i];
toscaContents = toscaContents.replaceAll(String.valueOf((char) hex), "");
}
toscaContents = toscaContents.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(toscaContents);
ToscaRepresentation t = new ToscaRepresentation(); ToscaRepresentation t = new ToscaRepresentation();
t.setName(name); t.setName(name);
t.setKvMap(map); t.setKvMap(map);
......
...@@ -210,4 +210,32 @@ public class Converter { ...@@ -210,4 +210,32 @@ public class Converter {
return p1; return p1;
} }
public static Map<String, Object> cleanStringContents(String toscaContents) {
//Remove '\' and 'n' if they are together and replace them with '\n'
char[] array = toscaContents.toCharArray();
StringBuilder sb = new StringBuilder();
int prevChar = -1;
for (int i = 0; i < array.length; i++) {
int currentChar = (int) array[i];
if (prevChar > 0 && prevChar == 92 && currentChar == 110) {
sb.delete(sb.length() - 1, sb.length());
sb.append('\n');
} else {
sb.append((char) currentChar);
}
prevChar = (int) array[i];
}
toscaContents = sb.toString();
toscaContents = toscaContents.replaceAll("(?m)^[ \t]*\r?\n", "");
for (int i = 0; i < Constants.BAD_CHARS.length; i++) {
int hex = Constants.BAD_CHARS[i];
toscaContents = toscaContents.replaceAll(String.valueOf((char) hex), "");
}
toscaContents = toscaContents.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(toscaContents);
return map;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment