Class: RXaal::XaalDoc

Inherits:
Object show all
Includes:
Serializable
Defined in:
lib/xaal_doc.rb

Constant Summary collapse

XAAL_NS_URI =
"http://www.cs.hut.fi/Research/SVG/XAAL"
XSI_URI =
"http://www.w3.org/2001/XMLSchema-instance"
XAAL_VERSION =
"0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXaalDoc

Returns a new instance of XaalDoc.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xaal_doc.rb', line 36

def initialize
  @namespaces = NSContainer.new
  @namespaces.add_ns(XAAL_NS_URI)
  @namespaces.add_ns(XSI_URI, "xsi")
  @top_level_elems = Array.new
  @metadata = Metadata.new(self)
  #self.styles = StyleContainer.new
  @initials = Array.new
  @seqs = Array.new
  @custom_top_level_elems = BoundArray.new(TopLevelElem)
end

Instance Attribute Details

#custom_top_level_elemsObject (readonly)

Returns the value of attribute custom_top_level_elems.



33
34
35
# File 'lib/xaal_doc.rb', line 33

def custom_top_level_elems
  @custom_top_level_elems
end

#defsObject (readonly)

Returns the value of attribute defs.



29
30
31
# File 'lib/xaal_doc.rb', line 29

def defs
  @defs
end

#general_optionsObject (readonly)

Returns the value of attribute general_options.



30
31
32
# File 'lib/xaal_doc.rb', line 30

def general_options
  @general_options
end

#global_stylesObject (readonly)

Returns the value of attribute global_styles.



29
30
31
# File 'lib/xaal_doc.rb', line 29

def global_styles
  @global_styles
end

#initialsObject (readonly)

Returns the value of attribute initials.



31
32
33
# File 'lib/xaal_doc.rb', line 31

def initials
  @initials
end

#metadataObject (readonly)

Returns the value of attribute metadata.



29
30
31
# File 'lib/xaal_doc.rb', line 29

def 
  @metadata
end

#namespacesObject (readonly)

Returns the value of attribute namespaces.



28
29
30
# File 'lib/xaal_doc.rb', line 28

def namespaces
  @namespaces
end

#seqsObject (readonly)

Returns the value of attribute seqs.



31
32
33
# File 'lib/xaal_doc.rb', line 31

def seqs
  @seqs
end

#xaal_versionObject (readonly)

Returns the value of attribute xaal_version.



27
28
29
# File 'lib/xaal_doc.rb', line 27

def xaal_version
  @xaal_version
end

Instance Method Details

#add_option(name, value) ⇒ Object



48
49
50
# File 'lib/xaal_doc.rb', line 48

def add_option (name, value)
  self.general_options[name] = value
end

#xaal_serialize(parent = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xaal_doc.rb', line 54

def xaal_serialize(parent=nil)
  
  doc = REXML::Document.new 
  doc << REXML::XMLDecl.default
  root = REXML::Element.new "xaal"
  doc.add(root)
  
  self.namespaces.each { |ns|
    pref = ns.prefix
    url = ns.url
    if (pref == "")
      #its the default
      root.add_namespace(url)
    else
      #its not
      root.add_namespace(pref, url)
    end
  }
  root.add_attribute('version', XAAL_VERSION)
  root.add_attribute(@namespaces.uri_to_ns[XSI_URI].prefix << ":schemaLocation", "http://www.cs.hut.fi/Research/SVG/XAAL xaal.xsd")
  
  self..xaal_serialize(root)
  init = REXML::Element.new "initial"
  root.elements << init
  
  initials.each { |i|
    i.xaal_serialize(init)
  }
  anim = REXML::Element.new "animation"
  root.elements << anim
  seqs.each { |s|
    s.xaal_serialize(anim)  
  }
  output_str = String.new
  doc.write(output_str, 3)
  
  return output_str
end