Class: ROGC::Formats::XML::VersionedOGC

Inherits:
Base show all
Defined in:
lib/rogc/formats/xml/versioned_ogc.rb

Direct Known Subclasses

WMSCapabilities::Base

Class Attribute Summary collapse

Attributes inherited from Base

#xml_readers

Instance Method Summary collapse

Methods inherited from Base

#child_value, #read_child_nodes, #read_node

Constructor Details

#initializeVersionedOGC

Returns a new instance of VersionedOGC.



17
18
19
# File 'lib/rogc/formats/xml/versioned_ogc.rb', line 17

def initialize
  super
end

Class Attribute Details

.versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/rogc/formats/xml/versioned_ogc.rb', line 6

def version
  @version
end

Instance Method Details

#get_parser(version) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rogc/formats/xml/versioned_ogc.rb', line 36

def get_parser(version)
  version ||= default_version
  profile = self.profile.nil? ? "" : "_" + self.profile

  if @parser.nil? || @parser.class.version != version
    # version = 1
    # format = "ROGC::Formats::WMSCapabilities::V#{version}".constantize
    parser_class_name = "V#{version.to_s.gsub(/\./, "_")}" + profile
    begin
      format = "#{self.class.name.deconstantize}::#{parser_class_name}".constantize
    rescue
      format = nil
    end
    if format.nil?
      if !profile.empty? && self.allow_fallback
        profile = ""
        parser_class_name = "V#{version.to_s.gsub(/\./, "_")}" + profile
        begin
          format = "#{self.class.name.deconstantize}::#{parser_class_name}".constantize
        rescue
          format = nil
        end
      end
      if format.nil?
        raise "Can't find a parser for version #{version} #{profile}"
      end
    end
        
    @parser = format.new
  else
    puts "Yahoo one parser"
  end

  @parser
end

#get_version(root, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rogc/formats/xml/versioned_ogc.rb', line 21

def get_version(root, options = {})
  lversion = nil

  unless root.nil?
    lversion = self.class.version
    if lversion.nil?
      lversion = root['version']
      lversion ||= default_version
    end
  else
    lversion = options[:version] || self.version || self.default_version
  end
  lversion
end

#read(data, options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rogc/formats/xml/versioned_ogc.rb', line 72

def read(data, options = {})
  if data.is_a?(String)
    data = StringIO.new(data)
  end
  xml_parser = LibXML::XML::Parser.io(data)
  xml = xml_parser.parse
  root = xml.root
  version = get_version(root)

  parser = get_parser(version)
  # puts parser.readers['wms']['Layer'].inspect
  capabilities = OpenStruct.new
  capabilities = parser.read_node(root, capabilities)
  capabilities.version = version
  capabilities
end