source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/wsdl/xmlSchema/importer.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.2 KB
Line 
1# WSDL4R - XSD importer library.
2# Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'soap/httpconfigloader'
10require 'wsdl/xmlSchema/parser'
11
12
13module WSDL
14module XMLSchema
15
16
17class Importer
18 def self.import(location, originalroot = nil)
19 new.import(location, originalroot)
20 end
21
22 def initialize
23 @web_client = nil
24 end
25
26 def import(location, originalroot = nil)
27 unless location.is_a?(URI)
28 location = URI.parse(location)
29 end
30 content = parse(fetch(location), location, originalroot)
31 content.location = location
32 content
33 end
34
35private
36
37 def parse(content, location, originalroot)
38 opt = {
39 :location => location,
40 :originalroot => originalroot
41 }
42 WSDL::XMLSchema::Parser.new(opt).parse(content)
43 end
44
45 def fetch(location)
46 warn("importing: #{location}") if $DEBUG
47 content = nil
48 if location.scheme == 'file' or
49 (location.relative? and FileTest.exist?(location.path))
50 content = File.open(location.path).read
51 elsif location.scheme and location.scheme.size == 1 and
52 FileTest.exist?(location.to_s)
53 # ToDo: remove this ugly workaround for a path with drive letter
54 # (D://foo/bar)
55 content = File.open(location.to_s).read
56 else
57 client = web_client.new(nil, "WSDL4R")
58 client.proxy = ::SOAP::Env::HTTP_PROXY
59 client.no_proxy = ::SOAP::Env::NO_PROXY
60 if opt = ::SOAP::Property.loadproperty(::SOAP::PropertyName)
61 ::SOAP::HTTPConfigLoader.set_options(client,
62 opt["client.protocol.http"])
63 end
64 content = client.get_content(location)
65 end
66 content
67 end
68
69 def web_client
70 @web_client ||= begin
71 require 'http-access2'
72 if HTTPAccess2::VERSION < "2.0"
73 raise LoadError.new("http-access/2.0 or later is required.")
74 end
75 HTTPAccess2::Client
76 rescue LoadError
77 warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
78 require 'soap/netHttpClient'
79 ::SOAP::NetHttpClient
80 end
81 @web_client
82 end
83end
84
85
86end
87end
Note: See TracBrowser for help on using the repository browser.