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.KeyDeclaration; 26 27 import org.xml.sax.Attributes ; 28 29 42 class ProcessorKey extends XSLTElementProcessor 43 { 44 45 61 public void startElement( 62 StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) 63 throws org.xml.sax.SAXException 64 { 65 66 KeyDeclaration kd = new KeyDeclaration(handler.getStylesheet(), handler.nextUid()); 67 68 kd.setDOMBackPointer(handler.getOriginatingNode()); 69 kd.setLocaterInfo(handler.getLocator()); 70 setPropertiesFromAttributes(handler, rawName, attributes, kd); 71 handler.getStylesheet().setKey(kd); 72 } 73 74 83 void setPropertiesFromAttributes( 84 StylesheetHandler handler, String rawName, Attributes attributes, 85 org.apache.xalan.templates.ElemTemplateElement target) 86 throws org.xml.sax.SAXException 87 { 88 89 XSLTElementDef def = getElemDef(); 90 91 Vector processedDefs = new Vector (); 94 int nAttrs = attributes.getLength(); 95 96 for (int i = 0; i < nAttrs; i++) 97 { 98 String attrUri = attributes.getURI(i); 99 String attrLocalName = attributes.getLocalName(i); 100 XSLTAttributeDef attrDef = def.getAttributeDef(attrUri, attrLocalName); 101 102 if (null == attrDef) 103 { 104 105 handler.error(attributes.getQName(i) 107 + "attribute is not allowed on the " + rawName 108 + " element!", null); 109 } 110 else 111 { 112 String valueString = attributes.getValue(i); 113 114 if (valueString.indexOf(org.apache.xpath.compiler.Keywords.FUNC_KEY_STRING 115 + "(") >= 0) 116 handler.error( 117 XSLMessages.createMessage( 118 XSLTErrorResources.ER_INVALID_KEY_CALL, null), null); 119 120 processedDefs.addElement(attrDef); 121 attrDef.setAttrValue(handler, attrUri, attrLocalName, 122 attributes.getQName(i), attributes.getValue(i), 123 target); 124 } 125 } 126 127 XSLTAttributeDef[] attrDefs = def.getAttributes(); 128 int nAttrDefs = attrDefs.length; 129 130 for (int i = 0; i < nAttrDefs; i++) 131 { 132 XSLTAttributeDef attrDef = attrDefs[i]; 133 String defVal = attrDef.getDefault(); 134 135 if (null != defVal) 136 { 137 if (!processedDefs.contains(attrDef)) 138 { 139 attrDef.setDefAttrValue(handler, target); 140 } 141 } 142 143 if (attrDef.getRequired()) 144 { 145 if (!processedDefs.contains(attrDef)) 146 handler.error( 147 XSLMessages.createMessage( 148 XSLTErrorResources.ER_REQUIRES_ATTRIB, new Object []{ rawName, 149 attrDef.getName() }), null); 150 } 151 } 152 } 153 } 154 | Popular Tags |