Created
September 2, 2013 17:45
-
-
Save kmila/6415417 to your computer and use it in GitHub Desktop.
List variables from freemarker file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// implementation-dependant (freemarker 2.3.14) | |
private List<String> getTemplateVariables(Template freemarkerTemplate) throws IOException, TemplateModelException { | |
SimpleSequence childNodes = (SimpleSequence) freemarkerTemplate.getRootTreeNode().getChildNodes(); | |
List<String> dollarVariables = new ArrayList<String>(); | |
for (Object object : childNodes.toList()) { | |
if (object instanceof TemplateElement && ((TemplateElement) object).getCanonicalForm().startsWith("$")) { | |
dollarVariables.add(((TemplateElement) object).getCanonicalForm()); | |
} | |
} | |
return dollarVariables; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment