Use enum in ISR class

This commit is contained in:
tipsy
2015-10-21 17:41:53 +02:00
parent f2d6621570
commit 04439d79de
2 changed files with 20 additions and 12 deletions

View File

@@ -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"); }

View File

@@ -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 {
}
}