@Override public String stringify(Object object) { if (object instanceof Class) { Class c = (Class) object; return "[" + c.getSimpleName() + "]"; } throw new MustacheException("Object was not a class: " + object); } }
public void execute() throws MojoExecutionException, MojoFailureException { SourceInclusionScanner scanner = includeStale ? new StaleSourceScanner(1024, Collections.singleton("**/*." + extension), Collections.<String>emptySet()) : new SimpleSourceInclusionScanner(Collections.singleton("**/*." + extension), Collections.<String>emptySet()); scanner.addSourceMapping(new SuffixMapping("." + extension, "." + extension)); MustacheFactory mustacheFactory = new DefaultMustacheFactory(); try { Set<File> files = scanner.getIncludedSources(sourceDirectory, outputDirectory); for (File file : files) { try { mustacheFactory.compile(new FileReader(file), file.getAbsolutePath()); } catch (MustacheException e) { throw new MojoFailureException(e.getMessage(), e); } } } catch (InclusionScanException | FileNotFoundException e) { throw new MojoExecutionException(e.getMessage()); } } }
public Object get(List<Object> scopes) { if (returnThis) { int length = scopes == null ? 0 : scopes.size(); return length == 0 ? null : scopes.get(length - 1); } try { return binding.get(scopes); } catch (MustacheException e) { e.setContext(tc); throw e; } catch (Throwable e) { throw new MustacheException(e.getMessage(), e, tc); } }
fail("Should have failed"); } catch (MustacheException me) { assertEquals("test not found in [test:1] @[test:1]", me.getCause().getMessage()); } catch (IOException e) { e.printStackTrace();
public void await() { try { latch.await(); } catch (InterruptedException e) { throw new MustacheException("Interrupted while waiting for completion", e); } }
public Object get(List<Object> scopes) { if (returnThis) { int length = scopes == null ? 0 : scopes.size(); return length == 0 ? null : scopes.get(length - 1); } try { return binding.get(scopes); } catch (MustacheException e) { e.setContext(tc); throw e; } catch (Throwable e) { throw new MustacheException(e.getMessage(), e, tc); } }
public void testEmptyMustache() { try { new DefaultMustacheFactory().compile(new StringReader("{{}}"), "test"); fail("Didn't throw an exception"); } catch (MustacheException e) { assertTrue(e.getMessage().startsWith("Empty mustache")); } }
/** * Use the file system to resolve mustache templates. * * @param fileRoot where in the file system to find the templates */ public FileSystemResolver(File fileRoot) { if (!fileRoot.exists()) { throw new MustacheException(fileRoot + " does not exist"); } if (!fileRoot.isDirectory()) { throw new MustacheException(fileRoot + " is not a directory"); } this.fileRoot = fileRoot; }
public Object get(List<Object> scopes) { if (returnThis) { int length = scopes == null ? 0 : scopes.size(); return length == 0 ? null : scopes.get(length - 1); } try { return binding.get(scopes); } catch (MustacheException e) { e.setContext(tc); throw e; } catch (Throwable e) { throw new MustacheException(e.getMessage(), e, tc); } }
public void testImproperlyClosedVariable() throws IOException { try { new DefaultMustacheFactory().compile(new StringReader("{{{#containers}} {{/containers}}"), "example"); fail("Should have throw MustacheException"); } catch (MustacheException actual) { assertEquals("Improperly closed variable in example:1 @[example:1]", actual.getMessage()); } }
protected Writer appendText(Writer writer) { if (appended != null) { try { // Avoid allocations at runtime if (appendedChars == null) { appendedChars = appended.toCharArray(); } writer.write(appendedChars); } catch (IOException e) { throw new MustacheException("Failed to write", e, tc); } } return writer; }
public void testMalformedTag() { try { String template = "\n{{$value}}\n{/value}}"; Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test"); StringWriter sw = new StringWriter(); mustache.execute(sw, new Object[0]); fail("Should have failed to compile"); } catch (MustacheException e) { assertEquals("Failed to close 'value' tag @[test:2]", e.getMessage()); } }
@Override protected MissingWrapper createMissingWrapper(String name, List<Guard> guards) { throw new MustacheException("Failed to find: " + name); } });
@Test public void testThrowMustacheExceptionInCaseOfNullHandler() throws Exception { try { String template = "<ol>\n" + " <li>{{test.1}}</li>\n" + " <li>{{test.0}}</li>\n" + " <li>{{test.3}}</li>\n" + "</ol>\n" + "<ol>\n" + "{{#test}}\n" + " <li>{{.}}</li>\n" + "{{/test}}\n" + "</ol>"; Object scope = new Object() { String[] test = new String[]{ "a", "b", "c", "d" }; }; DefaultMustacheFactory mf = new DefaultMustacheFactory(); mf.setObjectHandler(null); Mustache m = mf.compile(new StringReader(template), "template"); m.execute(new StringWriter(), scope).flush(); fail("should have thrown MustacheException"); } catch (MustacheException expected) { assertEquals("Failed to get value for test.1 @[template:2]", expected.getMessage()); } }
for (Object scope : scopes) { if (!(scope instanceof Class)) { throw new MustacheException("Only classes allowed with this object handler: " + scope); throw new MustacheException("Empty scopes"); throw new MustacheException("Invalid scope: " + scope); return ((Method) member).getReturnType(); } else { throw new MustacheException("Member not a field or method: " + member); throw new MustacheException("Failed to find matching field or method: " + name + " in " + scopes);
public void testLimitedDepthRecursion() { try { StringWriter sw = execute("infiniteparent.html", new Context()); fail("Should have failed"); } catch (StackOverflowError soe) { fail("Should not have overflowed the stack"); } catch (MustacheException e) { assertEquals("Maximum partial recursion limit reached: 100 @[infiniteparent.html:1]", e.getMessage()); } }
public static void escape(String value, Writer writer) { try { char[] chars = value.toCharArray(); int length = chars.length; int start = 0; for (int i = 0; i < length; i++) { char c = chars[i]; char[] escaped; // We only possibly escape chars in the range 0-96 if (c <= 96 && (escaped = ESC[c]) != null) { // Write from the last replacement to before this one if (i > start) writer.write(chars, start, i - start); // Write the replacement writer.write(escaped); // Move the pointer to the position after replacement start = i + 1; } } writer.write(chars, start, length - start); } catch (IOException e) { throw new MustacheException("Failed to encode value: " + value, e); } }
throw new OnlineToolException("Invalid SPDX Document: " + e.getMessage()); } catch (MustacheException e) { throw new OnlineToolException("Unexpected error reading the HTML template: " + e.getMessage()); } finally { if (writer != null) {
File fileRoot = (File) resourceObj; if (!fileRoot.exists()) { throw new MustacheException(fileRoot + " does not exist"); throw new MustacheException(fileRoot + " is not a directory"); throw new MustacheException("Invalid constructor parameter: " + resourceObj.toString());
throw new OnlineToolException("Invalid SPDX Document: " + e.getMessage()); } catch (MustacheException e) { throw new OnlineToolException("Unexpected error reading the HTML template: " + e.getMessage()); } finally { if (writer != null) {