1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.dom; 59 60 import com.sun.org.apache.xerces.internal.parsers.NonValidatingConfiguration; 61 import com.sun.org.apache.xerces.internal.impl.Constants; 62 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 63 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 64 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; 65 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 66 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 67 import com.sun.org.apache.xerces.internal.xni.QName; 68 import com.sun.org.apache.xerces.internal.xni.Augmentations; 69 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 70 import com.sun.org.apache.xerces.internal.xni.XMLString; 71 import com.sun.org.apache.xerces.internal.xni.XNIException; 72 import com.sun.org.apache.xerces.internal.util.XMLChar; 73 74 import org.w3c.dom.Element ; 75 76 83 public class DOMParser extends com.sun.org.apache.xerces.internal.parsers.DOMParser { 84 85 86 protected static final String ENTITY_MANAGER = 87 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 88 89 90 protected static final String DOCUMENT_CLASS = 91 Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_CLASS_NAME_PROPERTY; 92 93 94 protected static final String DEFER_EXPANSION = 95 Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE; 96 97 98 public static final String ERROR_REPORTER = 99 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 100 101 protected XMLLocator fLocator; 103 104 public DocumentImpl fDocumentImpl; 107 108 private DOMNodePool fNodePool; 109 110 114 117 public DOMParser() { 118 super(new NonValidatingConfiguration()); 122 try { 123 setProperty(DOCUMENT_CLASS, "com.sun.org.apache.xerces.internal.impl.xs.dom.DocumentImpl"); 125 setFeature(DEFER_EXPANSION, false); 127 128 } 129 catch (Exception e) { 130 } 131 fNodePool = new DOMNodePool(); 132 } 134 137 public void resetNodePool() { 138 fNodePool.reset(); 139 } 140 141 163 public void startDocument(XMLLocator locator, String encoding, 164 NamespaceContext namespaceContext, Augmentations augs) 165 throws XNIException { 166 167 super.startDocument(locator, encoding, namespaceContext, augs); 168 fDocumentImpl = (DocumentImpl)super.fDocumentImpl; 170 fDocumentImpl.fNodePool=fNodePool; 171 fLocator = locator; 172 173 } 175 private int fAnnotationDepth = -1; 178 private int fDepth = -1; 180 XMLErrorReporter fErrorReporter; 182 183 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 186 throws XNIException { 187 super.startElement(element, attributes, augs); 188 fDepth++; 189 if (fAnnotationDepth == -1) { 193 if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && 194 (element.localpart == SchemaSymbols.ELT_APPINFO || 195 element.localpart == SchemaSymbols.ELT_DOCUMENTATION)) { 196 fAnnotationDepth = fDepth; 197 } 198 } 199 } 200 201 public void characters(XMLString text, Augmentations augs) throws XNIException { 203 if (fAnnotationDepth == -1) { 205 for (int i=text.offset; i<text.offset+text.length; i++) { 206 if (!XMLChar.isSpace(text.ch[i])) { 208 if (fErrorReporter == null) { 210 try { 211 fErrorReporter = (XMLErrorReporter)getProperty(ERROR_REPORTER); 212 } catch (Exception e) { 213 } 215 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 216 XSMessageFormatter xmft = new XSMessageFormatter(); 217 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 218 } 219 } 220 String txt = new String (text.ch, i, text.length+text.offset-i); 222 fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 224 "s4s-elt-character", 225 new Object []{txt}, 226 XMLErrorReporter.SEVERITY_ERROR); 227 break; 228 } 229 } 230 } 234 else { 237 super.characters(text, augs); 238 } 239 } 240 241 public void endElement(QName element, Augmentations augs) throws XNIException { 243 super.endElement(element, augs); 244 if (fAnnotationDepth == fDepth) 247 fAnnotationDepth = -1; 248 fDepth--; 249 } 250 251 protected Element createElementNode(QName element) { 253 return fDocumentImpl.createElementNS(element.uri, element.rawname, 255 element.localpart, 256 fLocator.getLineNumber(), 257 fLocator.getColumnNumber()); 258 } 259 260 } | Popular Tags |