1 52 53 package freemarker.core; 54 55 import java.io.IOException ; 56 import freemarker.template.*; 57 58 61 final class Case extends TemplateElement { 62 63 64 boolean isDefault; 67 Expression expression; 68 69 Case(Expression expression, TemplateElement nestedBlock, boolean isDefault) 70 { 71 this.expression = expression; 72 this.nestedBlock = nestedBlock; 73 this.isDefault = isDefault; 74 } 75 76 void accept(Environment env) 77 throws TemplateException, IOException 78 { 79 if (nestedBlock != null) { 80 env.visit(nestedBlock); 81 } 82 } 83 84 public String getCanonicalForm() { 85 StringBuffer buf = new StringBuffer (); 86 if (isDefault) { 87 buf.append("<#default>"); 88 } 89 else { 90 buf.append("<#case "); 91 buf.append(expression.getCanonicalForm()); 92 buf.append(">"); 93 } 94 if (nestedBlock != null) { 95 buf.append(nestedBlock.getCanonicalForm()); 96 } 97 return buf.toString(); 98 } 99 100 public String getDescription() { 101 if (isDefault) { 102 return "default case"; 103 } 104 return "case " + expression; 105 } 106 } 107 | Popular Tags |