1 52 53 package freemarker.core; 54 55 import java.util.*; 56 import java.io.IOException ; 57 import freemarker.template.TemplateException; 58 59 62 final class MixedContent extends TemplateElement { 63 64 MixedContent() 65 { 66 nestedElements = new ArrayList(); 67 } 68 69 void addElement(TemplateElement element) { 70 nestedElements.add(element); 71 } 72 73 TemplateElement postParseCleanup(boolean stripWhitespace) 74 throws ParseException 75 { 76 super.postParseCleanup(stripWhitespace); 77 if (nestedElements.size() == 1) { 78 return (TemplateElement) nestedElements.get(0); 79 } 80 return this; 81 } 82 83 87 void accept(Environment env) 88 throws TemplateException, IOException 89 { 90 for (int i=0; i<nestedElements.size(); i++) { 91 TemplateElement element = (TemplateElement) nestedElements.get(i); 92 env.visit(element); 93 } 94 } 95 96 public String getCanonicalForm() { 97 StringBuffer buf = new StringBuffer (); 98 for (int i = 0; i<nestedElements.size(); i++) { 99 TemplateElement element = (TemplateElement) nestedElements.get(i); 100 buf.append(element.getCanonicalForm()); 101 } 102 return buf.toString(); 103 } 104 105 public String getDescription() { 106 if (parent == null) { 107 return "root element"; 108 } 109 return "content"; } 111 112 boolean isIgnorable() { 113 return nestedElements == null || nestedElements.size() == 0; 114 } 115 } 116 | Popular Tags |