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
4e97995c
Commit
4e97995c
authored
1 year ago
by
Jens Steidl
Browse files
Options
Downloads
Patches
Plain Diff
- added cli options
parent
156e6d53
No related branches found
No related tags found
No related merge requests found
Pipeline
#5563
failed
1 year ago
Stage: build
Stage: test
Stage: packaging
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java
+83
-4
83 additions, 4 deletions
...etta/dps/repository/plugin/XmlFormatValidationPlugin.java
with
83 additions
and
4 deletions
java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java
+
83
−
4
View file @
4e97995c
...
@@ -43,6 +43,15 @@ import java.util.Map;
...
@@ -43,6 +43,15 @@ import java.util.Map;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.Set
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.CommandLineParser
;
import
org.apache.commons.cli.DefaultParser
;
import
org.apache.commons.cli.HelpFormatter
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.ParseException
;
/**
/**
* XmlFormatValidationPlugin
* XmlFormatValidationPlugin
*
*
...
@@ -341,6 +350,15 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -341,6 +350,15 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin {
return
result
;
return
result
;
}
}
private
static
void
addFileOptionToMapOrFail
(
Map
<
String
,
String
>
initp
,
String
key
,
String
path
)
throws
ParseException
{
File
file
=
new
File
(
path
);
if
(
file
.
isFile
())
{
initp
.
put
(
key
,
path
);
}
else
{
throw
new
ParseException
(
"File '"
+
path
+
"' does not exist!"
);
}
}
private
boolean
checkIfWellformed
(
Document
doc
)
{
private
boolean
checkIfWellformed
(
Document
doc
)
{
/* detect XML type via NS */
/* detect XML type via NS */
boolean
isWellformedXml
=
false
;
boolean
isWellformedXml
=
false
;
...
@@ -408,11 +426,72 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin {
...
@@ -408,11 +426,72 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin {
* @param args list of files which should be scanned
* @param args list of files which should be scanned
*/
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
var
plugin
=
new
XmlFormatValidationPlugin
();
// create the command line options
Options
options
=
new
Options
();
options
.
addOption
(
Option
.
builder
(
"cd"
)
.
longOpt
(
"dtd-catalog"
)
.
hasArg
(
true
)
.
argName
(
"file"
)
.
numberOfArgs
(
1
)
.
desc
(
"path to DTD catalog file"
)
.
required
(
false
)
.
build
()
);
options
.
addOption
(
Option
.
builder
(
"cs"
)
.
longOpt
(
"schema-catalog"
)
.
hasArg
(
true
)
.
argName
(
"file"
)
.
numberOfArgs
(
1
)
.
desc
(
"path to schema catalog file"
)
.
required
(
false
)
.
build
()
);
options
.
addOption
(
Option
.
builder
(
"d"
)
.
longOpt
(
"debug"
)
.
hasArg
(
false
)
.
desc
(
"enable debug output"
)
.
required
(
false
)
.
build
()
);
// parse command line
CommandLineParser
parser
=
new
DefaultParser
();
CommandLine
line
=
null
;
Map
<
String
,
String
>
initp
=
new
HashMap
<>();
Map
<
String
,
String
>
initp
=
new
HashMap
<>();
initp
.
put
(
"catalog"
,
"/etc/xml/catalog"
);
try
{
initp
.
put
(
"schemacatalog"
,
"example_catalog/schema_catalog.xml"
);
line
=
parser
.
parse
(
options
,
args
);
//initp.put("debug", "true");
// DTD catalog
if
(
line
.
hasOption
(
"cd"
))
{
addFileOptionToMapOrFail
(
initp
,
"catalog"
,
line
.
getOptionValue
(
"cd"
));
}
else
{
addFileOptionToMapOrFail
(
initp
,
"catalog"
,
"/etc/xml/catalog"
);
}
// schema catalog
if
(
line
.
hasOption
(
"cs"
))
{
addFileOptionToMapOrFail
(
initp
,
"schemacatalog"
,
line
.
getOptionValue
(
"cs"
));
}
else
{
addFileOptionToMapOrFail
(
initp
,
"schemacatalog"
,
"example_catalog/schema_catalog.xml"
);
}
// debug log
if
(
line
.
hasOption
(
"d"
))
{
initp
.
put
(
"debug"
,
"true"
);
}
args
=
line
.
getArgs
();
// retrieve any left-over non-recognized options and arguments
// no validation targets
if
(
args
.
length
==
0
)
{
throw
new
ParseException
(
"No file(s) given to validate!"
);
}
}
catch
(
ParseException
exp
)
{
System
.
out
.
println
(
"\ninvalid usage: "
+
exp
.
getMessage
());
System
.
out
.
println
(
"---"
);
HelpFormatter
formatter
=
new
HelpFormatter
();
formatter
.
printHelp
(
"XmlFormatValidationPlugin.jar [options] file [file ...]"
,
options
);
System
.
exit
(
1
);
}
// run format validation
var
plugin
=
new
XmlFormatValidationPlugin
();
plugin
.
initParams
(
initp
);
plugin
.
initParams
(
initp
);
// output result
// output result
...
...
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