Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xml_plugin4rosetta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
xml_plugin4rosetta
Commits
9186e035
Commit
9186e035
authored
2 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- added errorhandler
parent
70e3e6af
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/org/slub/rosetta/dps/repository/plugin/Validation/SLUBValidateSchema.java
+25
-2
25 additions, 2 deletions
.../dps/repository/plugin/Validation/SLUBValidateSchema.java
with
25 additions
and
2 deletions
java/org/slub/rosetta/dps/repository/plugin/Validation/SLUBValidateSchema.java
+
25
−
2
View file @
9186e035
...
...
@@ -2,8 +2,10 @@ package org.slub.rosetta.dps.repository.plugin.Validation;
import
org.apache.xerces.jaxp.validation.XMLSchemaFactory
;
import
org.slub.rosetta.dps.repository.plugin.ValidationResourceResolver
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Node
;
import
org.xml.sax.ErrorHandler
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.SAXParseException
;
import
javax.xml.XMLConstants
;
import
javax.xml.transform.dom.DOMSource
;
...
...
@@ -16,6 +18,7 @@ import java.util.ArrayList;
import
java.util.List
;
public
class
SLUBValidateSchema
{
private
boolean
is_valid
=
true
;
private
final
List
<
String
>
errors
=
new
ArrayList
<>();
public
List
<
String
>
get_errors
()
{
return
errors
;
...
...
@@ -24,14 +27,33 @@ public class SLUBValidateSchema {
public
SLUBValidateSchema
(
ValidationResourceResolver
validationResourceResolver
)
{
this
.
validationResourceResolver
=
validationResourceResolver
;
}
public
boolean
validateAgainst
(
Document
docvalidate
,
URI
xsdUri
)
throws
IOException
{
private
final
ErrorHandler
validationErrorHandler
=
new
ErrorHandler
()
{
@Override
public
void
warning
(
SAXParseException
e
)
{
errors
.
add
(
"[WW] "
+
e
.
getMessage
());
}
@Override
public
void
error
(
SAXParseException
e
)
{
is_valid
=
false
;
errors
.
add
(
"[EE] "
+
e
.
getMessage
()
+
" line="
+
e
.
getLineNumber
()
+
" col="
+
e
.
getColumnNumber
());
}
@Override
public
void
fatalError
(
SAXParseException
e
)
{
is_valid
=
false
;
errors
.
add
(
"[EE] Fatal, "
+
e
.
getMessage
()
+
" line="
+
e
.
getLineNumber
()
+
" col="
+
e
.
getColumnNumber
());
}
};
public
boolean
validateAgainst
(
Node
docvalidate
,
URI
xsdUri
)
throws
IOException
{
boolean
isValidXml
=
false
;
try
{
SchemaFactory
sf
=
XMLSchemaFactory
.
newInstance
(
"http://www.w3.org/XML/XMLSchema/v1.1"
);
sf
.
setFeature
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
true
);
sf
.
setFeature
(
"http://apache.org/xml/features/validation/schema-full-checking"
,
true
);
sf
.
setFeature
(
"http://apache.org/xml/features/honour-all-schemaLocations"
,
true
);
sf
.
setResourceResolver
(
validationResourceResolver
);
Schema
s
=
sf
.
newSchema
(
xsdUri
.
toURL
());
Validator
v
=
s
.
newValidator
();
DOMSource
src
=
new
DOMSource
(
docvalidate
);
v
.
validate
(
src
);
...
...
@@ -48,4 +70,5 @@ public class SLUBValidateSchema {
}
return
isValidXml
;
}
}
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