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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
xml_plugin4rosetta
Commits
7bdd6aaf
Commit
7bdd6aaf
authored
2 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- add catalog resolving
parent
66b3a2bb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java
+41
-37
41 additions, 37 deletions
.../dps/repository/plugin/SLUBXmlFormatValidationPlugin.java
with
41 additions
and
37 deletions
java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java
+
41
−
37
View file @
7bdd6aaf
...
@@ -24,9 +24,10 @@ import org.xml.sax.ErrorHandler;
...
@@ -24,9 +24,10 @@ import org.xml.sax.ErrorHandler;
import
org.xml.sax.InputSource
;
import
org.xml.sax.InputSource
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.SAXParseException
;
import
org.xml.sax.SAXParseException
;
import
org.xml.sax.helpers.DefaultHandler
;
import
javax.xml.XMLConstants
;
import
javax.xml.XMLConstants
;
import
javax.xml.catalog.CatalogFeatures
;
import
javax.xml.catalog.CatalogManager
;
import
javax.xml.catalog.CatalogResolver
;
import
javax.xml.catalog.CatalogResolver
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.parsers.DocumentBuilderFactory
;
...
@@ -37,7 +38,9 @@ import javax.xml.validation.Schema;
...
@@ -37,7 +38,9 @@ import javax.xml.validation.Schema;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
...
@@ -78,48 +81,48 @@ class xmlInfoRecord {
...
@@ -78,48 +81,48 @@ class xmlInfoRecord {
}
}
class
ValidationCatalogResolver
implements
CatalogResolver
{
class
ValidationCatalogResolver
implements
CatalogResolver
{
private
HashMap
<
String
,
String
>
public2res
=
new
HashMap
()
{
private
final
HashMap
<
String
,
String
>
public2res
=
new
HashMap
<>
()
{
// TODO: add support for catalog.xml files.
// TODO: add support for catalog.xml files.
{
{
put
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1 20151215//EN"
,
"/resources/dtd/JATS-journalpublishing1.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1 20151215//EN"
,
"/resources/dtd/JATS-journalpublishing1.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD-Specific Modules v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-journalpubcustom-modules1.ent"
);
put
(
"-//Recordare//DTD MusicXML 4.0 Partwise//EN"
,
"http://www.musicxml.org/dtds/partwise.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) JATS DTD Suite Module of Modules v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-modules1.ent"
);
put
(
"-//OASIS//DTD DocBook XML V4.2//EN"
,
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) JATS DTD Suite Common Attributes (for all elements) v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-common-atts1.ent"
);
put
(
"-//OASIS//DTD DocBook XML V4.3//EN"
,
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD Customize Classes Module v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-journalpubcustom-classes1.ent"
);
put
(
"-//OASIS//DTD DocBook XML V4.4//EN"
,
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
);
put
(
"-//NLM//DTD JATS (Z39.96) Default Element Classes Module v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-default-classes1.ent"
);
put
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD Customize Mixes Module v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-journalpubcustom-mixes1.ent"
);
put
(
"-//NLM//DTD JATS (Z39.96) Default Element Mixes Module v1.1d1 20130915//EN"
,
"/resources/dtd/JATS-journalpubcustom-mixes1.ent"
);
}
};
private
HashSet
<
String
>
allowedDtds
=
new
HashSet
<>()
{
{
add
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1 20151215//EN"
);
}
}
};
};
private
final
HashSet
<
String
>
allowedDtds
=
new
HashSet
<>(
Arrays
.
asList
(
"-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1 20151215//EN"
));
@Override
@Override
public
InputSource
resolveEntity
(
String
publicId
,
String
systemId
)
{
public
InputSource
resolveEntity
(
String
publicId
,
String
systemId
)
{
System
.
out
.
println
(
"======"
);
System
.
out
.
println
(
"resolveEntity\n\tpublicId="
+
publicId
+
"\n\tsystemId="
+
systemId
);
/* TODO: only allow catalog calls to defined ressources */
if
(
allowedDtds
.
contains
(
publicId
))
{
if
(
allowedDtds
.
contains
(
publicId
))
{
/* todo */
System
.
out
.
println
(
"fallback to CatalogResolver"
);
DefaultHandler
defaultHandler
=
new
DefaultHandler
();
//CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, "continue").build();
try
{
var
strippedSystemId
=
systemId
;
return
defaultHandler
.
resolveEntity
(
publicId
,
systemId
);
if
(!
systemId
.
startsWith
(
"http://"
))
{
}
catch
(
IOException
e
)
{
strippedSystemId
=
"file:/etc/xml/"
+
systemId
.
substring
(
systemId
.
lastIndexOf
(
"/"
)
+
1
);
throw
new
RuntimeException
(
e
);
}
catch
(
SAXException
e
)
{
System
.
out
.
println
(
"default resolver exc: "
+
e
.
getMessage
());
e
.
getStackTrace
();
}
}
System
.
out
.
println
(
"\tusing URI="
+
strippedSystemId
);
CatalogResolver
cr
=
CatalogManager
.
catalogResolver
(
CatalogFeatures
.
defaults
(),
URI
.
create
(
strippedSystemId
));
return
cr
.
resolveEntity
(
publicId
,
systemId
);
}
}
if
(
public2res
.
containsKey
(
publicId
))
{
if
(
public2res
.
containsKey
(
publicId
))
{
System
.
out
.
println
(
"\tressoure="
+
public2res
.
get
(
publicId
));
System
.
out
.
println
(
"\tressour
c
e="
+
public2res
.
get
(
publicId
));
InputSource
is
=
new
InputSource
();
InputSource
is
=
new
InputSource
();
is
.
setByteStream
(
SLUBXmlFormatValidationPlugin
.
class
.
getResourceAsStream
(
public2res
.
get
(
publicId
)));
is
.
setByteStream
(
SLUBXmlFormatValidationPlugin
.
class
.
getResourceAsStream
(
public2res
.
get
(
publicId
)));
is
.
setPublicId
(
publicId
);
is
.
setPublicId
(
publicId
);
is
.
setSystemId
(
systemId
);
is
.
setSystemId
(
systemId
);
return
is
;
return
is
;
}
}
System
.
out
.
println
(
"======"
);
System
.
out
.
println
(
"\tnot implemented (no fallback, no mapping)"
);
System
.
out
.
println
(
"resolveEntity\n\tpublicId="
+
publicId
+
"\n\tsystemId="
+
systemId
);
if
(
systemId
.
startsWith
(
"http://"
))
{
CatalogResolver
cr
=
CatalogManager
.
catalogResolver
(
CatalogFeatures
.
defaults
(),
URI
.
create
(
systemId
));
return
cr
.
resolveEntity
(
publicId
,
systemId
);
}
return
null
;
return
null
;
}
}
...
@@ -148,17 +151,17 @@ class ValidationCatalogResolver implements CatalogResolver {
...
@@ -148,17 +151,17 @@ class ValidationCatalogResolver implements CatalogResolver {
class
ValidationErrorHandler
implements
ErrorHandler
{
class
ValidationErrorHandler
implements
ErrorHandler
{
@Override
@Override
public
void
warning
(
SAXParseException
e
)
throws
SAXException
{
public
void
warning
(
SAXParseException
e
)
{
System
.
out
.
println
(
"WARN: "
+
e
.
getMessage
());
//
System.out.println("WARN: " + e.getMessage());
}
}
@Override
@Override
public
void
error
(
SAXParseException
e
)
throws
SAXException
{
public
void
error
(
SAXParseException
e
)
{
System
.
out
.
println
(
"ERROR: "
+
e
.
getMessage
());
//
System.out.println("ERROR: " + e.getMessage());
}
}
@Override
@Override
public
void
fatalError
(
SAXParseException
e
)
throws
SAXException
{
public
void
fatalError
(
SAXParseException
e
)
{
System
.
out
.
println
(
"FATAL: "
+
e
.
getMessage
());
System
.
out
.
println
(
"FATAL: "
+
e
.
getMessage
());
}
}
}
}
...
@@ -174,8 +177,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -174,8 +177,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
private
boolean
valid
=
false
;
private
boolean
valid
=
false
;
private
boolean
wellformed
=
false
;
private
boolean
wellformed
=
false
;
private
final
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newDefaultInstance
();
private
final
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newDefaultInstance
();
private
List
<
String
>
errors
=
new
ArrayList
<>();
private
final
List
<
String
>
errors
=
new
ArrayList
<>();
private
List
<
String
>
detail
=
new
ArrayList
<>();
private
final
List
<
String
>
detail
s
=
new
ArrayList
<>();
private
static
final
HashSet
<
validationSchema
>
namespaceSchemaMap
=
new
HashSet
<>()
{
private
static
final
HashSet
<
validationSchema
>
namespaceSchemaMap
=
new
HashSet
<>()
{
{
{
add
(
new
validationSchema
(
"http://www.loc.gov/standards/alto/ns-v2#"
,
schema
,
"http://www.loc.gov/standards/alto/alto-v2.0.xsd"
));
add
(
new
validationSchema
(
"http://www.loc.gov/standards/alto/ns-v2#"
,
schema
,
"http://www.loc.gov/standards/alto/alto-v2.0.xsd"
));
...
@@ -186,8 +189,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -186,8 +189,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
// put("http://www.tei-c.org/ns/1.0", "");
// put("http://www.tei-c.org/ns/1.0", "");
}
}
};
};
private
ValidationCatalogResolver
validationCatalogResolver
=
new
ValidationCatalogResolver
();
private
final
ValidationCatalogResolver
validationCatalogResolver
=
new
ValidationCatalogResolver
();
private
ValidationErrorHandler
validationErrorHandler
=
new
ValidationErrorHandler
();
private
final
ValidationErrorHandler
validationErrorHandler
=
new
ValidationErrorHandler
();
public
SLUBXmlFormatValidationPlugin
()
{
public
SLUBXmlFormatValidationPlugin
()
{
dbf
.
setNamespaceAware
(
true
);
dbf
.
setNamespaceAware
(
true
);
dbf
.
setValidating
(
false
);
dbf
.
setValidating
(
false
);
...
@@ -304,6 +307,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -304,6 +307,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
dbf
.
setValidating
(
true
);
dbf
.
setValidating
(
true
);
DocumentBuilder
dbValidate
=
dbf
.
newDocumentBuilder
();
DocumentBuilder
dbValidate
=
dbf
.
newDocumentBuilder
();
Document
docValidate
;
Document
docValidate
;
dbValidate
.
setEntityResolver
(
validationCatalogResolver
);
dbValidate
.
setEntityResolver
(
validationCatalogResolver
);
dbValidate
.
setErrorHandler
(
validationErrorHandler
);
dbValidate
.
setErrorHandler
(
validationErrorHandler
);
reportDetail
(
"align entitity resolver"
);
reportDetail
(
"align entitity resolver"
);
...
@@ -338,7 +342,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -338,7 +342,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
}
}
private
void
reportDetail
(
String
msg
)
{
private
void
reportDetail
(
String
msg
)
{
detail
.
add
(
msg
);
detail
s
.
add
(
msg
);
System
.
out
.
println
(
msg
);
System
.
out
.
println
(
msg
);
}
}
...
@@ -364,7 +368,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -364,7 +368,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
@Override
@Override
public
String
getValidationDetails
()
{
public
String
getValidationDetails
()
{
return
detail
.
stream
().
reduce
(
""
,
(
all
,
res
)
->
all
.
concat
(
"\n"
)
.
concat
(
res
)
);
return
detail
s
.
stream
().
reduce
(
""
,
(
all
,
res
)
->
all
.
concat
(
"\n"
)
.
concat
(
res
)
);
}
}
/** stand-alone check, main file to call local installed clamd
/** stand-alone check, main file to call local installed clamd
...
...
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