source: gs2-extensions/xsd-to-gs-metaset/xsd_to_mds.bash@ 31098

Last change on this file since 31098 was 28383, checked in by ak19, 11 years ago

Added a bash script equivalent to the batch script added yesterday. Updated the Readme file and minor changes to the batch file too.

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/bin/bash
2
3function usage () {
4 echo ""
5 echo "Run as $0 <xsd file> <namespace> <setname (mds file name)>"
6 echo "E.g. xsd_to_mds.bat C:\<full-path>\CDWALite-xsd-public-v1-1.xsd cdwalite CDWALite"
7 echo ""
8}
9
10# Check for 3 cmd line args
11if [ -z "$3" ]; then
12 usage
13fi
14
15# xsd input file and setName of mds file for output
16xsd=$1
17mds=$2
18
19if [ ! -f "$xsd" ]; then
20 echo "XSD file $xsd does not exist."
21 exit -1
22fi
23
24if [ "x$GSDLHOME" = "x" ]; then
25 echo "No GSDLHOME set. Source the (gs3-)setup.(ba)sh file in your Greenstone before running this script."
26 exit -1
27fi
28
29outputdir=
30if [ "x$GSDL3SRCHOME" != "x" ]; then
31 outputdir=$GSDL3SRCHOME
32else
33 outputdir=$GSDLHOME
34fi
35outputfile=$outputdir/gli/metadata/$mds.mds
36xsl=$outputdir/gli/classes/xml/xsd-to-mds.xsl
37
38if [ ! -f "$xsl" ]; then
39 echo "XSLT file $xsl can't be found."
40 exit -1
41fi
42
43# See internal wiki page Writing_XSL#Running_ApplyXSLT_to_apply_an_XSLT_file_from_the_command_line
44# Bash doesn't like quotes (escaped quotes) around _any_ of the file paths below.
45mycmd="java -cp $GSDLHOME/bin/java/xalan.jar:$GSDLHOME/bin/java/ApplyXSLT.jar:$GSDLHOME/bin/java/. org.nzdl.gsdl.ApplyXSLT -t $xsl -x $xsd -o $outputfile"
46
47
48# Call the command
49$mycmd
50status=$?
51
52# http://stackoverflow.com/questions/11079017/operations-on-boolean-variables
53if [ $status != 0 ]; then
54 echo "*** Failed running: $mycmd"
55 echo "Return status: $status"
56 exit -1
57elif [ ! -e "$outputfile" ]; then
58 echo "**** XSLT transform failed: the file $outputfile was not generated. Ran command:"
59 echo "$mycmd"
60 exit -1
61else
62 echo "The file $outputfile has been generated."
63fi
64echo ""
Note: See TracBrowser for help on using the repository browser.