@@ -94,8 +94,7 @@ private STIXSchema() {
9494
9595 try {
9696 schemaResources = patternResolver
97- .getResources ("classpath:schemas/v" + version
98- + "/**/*.xsd" );
97+ .getResources ("classpath:schemas/v" + version + "/**/*.xsd" );
9998
10099 prefixSchemaBindings = new HashMap <String , String >();
101100
@@ -192,8 +191,12 @@ public String getVersion() {
192191 *
193192 * @param url
194193 * The URL object for the XML to be validated.
194+ * @return boolean True If the xmlText validates against the schema
195+ * @throws SAXException
196+ * If the a validation ErrorHandler has not been set, and
197+ * validation throws a SAXException
195198 */
196- public boolean validate (URL url ) {
199+ public boolean validate (URL url ) throws SAXException {
197200
198201 String xmlText = null ;
199202
@@ -211,8 +214,12 @@ public boolean validate(URL url) {
211214 *
212215 * @param xmlText
213216 * A string of XML text to be validated
217+ * @return boolean True If the xmlText validates against the schema
218+ * @throws SAXException
219+ * If the a validation ErrorHandler has not been set, and
220+ * validation throws a SAXException
214221 */
215- public boolean validate (String xmlText ) {
222+ public boolean validate (String xmlText ) throws SAXException {
216223
217224 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
218225 factory .setNamespaceAware (true );
@@ -251,12 +258,15 @@ public boolean validate(String xmlText) {
251258 try {
252259 validator .validate (new StreamSource (new ByteArrayInputStream (
253260 xmlText .getBytes (StandardCharsets .UTF_8 ))));
254-
255261 } catch (IOException e ) {
256262 throw new RuntimeException (e );
257263 } catch (SAXException e ) {
258- System .out .println ("---------\n " + e + "--------\n " );
259- return false ;
264+ if (this .validator .getErrorHandler () != null ) {
265+ return false ;
266+ } else {
267+ //re-throw the SAXException
268+ throw e ;
269+ }
260270 }
261271
262272 return true ;
0 commit comments