cheri 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +98 -0
- data/Rakefile +121 -0
- data/examples/hello_world_1.rb +28 -0
- data/examples/table_1.rb +44 -0
- data/lib/cheri/awt.rb +41 -0
- data/lib/cheri/builder.rb +31 -0
- data/lib/cheri/builder/awt/connecter.rb +63 -0
- data/lib/cheri/builder/awt/constants.rb +1003 -0
- data/lib/cheri/builder/awt/main.rb +191 -0
- data/lib/cheri/builder/awt/types.rb +220 -0
- data/lib/cheri/builder/base.rb +533 -0
- data/lib/cheri/builder/config.rb +187 -0
- data/lib/cheri/builder/connecter.rb +386 -0
- data/lib/cheri/builder/context.rb +655 -0
- data/lib/cheri/builder/generator.rb +425 -0
- data/lib/cheri/builder/html/charsets.rb +154 -0
- data/lib/cheri/builder/html/common.rb +32 -0
- data/lib/cheri/builder/html/connecter.rb +57 -0
- data/lib/cheri/builder/html/element.rb +156 -0
- data/lib/cheri/builder/html/main.rb +116 -0
- data/lib/cheri/builder/html/types.rb +123 -0
- data/lib/cheri/builder/main.rb +483 -0
- data/lib/cheri/builder/swing/connecter.rb +141 -0
- data/lib/cheri/builder/swing/constants.rb +420 -0
- data/lib/cheri/builder/swing/main.rb +446 -0
- data/lib/cheri/builder/swing/types.rb +270 -0
- data/lib/cheri/builder/xml/charsets.rb +154 -0
- data/lib/cheri/builder/xml/common.rb +32 -0
- data/lib/cheri/builder/xml/connecter.rb +42 -0
- data/lib/cheri/builder/xml/element.rb +189 -0
- data/lib/cheri/builder/xml/main.rb +130 -0
- data/lib/cheri/builder/xml/types.rb +36 -0
- data/lib/cheri/cheri.rb +70 -0
- data/lib/cheri/cjx.rb +3 -0
- data/lib/cheri/explorer.rb +32 -0
- data/lib/cheri/explorer/explorer.rb +560 -0
- data/lib/cheri/html.rb +31 -0
- data/lib/cheri/image/Delete24.gif +0 -0
- data/lib/cheri/image/Find24.gif +0 -0
- data/lib/cheri/image/FindAgain24.gif +0 -0
- data/lib/cheri/image/Refresh24.gif +0 -0
- data/lib/cheri/image/Search24.gif +0 -0
- data/lib/cheri/image/Thumbs.db +0 -0
- data/lib/cheri/image/cheri_icon_16x16.png +0 -0
- data/lib/cheri/image/cheri_icon_24x24.png +0 -0
- data/lib/cheri/image/cheri_logo_medium.png +0 -0
- data/lib/cheri/image/close_10x10.png +0 -0
- data/lib/cheri/image/close_10x10s.png +0 -0
- data/lib/cheri/image/close_12x12.png +0 -0
- data/lib/cheri/image/close_14x14.png +0 -0
- data/lib/cheri/image/close_24x24.png +0 -0
- data/lib/cheri/image/close_dim2_12x12.png +0 -0
- data/lib/cheri/image/close_dim_12x12.png +0 -0
- data/lib/cheri/image/cls_tree.png +0 -0
- data/lib/cheri/image/con_tree.png +0 -0
- data/lib/cheri/image/jruby_14x16.png +0 -0
- data/lib/cheri/image/jruby_logo.png +0 -0
- data/lib/cheri/image/mod_tree.png +0 -0
- data/lib/cheri/image/obj_tree.png +0 -0
- data/lib/cheri/image/ruby_16x16.png +0 -0
- data/lib/cheri/image/vars_tree.png +0 -0
- data/lib/cheri/java.rb +26 -0
- data/lib/cheri/java/builder.rb +28 -0
- data/lib/cheri/java/builder/main.rb +407 -0
- data/lib/cheri/java/builder/util.rb +480 -0
- data/lib/cheri/java/java.rb +56 -0
- data/lib/cheri/jruby.rb +32 -0
- data/lib/cheri/jruby/explorer.rb +43 -0
- data/lib/cheri/jruby/explorer/common.rb +38 -0
- data/lib/cheri/jruby/explorer/dialogs.rb +383 -0
- data/lib/cheri/jruby/explorer/explorer.rb +904 -0
- data/lib/cheri/jruby/explorer/splash.rb +80 -0
- data/lib/cheri/jruby/explorer/viewer.rb +619 -0
- data/lib/cheri/jruby/explorer/viewers.rb +1057 -0
- data/lib/cheri/jruby/jruby.rb +59 -0
- data/lib/cheri/swing.rb +41 -0
- data/lib/cheri/xml.rb +31 -0
- metadata +135 -0
@@ -0,0 +1,154 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
module Cheri
|
26
|
+
module Xml
|
27
|
+
module Charsets
|
28
|
+
SPECIAL = /[\000-\010\013\014\016-\037\046\074\076\200-\377]/
|
29
|
+
HIBYTES = /[\200-\377]/
|
30
|
+
class << self
|
31
|
+
def special?(str)
|
32
|
+
str =~ SPECIAL
|
33
|
+
end
|
34
|
+
# Returns a Charset if +str+ requires translation, else +nil+
|
35
|
+
def charset(str)
|
36
|
+
return nil unless str =~ SPECIAL
|
37
|
+
if str =~ HIBYTES
|
38
|
+
Utf8.detect?(str) ? Utf8 : Win1252
|
39
|
+
else
|
40
|
+
Iso8859
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end #self
|
44
|
+
module Charset
|
45
|
+
def xlat(i,o)
|
46
|
+
m = @map
|
47
|
+
i.each_byte do |b| o << m[b]; end
|
48
|
+
end
|
49
|
+
def map
|
50
|
+
@map
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module Win1252
|
55
|
+
extend Charset
|
56
|
+
@map = Array.new(256)
|
57
|
+
map = @map
|
58
|
+
0.upto(31) do |i| map[i] = 32; end
|
59
|
+
map[9] = ?\t
|
60
|
+
map[10] = ?\n
|
61
|
+
map[13] = ?\r
|
62
|
+
32.upto(127) do |i| map[i] = i; end
|
63
|
+
map[38] = '&'
|
64
|
+
map[60] = '<'
|
65
|
+
map[62] = '>'
|
66
|
+
# windows-1252 mappings
|
67
|
+
map[128] = '€'
|
68
|
+
map[129] = '?' #undefined
|
69
|
+
map[130] = '‚'
|
70
|
+
map[131] = 'ƒ'
|
71
|
+
map[132] = '„'
|
72
|
+
map[133] = '…'
|
73
|
+
map[134] = '†'
|
74
|
+
map[135] = '‡'
|
75
|
+
map[136] = 'ˆ'
|
76
|
+
map[137] = '‰'
|
77
|
+
map[138] = 'Š'
|
78
|
+
map[139] = '‹'
|
79
|
+
map[140] = 'Œ'
|
80
|
+
map[141] = '?' #undefined
|
81
|
+
map[142] = 'Ž'
|
82
|
+
map[143] = '?' #undefined
|
83
|
+
map[144] = '?' #undefined
|
84
|
+
map[145] = '‘'
|
85
|
+
map[146] = '’'
|
86
|
+
map[147] = '“'
|
87
|
+
map[148] = '”'
|
88
|
+
map[149] = '•'
|
89
|
+
map[150] = '–'
|
90
|
+
map[151] = '—'
|
91
|
+
map[152] = '˜'
|
92
|
+
map[153] = '™'
|
93
|
+
map[154] = 'š'
|
94
|
+
map[155] = '›'
|
95
|
+
map[156] = 'œ'
|
96
|
+
map[157] = '?' #undefined
|
97
|
+
map[158] = 'ž'
|
98
|
+
map[159] = 'Ÿ'
|
99
|
+
# 160-255 same for windows-1252 & ISO 8859-1 (Latin-1)
|
100
|
+
160.upto(255) do |i| map[i] = "&##{i};"; end
|
101
|
+
end
|
102
|
+
|
103
|
+
module Iso8859
|
104
|
+
extend Charset
|
105
|
+
# using same map for windows-1252 & ISO 8859-1, since the
|
106
|
+
# only detectable difference is use of 0x80-0x9f
|
107
|
+
@map = Win1252.map
|
108
|
+
end
|
109
|
+
|
110
|
+
module Utf8
|
111
|
+
extend Charset
|
112
|
+
|
113
|
+
# TODO: not quite correct for EO, F0, F4 ?
|
114
|
+
def self.detect?(str)
|
115
|
+
d = @detect
|
116
|
+
ct = 0
|
117
|
+
begin
|
118
|
+
str.each_byte do |b|
|
119
|
+
if b < 128
|
120
|
+
return false if ct > 0
|
121
|
+
elsif b < 192
|
122
|
+
return false if (ct -= 1) < 0
|
123
|
+
else
|
124
|
+
return false unless ct == 0
|
125
|
+
ct += d[b]
|
126
|
+
end
|
127
|
+
end #each_byte
|
128
|
+
ct == 0
|
129
|
+
rescue
|
130
|
+
false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
@map = Array.new(256)
|
135
|
+
map = @map
|
136
|
+
0.upto(31) do |i| map[i] = 32; end
|
137
|
+
map[9] = ?\t
|
138
|
+
map[10] = ?\n
|
139
|
+
map[13] = ?\r
|
140
|
+
32.upto(255) do |i| map[i] = i; end
|
141
|
+
map[38] = '&'
|
142
|
+
map[60] = '<'
|
143
|
+
map[62] = '>'
|
144
|
+
|
145
|
+
@detect = Array.new(256)
|
146
|
+
det = @detect
|
147
|
+
0x80.upto(0xBF) do |i| det[i] = -1; end
|
148
|
+
0xC2.upto(0xDF) do |i| det[i] = 1; end
|
149
|
+
0xE0.upto(0xEF) do |i| det[i] = 2; end
|
150
|
+
0xF0.upto(0xF4) do |i| det[i] = 3; end
|
151
|
+
end
|
152
|
+
end #Charsets
|
153
|
+
end #Xml
|
154
|
+
end #Cheri
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
|
26
|
+
module Cheri
|
27
|
+
module Xml
|
28
|
+
VERSION = Cheri::VERSION
|
29
|
+
class XmlException < Cheri::CheriException; end
|
30
|
+
class BuilderException < Cheri::Builder::BuilderException; end
|
31
|
+
end #Xml
|
32
|
+
end #Cheri
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
module Cheri
|
26
|
+
module Xml
|
27
|
+
|
28
|
+
XmlConnecter = Cheri::Builder::TypeConnecter.new do
|
29
|
+
|
30
|
+
type XmlElement do
|
31
|
+
connect XmlElement
|
32
|
+
connect Cheri::Builder::Content
|
33
|
+
end
|
34
|
+
|
35
|
+
type XmlRoot do
|
36
|
+
connect XmlElement
|
37
|
+
end
|
38
|
+
|
39
|
+
end #XmlConnecter
|
40
|
+
|
41
|
+
end #Xml
|
42
|
+
end #Cheri
|
@@ -0,0 +1,189 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
|
26
|
+
module Cheri
|
27
|
+
module Xml
|
28
|
+
|
29
|
+
# Marker 'interface' used by connecters.
|
30
|
+
module XmlElement
|
31
|
+
end #XmlElement
|
32
|
+
|
33
|
+
# Included by all Cheri::Xml builders
|
34
|
+
module XmlBuilder
|
35
|
+
CE = ' />'.freeze #:nodoc:
|
36
|
+
|
37
|
+
def empty_s(str='')
|
38
|
+
str << CE
|
39
|
+
end
|
40
|
+
|
41
|
+
def empty_io(ios)
|
42
|
+
ios << CE
|
43
|
+
end
|
44
|
+
|
45
|
+
def esc(inp,out=nil)
|
46
|
+
if @ctx[:xml_esc] && (cs = Charsets.charset(inp))
|
47
|
+
cs.xlat(inp,(out ||= ''))
|
48
|
+
out
|
49
|
+
elsif out
|
50
|
+
out << inp
|
51
|
+
else
|
52
|
+
inp
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end #XmlBuilder
|
56
|
+
|
57
|
+
class Elem
|
58
|
+
include Cheri::Builder::MarkupBuilder
|
59
|
+
include XmlBuilder
|
60
|
+
include XmlElement
|
61
|
+
|
62
|
+
def mod
|
63
|
+
Cheri::Xml
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class EmptyElem
|
68
|
+
include Cheri::Builder::EmptyMarkupBuilder
|
69
|
+
include XmlBuilder
|
70
|
+
include XmlElement
|
71
|
+
|
72
|
+
def mod
|
73
|
+
Cheri::Xml
|
74
|
+
end
|
75
|
+
|
76
|
+
def content?(value)
|
77
|
+
raise XmlException,"content not allowed for empty element #{@sym}: #{value}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
class TextElem
|
83
|
+
include Cheri::Builder::Builder
|
84
|
+
include Cheri::Builder::Content
|
85
|
+
include Cheri::Builder::ContentArgs
|
86
|
+
include XmlBuilder
|
87
|
+
|
88
|
+
def mod
|
89
|
+
Cheri::Xml
|
90
|
+
end
|
91
|
+
|
92
|
+
def object
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
96
|
+
def run
|
97
|
+
value = @ctx.call(self,&@blk) if @blk
|
98
|
+
add(value) if String === value
|
99
|
+
#add(value) if value && !(Appendable === value || BaseProxy === value)
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
# Appends content to +str+, or to an empty string if +str+ is omitted.
|
104
|
+
# Returns the result.
|
105
|
+
def to_s(str='')
|
106
|
+
@cont.each do |c|
|
107
|
+
if String === c
|
108
|
+
esc(c,str)
|
109
|
+
else
|
110
|
+
esc(c.to_s,str)
|
111
|
+
end
|
112
|
+
end if @cont
|
113
|
+
str
|
114
|
+
end
|
115
|
+
|
116
|
+
# Appends content to +ios+. Returns the result.
|
117
|
+
def to_io(ios)
|
118
|
+
@cont.each do |c|
|
119
|
+
if String === c
|
120
|
+
ios << esc(c)
|
121
|
+
else
|
122
|
+
ios << esc(c.to_s)
|
123
|
+
end
|
124
|
+
end if @cont
|
125
|
+
ios
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
class EscElem < TextElem
|
131
|
+
|
132
|
+
def esc(inp,out=nil)
|
133
|
+
if (cs = Charsets.charset(inp))
|
134
|
+
cs.xlat(inp,(out ||= ''))
|
135
|
+
out
|
136
|
+
elsif out
|
137
|
+
out << inp
|
138
|
+
else
|
139
|
+
inp
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
# TODO: special handling for these:
|
146
|
+
|
147
|
+
class XmlRoot
|
148
|
+
XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".freeze #:nodoc:
|
149
|
+
include Cheri::Builder::Builder
|
150
|
+
include Cheri::Builder::Content
|
151
|
+
include Cheri::Builder::ContentArgs
|
152
|
+
include XmlBuilder
|
153
|
+
|
154
|
+
def mod
|
155
|
+
Cheri::Xml
|
156
|
+
end
|
157
|
+
|
158
|
+
def object
|
159
|
+
self
|
160
|
+
end
|
161
|
+
|
162
|
+
def run
|
163
|
+
@ctx.call(self,&@blk) if @blk
|
164
|
+
self
|
165
|
+
end
|
166
|
+
|
167
|
+
# Appends content to +str+ (or new String if +str+ is omitted). Returns the result.
|
168
|
+
def to_s(str='')
|
169
|
+
return to_io(str) unless String === str
|
170
|
+
str << XML
|
171
|
+
cont_s(str)
|
172
|
+
str
|
173
|
+
end
|
174
|
+
|
175
|
+
# Appends content to +ios+. Returns the result.
|
176
|
+
def to_io(ios)
|
177
|
+
ios << XML
|
178
|
+
cont_io(ios)
|
179
|
+
ios
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
class ProcElem < Elem
|
186
|
+
end
|
187
|
+
|
188
|
+
end #Xml
|
189
|
+
end #Cheri
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
|
26
|
+
module Cheri
|
27
|
+
module Xml
|
28
|
+
|
29
|
+
include Cheri::Builder
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def append_features(clazz)
|
33
|
+
Cheri::Builder.module_included(self,clazz)
|
34
|
+
super
|
35
|
+
end
|
36
|
+
private :append_features
|
37
|
+
|
38
|
+
def factory
|
39
|
+
XmlFactory
|
40
|
+
end
|
41
|
+
|
42
|
+
def connecter
|
43
|
+
XmlConnecter
|
44
|
+
end
|
45
|
+
|
46
|
+
end #self
|
47
|
+
|
48
|
+
# Instance methods
|
49
|
+
|
50
|
+
# call-seq:
|
51
|
+
# xml([*args] [, &block]) -> XmlProxy if no block given, else result of block
|
52
|
+
#
|
53
|
+
def xml(*r,&k)
|
54
|
+
if (ctx = __cheri_ctx)
|
55
|
+
if k
|
56
|
+
if ctx.tos(XmlBuilder)
|
57
|
+
XmlFrame.new(ctx,*r,&k).run
|
58
|
+
else
|
59
|
+
ctx.msend(Cheri::Xml,:xml,*r,&k)
|
60
|
+
end
|
61
|
+
else
|
62
|
+
ctx[:xml_proxy] ||= XmlProxy.new(ctx,*r)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
private :xml
|
67
|
+
|
68
|
+
|
69
|
+
module XmlFactory
|
70
|
+
def self.builder(ctx,sym,*r,&k)
|
71
|
+
if (clazz = Types[sym])
|
72
|
+
clazz.new(ctx,sym,*r,&k)
|
73
|
+
elsif ctx[:xml_any] || ((acc = ctx[:xml_accept]) && acc[sym])
|
74
|
+
Elem.new(ctx,sym,*r,&k)
|
75
|
+
else
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end #XmlFactory
|
80
|
+
|
81
|
+
class XmlProxy < Cheri::Builder::BaseProxy
|
82
|
+
|
83
|
+
impl(Types.keys)
|
84
|
+
|
85
|
+
def mod
|
86
|
+
Cheri::Xml
|
87
|
+
end
|
88
|
+
private :mod
|
89
|
+
|
90
|
+
def [](opts)
|
91
|
+
if Symbol === opts
|
92
|
+
case opts
|
93
|
+
when :any : @ctx[:xml_any] = true
|
94
|
+
when :esc : @ctx[:xml_esc] = true
|
95
|
+
else raise ArgumentError,"invalid simple xml option: :#{opts}"
|
96
|
+
end
|
97
|
+
elsif Hash === opts
|
98
|
+
@ctx[:xml_any] = opts[:any] != false if opts[:any] != nil
|
99
|
+
@ctx[:xml_esc] = opts[:esc] != false if opts[:esc] != nil
|
100
|
+
if (accept = opts[:accept])
|
101
|
+
raise Cheri.type_error(accept,Array) unless Array === accept
|
102
|
+
acc = {}
|
103
|
+
accept.each do |a|
|
104
|
+
raise Cheri.type_error(a,Symbol) unless Symbol === a
|
105
|
+
acc[a] = true
|
106
|
+
end
|
107
|
+
@ctx[:xml_accept] = acc
|
108
|
+
@ctx[:xml_any] = nil
|
109
|
+
end
|
110
|
+
else
|
111
|
+
raise Cheri.type_error(opts,Hash,Symbol)
|
112
|
+
end
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
|
116
|
+
end #XmlProxy
|
117
|
+
|
118
|
+
class XmlFrame
|
119
|
+
include Cheri::Builder::Frame
|
120
|
+
def initialize(ctx,*r,&k)
|
121
|
+
super
|
122
|
+
@obj = ctx[:xml_proxy] ||= XmlProxy.new(ctx,*r)
|
123
|
+
end
|
124
|
+
def mod
|
125
|
+
Cheri::Xml
|
126
|
+
end
|
127
|
+
end #XmlFrame
|
128
|
+
|
129
|
+
end #Xml
|
130
|
+
end #Cheri
|