MCPcopy Create free account
hub / github.com/apache/freemarker / accept

Method accept

src/main/java/freemarker/core/Include.java:123–170  ·  view source on GitHub ↗
(Environment env)

Source from the content-addressed store, hash-verified

121 }
122
123 void accept(Environment env) throws TemplateException, IOException {
124 String templateNameString = includedTemplateName.getStringValue(env);
125 if( templateNameString == null ) {
126 String msg = "Error " + getStartLocation()
127 + "The expression " + includedTemplateName + " is undefined.";
128 throw new InvalidReferenceException(msg, env);
129 }
130 String enc = encoding;
131 if (encoding == null && encodingExp != null) {
132 enc = encodingExp.getStringValue(env);
133 }
134
135 boolean parse = this.parse;
136 if (parseExp != null) {
137 TemplateModel tm = parseExp.getAsTemplateModel(env);
138 if(tm == null) {
139 if(env.isClassicCompatible()) {
140 parse = false;
141 }
142 else {
143 assertNonNull(tm, parseExp, env);
144 }
145 }
146 if (tm instanceof TemplateScalarModel) {
147 parse = getYesNo(EvaluationRules.getString((TemplateScalarModel)tm, parseExp, env));
148 }
149 else {
150 parse = parseExp.isTrue(env);
151 }
152 }
153
154 Template includedTemplate;
155 try {
156 templateNameString = TemplateCache.getFullTemplatePath(env, templatePath, templateNameString);
157 includedTemplate = env.getTemplateForInclusion(templateNameString, enc, parse);
158 }
159 catch (ParseException pe) {
160 String msg = "Error parsing included template "
161 + templateNameString + "\n" + pe.getMessage();
162 throw new TemplateException(msg, pe, env);
163 }
164 catch (IOException ioe) {
165 String msg = "Error reading included file "
166 + templateNameString;
167 throw new TemplateException(msg, ioe, env);
168 }
169 env.include(includedTemplate);
170 }
171
172 public String getCanonicalForm() {
173 StringBuilder buf = new StringBuilder("<#include ");

Callers

nothing calls this directly

Calls 12

getYesNoMethod · 0.95
getStringMethod · 0.95
getFullTemplatePathMethod · 0.95
getStartLocationMethod · 0.80
getAsTemplateModelMethod · 0.80
isClassicCompatibleMethod · 0.80
assertNonNullMethod · 0.80
getStringValueMethod · 0.45
isTrueMethod · 0.45
getMessageMethod · 0.45
includeMethod · 0.45

Tested by

no test coverage detected