1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd; 59 60 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 61 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 62 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 63 import com.sun.org.apache.xerces.internal.xni.Augmentations; 64 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 65 import com.sun.org.apache.xerces.internal.xni.QName; 66 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 67 import com.sun.org.apache.xerces.internal.xni.XNIException; 68 69 98 public class XML11NSDTDValidator extends XML11DTDValidator { 99 100 101 private QName fAttributeQName = new QName(); 102 103 104 protected final void startNamespaceScope(QName element, XMLAttributes attributes, Augmentations augs) 105 throws XNIException { 106 107 fNamespaceContext.pushContext(); 109 110 if (element.prefix == XMLSymbols.PREFIX_XMLNS) { 111 fErrorReporter.reportError( 112 XMLMessageFormatter.XMLNS_DOMAIN, 113 "ElementXMLNSPrefix", 114 new Object [] { element.rawname }, 115 XMLErrorReporter.SEVERITY_FATAL_ERROR); 116 } 117 118 int length = attributes.getLength(); 120 for (int i = 0; i < length; i++) { 121 String localpart = attributes.getLocalName(i); 122 String prefix = attributes.getPrefix(i); 123 if (prefix == XMLSymbols.PREFIX_XMLNS || prefix == XMLSymbols.EMPTY_STRING 126 && localpart == XMLSymbols.PREFIX_XMLNS) { 127 128 String uri = fSymbolTable.addSymbol(attributes.getValue(i)); 130 131 if (prefix == XMLSymbols.PREFIX_XMLNS && localpart == XMLSymbols.PREFIX_XMLNS) { 133 fErrorReporter.reportError( 134 XMLMessageFormatter.XMLNS_DOMAIN, 135 "CantBindXMLNS", 136 new Object [] { attributes.getQName(i)}, 137 XMLErrorReporter.SEVERITY_FATAL_ERROR); 138 } 139 140 if (uri == NamespaceContext.XMLNS_URI) { 142 fErrorReporter.reportError( 143 XMLMessageFormatter.XMLNS_DOMAIN, 144 "CantBindXMLNS", 145 new Object [] { attributes.getQName(i)}, 146 XMLErrorReporter.SEVERITY_FATAL_ERROR); 147 } 148 149 if (localpart == XMLSymbols.PREFIX_XML) { 151 if (uri != NamespaceContext.XML_URI) { 152 fErrorReporter.reportError( 153 XMLMessageFormatter.XMLNS_DOMAIN, 154 "CantBindXML", 155 new Object [] { attributes.getQName(i)}, 156 XMLErrorReporter.SEVERITY_FATAL_ERROR); 157 } 158 } 159 else { 161 if (uri == NamespaceContext.XML_URI) { 162 fErrorReporter.reportError( 163 XMLMessageFormatter.XMLNS_DOMAIN, 164 "CantBindXML", 165 new Object [] { attributes.getQName(i)}, 166 XMLErrorReporter.SEVERITY_FATAL_ERROR); 167 } 168 } 169 170 prefix = localpart != XMLSymbols.PREFIX_XMLNS ? localpart : XMLSymbols.EMPTY_STRING; 171 172 fNamespaceContext.declarePrefix(prefix, uri.length() != 0 ? uri : null); 176 } 177 } 178 179 String prefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; 181 element.uri = fNamespaceContext.getURI(prefix); 182 if (element.prefix == null && element.uri != null) { 183 element.prefix = XMLSymbols.EMPTY_STRING; 184 } 185 if (element.prefix != null && element.uri == null) { 186 fErrorReporter.reportError( 187 XMLMessageFormatter.XMLNS_DOMAIN, 188 "ElementPrefixUnbound", 189 new Object [] { element.prefix, element.rawname }, 190 XMLErrorReporter.SEVERITY_FATAL_ERROR); 191 } 192 193 for (int i = 0; i < length; i++) { 195 attributes.getName(i, fAttributeQName); 196 String aprefix = fAttributeQName.prefix != null ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING; 197 String arawname = fAttributeQName.rawname; 198 if (arawname == XMLSymbols.PREFIX_XMLNS) { 199 fAttributeQName.uri = fNamespaceContext.getURI(XMLSymbols.PREFIX_XMLNS); 200 attributes.setName(i, fAttributeQName); 201 } else if (aprefix != XMLSymbols.EMPTY_STRING) { 202 fAttributeQName.uri = fNamespaceContext.getURI(aprefix); 203 if (fAttributeQName.uri == null) { 204 fErrorReporter.reportError( 205 XMLMessageFormatter.XMLNS_DOMAIN, 206 "AttributePrefixUnbound", 207 new Object [] { element.rawname, arawname, aprefix }, 208 XMLErrorReporter.SEVERITY_FATAL_ERROR); 209 } 210 attributes.setName(i, fAttributeQName); 211 } 212 } 213 214 int attrCount = attributes.getLength(); 217 for (int i = 0; i < attrCount - 1; i++) { 218 String auri = attributes.getURI(i); 219 if (auri == null || auri == NamespaceContext.XMLNS_URI) { 220 continue; 221 } 222 String alocalpart = attributes.getLocalName(i); 223 for (int j = i + 1; j < attrCount; j++) { 224 String blocalpart = attributes.getLocalName(j); 225 String buri = attributes.getURI(j); 226 if (alocalpart == blocalpart && auri == buri) { 227 fErrorReporter.reportError( 228 XMLMessageFormatter.XMLNS_DOMAIN, 229 "AttributeNSNotUnique", 230 new Object [] { element.rawname, alocalpart, auri }, 231 XMLErrorReporter.SEVERITY_FATAL_ERROR); 232 } 233 } 234 } 235 236 } 238 239 protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty) 240 throws XNIException { 241 242 String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; 244 element.uri = fNamespaceContext.getURI(eprefix); 245 if (element.uri != null) { 246 element.prefix = eprefix; 247 } 248 249 if (fDocumentHandler != null) { 251 if (!isEmpty) { 252 fDocumentHandler.endElement(element, augs); 253 } 254 } 255 256 fNamespaceContext.popContext(); 258 259 } } 261 | Popular Tags |