Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
467d2470
Commit
467d2470
authored
8 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Providing qualified test failure message in case of invalid schema files
parent
35a294bb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ws/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java
+19
-7
19 additions, 7 deletions
...ava/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java
with
19 additions
and
7 deletions
ws/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java
+
19
−
7
View file @
467d2470
...
...
@@ -16,6 +16,7 @@ import org.jdom2.input.SAXBuilder;
import
org.jdom2.input.sax.XMLReaderSAX2Factory
;
import
org.jdom2.input.sax.XMLReaders
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.SAXParseException
;
/**
* Test and evaluate an individual XML instance.
...
...
@@ -23,6 +24,7 @@ import org.xml.sax.SAXException;
*/
public
class
InstanceTest
{
private
static
Logger
log
=
LogManager
.
getLogger
(
InstanceTest
.
class
);
final
SAXBuilder
parser
=
new
SAXBuilder
(
XMLReaders
.
XSDVALIDATING
);
final
SAXBuilder
b
=
new
SAXBuilder
(
new
XMLReaderSAX2Factory
(
false
));
...
...
@@ -56,8 +58,6 @@ public class InstanceTest {
*/
public
final
Optional
<
String
>
errMsg
;
private
static
Logger
log
=
LogManager
.
getLogger
(
InstanceTest
.
class
);
@Override
public
String
toString
()
{
...
...
@@ -89,11 +89,13 @@ public class InstanceTest {
try
{
s
=
sf
.
newSchema
(
new
File
(
xsdSchemaFilename
));
validator
=
s
.
newValidator
();
}
catch
(
SAXException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
}
catch
(
final
SAXParseException
e
)
{
System
.
err
.
println
(
getErrorDescription
(
e
));
System
.
exit
(
1
);
}
catch
(
SAXException
e
)
{
System
.
err
.
println
(
getErrorDescription
(
e
,
xsdSchemaFilename
));
System
.
exit
(
1
);
}
this
.
instanceFilename
=
xmlInstance
;
...
...
@@ -161,4 +163,14 @@ public class InstanceTest {
}
}
static
String
getErrorDescription
(
final
SAXParseException
e
)
{
return
"Your schema cannot be parsed:\n"
+
e
.
getSystemId
()
+
", line "
+
e
.
getLineNumber
()
+
", column "
+
e
.
getLineNumber
()
+
": "
+
e
.
getLocalizedMessage
()
+
"\nThis may indicate your document is not well-formed\n\nAborting!\n\n\n"
;
}
static
String
getErrorDescription
(
final
SAXException
e
,
final
String
fileName
)
{
return
"Your schema "
+
fileName
+
" cannot be parsed:\n"
+
e
.
getLocalizedMessage
()
+
"\nAre you using non-standard features?\n\nAborting!\n\n\n"
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment