Sha256: 9c00216022b2be8062b99e3f6f79e1afbfb51eb2f61dba1412c4fda23acea175

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

#!/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] [workflow def] ...\n"
    print "  <workflow def> - 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openwferu-0.9.1 bin/validate-workflow.rb