From 9c37ed608370ee5d47d5290593bd5a5eeba13594 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Tue, 10 Oct 2006 15:10:16 +0000 Subject: [PATCH] added full RelaxNG based config file syntax checking which checks every filter according to it's own rules. These are exported by the 'make' target to RelaxNG XML and XML Schema instances using the nifty 'trang' utility. added check of all config files in etc dir according to both RelaxNG XML and XML Schema instances. check targets are 'make check_xsd' and 'make check_rng' when standing in 'etc' directory. Still missing to integrate XML checks into 'make check' target. --- Makefile.am | 4 +- configure.ac | 3 + etc/Makefile.am | 41 +- etc/config-imagine.xml | 117 ---- etc/config-sru-to-z3950.xml | 4 +- etc/config-zurg.xml | 8 +- etc/experiment-query-config-translate.php | 173 ----- etc/queryinfo.xml | 350 --------- etc/retrievalinfo.xml | 104 --- etc/zeerex-explain.xml | 740 -------------------- xml/Makefile.am | 4 + xml/experiments/config-imagine.xml | 117 ++++ .../experiment-query-config-translate.php | 173 +++++ xml/schema/Makefile.am | 20 + xml/schema/metaproxy.rnc | 55 +- 15 files changed, 404 insertions(+), 1509 deletions(-) delete mode 100644 etc/config-imagine.xml delete mode 100755 etc/experiment-query-config-translate.php delete mode 100644 etc/queryinfo.xml delete mode 100644 etc/retrievalinfo.xml delete mode 100644 etc/zeerex-explain.xml create mode 100644 xml/Makefile.am create mode 100644 xml/experiments/config-imagine.xml create mode 100755 xml/experiments/experiment-query-config-translate.php create mode 100644 xml/schema/Makefile.am diff --git a/Makefile.am b/Makefile.am index 766e8ef..ea1a3c9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ ## This file is part of Metaproxy ## Copyright (C) 2005-2006, Index Data ApS -## $Id: Makefile.am,v 1.17 2006-09-29 09:43:56 marc Exp $ +## $Id: Makefile.am,v 1.18 2006-10-10 15:10:16 marc Exp $ -SUBDIRS = src doc etc +SUBDIRS = src xml doc etc ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index ed7d326..99acb1e 100644 --- a/configure.ac +++ b/configure.ac @@ -105,6 +105,9 @@ AC_CONFIG_FILES([ Makefile src/Makefile src/Jamfile + xml/Makefile + xml/schema/Makefile + xml/xslt/Makefile doc/Makefile doc/local.ent doc/common/Makefile diff --git a/etc/Makefile.am b/etc/Makefile.am index 7b3c811..4c4a498 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -1,26 +1,41 @@ -# $Id: Makefile.am,v 1.3 2006-06-19 13:29:30 adam Exp $ +# $Id: Makefile.am,v 1.4 2006-10-10 15:10:16 marc Exp $ # This doesn't actually build anything, it just tests whether the # configuration files here correspond with the schema. etcdatadir = $(pkgdatadir)/etc -config = config0.xml config1.xml config2.xml \ - config3.xml config4.xml config5.xml \ - config-simple-multi.xml config-local.xml \ - config-shared1.xml +xmlconfig = config-bytarget.xml \ + config-local.xml \ + config-record-transform.xml \ + config-shared1.xml \ + config-simple-multi.xml \ + config-sru-to-z3950.xml \ + config-zurg.xml \ + config0.xml \ + config1.xml \ + config2.xml \ + config3.xml \ + config4.xml \ + config5.xml -misc = example.simple-auth example.target-auth pqf2pqf.xsl +config = example.simple-auth example.target-auth pqf2pqf.xsl -etcdata_DATA = $(config) $(misc) + +rng = ../xml/schema/metaproxy.rng +xsd = ../xml/schema/metaproxy.xsd + +etcdata_DATA = $(xmlconfig) $(config) EXTRA_DIST = $(etcdata_DATA) -test: test-config0 test-config1 test-config2 \ - test-config3 test-config4 test-config5 \ - test-config-simple-multi test-config-local \ - test-config-shared1 +.PHONY: check_rng +check_rng: + xmllint --noout --relaxng $(rng) $(xmlconfig) + +.PHONY: check_xsd +check_xsd: + xmllint --noout --schema $(xsd) $(xmlconfig) + -test-%: %.xml config.xsd - xmllint --noout --schema config.xsd $< diff --git a/etc/config-imagine.xml b/etc/config-imagine.xml deleted file mode 100644 index 7879f5a..0000000 --- a/etc/config-imagine.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - @:210 - - - out.log - - - std::cerr - - - - - - - - - - - - - - - - - - - mylog.log - - - - - - - - localhost:9999/A - - - - - - localhost:9999/B - - - - - - - - - - - - - - - - - - - - - - diff --git a/etc/config-sru-to-z3950.xml b/etc/config-sru-to-z3950.xml index f070e93..ea978d9 100644 --- a/etc/config-sru-to-z3950.xml +++ b/etc/config-sru-to-z3950.xml @@ -1,5 +1,5 @@ - + @@ -17,7 +17,7 @@ SRU/W - + Z3950 diff --git a/etc/config-zurg.xml b/etc/config-zurg.xml index e7ff942..09be83c 100644 --- a/etc/config-zurg.xml +++ b/etc/config-zurg.xml @@ -1,9 +1,7 @@ - + - - @@ -14,7 +12,7 @@ F - ../etc/example.simple-auth + etc/example.simple-auth @@ -67,7 +65,7 @@ M - ../etc/example.target-auth + etc/example.target-auth diff --git a/etc/experiment-query-config-translate.php b/etc/experiment-query-config-translate.php deleted file mode 100755 index 38e764e..0000000 --- a/etc/experiment-query-config-translate.php +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/php -command()); - -$config = new Config; -$config->load($command->config()); -$config->parse(); -$config->cql_check_boolean("and"); -$config->cql_check_boolean("notexist"); -$config->cql_check_apt("cql", "all", "="); -$config->cql_check_apt("cql", "all", "notexist"); -$config->cql_check_apt("cql", "notexist", "="); -$config->cql_check_apt("notexist", "all", "<>"); - - -print("DONE\n"); -exit(0); - - -class Command { - private $options; - private $command; - private $short_format_config = 'hc:s:t:'; - private $syntax_config = array('ccl', 'cql', 'pqf'); - - - public function __construct() { - $args = Console_Getopt::readPHPArgv(); - - if ( PEAR::isError($args) ) { - fwrite(STDERR,$args->getMessage()."\n"); - exit(1); - } - - // Compatibility between "php script.php" and "./script.php" - if ( realpath($_SERVER['argv'][0]) == __FILE__ ) { - $this->options - = Console_Getopt::getOpt($args, $this->short_format_config); - } else { - $this->options - = Console_Getopt::getOpt2($args, $this->short_format_config); - } - - // Check for invalid options - if ( PEAR::isError($this->options) ) { - fwrite(STDERR, $this->options->getMessage()."\n"); - $this->help(); - } - - $this->command = array(); - - // Loop through the user provided options - foreach ( $this->options[0] as $option ) { - switch ( $option[0] ) { - case 'h': - help(); - break; - case 's': - $this->command['syntax'] = $option[1]; - break; - case 't': - $this->command['transform'] = $option[1]; - break; - case 'c': - $this->command['config'] = $option[1]; - break; - } - } - - // Loop through the user provided options - foreach ($this->options[1] as $argument ) { - $this->command['query'] .= ' ' . $argument; - } - } - - - public function help() { - fwrite(STDERR, " Usage:\n"); - fwrite(STDERR, " ./experiment-query-config-translate.php -s syntax -t transform -c config.xml query\n"); - fwrite(STDERR, " Experiment with general query configuration syntax and transformations.\n"); - fwrite(STDERR, " -c config.xml XML config file\n"); - fwrite(STDERR, " -s syntax Syntax of source query language, 'ccl', 'cql', 'pqf'\n"); - fwrite(STDERR, " -t transform Syntax of transformed query language, 'ccl', 'cql', 'pqf'\n"); - fwrite(STDERR, " -h Display help\n"); - fwrite(STDERR, " query Valid query in specified syntax\n"); - exit(0); - } - - public function command() { - return $this->command; - } - - public function syntax() { - return $this->command['syntax']; - } - - public function transform() { - return $this->command['transform']; - } - - public function config() { - return $this->command['config']; - } - - public function query() { - return $this->commamd['query']; - } - -} - -class Config { - private $xml_conf; - - public function load($xml_file){ - $this->xml_conf = @simplexml_load_file($xml_file) - or die("Unable to load XML config file '" . $xml_file ."'\n"); - $this->xml_conf->registerXPathNamespace('iq', - 'http://indexdata.com/query'); - } - - public function parse(){ - //foreach ($this->xml_conf->xpath('//desc') as $desc) { - //echo "$desc\n"; - - $namespaces = $this->xml_conf->getNamespaces(true); - foreach ($namespaces as $ns){ - print("namespace '" . $ns . "'\n"); - } - - foreach ($this->xml_conf->xpath('//iq:syntax') as $syntax){ - print("syntax '" . $syntax['name'] . "'\n"); - } - - } - - public function cql_check_boolean($boolean){ - foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:boolean") - as $b){ - if ($b['name'] == $boolean ){ - print("CQL boolean '" . $boolean . "' exists\n"); - return; - } - } - print("CQL boolean '" . $boolean . "' error\n"); - } - - public function cql_check_apt($set, $index, $relation){ - print("CQL APT set'" . $set . "' index '" . $index - . "' relation '" . $relation . "' check\n"); - - foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:set") - as $s){ - if ($s['name'] == $set ){ - print("CQL APT set'" . $set . "' OK\n"); - foreach ($set->xpath("//iq:index") as $i){ - - print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n"); - return; - } - - print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n"); - return; - } - } - print("CQL APT set'" . $set . "' ERROR\n"); - } - -} - diff --git a/etc/queryinfo.xml b/etc/queryinfo.xml deleted file mode 100644 index efcfebc..0000000 --- a/etc/queryinfo.xml +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - CQL Standard Set - - - - - - - - - - - - - - - - - - - Record Standard Set - - - - Dublin Core Set - - - - - - - - - - - - - - - BIB-1 Z39.50 Standard Set - - - - - - - - Title - - - ISBN - - - - - - - - ISSN - - - - Date - - - - Abstract - - - Author - - - Any - - - - - - - - - - - - Explain Z39.50 Standard Set - - - Gils Z39.50 Standard Set - - - - CCL Query Language - English Configuration - CCL Søgesprog - Dansk Konfiguration - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/etc/retrievalinfo.xml b/etc/retrievalinfo.xml deleted file mode 100644 index 0f4bafb..0000000 --- a/etc/retrievalinfo.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - Marc21 - - Full Marc21 Record - - - - Brief Marc21 Record - - - - - - - XML - - MarcXML - - - - - - - - Marc XChange - - - - - - - - Dublin Core - - - - - - - - - - - \ No newline at end of file diff --git a/etc/zeerex-explain.xml b/etc/zeerex-explain.xml deleted file mode 100644 index c19dde2..0000000 --- a/etc/zeerex-explain.xml +++ /dev/null @@ -1,740 +0,0 @@ - - - - - - - - - - - - - - - - - foo.indexdata.dk - 80 - - Default - - - - - - Metaproxy SRU/SRW/Z39.50 server - - - Test ZeeRex Explain for SRU and CQL-to-PQF query Metaproxy filter - - - Marc Cromme, Index Data Aps, - http://www.indexdata.dk - - Marc Cromme, marc(at)indexdata(dot)com - - - - - - Implemented for Talis - - - - Index Data Metaproxy http://www.indexdata.dk - - - - http://foo.indexdata.dk:80 - http://foo.indexdata.dk:80 - http://foo.indexdata.dk:80 - - - - - - - - - - - - - - - - - - - - - - - CQL Standard Set - - - - - - - - - - - - - - - - - - - Record Standard Set - - - - Dublin Core Set - - - - - - - - - - - - - - - BIB-1 Z39.50 Standard Set - - - - - - - - Title - - - ISBN - - - - - - - - ISSN - - - - Date - - - - Abstract - - - Author - - - Any - - - - - - - - - - - - Explain Z39.50 Standard Set - - - Gils Z39.50 Standard Set - - - - CCL Query Language - English Configuration - CCL Søgesprog - Dansk Konfiguration - - - - - - - - - - - - - - - - - - - - - - - - - - - CQL Standard Set - - - Record Standard Set - - - Dublin Core Set - - - BIB-1 Z39.50 Standard Set - - - - - - CQL Server Choice - serverChoice - - text - - - - CQL All - all - - text - - - - - - Record ID - id - - rec:id - 3 - - - - - - - DC Title - title - - dc:title - - - - DC Creator - creator - - dc:creator - - - - DC Subject - subject - - dc:subject - - - - DC Description - description - - dc:description - - - - - DC Publisher - publisher - - dc:publisher - - - - DC Contributor - contributor - - dc:contributor - - - - DC Date - date - - dc:date - - - - DC Type - type - - dc:type - - - - DC Format - format - - - - - - DC Identifier - identifier - - dc:identifier - - - - DC Source - source - - dc:source - - - - DC Language - language - - dc:language - - - - DC Relation - relation - - dc:relation - - - - DC Coverage - coverage - - dc:coverage - - - - DC Rights - rights - - dc:rights - - - - - - - - - - - Marc21 - - Full Marc21 Record - - - - Brief Marc21 Record - - - - - - - XML - - MarcXML - - - - - - - - Marc XChange - - - - - - - - Dublin Core - - - - - - - - - - - - - - - - - cql - - all - - - = - - < - <= - = - >= - > - - - - - - - relevant - - - - - - - - - - - - - - - - - * - ? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - index - - - - - - - docpath/sru.xsl - - - xml - - - - - - - - - - - - - - - - - - - - - - - 20 - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/xml/Makefile.am b/xml/Makefile.am new file mode 100644 index 0000000..5a61760 --- /dev/null +++ b/xml/Makefile.am @@ -0,0 +1,4 @@ +# $Id: Makefile.am,v 1.1 2006-10-10 15:10:17 marc Exp $ + +SUBDIRS = schema xslt + diff --git a/xml/experiments/config-imagine.xml b/xml/experiments/config-imagine.xml new file mode 100644 index 0000000..7879f5a --- /dev/null +++ b/xml/experiments/config-imagine.xml @@ -0,0 +1,117 @@ + + + + + + + + @:210 + + + out.log + + + std::cerr + + + + + + + + + + + + + + + + + + + mylog.log + + + + + + + + localhost:9999/A + + + + + + localhost:9999/B + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml/experiments/experiment-query-config-translate.php b/xml/experiments/experiment-query-config-translate.php new file mode 100755 index 0000000..38e764e --- /dev/null +++ b/xml/experiments/experiment-query-config-translate.php @@ -0,0 +1,173 @@ +#!/usr/bin/php +command()); + +$config = new Config; +$config->load($command->config()); +$config->parse(); +$config->cql_check_boolean("and"); +$config->cql_check_boolean("notexist"); +$config->cql_check_apt("cql", "all", "="); +$config->cql_check_apt("cql", "all", "notexist"); +$config->cql_check_apt("cql", "notexist", "="); +$config->cql_check_apt("notexist", "all", "<>"); + + +print("DONE\n"); +exit(0); + + +class Command { + private $options; + private $command; + private $short_format_config = 'hc:s:t:'; + private $syntax_config = array('ccl', 'cql', 'pqf'); + + + public function __construct() { + $args = Console_Getopt::readPHPArgv(); + + if ( PEAR::isError($args) ) { + fwrite(STDERR,$args->getMessage()."\n"); + exit(1); + } + + // Compatibility between "php script.php" and "./script.php" + if ( realpath($_SERVER['argv'][0]) == __FILE__ ) { + $this->options + = Console_Getopt::getOpt($args, $this->short_format_config); + } else { + $this->options + = Console_Getopt::getOpt2($args, $this->short_format_config); + } + + // Check for invalid options + if ( PEAR::isError($this->options) ) { + fwrite(STDERR, $this->options->getMessage()."\n"); + $this->help(); + } + + $this->command = array(); + + // Loop through the user provided options + foreach ( $this->options[0] as $option ) { + switch ( $option[0] ) { + case 'h': + help(); + break; + case 's': + $this->command['syntax'] = $option[1]; + break; + case 't': + $this->command['transform'] = $option[1]; + break; + case 'c': + $this->command['config'] = $option[1]; + break; + } + } + + // Loop through the user provided options + foreach ($this->options[1] as $argument ) { + $this->command['query'] .= ' ' . $argument; + } + } + + + public function help() { + fwrite(STDERR, " Usage:\n"); + fwrite(STDERR, " ./experiment-query-config-translate.php -s syntax -t transform -c config.xml query\n"); + fwrite(STDERR, " Experiment with general query configuration syntax and transformations.\n"); + fwrite(STDERR, " -c config.xml XML config file\n"); + fwrite(STDERR, " -s syntax Syntax of source query language, 'ccl', 'cql', 'pqf'\n"); + fwrite(STDERR, " -t transform Syntax of transformed query language, 'ccl', 'cql', 'pqf'\n"); + fwrite(STDERR, " -h Display help\n"); + fwrite(STDERR, " query Valid query in specified syntax\n"); + exit(0); + } + + public function command() { + return $this->command; + } + + public function syntax() { + return $this->command['syntax']; + } + + public function transform() { + return $this->command['transform']; + } + + public function config() { + return $this->command['config']; + } + + public function query() { + return $this->commamd['query']; + } + +} + +class Config { + private $xml_conf; + + public function load($xml_file){ + $this->xml_conf = @simplexml_load_file($xml_file) + or die("Unable to load XML config file '" . $xml_file ."'\n"); + $this->xml_conf->registerXPathNamespace('iq', + 'http://indexdata.com/query'); + } + + public function parse(){ + //foreach ($this->xml_conf->xpath('//desc') as $desc) { + //echo "$desc\n"; + + $namespaces = $this->xml_conf->getNamespaces(true); + foreach ($namespaces as $ns){ + print("namespace '" . $ns . "'\n"); + } + + foreach ($this->xml_conf->xpath('//iq:syntax') as $syntax){ + print("syntax '" . $syntax['name'] . "'\n"); + } + + } + + public function cql_check_boolean($boolean){ + foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:boolean") + as $b){ + if ($b['name'] == $boolean ){ + print("CQL boolean '" . $boolean . "' exists\n"); + return; + } + } + print("CQL boolean '" . $boolean . "' error\n"); + } + + public function cql_check_apt($set, $index, $relation){ + print("CQL APT set'" . $set . "' index '" . $index + . "' relation '" . $relation . "' check\n"); + + foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:set") + as $s){ + if ($s['name'] == $set ){ + print("CQL APT set'" . $set . "' OK\n"); + foreach ($set->xpath("//iq:index") as $i){ + + print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n"); + return; + } + + print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n"); + return; + } + } + print("CQL APT set'" . $set . "' ERROR\n"); + } + +} + diff --git a/xml/schema/Makefile.am b/xml/schema/Makefile.am new file mode 100644 index 0000000..4a2971f --- /dev/null +++ b/xml/schema/Makefile.am @@ -0,0 +1,20 @@ +# $Id: Makefile.am,v 1.1 2006-10-10 15:10:18 marc Exp $ + +xmlschemadatadir = $(pkgdatadir)/xml/schema + +schemas = metaproxy.rnc metaproxy.rng metaproxy.xsd + +xmlschemadata_DATA = $(schemas) + +EXTRA_DIST = $(xmlschemadata_DATA) + + + +# pattern compile RelaxNG Compact to RelaxNG XML +%.rng : %.rnc + trang $< $@ + +# pattern compile RelaxNG Compact to XML Schema +%.xsd : %.rnc + trang $< $@ + diff --git a/xml/schema/metaproxy.rnc b/xml/schema/metaproxy.rnc index bd94035..8e92daa 100644 --- a/xml/schema/metaproxy.rnc +++ b/xml/schema/metaproxy.rnc @@ -1,5 +1,5 @@ # Metaproxy XML config file schemas -# $Id: metaproxy.rnc,v 1.4 2006-10-06 22:51:40 marc Exp $ +# $Id: metaproxy.rnc,v 1.5 2006-10-10 15:10:18 marc Exp $ # # Copyright (c) 2005-2006, Index Data. # @@ -49,6 +49,9 @@ filter = | filter_log | filter_multi | filter_query_rewrite + | filter_record_transform + | filter_session_shared + | filter_sru_z3950 | filter_virt_db | filter_z3950_client } @@ -94,11 +97,13 @@ filter_log = attribute type { "log" }, attribute id { xsd:NCName }?, attribute name { xsd:NCName }?, - element message { xsd:NCName }, + element message { xsd:string }?, element filename { xsd:string }?, element category { + attribute init-options { xsd:boolean }?, attribute request-session { xsd:boolean }?, attribute response-session { xsd:boolean }?, + attribute apdu { xsd:boolean }?, attribute request-apdu { xsd:boolean }?, attribute response-apdu { xsd:boolean }? }? @@ -119,6 +124,29 @@ filter_query_rewrite = attribute name { xsd:NCName }?, element xslt { xsd:string } +filter_record_transform = + attribute type { "record_transform" }, + attribute id { xsd:NCName }?, + attribute name { xsd:NCName }?, + retrievalinfo + +filter_session_shared = + attribute type { "session_shared" }, + attribute id { xsd:NCName }?, + attribute name { xsd:NCName }?, + element resultset { + attribute max { xsd:integer }, + attribute ttl { xsd:integer } + }, + element session { + attribute ttl { xsd:integer } + } + +filter_sru_z3950 = + attribute type { "sru_z3950" }, + attribute id { xsd:NCName }?, + attribute name { xsd:NCName }? + filter_virt_db = attribute type { "virt_db" }, attribute id { xsd:NCName }?, @@ -133,4 +161,25 @@ filter_z3950_client = attribute type { "z3950_client" }, attribute id { xsd:NCName }?, attribute name { xsd:NCName }?, - element timeout { xsd:integer } + element timeout { xsd:integer }? + +retrievalinfo = + element retrievalinfo { + element retrieval { + attribute syntax { xsd:string }, + attribute name { xsd:string }?, + attribute identifier { xsd:string }?, + attribute backendsyntax { xsd:string }?, + attribute backendname { xsd:string }?, + element convert { + element marc { + attribute inputformat { xsd:string }, + attribute outputformat { xsd:string }, + attribute inputcharset { xsd:string } + }, + element xslt { + attribute stylesheet { xsd:string } + }? + }? + }+ + } -- 1.7.10.4