public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { if (fNeedPushNSContext) { fNamespaceContext.pushContext(); } fNeedPushNSContext = true; // Fill element QName fillQName(fElementQName, uri, localName, qName); // Fill XMLAttributes if (atts instanceof Attributes2) { fillXMLAttributes2((Attributes2) atts); } else { fillXMLAttributes(atts); } try { fSchemaValidator.startElement(fElementQName, fAttributes, null); } catch (XMLParseException e) { throw Util.toSAXParseException(e); } catch (XNIException e) { throw Util.toSAXException(e); } }
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { try { fTempString.setValues(ch, start, length); fSchemaValidator.ignorableWhitespace(fTempString, null); } catch (XMLParseException e) { throw Util.toSAXParseException(e); } catch (XNIException e) { throw Util.toSAXException(e); } }
public void endDocument() throws SAXException { fSAXLocatorWrapper.setLocator(null); try { fSchemaValidator.endDocument(null); } catch (XMLParseException e) { throw Util.toSAXParseException(e); } catch (XNIException e) { throw Util.toSAXException(e); } }
public void endElement(String uri, String localName, String qName) throws SAXException { fillQName(fElementQName, uri, localName, qName); try { fSchemaValidator.endElement(fElementQName, null); } catch (XMLParseException e) { throw Util.toSAXParseException(e); } catch (XNIException e) { throw Util.toSAXException(e); } finally { fNamespaceContext.popContext(); } }
public void startDocument() throws SAXException { fComponentManager.reset(); fSchemaValidator.setDocumentHandler(this); fValidationManager.setEntityState(this); fTypeInfoProvider.finishStartElement(); // cleans up TypeInfoProvider fNeedPushNSContext = true; if (fUnparsedEntities != null && !fUnparsedEntities.isEmpty()) { // should only clear this if the last document contained unparsed entities fUnparsedEntities.clear(); } fErrorReporter.setDocumentLocator(fSAXLocatorWrapper); try { fSchemaValidator.startDocument( fSAXLocatorWrapper, fSAXLocatorWrapper.getEncoding(), fNamespaceContext, null); } catch (XMLParseException e) { throw Util.toSAXParseException(e); } catch (XNIException e) { throw Util.toSAXException(e); } }
public Schema newSchema(Source[] schemas) throws SAXException { // this will let the loader store parsed Grammars into the pool. XMLGrammarPoolImplExtension pool = new XMLGrammarPoolImplExtension(); fXMLGrammarPoolWrapper.setGrammarPool(pool); XMLInputSource[] xmlInputSources = new XMLInputSource[schemas.length]; InputStream inputStream; Reader reader; for (int i = 0; i < schemas.length; i++) { Source source = schemas[i]; if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; String publicId = streamSource.getPublicId(); String systemId = streamSource.getSystemId(); inputStream = streamSource.getInputStream(); reader = streamSource.getReader(); xmlInputSources[i] = new XMLInputSource(publicId, systemId, null); xmlInputSources[i].setByteStream(inputStream); xmlInputSources[i].setCharacterStream(reader); } else if (source instanceof SAXSource) { SAXSource saxSource = (SAXSource) source; InputSource inputSource = saxSource.getInputSource(); if (inputSource == null) { throw new SAXException( JAXPValidationMessageFormatter.formatMessage( Locale.getDefault(), "SAXSourceNullInputSource", null)); } xmlInputSources[i] = new SAXInputSource(saxSource.getXMLReader(), inputSource); } else if (source instanceof DOMSource) { DOMSource domSource = (DOMSource) source; Node node = domSource.getNode(); String systemID = domSource.getSystemId(); xmlInputSources[i] = new DOMInputSource(node, systemID); } else if (source == null) { throw new NullPointerException( JAXPValidationMessageFormatter.formatMessage( Locale.getDefault(), "SchemaSourceArrayMemberNull", null)); } else { throw new IllegalArgumentException( JAXPValidationMessageFormatter.formatMessage( Locale.getDefault(), "SchemaFactorySourceUnrecognized", new Object[] {source.getClass().getName()})); } } try { fXMLSchemaLoader.loadGrammar(xmlInputSources); } catch (XNIException e) { // this should have been reported to users already. throw Util.toSAXException(e); } catch (IOException e) { // this hasn't been reported, so do so now. SAXParseException se = new SAXParseException(e.getMessage(), null, e); fErrorHandler.error(se); throw se; // and we must throw it. } // Clear reference to grammar pool. fXMLGrammarPoolWrapper.setGrammarPool(null); // Select Schema implementation based on grammar count. final int grammarCount = pool.getGrammarCount(); if (grammarCount > 1) { return new XMLSchema(new ReadOnlyGrammarPool(pool)); } else if (grammarCount == 1) { Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA); return new SimpleXMLSchema(grammars[0]); } else { return EmptyXMLSchema.getInstance(); } }