3 # Shell script that creates a new transformation plug-in (both main and
4 # abstract class) using a template.
6 # The 'description' parameter will add a new entry in the language file.
7 # Watch out for special escaping.
11 # $3: Transformation Name
12 # $4: (optional) Description
15 if [ -n "$GATEWAY_INTERFACE" ] ; then
16 echo 'Can not invoke as CGI!'
20 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
21 echo -e "Usage: ./generator_plugin.sh MIMEType MIMESubtype TransformationName [Description]\n"
25 # make sure that the MIME Type, MIME Subtype and Transformation names
26 # are in the correct format
28 # make all names lowercase
29 MT
="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
30 MS
="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
31 TN
="$(echo "$3" | tr '[:upper:]' '[:lower:]')"
32 # make first letter uppercase
37 # make the first letter after each underscore uppercase
38 # define the name of the main class file and of its template
39 CLASS_NAME
=$
(echo "$MT"_
"$MS"_
"$TN" |
sed -e 's/_./\U&\E/g')
40 BASE_DIR
="./src/Plugins/Transformations"
41 ClassFile
="$BASE_DIR"/"$CLASS_NAME".php
42 Template
="$BASE_DIR"/TEMPLATE
43 # define the name of the abstract class file and its template
44 AbstractClassFile
="$BASE_DIR"/Abs
/"$TN"TransformationsPlugin.php
45 AbstractTemplate
="$BASE_DIR"/TEMPLATE_ABSTRACT
46 # replace template names with argument names
47 sed "s/\[MIMEType]/$MT/; s/\[MIMESubtype\]/$MS/; s/\[TransformationName\]/$TN/;" < $Template > "$ClassFile"
48 echo "Created $ClassFile"
50 GenerateAbstractClass
=1
52 if [ "$4" == "--generate_only_main_class" ]; then
53 if [ -e "$AbstractClassFile" ]; then
54 GenerateAbstractClass
=0
59 if [ $GenerateAbstractClass -eq 1 ]; then
60 # replace template names with argument names
61 sed "s/\[TransformationName\]/$TN/; s/Description of the transformation./$4/;" < $AbstractTemplate > "$AbstractClassFile"
62 echo "Created $AbstractClassFile"