mrglavas 2004/10/28 22:05:13 Modified: java/src/org/apache/xerces/impl/xs/traversers XSAttributeChecker.java java/src/org/apache/xerces/impl/xs SchemaSymbols.java Log: Both <schema> and <documentation> may have an xml:lang attribute of type language. We need to check that when these attributes appear in a schema document on these elements that their value is valid with respect to the language type. Also fixed a couple bugs where we were incorrectly processing xml* and xmlns* attributes. Revision Changes Path 1.36 +41 -26 xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java Index: XSAttributeChecker.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- XSAttributeChecker.java 29 Oct 2004 04:07:12 -0000 1.35 +++ XSAttributeChecker.java 29 Oct 2004 05:05:13 -0000 1.36 @@ -18,7 +18,6 @@ import java.util.Enumeration; import java.util.Hashtable; -import java.util.Locale; import java.util.StringTokenizer; import java.util.Vector; @@ -30,13 +29,13 @@ import org.apache.xerces.impl.xs.XSAttributeDecl; import org.apache.xerces.impl.xs.XSGrammarBucket; import org.apache.xerces.impl.xs.XSWildcardDecl; -import org.apache.xerces.xs.XSConstants; import org.apache.xerces.impl.xs.util.XInt; import org.apache.xerces.impl.xs.util.XIntPool; import org.apache.xerces.util.DOMUtil; import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.XMLSymbols; import org.apache.xerces.xni.QName; +import org.apache.xerces.xs.XSConstants; import org.w3c.dom.Attr; import org.w3c.dom.Element; @@ -113,6 +112,7 @@ public static final int ATTIDX_VALUE = ATTIDX_COUNT++; public static final int ATTIDX_ENUMNSDECLS = ATTIDX_COUNT++; public static final int ATTIDX_VERSION = ATTIDX_COUNT++; + public static final int ATTIDX_XML_LANG = ATTIDX_COUNT++; public static final int ATTIDX_XPATH = ATTIDX_COUNT++; public static final int ATTIDX_FROMDEFAULT = ATTIDX_COUNT++; //public static final int ATTIDX_OTHERVALUES = ATTIDX_COUNT++; @@ -156,9 +156,10 @@ protected static final int DT_NCNAME = 5; protected static final int DT_XPATH = 6; protected static final int DT_XPATH1 = 7; + protected static final int DT_LANGUAGE = 8; // used to store extra datatype validators - protected static final int DT_COUNT = DT_XPATH1 + 1; + protected static final int DT_COUNT = DT_LANGUAGE + 1; private static final XSSimpleType[] fExtraDVs = new XSSimpleType[DT_COUNT]; static { // step 5: register all datatype validators for new types @@ -179,6 +180,8 @@ fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; // xpath = a subset of XPath expression fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; + // language + fExtraDVs[DT_LANGUAGE] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_LANGUAGE); } protected static final int DT_BLOCK = -1; @@ -247,6 +250,7 @@ int ATT_VALUE_STR_N = attCount++; int ATT_VALUE_WS_N = attCount++; int ATT_VERSION_N = attCount++; + int ATT_XML_LANG = attCount++; int ATT_XPATH_R = attCount++; int ATT_XPATH1_R = attCount++; @@ -432,6 +436,10 @@ DT_TOKEN, ATTIDX_VERSION, null); + allAttrs[ATT_XML_LANG] = new OneAttr(SchemaSymbols.ATT_XML_LANG, + DT_LANGUAGE, + ATTIDX_XML_LANG, + null); allAttrs[ATT_XPATH_R] = new OneAttr(SchemaSymbols.ATT_XPATH, DT_XPATH, ATTIDX_XPATH, @@ -779,10 +787,11 @@ fEleAttrsMapL.put(SchemaSymbols.ELT_APPINFO, oneEle); // for element "documentation" - local - attrList = Container.getContainer(1); + attrList = Container.getContainer(2); // source = anyURI attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]); - // xml:lang = language ??? + // xml:lang = language + attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]); oneEle = new OneElement (attrList); fEleAttrsMapG.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle); fEleAttrsMapL.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle); @@ -829,7 +838,7 @@ fEleAttrsMapL.put(SchemaSymbols.ELT_UNION, oneEle); // for element "schema" - global - attrList = Container.getContainer(7); + attrList = Container.getContainer(8); // attributeFormDefault = (qualified | unqualified) : unqualified attrList.put(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, allAttrs[ATT_ATTRIBUTE_FD_D]); // blockDefault = (#all | List of (substitution | extension | restriction | list | union)) : '' @@ -844,7 +853,8 @@ attrList.put(SchemaSymbols.ATT_TARGETNAMESPACE, allAttrs[ATT_TARGET_N_N]); // version = token attrList.put(SchemaSymbols.ATT_VERSION, allAttrs[ATT_VERSION_N]); - // xml:lang = language ??? + // xml:lang = language + attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]); oneEle = new OneElement (attrList); fEleAttrsMapG.put(SchemaSymbols.ELT_SCHEMA, oneEle); @@ -1067,29 +1077,27 @@ // get the attribute name/value //String attrName = DOMUtil.getLocalName(sattr); String attrName = sattr.getName(); + String attrURI = DOMUtil.getNamespaceURI(sattr); String attrVal = DOMUtil.getValue(sattr); - - // we don't want to add namespace declarations to the non-schema attributes - if (attrName.startsWith("xmlns")) { - continue; - } - - // skip anything starts with x/X m/M l/L - // add this to the list of "non-schema" attributes - if (attrName.toLowerCase(Locale.ENGLISH).startsWith("xml")) { - if(attrValues[ATTIDX_NONSCHEMA] == null) { - // these are usually small - attrValues[ATTIDX_NONSCHEMA] = new Vector(4,2); + + if (attrName.startsWith("xml")) { + String attrPrefix = DOMUtil.getPrefix(sattr); + // we don't want to add namespace declarations to the non-schema attributes + if ("xmlns".equals(attrPrefix) || "xmlns".equals(attrName)) { + continue; + } + // Both <schema> and <documentation> may have an xml:lang attribute. + // Set the URI for this attribute to null so that we process it + // like any other schema attribute. + else if (SchemaSymbols.ATT_XML_LANG.equals(attrName) && + (SchemaSymbols.ELT_SCHEMA.equals(elName) || + SchemaSymbols.ELT_DOCUMENTATION.equals(elName))) { + attrURI = null; } - ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrName); - ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrVal); - //otherValues.put(attrName, attrVal); - continue; } // for attributes with namespace prefix // - String attrURI = DOMUtil.getNamespaceURI(sattr); if (attrURI != null && attrURI.length() != 0) { // attributes with schema namespace are not allowed // and not allowed on "document" and "appInfo" @@ -1222,7 +1230,14 @@ // To validate these types, we don't actually need to normalize the // strings. We only need to remove the whitespace from both ends. // In some special cases (list types), StringTokenizer can correctly - // process the un-normalized whitespace. + // process the un-normalized whitespace. + /** + * REVISIT: Trim removes all leading and trailing characters less + * than or equal to U+0020. This is okay for XML 1.0 since all + * of the valid characters in that range are white space but + * in XML 1.1 control chars are allowed. We shouldn't be trimming + * those. -- mrglavas + */ String value = ivalue.trim(); Object retValue = null; Vector memberType; 1.10 +3 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/SchemaSymbols.java Index: SchemaSymbols.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/SchemaSymbols.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SchemaSymbols.java 6 Oct 2004 15:14:55 -0000 1.9 +++ SchemaSymbols.java 29 Oct 2004 05:05:13 -0000 1.10 @@ -88,7 +88,7 @@ public static final String ELT_UNIQUE = "unique".intern(); public static final String ELT_WHITESPACE = "whiteSpace".intern(); - // all possible schema attribute names + // all possible schema attribute names (and xml:lang defined on <schema> and <documentation>) public static final String ATT_ABSTRACT = "abstract".intern(); public static final String ATT_ATTRIBUTEFORMDEFAULT = "attributeFormDefault".intern(); public static final String ATT_BASE = "base".intern(); @@ -122,6 +122,7 @@ public static final String ATT_USE = "use".intern(); public static final String ATT_VALUE = "value".intern(); public static final String ATT_VERSION = "version".intern(); + public static final String ATT_XML_LANG = "xml:lang".intern(); public static final String ATT_XPATH = "xpath".intern(); // all possible schema attribute values
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]