658 659 public void validate(Source source, Result result) 660 throws SAXException, IOException { 661 if (result instanceof SAXResult || result == null) { 662 final SAXSource saxSource = (SAXSource) source; 663 final SAXResult saxResult = (SAXResult) result; 664 665 if (result != null) { 666 setContentHandler(saxResult.getHandler()); 667 } 668 669 try { 670 XMLReader reader = saxSource.getXMLReader(); 671 if( reader==null ) { 672 // create one now 673 SAXParserFactory spf = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ? 674 SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); 675 spf.setNamespaceAware(true); 676 try { 677 reader = spf.newSAXParser().getXMLReader(); 678 // If this is a Xerces SAX parser, set the security manager if there is one 679 if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) { 680 SecurityManager securityManager = (SecurityManager) fComponentManager.getProperty(SECURITY_MANAGER); 681 if (securityManager != null) { 682 try { 683 reader.setProperty(SECURITY_MANAGER, securityManager); 684 } 685 // Ignore the exception if the security manager cannot be set. 686 catch (SAXException exc) {} 687 } 688 } 689 } catch( Exception e ) { 690 // this is impossible, but better safe than sorry 691 throw new FactoryConfigurationError(e); 692 } 693 } 694 695 // If XML names and Namespace URIs are already internalized we 696 // can avoid running them through the SymbolTable. 697 try { 698 fStringsInternalized = reader.getFeature(STRING_INTERNING); 699 } 700 catch (SAXException exc) { 701 // The feature isn't recognized or getting it is not supported. 702 // In either case, assume that strings are not internalized. 703 fStringsInternalized = false; 704 } 705 706 ErrorHandler errorHandler = fComponentManager.getErrorHandler(); 707 reader.setErrorHandler(errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance()); | 658 659 public void validate(Source source, Result result) 660 throws SAXException, IOException { 661 if (result instanceof SAXResult || result == null) { 662 final SAXSource saxSource = (SAXSource) source; 663 final SAXResult saxResult = (SAXResult) result; 664 665 if (result != null) { 666 setContentHandler(saxResult.getHandler()); 667 } 668 669 try { 670 XMLReader reader = saxSource.getXMLReader(); 671 if( reader==null ) { 672 // create one now 673 SAXParserFactory spf = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ? 674 SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); 675 spf.setNamespaceAware(true); 676 try { 677 reader = spf.newSAXParser().getXMLReader(); 678 reader.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, 679 fComponentManager.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD)); 680 // If this is a Xerces SAX parser, set the security manager if there is one 681 if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) { 682 SecurityManager securityManager = (SecurityManager) fComponentManager.getProperty(SECURITY_MANAGER); 683 if (securityManager != null) { 684 try { 685 reader.setProperty(SECURITY_MANAGER, securityManager); 686 } 687 // Ignore the exception if the security manager cannot be set. 688 catch (SAXException exc) {} 689 } 690 reader.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, 691 fComponentManager.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD)); 692 } 693 } catch( Exception e ) { 694 // this is impossible, but better safe than sorry 695 throw new FactoryConfigurationError(e); 696 } 697 } 698 699 // If XML names and Namespace URIs are already internalized we 700 // can avoid running them through the SymbolTable. 701 try { 702 fStringsInternalized = reader.getFeature(STRING_INTERNING); 703 } 704 catch (SAXException exc) { 705 // The feature isn't recognized or getting it is not supported. 706 // In either case, assume that strings are not internalized. 707 fStringsInternalized = false; 708 } 709 710 ErrorHandler errorHandler = fComponentManager.getErrorHandler(); 711 reader.setErrorHandler(errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance()); |