1 52 53 package freemarker.core; 54 55 import java.io.IOException ; 56 import freemarker.template.*; 57 58 59 62 final class RecurseNode extends TemplateElement { 63 64 Expression targetNode, namespaces; 65 66 RecurseNode(Expression targetNode, Expression namespaces) { 67 this.targetNode = targetNode; 68 this.namespaces = namespaces; 69 } 70 71 void accept(Environment env) throws IOException , TemplateException { 72 TemplateModel node = targetNode == null ? null : targetNode.getAsTemplateModel(env); 73 TemplateModel nss = namespaces == null ? null : namespaces.getAsTemplateModel(env); 74 if (namespaces instanceof StringLiteral) { 75 nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null); 76 } 77 else if (namespaces instanceof ListLiteral) { 78 nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env); 79 } 80 if (node != null && !(node instanceof TemplateNodeModel)) { 81 throw new TemplateException("Expecting an XML node here, for expression: " + targetNode + ", found a: " + node.getClass().getName(), env); 82 } 83 if (nss != null) { 84 if (nss instanceof TemplateHashModel) { 85 SimpleSequence ss = new SimpleSequence(1); 86 ss.add(nss); 87 nss = ss; 88 } 89 else if (!(nss instanceof TemplateSequenceModel)) { 90 throw new TemplateException("Expecting a sequence of namespaces after 'using'", env); 91 } 92 } 93 94 env.recurse((TemplateNodeModel) node, (TemplateSequenceModel) nss); 95 } 96 97 public String getCanonicalForm() { 98 String result = "<#recurse"; 99 if (targetNode != null) result += (" " + targetNode.getCanonicalForm()); 100 if (namespaces != null) result += (" using " + namespaces.getCanonicalForm()); 101 return result + "/>"; 102 } 103 104 public String getDescription() { 105 return "recurse instruction"; 106 } 107 } 108 | Popular Tags |