xmlutils 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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +77 -0
- data/bin/xmltogdl +88 -0
- data/docs/README.txt +20 -0
- data/lib/xmlutils/contextlistener.rb +432 -0
- data/lib/xmlutils/contextparser.rb +111 -0
- data/lib/xmlutils/dumplistener.rb +57 -0
- data/lib/xmlutils/gdlcontext.rb +305 -0
- data/lib/xmlutils/gdlcontextobjs.rb +286 -0
- data/lib/xmlutils/gdldoc.rb +547 -0
- data/lib/xmlutils/gdldocbuilder.rb +181 -0
- data/lib/xmlutils/gdllistener.rb +265 -0
- data/lib/xmlutils/gdltemplate.rb +488 -0
- data/lib/xmlutils/lineparser.rb +193 -0
- data/lib/xmlutils/listener.rb +459 -0
- data/lib/xmlutils/rulelistener.rb +414 -0
- data/lib/xmlutils/ruleparser.rb +112 -0
- data/lib/xmlutils/varlistener.rb +86 -0
- data/lib/xmlutils/version.rb +5 -0
- data/lib/xmlutils/xmlrulevisitor.rb +704 -0
- data/lib/xmlutils/xmltogdlcontroller.rb +93 -0
- data/lib/xmlutils/xmltogdltask.rb +23 -0
- data/lib/xmlutils/xmlvisitor.rb +690 -0
- data/lib/xmlutils.rb +40 -0
- data/rakefile.rb +34 -0
- data/unittests/2830.xml +1 -0
- data/unittests/chunks.rb +31 -0
- data/unittests/curDirTest.rb +2 -0
- data/unittests/data/2830-GENERATED.gdl +309 -0
- data/unittests/data/2830-GENERATED.xml +1 -0
- data/unittests/data/AUGuideline.xml +12 -0
- data/unittests/data/AUGuideline.xml.gdl +19190 -0
- data/unittests/data/BAKUP.DCTEST1.xml +1 -0
- data/unittests/data/DCTEST.xml +1 -0
- data/unittests/data/DCTEST1.xml +1 -0
- data/unittests/data/DCTEST1.xml.gdl +14890 -0
- data/unittests/data/DCTEST1.xml.rename.csv +180 -0
- data/unittests/data/DCTEST1wLookups.xml +174 -0
- data/unittests/data/DCTEST1wLookups.xml.gdl +127 -0
- data/unittests/data/GENERATED.gdl.xml +1 -0
- data/unittests/data/Message.xml +1 -0
- data/unittests/data/Message.xml.gdl +142 -0
- data/unittests/data/Pricing2ndGuideline.xml +1 -0
- data/unittests/data/Pricing2ndGuideline.xml.gdl +52670 -0
- data/unittests/data/Z-TEMP-Jeff.xml +1 -0
- data/unittests/data/Z-TEMP-Jeff.xml.gdl +288 -0
- data/unittests/tc_convert_xml_to_gdl.rb +23 -0
- data/unittests/ts_allTests.rb +2 -0
- data/xmlutils.gemspec +25 -0
- metadata +139 -0
@@ -0,0 +1,265 @@
|
|
1
|
+
#
|
2
|
+
# File: gdlListener.rb
|
3
|
+
#
|
4
|
+
# Adds rule and ruleset names and aliases to a list (figuratively).
|
5
|
+
#
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'rexml/streamlistener'
|
9
|
+
require 'xmlutils/gdlcontext'
|
10
|
+
require 'xmlutils/gdlcontextobjs'
|
11
|
+
require 'xmlutils/listener'
|
12
|
+
|
13
|
+
include REXML
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
#################################################
|
19
|
+
#
|
20
|
+
# class GdlListener
|
21
|
+
#
|
22
|
+
#################################################
|
23
|
+
class GdlListener < Listener
|
24
|
+
|
25
|
+
attr_reader :context
|
26
|
+
attr_writer :gdl
|
27
|
+
|
28
|
+
attr_writer :inGuideline
|
29
|
+
attr_writer :inRule
|
30
|
+
attr_writer :inRuleset
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def initialize(ctx)
|
38
|
+
super()
|
39
|
+
@context = ctx
|
40
|
+
@gdl = nil
|
41
|
+
@inGuideline = false
|
42
|
+
@inRule = false
|
43
|
+
@inRuleset = false
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def inGuideline?
|
50
|
+
return @inGuideline
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
def inRule?
|
57
|
+
return @inRule
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
def inRuleset?
|
64
|
+
return @inRuleset
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
#-------------------------------------------------------------------------------------------------------------#
|
71
|
+
# tag_start - A start tag has been parsed
|
72
|
+
#
|
73
|
+
# tag - name of tag (element name)
|
74
|
+
# attributes - element tag attributes
|
75
|
+
#------------------------------------------------------------------------------------------------------------#
|
76
|
+
def tag_start(tag, attributes)
|
77
|
+
|
78
|
+
case tag
|
79
|
+
when 'Guideline'
|
80
|
+
openGuideline(attributes)
|
81
|
+
|
82
|
+
when 'Rule'
|
83
|
+
openRule(attributes)
|
84
|
+
|
85
|
+
when 'Ruleset'
|
86
|
+
openRuleset(attributes)
|
87
|
+
|
88
|
+
else
|
89
|
+
openUnknown(tag, attributes) # Don't care
|
90
|
+
end # case
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
#-------------------------------------------------------------------------------------------------------------#
|
98
|
+
# tag_end - An ending tag has been parsed
|
99
|
+
#
|
100
|
+
# tag - name of tag (element name)
|
101
|
+
#------------------------------------------------------------------------------------------------------------#
|
102
|
+
def tag_end(tag)
|
103
|
+
|
104
|
+
case tag
|
105
|
+
when 'Guideline'
|
106
|
+
closeGuideline()
|
107
|
+
|
108
|
+
when 'Rule'
|
109
|
+
closeRule()
|
110
|
+
|
111
|
+
when 'Ruleset'
|
112
|
+
closeRuleset()
|
113
|
+
|
114
|
+
else
|
115
|
+
closeUnknown(tag) # Don't care
|
116
|
+
end # case
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
#-------------------------------------------------------------------------------------------------------------#
|
124
|
+
# openGuideline - Add a Guideline to the context object
|
125
|
+
#
|
126
|
+
# attributes - Guideline element attributes
|
127
|
+
#
|
128
|
+
#------------------------------------------------------------------------------------------------------------#
|
129
|
+
def openGuideline(attributes)
|
130
|
+
return unless (!inGuideline?)
|
131
|
+
|
132
|
+
if ($DEBUG)
|
133
|
+
puts "openGuideline:"
|
134
|
+
|
135
|
+
if(!attributes.empty?)
|
136
|
+
puts " Attr:"
|
137
|
+
attributes.each do |attr|
|
138
|
+
puts " #{attr[0]}: #{attr[1]}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end # if $DEBUG
|
142
|
+
|
143
|
+
@gdl = Guideline.new(attributes)
|
144
|
+
|
145
|
+
@inGuideline = true
|
146
|
+
|
147
|
+
end # openGuideline
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
#-------------------------------------------------------------------------------------------------------------#
|
152
|
+
# closeGuideline - Close a Guideline object
|
153
|
+
#
|
154
|
+
#
|
155
|
+
#------------------------------------------------------------------------------------------------------------#
|
156
|
+
def closeGuideline()
|
157
|
+
if (inGuideline?)
|
158
|
+
@GuidelineOpen = false
|
159
|
+
@context.guideline = @gdl
|
160
|
+
|
161
|
+
puts "closeGuideline" unless (!$DEBUG)
|
162
|
+
puts "" unless (!$DEBUG)
|
163
|
+
end # if
|
164
|
+
|
165
|
+
end # closeGuideline
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
#-------------------------------------------------------------------------------------------------------------#
|
170
|
+
# openRule - Add a rule to the context object
|
171
|
+
#
|
172
|
+
# attributes - rule element attributes
|
173
|
+
#
|
174
|
+
#------------------------------------------------------------------------------------------------------------#
|
175
|
+
def openRule(attributes)
|
176
|
+
return unless (inGuideline? && (!inRuleset?))
|
177
|
+
|
178
|
+
if ($DEBUG)
|
179
|
+
puts "openRule:"
|
180
|
+
|
181
|
+
if(!attributes.empty?)
|
182
|
+
puts " Attr:"
|
183
|
+
attributes.each do |attr|
|
184
|
+
puts " #{attr[0]}: #{attr[1]}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end # if $DEBUG
|
188
|
+
|
189
|
+
ruleAlias = attributes["Name"]
|
190
|
+
item = ["rule", "#{ruleAlias}"]
|
191
|
+
|
192
|
+
@gdl.addItem(item)
|
193
|
+
@inRule = true
|
194
|
+
|
195
|
+
puts "Guideline item: [#{item[0]}] #{item[1]}" if verbose?
|
196
|
+
|
197
|
+
end # openRule
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
#-------------------------------------------------------------------------------------------------------------#
|
202
|
+
# closeRule - Close a rule object
|
203
|
+
#
|
204
|
+
#
|
205
|
+
#------------------------------------------------------------------------------------------------------------#
|
206
|
+
def closeRule()
|
207
|
+
if (inRule?)
|
208
|
+
@inRule = false
|
209
|
+
|
210
|
+
puts "closeRule" unless (!$DEBUG)
|
211
|
+
puts "" unless (!$DEBUG)
|
212
|
+
end # if
|
213
|
+
|
214
|
+
end # closeRule
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
#-------------------------------------------------------------------------------------------------------------#
|
219
|
+
# openRuleset - Open a ruleset object
|
220
|
+
#
|
221
|
+
# attributes - ruleset element attributes
|
222
|
+
#
|
223
|
+
#------------------------------------------------------------------------------------------------------------#
|
224
|
+
def openRuleset(attributes)
|
225
|
+
return unless (inGuideline? && (!inRuleset?))
|
226
|
+
|
227
|
+
if ($DEBUG)
|
228
|
+
puts "openRuleset:"
|
229
|
+
|
230
|
+
if(!attributes.empty?)
|
231
|
+
puts " Attr:"
|
232
|
+
attributes.each do |attr|
|
233
|
+
puts " #{attr[0]}: #{attr[1]}"
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end # if $DEBUG
|
237
|
+
|
238
|
+
rsAlias = attributes["Name"]
|
239
|
+
item = ["ruleset", "#{rsAlias}"]
|
240
|
+
|
241
|
+
@gdl.addItem(item)
|
242
|
+
@inRuleset = true
|
243
|
+
|
244
|
+
puts "Guideline item: [#{item[0]}] #{item[1]}" if verbose?
|
245
|
+
|
246
|
+
end # openRuleset
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
#-------------------------------------------------------------------------------------------------------------#
|
251
|
+
# closeRuleset - Close a ruleset object
|
252
|
+
#
|
253
|
+
#
|
254
|
+
#------------------------------------------------------------------------------------------------------------#
|
255
|
+
def closeRuleset()
|
256
|
+
if (inRuleset?)
|
257
|
+
@inRuleset = false
|
258
|
+
|
259
|
+
puts "closeRuleset" unless (!$DEBUG)
|
260
|
+
puts "" unless (!$DEBUG)
|
261
|
+
end # if
|
262
|
+
|
263
|
+
end # closeRuleset
|
264
|
+
end # class GdlListener
|
265
|
+
|