Strabon

changeset 284:1a40315b8cb4

Added queryfile function that takese as an argument the path of a file containing the query to be executed
author Kostis Kyzirakos <kkyzir@di.uoa.gr>
date Mon Jun 18 20:56:00 2012 +0300 (2012-06-18)
parents b50c41d76b1f
children daaf7760fc46
files scripts/endpoint
line diff
     1.1 --- a/scripts/endpoint	Sat Jun 16 22:25:57 2012 +0300
     1.2 +++ b/scripts/endpoint	Mon Jun 18 20:56:00 2012 +0300
     1.3 @@ -14,7 +14,7 @@
     1.4  	echo
     1.5  	echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
     1.6  	echo
     1.7 -	echo "	COMMAND	 : one of query, update, store, or help"
     1.8 +	echo "	COMMAND	 : one of query, queryfile, update, store, or help"
     1.9  	echo "	ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)"
    1.10  	echo "	ARGS	 : arguments according to selected command"
    1.11  	echo 
    1.12 @@ -33,6 +33,15 @@
    1.13  	echo "			  \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
    1.14  }
    1.15  
    1.16 +function help_queryfile() {
    1.17 +        echo "Usage: ${CMD} queryfile ENDPOINT SPARQL_QUERY_FILE [RESULT_FORMAT]"
    1.18 +        echo
    1.19 +        echo "  ENDPOINT          : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.20 +        echo "  SPARQL_QUERY_FILE : the file that contain the SPARQL query to execute"
    1.21 +        echo "  RESULT_FORMAT     : the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
    1.22 +        echo "                      \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
    1.23 +}
    1.24 +
    1.25  function help_update() {
    1.26  	echo "Usage: ${CMD} update ENDPOINT SPARQL_QUERY"
    1.27  	echo
    1.28 @@ -71,6 +80,9 @@
    1.29  				query)
    1.30  					help_query
    1.31  					;;
    1.32 +				queryfile)
    1.33 +					help_queryfile
    1.34 +					;;
    1.35  				update)
    1.36  					help_update
    1.37  					;;
    1.38 @@ -123,6 +135,45 @@
    1.39  
    1.40  		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.41  		;;
    1.42 +	queryfile)
    1.43 +		shift
    1.44 +		if ! test $# -ge 2; then
    1.45 +			help_queryfile
    1.46 +			exit 1
    1.47 +		fi
    1.48 +
    1.49 +		if [ ! -f ${2} ];
    1.50 +		then
    1.51 +			echo "${CMD}: File not found."
    1.52 +			exit 2
    1.53 +		fi
    1.54 +
    1.55 +		URL="${1}/Query"
    1.56 +		QUERY=`cat ${2} | sed 's/\"/\\\"/g'`
    1.57 +
    1.58 +		shift
    1.59 +		shift
    1.60 +		
    1.61 +		# set default format
    1.62 +		FORMAT="XML"
    1.63 +		if test $# -eq 1; then
    1.64 +			FORMAT="${1}"
    1.65 +		fi
    1.66 +
    1.67 +		case "${FORMAT}" in
    1.68 +			[Kk][Mm][Ll][Mm][Aa][Pp]|[Gg][Ee][Oo][Jj][Ss][Oo][Nn]|[Hh][Tt][Mm][Ll]|[Kk][mM][Zz][Mm][Aa][Pp]|[Xx][Mm][Ll]|[Kk][Mm][Ll])
    1.69 +				shift
    1.70 +				;;
    1.71 +			*)
    1.72 +				echo "${CMD}: unknown format \"${FORMAT}\"."
    1.73 +				echo "${CMD}: possible values are \`KMLMAP\, \`GEOJSON' \`HTML', \`KMZMAP', \`XML' (default), or \`KML'"
    1.74 +				exit 2
    1.75 +				;;
    1.76 +		esac
    1.77 +
    1.78 +		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.79 +		;;
    1.80 +
    1.81  	update)
    1.82  		shift
    1.83  		if ! test $# -eq 2; then