Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
75c0e581
Commit
75c0e581
authored
May 17, 2023
by
Matthias Betz
Browse files
fixing incompatibility with citygml4j 3 regarding xslt transformers
parent
358dfea5
Pipeline
#7497
passed with stage
in 1 minute and 10 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java
View file @
75c0e581
...
...
@@ -47,6 +47,7 @@ import org.apache.logging.log4j.LogManager;
import
org.apache.logging.log4j.Logger
;
import
org.citygml4j.core.ade.ADEException
;
import
org.citygml4j.core.ade.ADERegistry
;
import
org.citygml4j.core.model.CityGMLVersion
;
import
org.citygml4j.core.model.ade.ADEProperty
;
import
org.citygml4j.core.model.core.AbstractCityObject
;
import
org.citygml4j.core.model.core.AbstractCityObjectProperty
;
...
...
@@ -55,7 +56,6 @@ import org.citygml4j.core.model.core.CityModel;
import
org.citygml4j.core.util.CityGMLConstants
;
import
org.citygml4j.xml.CityGMLContext
;
import
org.citygml4j.xml.CityGMLContextException
;
import
org.citygml4j.xml.module.citygml.CityGMLModule
;
import
org.citygml4j.xml.module.citygml.CityGMLModules
;
import
org.citygml4j.xml.reader.ChunkOptions
;
import
org.citygml4j.xml.reader.CityGMLInputFactory
;
...
...
@@ -121,6 +121,7 @@ public class CityGmlParser {
private
static
List
<
QName
>
chunkProperties
=
new
ArrayList
<>();
static
{
System
.
setProperty
(
"javax.xml.transform.TransformerFactory"
,
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"
);
FACTORY
=
SAXParserFactory
.
newInstance
();
try
{
FACTORY
.
setFeature
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
true
);
...
...
@@ -311,8 +312,8 @@ public class CityGmlParser {
return
null
;
}
CityGMLContext
gmlContext
=
CityGmlParser
.
getContext
();
CityGML
Module
module
=
CityGMLModules
.
getCityGML
Module
(
reader
.
getName
().
getNamespaceURI
());
CityGMLOutputFactory
factory
=
gmlContext
.
createCityGMLOutputFactory
(
module
.
getCityGMLV
ersion
()
);
CityGML
Version
version
=
CityGMLModules
.
getCityGML
Version
(
reader
.
getName
().
getNamespaceURI
());
CityGMLOutputFactory
factory
=
gmlContext
.
createCityGMLOutputFactory
(
v
ersion
);
CityGMLChunkWriter
writer
=
factory
.
createCityGMLChunkWriter
(
new
File
(
outputFile
),
StandardCharsets
.
UTF_8
.
name
());
writer
.
withPrefix
(
"qual"
,
QualityADEModule
.
NAMESPACE_URI
);
...
...
@@ -336,8 +337,8 @@ public class CityGmlParser {
if
(
chunk
instanceof
CityModel
cModel
)
{
cModel
.
setCityObjectMembers
(
null
);
mapper
.
setCityModel
(
cModel
);
CityGML
Module
module
=
CityGMLModules
.
getCityGML
Module
(
reader
.
getName
().
getNamespaceURI
());
mapper
.
setCityGMLVersion
(
module
.
getCityGMLV
ersion
()
);
CityGML
Version
version
=
CityGMLModules
.
getCityGML
Version
(
reader
.
getName
().
getNamespaceURI
());
mapper
.
setCityGMLVersion
(
v
ersion
);
}
else
if
(
chunk
instanceof
AbstractCityObject
aco
)
{
acos
.
add
(
aco
);
aco
.
accept
(
mapper
);
...
...
CityDoctorParent/CityDoctorValidation/pom.xml
View file @
75c0e581
...
...
@@ -21,10 +21,6 @@
<groupId>
de.hft.stuttgart
</groupId>
<artifactId>
CityDoctorCheckResult
</artifactId>
</dependency>
<dependency>
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
...
...
@@ -38,6 +34,10 @@
<groupId>
xml-apis
</groupId>
<artifactId>
xml-apis
</artifactId>
</exclusion>
<exclusion>
<groupId>
xalan
</groupId>
<artifactId>
xalan
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
...
...
@@ -60,6 +60,17 @@
<groupId>
de.hft.stuttgart
</groupId>
<artifactId>
citygml4j-quality-ade
</artifactId>
</dependency>
<dependency>
<groupId>
name.dmaus.schxslt
</groupId>
<artifactId>
schxslt
</artifactId>
<version>
1.9.5
</version>
</dependency>
<dependency>
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
</dependency>
<!--
-->
</dependencies>
<build>
...
...
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java
View file @
75c0e581
...
...
@@ -38,17 +38,19 @@ import java.util.Set;
import
java.util.stream.Stream
;
import
javax.xml.XMLConstants
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.transform.Result
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.Transformer
;
import
javax.xml.transform.TransformerException
;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.URIResolver
;
import
javax.xml.transform.dom.DOMResult
;
import
javax.xml.transform.dom.DOMSource
;
import
javax.xml.transform.sax.SAXResult
;
import
javax.xml.transform.stream.StreamSource
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.w3c.dom.Document
;
import
de.hft.stuttgart.citydoctor2.check.error.AttributeInvalidError
;
import
de.hft.stuttgart.citydoctor2.check.error.AttributeMissingError
;
...
...
@@ -85,15 +87,6 @@ import de.hft.stuttgart.quality.model.properties.RequirementProperty;
import
de.hft.stuttgart.quality.model.types.Checking
;
import
de.hft.stuttgart.quality.model.types.Parameter
;
import
de.hft.stuttgart.quality.model.types.ValidationPlan
;
import
net.sf.saxon.lib.ResourceResolverWrappingURIResolver
;
import
net.sf.saxon.s9api.DOMDestination
;
import
net.sf.saxon.s9api.Destination
;
import
net.sf.saxon.s9api.Processor
;
import
net.sf.saxon.s9api.SAXDestination
;
import
net.sf.saxon.s9api.SaxonApiException
;
import
net.sf.saxon.s9api.XsltCompiler
;
import
net.sf.saxon.s9api.XsltExecutable
;
import
net.sf.saxon.s9api.XsltTransformer
;
/**
* The main container class for checking. It contains the logic for validation,
...
...
@@ -446,54 +439,47 @@ public class Checker {
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
Localization
.
getText
(
"Checker.schematronValidation"
));
}
Processor
processor
=
new
Processor
(
false
);
XsltCompiler
xsltCompiler
=
processor
.
newXsltCompiler
();
xsltCompiler
.
setResourceResolver
(
new
ResourceResolverWrappingURIResolver
(
new
URIResolver
()
{
@Override
public
Source
resolve
(
String
href
,
String
base
)
throws
TransformerException
{
return
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
href
));
}
}));
try
{
XsltExecutable
includeExecutable
=
xsltCompiler
.
compile
(
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_dsdl_include.xsl"
)));
XsltTransformer
includeTransformer
=
includeExecutable
.
load
();
includeTransformer
.
setSource
(
new
StreamSource
(
new
File
(
config
.
getSchematronFilePath
())));
XsltExecutable
expandExecutable
=
xsltCompiler
.
compile
(
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_abstract_expand.xsl"
)));
XsltTransformer
expandTransformer
=
expandExecutable
.
load
();
includeTransformer
.
setDestination
(
expandTransformer
);
XsltExecutable
xslt2Executable
=
xsltCompiler
.
compile
(
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_svrl_for_xslt2.xsl"
)));
XsltTransformer
xslt2Transformer
=
xslt2Executable
.
load
();
expandTransformer
.
setDestination
(
xslt2Transformer
);
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
factory
.
setAttribute
(
XMLConstants
.
ACCESS_EXTERNAL_DTD
,
""
);
factory
.
setAttribute
(
XMLConstants
.
ACCESS_EXTERNAL_SCHEMA
,
""
);
factory
.
setFeature
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
true
);
Document
doc
=
factory
.
newDocumentBuilder
().
newDocument
();
DOMDestination
domDestination
=
new
DOMDestination
(
doc
);
xslt2Transformer
.
setDestination
(
domDestination
);
includeTransformer
.
transform
();
XsltExecutable
schematronExecutable
=
xsltCompiler
.
compile
(
new
DOMSource
(
doc
));
XsltTransformer
schematronTransformer
=
schematronExecutable
.
load
();
schematronTransformer
.
setSource
(
new
StreamSource
(
in
));
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
(
"net.sf.saxon.TransformerFactoryImpl"
,
Checker
.
class
.
getClassLoader
());
transformerFactory
.
setAttribute
(
XMLConstants
.
ACCESS_EXTERNAL_DTD
,
""
);
transformerFactory
.
setFeature
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
true
);
transformerFactory
.
setURIResolver
(
new
URIResolver
()
{
@Override
public
Source
resolve
(
String
href
,
String
base
)
throws
TransformerException
{
return
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
href
));
}
});
Source
dsdlXslSource
=
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_dsdl_include.xsl"
));
Transformer
dsdlXslTransformer
=
transformerFactory
.
newTransformer
(
dsdlXslSource
);
DOMResult
dsdlXslResult
=
new
DOMResult
();
dsdlXslTransformer
.
transform
(
new
StreamSource
(
new
File
(
config
.
getSchematronFilePath
())),
dsdlXslResult
);
Source
abstractExpandXsl
=
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_abstract_expand.xsl"
));
Transformer
abstractExpandTransformer
=
transformerFactory
.
newTransformer
(
abstractExpandXsl
);
DOMResult
abstractExpandResult
=
new
DOMResult
();
abstractExpandTransformer
.
transform
(
new
DOMSource
(
dsdlXslResult
.
getNode
()),
abstractExpandResult
);
Source
svrlXslSource
=
new
StreamSource
(
Checker
.
class
.
getResourceAsStream
(
"iso_svrl_for_xslt2.xsl"
));
Transformer
svrlTransformer
=
transformerFactory
.
newTransformer
(
svrlXslSource
);
DOMResult
schematronXsltResult
=
new
DOMResult
();
svrlTransformer
.
transform
(
new
DOMSource
(
abstractExpandResult
.
getNode
()),
schematronXsltResult
);
Transformer
schematronTransformer
=
transformerFactory
.
newTransformer
(
new
DOMSource
(
schematronXsltResult
.
getNode
()));
Source
cityGmlSource
=
new
StreamSource
(
in
);
SvrlContentHandler
handler
=
new
SvrlContentHandler
();
Destination
dest
=
new
SAXDestination
(
handler
);
schematronTransformer
.
setDestination
(
dest
);
schematronTransformer
.
transform
();
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
Localization
.
getText
(
"Checker.finishedSchematron"
));
}
Result
finalResult
=
new
SAXResult
(
handler
);
schematronTransformer
.
transform
(
cityGmlSource
,
finalResult
);
return
handler
;
}
catch
(
SaxonApiException
|
ParserConfiguration
Exception
e
)
{
}
catch
(
Transformer
Exception
e
)
{
logger
.
catching
(
e
);
}
}
...
...
CityDoctorParent/pom.xml
View file @
75c0e581
...
...
@@ -98,8 +98,8 @@
<dependency>
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
<version>
1
1.3
</version>
</dependency>
<version>
1
2.2
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>
org.hibernate
</groupId>
...
...
@@ -109,12 +109,12 @@
<dependency>
<groupId>
org.citygml4j
</groupId>
<artifactId>
citygml4j-core
</artifactId>
<version>
3.0.0
-rc.4
</version>
<version>
3.0.0
</version>
</dependency>
<dependency>
<groupId>
org.citygml4j
</groupId>
<artifactId>
citygml4j-xml
</artifactId>
<version>
3.0.0
-rc.4
</version>
<version>
3.0.0
</version>
</dependency>
<dependency>
<groupId>
de.hft.stuttgart
</groupId>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment