~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/wsdl/xmlSchema/importer.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# WSDL4R - XSD importer library.
 
2
# Copyright (C) 2003, 2005  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 
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
 
 
9
require 'soap/httpconfigloader'
 
10
require 'wsdl/xmlSchema/parser'
 
11
 
 
12
 
 
13
module WSDL
 
14
module XMLSchema
 
15
 
 
16
 
 
17
class 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
 
 
35
private
 
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
 
83
end
 
84
 
 
85
 
 
86
end
 
87
end