forked from UB-Mannheim/ocr-fileformat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
82 lines (66 loc) · 1.76 KB
/
lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
if [[ -z "$SHAREDIR" || ! -d "$SHAREDIR" ]];then
echo_err "!! Set \$SHAREDIR before sourcing $0 !!"
exit 1
fi
DEBUG=0
XSLT_SCRIPTS=($(cd "$SHAREDIR/xslt"; find -name '*.xsl' |sed 's,^./,,'|sed 's/\.xsl$//'|sort))
XSLT_IN=()
XSLT_OUT=()
SAXON_JAR="$SHAREDIR/vendor/saxon9he.jar"
XSD_VALIDATOR_DIR="$SHAREDIR/vendor/xsd-validator"
XSD_SCHEMAS=($(cd "$SHAREDIR/xsd"; find -name '*.xsd'|sort|sed 's/\.xsd//'|sed 's,./, ,'))
XSD_ARGS=()
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
show_schemas() {
echo -e "Schemas:"
local schema
for schema in "${XSD_SCHEMAS[@]}";do
echo " - $schema"
done
}
setupFormats() {
local in_fmt out_fmt
for fmt in "${XSLT_SCRIPTS[@]}";do
in_fmt="${fmt//__*/}"
out_fmt="${fmt//*__/}"
if ! containsElement "$in_fmt" "${XSLT_IN[@]}";then XSLT_IN+=($in_fmt);fi
if ! containsElement "$out_fmt" "${XSLT_OUT[@]}";then XSLT_OUT+=($out_fmt);fi
done
}
setupFormats
show_input_formats() {
echo "Input formats:"
for i in "${XSLT_IN[@]}";do echo " - ${i}"; done
}
show_output_formats() {
echo "Output formats:"
for i in "${XSLT_OUT[@]}";do echo " - ${i}"; done
}
exec_saxon() {
SAXON_ARGS=("$@")
if [[ "$DEBUG" -gt 0 ]];then
echo_err Executing "java -jar $SAXON_JAR" "${SAXON_ARGS[@]}"
fi
if [[ "$DEBUG" -gt 1 ]];then
SAXON_ARGS+=('-t')
fi
java -jar "$SAXON_JAR" "${SAXON_ARGS[@]}"
}
exec_xsdv() {
schema="$1"
file="$2"
cd "$XSD_VALIDATOR_DIR"
if ((DEBUG > 0));then
echo_err "PWD: '$PWD'"
echo_err "./xsdv.sh '$SHAREDIR/xsd/${schema}.xsd' '$file'"
fi
./xsdv.sh "$SHAREDIR/xsd/${schema}.xsd" "$file"
}
echo_err() {
echo "$@" >&2;
}