1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.res.XSLTErrorResources; 24 import org.apache.xalan.transformer.TransformerImpl; 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.objects.XObject; 27 28 37 public class ElemChoose extends ElemTemplateElement 38 { 39 40 46 public int getXSLToken() 47 { 48 return Constants.ELEMNAME_CHOOSE; 49 } 50 51 56 public String getNodeName() 57 { 58 return Constants.ELEMNAME_CHOOSE_STRING; 59 } 60 61 65 public ElemChoose(){} 66 67 77 public void execute(TransformerImpl transformer) throws TransformerException 78 { 79 80 if (TransformerImpl.S_DEBUG) 81 transformer.getTraceManager().fireTraceEvent(this); 82 83 boolean found = false; 84 85 for (ElemTemplateElement childElem = getFirstChildElem(); 86 childElem != null; childElem = childElem.getNextSiblingElem()) 87 { 88 int type = childElem.getXSLToken(); 89 90 if (Constants.ELEMNAME_WHEN == type) 91 { 92 found = true; 93 94 ElemWhen when = (ElemWhen) childElem; 95 96 XPathContext xctxt = transformer.getXPathContext(); 98 int sourceNode = xctxt.getCurrentNode(); 99 100 102 105 if (TransformerImpl.S_DEBUG) 106 { 107 XObject test = when.getTest().execute(xctxt, sourceNode, when); 108 109 if (TransformerImpl.S_DEBUG) 110 transformer.getTraceManager().fireSelectedEvent(sourceNode, when, 111 "test", when.getTest(), test); 112 113 if (test.bool()) 114 { 115 transformer.getTraceManager().fireTraceEvent(when); 116 117 transformer.executeChildTemplates(when, true); 118 119 transformer.getTraceManager().fireTraceEndEvent(when); 120 121 return; 122 } 123 124 } 125 else if (when.getTest().bool(xctxt, sourceNode, when)) 126 { 127 transformer.executeChildTemplates(when, true); 128 129 return; 130 } 131 } 132 else if (Constants.ELEMNAME_OTHERWISE == type) 133 { 134 found = true; 135 136 if (TransformerImpl.S_DEBUG) 137 transformer.getTraceManager().fireTraceEvent(childElem); 138 139 transformer.executeChildTemplates(childElem, true); 141 142 if (TransformerImpl.S_DEBUG) 143 transformer.getTraceManager().fireTraceEndEvent(childElem); 144 return; 145 } 146 } 147 148 if (!found) 149 transformer.getMsgMgr().error( 150 this, XSLTErrorResources.ER_CHOOSE_REQUIRES_WHEN); 151 152 if (TransformerImpl.S_DEBUG) 153 transformer.getTraceManager().fireTraceEndEvent(this); 154 } 155 156 165 public ElemTemplateElement appendChild(ElemTemplateElement newChild) 166 { 167 168 int type = ((ElemTemplateElement) newChild).getXSLToken(); 169 170 switch (type) 171 { 172 case Constants.ELEMNAME_WHEN : 173 case Constants.ELEMNAME_OTHERWISE : 174 175 break; 177 default : 178 error(XSLTErrorResources.ER_CANNOT_ADD, 179 new Object []{ newChild.getNodeName(), 180 this.getNodeName() }); 182 } 184 185 return super.appendChild(newChild); 186 } 187 188 192 public boolean canAcceptVariables() 193 { 194 return false; 195 } 196 197 } 198 | Popular Tags |