public boolean contains(String path) { if (stack.contains(path)) { return true; } if (parent != null) { return parent.contains(path); } return false; }
public void popFromStack() { fromStack.pop(); }
public void pushFromStack(String path, int lineNumber, int startPosition) { fromStack.push(path, lineNumber, startPosition); }
try { if (interpreter.getConfig().isEnableRecursiveMacroCalls()) { macroStack.pushWithoutCycleCheck(getName()); } else { macroStack.push(getName(), -1, -1); throw new ELException(LocalMessages.get("error.function.invocation", getName()), e.getCause()); } finally { macroStack.pop();
@Override public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { HelperStringTokenizer helper = new HelperStringTokenizer(tagNode.getHelpers()); if (!helper.hasNext()) { throw new TemplateSyntaxException(tagNode.getMaster().getImage(), "Tag 'include' expects template path", tagNode.getLineNumber(), tagNode.getStartPosition()); } String path = StringUtils.trimToEmpty(helper.next()); String templateFile = interpreter.resolveString(path, tagNode.getLineNumber(), tagNode.getStartPosition()); try { interpreter.getContext().getIncludePathStack().push(templateFile, tagNode.getLineNumber(), tagNode.getStartPosition()); } catch (IncludeTagCycleException e) { interpreter.addError(new TemplateError(ErrorType.WARNING, ErrorReason.EXCEPTION, ErrorItem.TAG, "Include cycle detected for path: '" + templateFile + "'", null, tagNode.getLineNumber(), tagNode.getStartPosition(), e, BasicTemplateErrorCategory.INCLUDE_CYCLE_DETECTED, ImmutableMap.of("path", templateFile))); return ""; } try { String template = interpreter.getResource(templateFile); Node node = interpreter.parse(template); interpreter.getContext().addDependency("coded_files", templateFile); JinjavaInterpreter child = new JinjavaInterpreter(interpreter); String result = child.render(node); interpreter.addAllErrors(child.getErrorsCopy()); return result; } catch (IOException e) { throw new InterpretException(e.getMessage(), e, tagNode.getLineNumber(), tagNode.getStartPosition()); } finally { interpreter.getContext().getIncludePathStack().pop(); } }
public Context(Context parent, Map<String, ?> bindings, Map<Library, Set<String>> disabled) { super(parent); this.disabled = disabled; if (bindings != null) { this.putAll(bindings); } this.parent = parent; this.extendPathStack = new CallStack(parent == null ? null : parent.getExtendPathStack(), ExtendsTagCycleException.class); this.importPathStack = new CallStack(parent == null ? null : parent.getImportPathStack(), ImportTagCycleException.class); this.includePathStack = new CallStack(parent == null ? null : parent.getIncludePathStack(), IncludeTagCycleException.class); this.macroStack = new CallStack(parent == null ? null : parent.getMacroStack(), MacroTagCycleException.class); this.fromStack = new CallStack(parent == null ? null : parent.getFromStack(), FromTagCycleException.class); if (disabled == null) { disabled = new HashMap<>(); } this.expTestLibrary = new ExpTestLibrary(parent == null, disabled.get(Library.EXP_TEST)); this.filterLibrary = new FilterLibrary(parent == null, disabled.get(Library.FILTER)); this.tagLibrary = new TagLibrary(parent == null, disabled.get(Library.TAG)); this.functionLibrary = new FunctionLibrary(parent == null, disabled.get(Library.FUNCTION)); }
public Optional<String> pop() { if (stack.isEmpty()) { if (parent != null) { return parent.pop(); } return Optional.empty(); } return Optional.of(stack.pop()); } }
interpreter.getContext().getImportPathStack().push(path, tagNode.getLineNumber(), tagNode.getStartPosition()); } catch (ImportTagCycleException e) { interpreter.addError(new TemplateError(ErrorType.WARNING, ErrorReason.EXCEPTION, ErrorItem.TAG,
public void push(String path, int lineNumber, int startPosition) { if (contains(path)) { throw TagCycleException.create(exceptionClass, path, Optional.of(lineNumber), Optional.of(startPosition)); } stack.push(path); }
context.getExtendPathStack().pop();
@Override public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { HelperStringTokenizer tokenizer = new HelperStringTokenizer(tagNode.getHelpers()); if (!tokenizer.hasNext()) { throw new TemplateSyntaxException(tagNode.getMaster().getImage(), "Tag 'extends' expects template path", tagNode.getLineNumber(), tagNode.getStartPosition()); } String path = interpreter.resolveString(tokenizer.next(), tagNode.getLineNumber(), tagNode.getStartPosition()); interpreter.getContext().getExtendPathStack().push(path, tagNode.getLineNumber(), tagNode.getStartPosition()); try { String template = interpreter.getResource(path); Node node = interpreter.parse(template); interpreter.getContext().addDependency("coded_files", path); interpreter.addExtendParentRoot(node); return ""; } catch (IOException e) { throw new InterpretException(e.getMessage(), e, tagNode.getLineNumber(), tagNode.getStartPosition()); } }