1 28 29 package com.caucho.xsl.java; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.xsl.XslParseException; 33 34 import java.util.ArrayList ; 35 36 39 public class XslChoose extends XslNode { 40 private ArrayList <XslWhen> _tests = new ArrayList <XslWhen>(); 41 private XslOtherwise _otherwise; 42 43 46 public String getTagName() 47 { 48 return "xsl:choose"; 49 } 50 51 54 public void addChild(XslNode node) 55 throws XslParseException 56 { 57 if (node instanceof XslWhen) { 58 _tests.add((XslWhen) node); 59 } 60 else if (node instanceof XslOtherwise) { 61 _otherwise = (XslOtherwise) node; 62 } 63 else 64 super.addChild(node); 65 } 66 67 72 public void generate(JavaWriter out) 73 throws Exception 74 { 75 if (_tests.size() == 0) { 76 if (_otherwise != null) 77 _otherwise.generate(out); 78 } 79 else { 80 for (int i = 0; i < _tests.size(); i++) { 81 if (i != 0) 82 out.print("else "); 83 84 _tests.get(i).generate(out); 85 } 86 87 if (_otherwise != null) { 88 out.print("else "); 89 _otherwise.generate(out); 90 } 91 } 92 } 93 } 94 | Popular Tags |