RockerUtil { static public ContentType templateNameToContentType(String templateName) { int pos = templateName.lastIndexOf('.'); if (pos < 0) { throw new IllegalArgumentException("Invalid template name format (unable find last dot character)"); } String ext = templateName.substring(pos+1); for (ContentType type : ContentType.values()) { if (type.toString().equalsIgnoreCase(ext)) { return type; } } throw new IllegalArgumentException("Unsupported content type for extension [" + ext + "] for template name [" + templateName + "]"); }  static boolean isJava8Plus(TemplateModel model); static boolean isJavaIdentifier(String identifier); static String pathToPackageName(Path path); static Path packageNameToPath(String packageName); static boolean isRelativePath(Path baseDir, Path file); static int countChars(String value, char ch); static boolean isWhitespaceNoLineBreak(char c); static boolean isWhitespace(char c); static boolean isWhitespace(String s); static String consoleFriendlyText(String s); static String templateNameToName(String templateName); static ContentType templateNameToContentType(String templateName); static Collection<File> listFileTree(File dir); static String qualifiedClassName(Object obj); static String qualifiedClassName(Class<?> type); static String unqualifiedClassName(Object obj); static String unqualifiedClassName(Class<?> type); static String chompClosureOpen(String expr); static String chompClosureAssignmentOpen(String expr); static List<String> stringIntoChunks(String s, int chunkSize); static List<String> getTextAsJavaByteArrayInitializer(String text, String charsetName, int maxArraySize); static void appendByteAsJavaByteInitializer(StringBuilder sb, byte b); static String md5(File f); static String byteArrayToHex(byte[] a); static final CharSequenceTranslator ESCAPE_JAVA; }
@Test public void templateNameToContentType() throws Exception { Assert.assertEquals(ContentType.HTML, RockerUtil.templateNameToContentType("index.rocker.html")); Assert.assertEquals(ContentType.RAW, RockerUtil.templateNameToContentType("index.rocker.raw")); Assert.assertEquals(ContentType.HTML, RockerUtil.templateNameToContentType("index.html")); try { RockerUtil.templateNameToContentType("index"); Assert.fail("Exception expected"); } catch (IllegalArgumentException e) { } try { RockerUtil.templateNameToContentType("index.unsupported"); Assert.fail("Exception expected"); } catch (IllegalArgumentException e) { } }