From 04439d79de776284c0bc2b770667992f1168912e Mon Sep 17 00:00:00 2001 From: tipsy Date: Wed, 21 Oct 2015 17:41:53 +0200 Subject: [PATCH] Use enum in ISR class --- src/main/java/j2html/TagCreator.java | 8 +++---- .../j2html/tags/InlineStaticResource.java | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/j2html/TagCreator.java b/src/main/java/j2html/TagCreator.java index 6d60f8c..389a6a1 100644 --- a/src/main/java/j2html/TagCreator.java +++ b/src/main/java/j2html/TagCreator.java @@ -11,11 +11,11 @@ public class TagCreator { public static Text text(String text) { return new Text(text); } public static UnescapedText unsafeHtml(String html) { return new UnescapedText(html); } - public static ContainerTag inlineCss(String path) { return InlineStaticResource.get(path, "css"); } - public static ContainerTag inlineJs(String path) { return InlineStaticResource.get(path, "js"); } + public static ContainerTag inlineCss(String path) { return InlineStaticResource.get(path, InlineStaticResource.TargetFormat.CSS); } + public static ContainerTag inlineJs(String path) { return InlineStaticResource.get(path, InlineStaticResource.TargetFormat.JS); } - public static ContainerTag inlineCssMin(String path) { return InlineStaticResource.get(path, "css.min"); } - public static ContainerTag inlineJsMin(String path) { return InlineStaticResource.get(path, "js.min"); } + public static ContainerTag inlineCssMin(String path) { return InlineStaticResource.get(path, InlineStaticResource.TargetFormat.CSS_MIN); } + public static ContainerTag inlineJsMin(String path) { return InlineStaticResource.get(path, InlineStaticResource.TargetFormat.JS_MIN); } //EmptyTags public static EmptyTag area() { return new EmptyTag("area"); } diff --git a/src/main/java/j2html/tags/InlineStaticResource.java b/src/main/java/j2html/tags/InlineStaticResource.java index 666b9b0..bd59931 100644 --- a/src/main/java/j2html/tags/InlineStaticResource.java +++ b/src/main/java/j2html/tags/InlineStaticResource.java @@ -6,16 +6,23 @@ import static j2html.TagCreator.*; public class InlineStaticResource { - public static ContainerTag get(String path, String type) { - ContainerTag errorTag = script().with(unsafeHtml("alert('Unable to read file. File: \"" + path + "\", Type: \"" + type + "\"')")); + public enum TargetFormat { + CSS_MIN, + CSS, + JS_MIN, + JS; + } + + public static ContainerTag get(String path, TargetFormat format) { + ContainerTag errorTag = script().with(unsafeHtml("alert('Unable to read file. File: \"" + path + "\", Type: \"" + format + "\"')")); try { String fileString = new String(Files.readAllBytes(Paths.get(InlineStaticResource.class.getResource(path).toURI())), "UTF-8"); - switch(type) { - case "css.min" : return style().with(unsafeHtml(compressCss(fileString))); - case "js.min" : return script().with(unsafeHtml(compressJs(fileString, path))); - case "css" : return style().with(unsafeHtml(fileString)); - case "js" : return script().with(unsafeHtml(fileString)); - default : return errorTag; + switch(format) { + case CSS_MIN : return style().with(unsafeHtml(compressCss(fileString))); + case JS_MIN : return script().with(unsafeHtml(compressJs(fileString, path))); + case CSS : return style().with(unsafeHtml(fileString)); + case JS : return script().with(unsafeHtml(fileString)); + default : return errorTag; } } catch (Exception e) { return errorTag; @@ -31,3 +38,4 @@ public class InlineStaticResource { } } +