1 52 53 package freemarker.core; 54 55 import freemarker.template.*; 56 57 60 final class Identifier extends Expression { 61 62 private final String name; 63 64 Identifier(String name) { 65 this.name = name; 66 } 67 68 TemplateModel _getAsTemplateModel(Environment env) throws TemplateException { 69 try { 70 return env.getVariable(name); 71 } catch (NullPointerException e) { 72 if (env == null) { 73 throw new TemplateException("Variables are not available " 74 + "(certainly you are in a parse-time executed directive). The name of the variable " 75 + "you tried to read: " + name, null); 76 } else { 77 throw e; 78 } 79 } 80 } 81 82 public String toString() { 83 return name; 84 } 85 86 public String getCanonicalForm() { 87 return name; 88 } 89 90 boolean isLiteral() { 91 return false; 92 } 93 94 Expression _deepClone(String name, Expression subst) { 95 if(this.name.equals(name)) { 96 return subst.deepClone(null, null); 97 } 98 return new Identifier(this.name); 99 } 100 101 } 102 | Popular Tags |