#!/usr/bin/env ruby # # Program Name: validate-workflow.rb # Purpose: A helper script that validates a workflow document against # a XML Schema # Author: Alain Hoang # Version: 0.1 # Notes: Uses Ruby's libxml library to handle the parsing # Stdlib require 'net/http' require 'uri' # From the gems archive require 'rubygems' require 'xml/libxml' module OpenWFEru # Validates a workflow definition against the Workflow XML Schema # defined at http://www.openwfe.org/flowdef.xsd class WorkflowValidator OPENWFE_FLOWDEF_URL='http://www.openwfe.org/flowdef.xsd' # Class method for validating a xml file against the # OpenWFE XML Schema def WorkflowValidator.validate(file) # Should only be initialized once during the lifetime # of the program if not defined? @@schema xsd_str = Net::HTTP.get URI.parse(OPENWFE_FLOWDEF_URL) @@schema = XML::Schema.from_string(xsd_str) end xmldoc = XML::Document.file(file) xmldoc.validate_schema(@@schema) end end end def usage print "Usage: #{$0} [workflow def] [workflow def] ...\n" print " - workflow definition file\n" end def main # Make sure we have at least one argument or bail if ARGV.length == 0 usage exit 1 end # Loop through all arguments and validate the file ARGV.each do |f| print "Trying to validate #{f}... " if OpenWFEru::WorkflowValidator.validate(f) print "PASSED\n" else print "FAILED\n" end end end if $0 == __FILE__ main end