Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
313d0081
Commit
313d0081
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Refactor: Rework parsing of CityGmlZipEntry
parent
6198d102
master
dev
dev_cpp_code_conversion
dev_gui_features_zip_loading
3.17.0
archive/dev_gui_features_zip_loading
2 merge requests
!28
Version 3.17.0 Release
,
!26
Add ZIP-archive support
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java
+51
-16
...va/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java
CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java
+1
-3
.../hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java
with
52 additions
and
19 deletions
+52
-19
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java
+
51
-
16
View file @
313d0081
...
...
@@ -26,6 +26,8 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
javax.xml.XMLConstants
;
import
javax.xml.namespace.QName
;
...
...
@@ -189,28 +191,61 @@ public class CityGmlParser {
}
}
public
static
CityDoctorModel
parseCityGmlStream
(
InputStream
is
,
ParserConfiguration
config
)
throws
CityGmlParseException
,
InvalidGmlFileException
{
return
parseCityGmlStream
(
is
,
config
,
null
,
null
);
}
public
static
CityDoctorModel
parseCityGmlZipEntry
(
ZipEntry
entry
,
ZipFile
archive
,
ParserConfiguration
config
)
throws
CityGmlParseException
,
InvalidGmlFileException
,
IOException
{
CityGMLContext
context
=
getContext
();
public
static
CityDoctorModel
parseCityGmlStream
(
InputStream
is
,
ParserConfiguration
config
,
ProgressListener
l
)
throws
CityGmlParseException
,
InvalidGmlFileException
{
return
parseCityGmlStream
(
is
,
config
,
l
,
null
);
if
(
config
.
getValidate
())
{
InputStream
vis
=
archive
.
getInputStream
(
entry
);
List
<
String
>
messages
=
validateStream
(
vis
,
context
);
if
(!
messages
.
isEmpty
())
{
throw
new
InvalidGmlFileException
(
"Invalid GML File. First error: \n"
+
messages
.
get
(
0
));
}
}
InputStream
is
=
archive
.
getInputStream
(
entry
);
return
parseCityGmlStream
(
is
,
config
,
context
);
}
public
static
CityDoctorModel
parseCityGmlStream
(
InputStream
is
,
ParserConfiguration
config
,
ProgressListener
l
,
GMLValidationHandler
handler
)
throws
CityGmlParseException
,
InvalidGmlFileException
{
CityGMLContext
context
=
getContext
();
private
static
List
<
String
>
validateStream
(
InputStream
vis
,
CityGMLContext
context
)
throws
CityGmlParseException
{
GMLValidationHandler
handler
=
new
GMLValidationHandler
();
if
(
config
.
getValidate
())
{
//TODO: Think of something to XML-validate Inputstream
try
{
BufferedInputStream
bis
=
new
BufferedInputStream
(
vis
);
SchemaHandler
schemaHandler
=
new
ValidationSchemaHandler
(
context
.
getDefaultSchemaHandler
());
readAdditionalSchemaDefinitions
(
context
,
bis
,
schemaHandler
);
Source
[]
schemas
=
schemaHandler
.
getSchemas
();
SchemaFactory
schemaFactory
=
SchemaFactory
.
newInstance
(
XMLConstants
.
W3C_XML_SCHEMA_NS_URI
);
schemaFactory
.
setFeature
(
"http://apache.org/xml/features/disallow-doctype-decl"
,
true
);
Schema
schema
=
schemaFactory
.
newSchema
(
schemas
);
Validator
validator
=
schema
.
newValidator
();
validator
.
setErrorHandler
(
handler
);
validator
.
validate
(
new
StreamSource
(
bis
));
return
handler
.
getMessages
();
}
catch
(
SchemaHandlerException
|
SAXException
|
IOException
e
)
{
throw
new
CityGmlParseException
(
"Failed to validate CityGML file"
,
e
);
}
}
//XML validation requires looking at nesting of tags
//not a problem for small files, but big files will run into memory limit and crash
// Maybe do it dirty by writing stream to temp file and passing it to parseCityGmlFile()?
throw
new
InvalidGmlFileException
(
"Invalid GML File."
);
private
static
void
readAdditionalSchemaDefinitions
(
CityGMLContext
context
,
BufferedInputStream
bis
,
SchemaHandler
schemaHandler
)
throws
CityGmlParseException
{
bis
.
mark
(
Integer
.
MAX_VALUE
);
try
(
XMLReader
reader
=
XMLReaderFactory
.
newInstance
(
context
.
getXMLObjects
())
.
withSchemaHandler
(
schemaHandler
)
.
createReader
(
bis
))
{
reader
.
nextTag
();
bis
.
reset
();
}
catch
(
Exception
e
)
{
throw
new
CityGmlParseException
(
"Failed to read Schema from stream."
,
e
);
}
}
public
static
CityDoctorModel
parseCityGmlStream
(
InputStream
is
,
ParserConfiguration
config
,
CityGMLContext
context
)
throws
CityGmlParseException
{
return
parseCityGmlStream
(
is
,
config
,
null
,
context
);
}
public
static
CityDoctorModel
parseCityGmlStream
(
InputStream
is
,
ParserConfiguration
config
,
ProgressListener
l
,
CityGMLContext
context
)
throws
CityGmlParseException
{
try
{
BufferedInputStream
bis
=
new
BufferedInputStream
(
is
);
...
...
This diff is collapsed.
Click to expand it.
CityDoctorParent/Extensions/CityDoctorZipLoader/src/main/java/de/hft/stuttgart/citydoctor2/ziploader/CityGmlZipEntry.java
+
1
-
3
View file @
313d0081
...
...
@@ -13,7 +13,6 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipInputStream
;
public
class
CityGmlZipEntry
{
...
...
@@ -31,9 +30,8 @@ public class CityGmlZipEntry {
return
new
ErroneousEntry
(
entry
,
ZipEntryErrorType
.
EXCESSIVE_FILESIZE
);
}
else
{
try
{
InputStream
is
=
archive
.
getInputStream
(
entry
);
CityGmlParser
.
gagLogger
(
true
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGml
Stream
(
is
,
config
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGml
ZipEntry
(
entry
,
archive
,
config
);
return
new
CityGmlZipEntry
(
entry
.
getName
(),
model
);
}
catch
(
CityGmlParseException
|
InvalidGmlFileException
e
)
{
logger
.
error
(
e
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets