You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/09/27 23:43:40 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/processor ProcessorKey.java
mmidy 00/09/27 14:43:38
Modified: java/src/org/apache/xalan/processor ProcessorKey.java
Log:
Disallow recursive key calls
Revision Changes Path
1.3 +74 -0 xml-xalan/java/src/org/apache/xalan/processor/ProcessorKey.java
Index: ProcessorKey.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorKey.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProcessorKey.java 2000/08/08 00:27:17 1.2
+++ ProcessorKey.java 2000/09/27 21:43:36 1.3
@@ -59,7 +59,11 @@
import org.apache.xalan.templates.KeyDeclaration;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
+import java.util.Vector;
+
/**
* Processor for xsl:key markup.
* <pre>
@@ -75,6 +79,7 @@
*/
class ProcessorKey extends XSLTElementProcessor
{
+ static final String FUNC_KEY_STRING = "key";
/**
* Receive notification of the start of an xsl:key element.
*
@@ -110,5 +115,74 @@
setPropertiesFromAttributes(handler, rawName, attributes, kd);
handler.getStylesheet().setKey(kd);
+ }
+
+ /**
+ * Set the properties of an object from the given attribute list.
+ * @param handler The stylesheet's Content handler, needed for
+ * error reporting.
+ * @param rawName The raw name of the owner element, needed for
+ * error reporting.
+ * @param attributes The list of attributes.
+ * @param target The target element where the properties will be set.
+ */
+ void setPropertiesFromAttributes(StylesheetHandler handler,
+ String rawName,
+ Attributes attributes,
+ Object target)
+ throws SAXException
+ {
+ XSLTElementDef def = getElemDef();
+
+ // Keep track of which XSLTAttributeDefs have been processed, so
+ // I can see which default values need to be set.
+ Vector processedDefs = new Vector();
+ int nAttrs = attributes.getLength();
+ for(int i = 0; i < nAttrs; i++)
+ {
+ String attrUri = attributes.getURI(i);
+ String attrLocalName = attributes.getLocalName(i);
+ XSLTAttributeDef attrDef = def.getAttributeDef( attrUri, attrLocalName );
+
+ if(null == attrDef)
+ {
+ // Then barf, because this element does not allow this attribute.
+ handler.error(attributes.getQName(i)+
+ "attribute is not allowed on the "+
+ rawName+" element!", null);
+ }
+ else
+ {
+ String valueString = attributes.getValue(i);
+ if (valueString.indexOf(FUNC_KEY_STRING) >= 0)
+ handler.error(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_KEY_CALL, null), null);
+ processedDefs.addElement(attrDef);
+ attrDef.setAttrValue(handler, attrUri, attrLocalName,
+ attributes.getQName(i),
+ attributes.getValue(i),
+ target);
+ }
+ }
+
+ XSLTAttributeDef[] attrDefs = def.getAttributes();
+ int nAttrDefs = attrDefs.length;
+ for(int i = 0; i < nAttrDefs; i++)
+ {
+ XSLTAttributeDef attrDef = attrDefs[i];
+ String defVal = attrDef.getDefault();
+ if(null != defVal)
+ {
+ if(!processedDefs.contains(attrDef))
+ {
+ attrDef.setDefAttrValue(handler, target);
+ }
+ }
+ if (attrDef.getRequired())
+ {
+ if(!processedDefs.contains(attrDef))
+ handler.error(XSLMessages.createMessage(XSLTErrorResources.ER_REQUIRES_ATTRIB, new Object[]{rawName, attrDef.getName()}) , null);
+ }
+ }
+
}
}