1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
45 import com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker; |
45 import com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker; |
46 import com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker; |
46 import com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker; |
47 import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker; |
47 import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker; |
48 import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic; |
48 import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic; |
49 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter; |
49 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter; |
|
50 import com.sun.xml.internal.bind.v2.util.XmlFactory; |
50 import com.sun.xml.internal.xsom.XSSchemaSet; |
51 import com.sun.xml.internal.xsom.XSSchemaSet; |
51 import com.sun.xml.internal.xsom.parser.JAXPParser; |
52 import com.sun.xml.internal.xsom.parser.JAXPParser; |
52 import com.sun.xml.internal.xsom.parser.XMLParser; |
53 import com.sun.xml.internal.xsom.parser.XMLParser; |
53 import com.sun.xml.internal.xsom.parser.XSOMParser; |
54 import com.sun.xml.internal.xsom.parser.XSOMParser; |
54 import java.net.URI; |
|
55 import java.net.URISyntaxException; |
|
56 import javax.xml.XMLConstants; |
55 import javax.xml.XMLConstants; |
57 |
56 |
58 import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder; |
57 import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder; |
59 import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder; |
58 import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder; |
60 import com.sun.xml.internal.rngom.digested.DPattern; |
59 import com.sun.xml.internal.rngom.digested.DPattern; |
296 */ |
295 */ |
297 public DOMForest buildDOMForest( InternalizationLogic logic ) |
296 public DOMForest buildDOMForest( InternalizationLogic logic ) |
298 throws SAXException { |
297 throws SAXException { |
299 |
298 |
300 // parse into DOM forest |
299 // parse into DOM forest |
301 DOMForest forest = new DOMForest(logic); |
300 DOMForest forest = new DOMForest(logic, opt); |
302 |
301 |
303 forest.setErrorHandler(errorReceiver); |
302 forest.setErrorHandler(errorReceiver); |
304 if(opt.entityResolver!=null) |
303 if(opt.entityResolver!=null) |
305 forest.setEntityResolver(opt.entityResolver); |
304 forest.setEntityResolver(opt.entityResolver); |
306 |
305 |
341 /** |
340 /** |
342 * Parses a set of XML Schema files into an annotated grammar. |
341 * Parses a set of XML Schema files into an annotated grammar. |
343 */ |
342 */ |
344 public XSSchemaSet loadXMLSchema() throws SAXException { |
343 public XSSchemaSet loadXMLSchema() throws SAXException { |
345 |
344 |
346 if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver)) { |
345 if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) { |
347 // schema error. error should have been reported |
346 // schema error. error should have been reported |
348 return null; |
347 return null; |
349 } |
348 } |
350 |
349 |
351 if(opt.getBindFiles().length==0) { |
350 if(opt.getBindFiles().length==0) { |
352 // no external binding. try the speculative no DOMForest execution, |
351 // no external binding. try the speculative no DOMForest execution, |
353 // which is faster if the speculation succeeds. |
352 // which is faster if the speculation succeeds. |
354 try { |
353 try { |
355 return createXSOMSpeculative(); |
354 return createXSOMSpeculative(); |
356 } catch( SpeculationFailure _ ) { |
355 } catch( SpeculationFailure e) { |
357 // failed. go the slow way |
356 // failed. go the slow way |
358 } |
357 } |
359 } |
358 } |
360 |
359 |
361 // the default slower way is to parse everything into DOM first. |
360 // the default slower way is to parse everything into DOM first. |
409 if (xs == null) |
408 if (xs == null) |
410 return null; |
409 return null; |
411 return BGMBuilder.build(xs, codeModel, errorReceiver, opt); |
410 return BGMBuilder.build(xs, codeModel, errorReceiver, opt); |
412 } |
411 } |
413 |
412 |
|
413 /** |
|
414 * Potentially problematic - make sure the parser instance passed is initialized |
|
415 * with proper security feature. |
|
416 * |
|
417 * @param parser |
|
418 * @return |
|
419 */ |
414 public XSOMParser createXSOMParser(XMLParser parser) { |
420 public XSOMParser createXSOMParser(XMLParser parser) { |
415 // set up other parameters to XSOMParser |
421 // set up other parameters to XSOMParser |
416 XSOMParser reader = new XSOMParser(new XMLSchemaParser(parser)); |
422 XSOMParser reader = new XSOMParser(new XMLSchemaParser(parser)); |
417 reader.setAnnotationParser(new AnnotationParserFactoryImpl(opt)); |
423 reader.setAnnotationParser(new AnnotationParserFactoryImpl(opt)); |
418 reader.setErrorHandler(errorReceiver); |
424 reader.setErrorHandler(errorReceiver); |
463 private XSSchemaSet createXSOMSpeculative() throws SAXException, SpeculationFailure { |
469 private XSSchemaSet createXSOMSpeculative() throws SAXException, SpeculationFailure { |
464 |
470 |
465 // check if the schema contains external binding files. If so, speculation is a failure. |
471 // check if the schema contains external binding files. If so, speculation is a failure. |
466 |
472 |
467 XMLParser parser = new XMLParser() { |
473 XMLParser parser = new XMLParser() { |
468 private final JAXPParser base = new JAXPParser(); |
474 private final JAXPParser base = new JAXPParser(XmlFactory.createParserFactory(opt.disableXmlSecurity)); |
469 |
475 |
470 public void parse(InputSource source, ContentHandler handler, |
476 public void parse(InputSource source, ContentHandler handler, |
471 ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException { |
477 ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException { |
472 // set up the chain of handlers. |
478 // set up the chain of handlers. |
473 handler = wrapBy( new SpeculationChecker(), handler ); |
479 handler = wrapBy( new SpeculationChecker(), handler ); |