@Test public void testMissingValues() throws Exception { assertEquals("<div>-missing value-</div>-missing value-", helper.replace("<div>{{key2}}</div>{{key3}}", null)); assertEquals("<div>-missing value-</div>-missing value-", helper.replace("<div>{{key2}}</div>{{key3}}", "")); assertEquals("<div>/ui/img/image_preview.png</div>-missing value-", helper.replace("<div>{{key1}}</div>{{key3}}", null)); }
public String replace(String text, String values) { if (params == null) { return text; } JsonObject obj = parseValues(values); for (TemplateParam p : params) { String value = "-missing value-"; if (obj != null && obj.has(p.getKey())) { value = obj.get(p.getKey()).getAsString(); if ("file".equalsIgnoreCase(p.getType())) { value = "/s/api/fileservice/files/" + value + "/content"; } } else if ("file".equalsIgnoreCase(p.getType())) { value = "/ui/img/image_preview.png"; } text = StringUtils.replace(text, "{{" + p.getKey() + "}}", value); } return text; }
TemplateHelper { public String replace(String text, String values) { if (params == null) { return text; } JsonObject obj = parseValues(values); for (TemplateParam p : params) { String value = "-missing value-"; if (obj != null && obj.has(p.getKey())) { value = obj.get(p.getKey()).getAsString(); if ("file".equalsIgnoreCase(p.getType())) { value = "/s/api/fileservice/files/" + value + "/content"; } } else if ("file".equalsIgnoreCase(p.getType())) { value = "/ui/img/image_preview.png"; } text = StringUtils.replace(text, "{{" + p.getKey() + "}}", value); } return text; } }
TemplateHelper { public String replace(String text, String values) { if (params == null) { return text; } JsonObject obj = parseValues(values); for (TemplateParam p : params) { String value = "-missing value-"; if (obj != null && obj.has(p.getKey())) { value = obj.get(p.getKey()).getAsString(); if ("file".equalsIgnoreCase(p.getType())) { value = "/s/api/fileservice/files/" + value + "/content"; } } else if ("file".equalsIgnoreCase(p.getType())) { value = "/ui/img/image_preview.png"; } text = StringUtils.replace(text, "{{" + p.getKey() + "}}", value); } return text; } TemplateHelper(String params); }
TemplateHelper { public String replace(String text, String values) { if (params == null) { return text; } JsonObject obj = parseValues(values); for (TemplateParam p : params) { String value = "-missing value-"; if (obj != null && obj.has(p.getKey())) { value = obj.get(p.getKey()).getAsString(); if ("file".equalsIgnoreCase(p.getType())) { value = "/s/api/fileservice/files/" + value + "/content"; } } else if ("file".equalsIgnoreCase(p.getType())) { value = "/ui/img/image_preview.png"; } text = StringUtils.replace(text, "{{" + p.getKey() + "}}", value); } return text; } TemplateHelper(String params); String replace(String text, String values); boolean containsFile(File file, String values); }
TemplateHelper { public String replace(String text, String values) { if (params == null) { return text; } JsonObject obj = parseValues(values); for (TemplateParam p : params) { String value = "-missing value-"; if (obj != null && obj.has(p.getKey())) { value = obj.get(p.getKey()).getAsString(); if ("file".equalsIgnoreCase(p.getType())) { value = "/s/api/fileservice/files/" + value + "/content"; } } else if ("file".equalsIgnoreCase(p.getType())) { value = "/ui/img/image_preview.png"; } text = StringUtils.replace(text, "{{" + p.getKey() + "}}", value); } return text; } TemplateHelper(String params); String replace(String text, String values); boolean containsFile(File file, String values);  }