1 16 19 package org.apache.xalan.processor; 20 21 import java.util.Vector ; 22 23 import org.apache.xalan.res.XSLMessages; 24 import org.apache.xalan.res.XSLTErrorResources; 25 import org.apache.xalan.templates.ElemTemplateElement; 26 import org.apache.xml.utils.IntStack; 27 28 import org.xml.sax.Attributes ; 29 import org.xml.sax.InputSource ; 30 import org.xml.sax.helpers.AttributesImpl ; 31 32 37 public class XSLTElementProcessor extends ElemTemplateElement 38 { 39 40 44 XSLTElementProcessor(){} 45 46 private IntStack m_savedLastOrder; 47 48 51 private XSLTElementDef m_elemDef; 52 53 58 XSLTElementDef getElemDef() 59 { 60 return m_elemDef; 61 } 62 63 68 void setElemDef(XSLTElementDef def) 69 { 70 m_elemDef = def; 71 } 72 73 85 public InputSource resolveEntity( 86 StylesheetHandler handler, String publicId, String systemId) 87 throws org.xml.sax.SAXException 88 { 89 return null; 90 } 91 92 103 public void notationDecl(StylesheetHandler handler, String name, 104 String publicId, String systemId) 105 { 106 107 } 109 110 122 public void unparsedEntityDecl(StylesheetHandler handler, String name, 123 String publicId, String systemId, 124 String notationName) 125 { 126 127 } 129 130 136 public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException 137 { 138 139 } 141 142 153 public void startElement( 154 StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) 155 throws org.xml.sax.SAXException 156 { 157 158 if (m_savedLastOrder == null) 159 m_savedLastOrder = new IntStack(); 160 m_savedLastOrder.push(getElemDef().getLastOrder()); 161 getElemDef().setLastOrder(-1); 162 } 163 164 175 public void endElement( 176 StylesheetHandler handler, String uri, String localName, String rawName) 177 throws org.xml.sax.SAXException 178 { 179 if (m_savedLastOrder != null && !m_savedLastOrder.empty()) 180 getElemDef().setLastOrder(m_savedLastOrder.pop()); 181 182 if (!getElemDef().getRequiredFound()) 183 handler.error(XSLTErrorResources.ER_REQUIRED_ELEM_NOT_FOUND, new Object []{getElemDef().getRequiredElem()}, null); 184 } 185 186 196 public void characters( 197 StylesheetHandler handler, char ch[], int start, int length) 198 throws org.xml.sax.SAXException 199 { 200 handler.error(XSLTErrorResources.ER_CHARS_NOT_ALLOWED, null, null); } 203 204 214 public void ignorableWhitespace( 215 StylesheetHandler handler, char ch[], int start, int length) 216 throws org.xml.sax.SAXException 217 { 218 219 } 221 222 231 public void processingInstruction( 232 StylesheetHandler handler, String target, String data) 233 throws org.xml.sax.SAXException 234 { 235 236 } 238 239 246 public void skippedEntity(StylesheetHandler handler, String name) 247 throws org.xml.sax.SAXException 248 { 249 250 } 252 253 262 void setPropertiesFromAttributes( 263 StylesheetHandler handler, String rawName, Attributes attributes, 264 ElemTemplateElement target) 265 throws org.xml.sax.SAXException 266 { 267 setPropertiesFromAttributes(handler, rawName, attributes, target, true); 268 } 269 270 284 Attributes setPropertiesFromAttributes( 285 StylesheetHandler handler, String rawName, Attributes attributes, 286 ElemTemplateElement target, boolean throwError) 287 throws org.xml.sax.SAXException 288 { 289 290 XSLTElementDef def = getElemDef(); 291 AttributesImpl undefines = null; 292 boolean isCompatibleMode = ((null != handler.getStylesheet() 293 && handler.getStylesheet().getCompatibleMode()) 294 || !throwError); 295 if (isCompatibleMode) 296 undefines = new AttributesImpl (); 297 298 299 Vector processedDefs = new Vector (); 302 303 Vector errorDefs = new Vector (); 305 int nAttrs = attributes.getLength(); 306 307 for (int i = 0; i < nAttrs; i++) 308 { 309 String attrUri = attributes.getURI(i); 310 if((null != attrUri) && (attrUri.length() == 0) 312 && (attributes.getQName(i).startsWith("xmlns:") || 313 attributes.getQName(i).equals("xmlns"))) 314 { 315 attrUri = org.apache.xalan.templates.Constants.S_XMLNAMESPACEURI; 316 } 317 String attrLocalName = attributes.getLocalName(i); 318 XSLTAttributeDef attrDef = def.getAttributeDef(attrUri, attrLocalName); 319 320 if (null == attrDef) 321 { 322 if (!isCompatibleMode) 323 { 324 325 handler.error(XSLTErrorResources.ER_ATTR_NOT_ALLOWED, new Object []{attributes.getQName(i), rawName}, null); } 330 else 331 { 332 undefines.addAttribute(attrUri, attrLocalName, 333 attributes.getQName(i), 334 attributes.getType(i), 335 attributes.getValue(i)); 336 } 337 } 338 else 339 { 340 342 boolean success = attrDef.setAttrValue(handler, attrUri, attrLocalName, 343 attributes.getQName(i), attributes.getValue(i), 344 target); 345 346 if (success) 348 processedDefs.addElement(attrDef); 349 else 350 errorDefs.addElement(attrDef); 351 } 352 } 353 354 XSLTAttributeDef[] attrDefs = def.getAttributes(); 355 int nAttrDefs = attrDefs.length; 356 357 for (int i = 0; i < nAttrDefs; i++) 358 { 359 XSLTAttributeDef attrDef = attrDefs[i]; 360 String defVal = attrDef.getDefault(); 361 362 if (null != defVal) 363 { 364 if (!processedDefs.contains(attrDef)) 365 { 366 attrDef.setDefAttrValue(handler, target); 367 } 368 } 369 370 if (attrDef.getRequired()) 371 { 372 if ((!processedDefs.contains(attrDef)) && (!errorDefs.contains(attrDef))) 373 handler.error( 374 XSLMessages.createMessage( 375 XSLTErrorResources.ER_REQUIRES_ATTRIB, new Object []{ rawName, 376 attrDef.getName() }), null); 377 } 378 } 379 380 return undefines; 381 } 382 } 383 | Popular Tags |