Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9e7447

Browse filesBrowse files
committed
change to allow validation to thrown SAXException, when no ErrorHandler is set
1 parent d5366f7 commit e9e7447
Copy full SHA for e9e7447

File tree

Expand file treeCollapse file tree

5 files changed

+32
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+32
-9
lines changed
Open diff view settings
Collapse file

‎buildSrc/src/main/groovy/org/mitre/stix/GeneratedSourceTransformationTask.groovy‎

Copy file name to clipboardExpand all lines: buildSrc/src/main/groovy/org/mitre/stix/GeneratedSourceTransformationTask.groovy
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,20 @@ class GeneratedSourceTransformationTask extends DefaultTask {
304304
[
305305
imports:
306306
[
307+
"org.xml.sax.SAXException"
307308
],
308309
template:
309310
"""\
310311
/**
311312
* Validates the XML representation of this \${name} instance
312313
* Returning true indicating a successful validation, false if not.
313314
*
314-
* @return boolean
315+
* @return boolean True If it validates against the schema
316+
* @throws SAXException
317+
* If the a validation ErrorHandler has not been set, and
318+
* validation throws a SAXException
315319
*/
316-
public boolean validate() {
320+
public boolean validate() throws SAXException {
317321
return STIXSchema.getInstance().validate(toXMLString());
318322
}
319323
"""
Collapse file

‎src/main/java/org/mitre/stix/STIXSchema.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/mitre/stix/STIXSchema.java
+17-7Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
Collapse file

‎src/main/java/org/mitre/stix/examples/CIQIdentity.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/mitre/stix/examples/CIQIdentity.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.mitre.stix.stix_1.IndicatorsType;
4444
import org.mitre.stix.stix_1.STIXHeaderType;
4545
import org.mitre.stix.stix_1.STIXPackage;
46+
import org.xml.sax.SAXException;
4647

4748
/**
4849
* An example of how to add CIQ Identity information to a STIX Indicator.
@@ -190,6 +191,8 @@ public static void main(String[] args) {
190191

191192
} catch (DatatypeConfigurationException e) {
192193
throw new RuntimeException(e);
194+
} catch (SAXException e) {
195+
e.printStackTrace();
193196
}
194197
}
195198
}
Collapse file

‎src/main/java/org/mitre/stix/examples/CreationToolMetadata.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/mitre/stix/examples/CreationToolMetadata.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.mitre.stix.common_1.StructuredTextType;
2121
import org.mitre.stix.stix_1.STIXHeaderType;
2222
import org.mitre.stix.stix_1.STIXPackage;
23+
import org.xml.sax.SAXException;
2324

2425
/**
2526
* Build a STIX Document with Tool Information
@@ -69,6 +70,8 @@ public static void main(String[] args) {
6970

7071
} catch (DatatypeConfigurationException e) {
7172
throw new RuntimeException(e);
73+
} catch (SAXException e) {
74+
e.printStackTrace();
7275
}
7376
}
7477
}
Collapse file

‎src/main/java/org/mitre/stix/examples/IndicatorHash.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/mitre/stix/examples/IndicatorHash.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.mitre.stix.stix_1.IndicatorsType;
3333
import org.mitre.stix.stix_1.STIXHeaderType;
3434
import org.mitre.stix.stix_1.STIXPackage;
35+
import org.xml.sax.SAXException;
3536

3637
/**
3738
* Build a STIX Indicator document containing a File observable with an
@@ -129,6 +130,8 @@ public static void main(String[] args) {
129130

130131
} catch (DatatypeConfigurationException e) {
131132
throw new RuntimeException(e);
133+
} catch (SAXException e) {
134+
e.printStackTrace();
132135
}
133136
}
134137
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.