xmlutils 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,547 @@
|
|
1
|
+
#
|
2
|
+
# File: gdlDoc.rb
|
3
|
+
#
|
4
|
+
# This class is used to create the final GDL document
|
5
|
+
#
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'xmlutils/gdlcontextobjs'
|
9
|
+
require 'xmlutils/gdltemplate'
|
10
|
+
require 'date'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
#################################################
|
17
|
+
#
|
18
|
+
# class GdlDoc
|
19
|
+
#
|
20
|
+
#################################################
|
21
|
+
class GdlDoc
|
22
|
+
|
23
|
+
attr_reader :context
|
24
|
+
attr_reader :srcPath
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
def initialize(srcPath, ctx)
|
30
|
+
super()
|
31
|
+
@srcPath = srcPath
|
32
|
+
@context = ctx
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#------------------------------------------------------------------------------------------------------------#
|
39
|
+
# setOptions - Set configuration option flags
|
40
|
+
#
|
41
|
+
# flg - Array of options or single string option. Currently, only -v: verbose is available
|
42
|
+
#
|
43
|
+
#------------------------------------------------------------------------------------------------------------#
|
44
|
+
def setOptions(flgs)
|
45
|
+
if (flgs.class == Array)
|
46
|
+
flgs.each do |f|
|
47
|
+
case f
|
48
|
+
when '-v'
|
49
|
+
@verbose = true
|
50
|
+
end
|
51
|
+
end # flgs.each
|
52
|
+
|
53
|
+
return
|
54
|
+
end # if flgs
|
55
|
+
|
56
|
+
case flgs
|
57
|
+
when '-v'
|
58
|
+
@verbose = true
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
#-------------------------------------------------------------------------------------------------------------#
|
67
|
+
# currentDate - Generate today's date string
|
68
|
+
#
|
69
|
+
#
|
70
|
+
#------------------------------------------------------------------------------------------------------------#
|
71
|
+
def currentDate()
|
72
|
+
now = DateTime::now()
|
73
|
+
return now.strftime("%m/%d/%Y %H:%M:%S")
|
74
|
+
end # currentDate
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
#-------------------------------------------------------------------------------------------------------------#
|
80
|
+
# generate - Generate a GDL document
|
81
|
+
#
|
82
|
+
# returns string - generated file name
|
83
|
+
#
|
84
|
+
#------------------------------------------------------------------------------------------------------------#
|
85
|
+
def generate()
|
86
|
+
destDir = @context.options[:destdir]
|
87
|
+
destFile = @context.options[:destfile]
|
88
|
+
if(nil == destFile || destFile.empty?)
|
89
|
+
destFile = File.basename(@srcPath, ".xml") + ".gdl"
|
90
|
+
end
|
91
|
+
|
92
|
+
if ($DEBUG)
|
93
|
+
puts "generate:"
|
94
|
+
puts " sourcePath: #{@srcPath}"
|
95
|
+
puts " destDir: #{destDir}"
|
96
|
+
puts " destFile: #{destFile}"
|
97
|
+
puts " context: #{@context}"
|
98
|
+
end # if $DEBUG
|
99
|
+
|
100
|
+
tpl = GdlTemplate.new
|
101
|
+
|
102
|
+
genFile = File.join(destDir, destFile)
|
103
|
+
|
104
|
+
createOutdir(destDir)
|
105
|
+
|
106
|
+
File.open("#{genFile}", "w") do |ofile|
|
107
|
+
|
108
|
+
ofile << tpl.fileHeader(@srcPath, currentDate() )
|
109
|
+
|
110
|
+
|
111
|
+
ofile << tpl.sectionComment("DPM Definitions")
|
112
|
+
|
113
|
+
vars = @context.dpms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
114
|
+
vars.each do |rDpm|
|
115
|
+
dpm = rDpm[1]
|
116
|
+
if (dpm.varType == "DPM")
|
117
|
+
ofile << tpl.dpm(dpm.prodType, dpm.name, dpm.alias)
|
118
|
+
end # if dpm
|
119
|
+
end # do
|
120
|
+
|
121
|
+
# @context.dpms.each do |key, dpm|
|
122
|
+
# if (dpm.varType == "DPM")
|
123
|
+
# ofile << tpl.dpm(dpm.prodType, dpm.name, dpm.alias)
|
124
|
+
# end # if dpm
|
125
|
+
# end # dpms.each
|
126
|
+
|
127
|
+
|
128
|
+
ofile << tpl.sectionComment("DSM Definitions")
|
129
|
+
|
130
|
+
|
131
|
+
vars = @context.dpms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
132
|
+
vars.each do |rDpm|
|
133
|
+
dpm = rDpm[1]
|
134
|
+
if (dpm.varType == "DSM")
|
135
|
+
ofile << tpl.dsm(dpm.prodType, dpm.name, dpm.alias)
|
136
|
+
end # if dpm
|
137
|
+
end # do
|
138
|
+
|
139
|
+
# @context.dpms.each do |key, dpm|
|
140
|
+
# if (dpm.varType == "DSM")
|
141
|
+
# ofile << tpl.dsm(dpm.prodType, dpm.name, dpm.alias)
|
142
|
+
# end # if dsm
|
143
|
+
# end # dsms.each
|
144
|
+
|
145
|
+
#@context.ppms.each do |p|
|
146
|
+
# puts p.inspect
|
147
|
+
#end
|
148
|
+
|
149
|
+
# @context.ppms consists of an array of [ppm alias, ppm object]s
|
150
|
+
#vars = @context.ppms.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
151
|
+
|
152
|
+
prds = @context.ppms.select {|a,b| b.varType == "prd"}
|
153
|
+
prds.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
154
|
+
|
155
|
+
apps = @context.ppms.select {|a,b| b.varType == "app"}
|
156
|
+
apps.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
157
|
+
|
158
|
+
crds = @context.ppms.select {|a,b| b.varType == "crd"}
|
159
|
+
crds.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
160
|
+
|
161
|
+
ofile << tpl.sectionComment("PPM Definitions (PRD)")
|
162
|
+
prds.each do |rPpm|
|
163
|
+
ppm = rPpm[1]
|
164
|
+
ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias)
|
165
|
+
end # do
|
166
|
+
|
167
|
+
ofile << tpl.sectionComment("PPM Definitions (APP)")
|
168
|
+
apps.each do |rPpm|
|
169
|
+
ppm = rPpm[1]
|
170
|
+
ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias)
|
171
|
+
end # do
|
172
|
+
|
173
|
+
ofile << tpl.sectionComment("PPM Definitions (CRD)")
|
174
|
+
crds.each do |rPpm|
|
175
|
+
ppm = rPpm[1]
|
176
|
+
ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias)
|
177
|
+
end # do
|
178
|
+
|
179
|
+
# @context.ppms.each do |key, ppm|
|
180
|
+
# ofile << tpl.ppm(ppm.dataType, ppm.varType, ppm.name, ppm.alias)
|
181
|
+
# end # ppms.each
|
182
|
+
|
183
|
+
|
184
|
+
ofile << tpl.multiLineComment(buildLookupList(), "Lookups that need to be imported")
|
185
|
+
|
186
|
+
|
187
|
+
ofile << tpl.sectionComment("Rule Definitions")
|
188
|
+
|
189
|
+
rules = @context.rules.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
190
|
+
rules.each do |rrule|
|
191
|
+
rule = rrule[1]
|
192
|
+
ofile << tpl.rule(rule)
|
193
|
+
end # do
|
194
|
+
|
195
|
+
# @context.rules.each do |key, rule|
|
196
|
+
# ofile << tpl.rule(rule)
|
197
|
+
# end # rules.each
|
198
|
+
|
199
|
+
|
200
|
+
ofile << tpl.sectionComment("Ruleset Definitions")
|
201
|
+
|
202
|
+
rulesets = @context.rulesets.sort {|a, b| a[1].name.downcase <=> b[1].name.downcase}
|
203
|
+
rulesets.each do |rruleset|
|
204
|
+
ruleset = rruleset[1]
|
205
|
+
ofile << tpl.ruleset(ruleset, @context)
|
206
|
+
end # do
|
207
|
+
|
208
|
+
# @context.rulesets.each do |key, ruleset|
|
209
|
+
# ofile << tpl.ruleset(ruleset, @context)
|
210
|
+
# end # ruleset.each
|
211
|
+
|
212
|
+
|
213
|
+
ofile << tpl.sectionComment("Guideline Definition")
|
214
|
+
ofile << tpl.guideline(@context)
|
215
|
+
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
return genFile
|
220
|
+
|
221
|
+
end # generate
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
#-------------------------------------------------------------------------------------------------------------#
|
227
|
+
# generateRenameList - Generate a CSV rename list
|
228
|
+
#
|
229
|
+
# returns string - generated file name
|
230
|
+
#
|
231
|
+
#------------------------------------------------------------------------------------------------------------#
|
232
|
+
def generateRenameList()
|
233
|
+
destDir = @context.options[:destdir]
|
234
|
+
destFile = @context.options[:destfile]
|
235
|
+
if(nil == destFile || destFile.empty?)
|
236
|
+
destFile = File.basename(@srcPath, ".xml") + ".gdl"
|
237
|
+
end
|
238
|
+
|
239
|
+
destFile = File.basename(destFile, ".gdl") + ".rename.csv"
|
240
|
+
|
241
|
+
if ($DEBUG)
|
242
|
+
puts "generateRenameList:"
|
243
|
+
puts " sourcePath: #{@srcPath}"
|
244
|
+
puts " destDir: #{destDir}"
|
245
|
+
puts " context: #{@context}"
|
246
|
+
end # if $DEBUG
|
247
|
+
|
248
|
+
genFile = File.join(destDir, destFile)
|
249
|
+
|
250
|
+
createOutdir(destDir)
|
251
|
+
|
252
|
+
File.open("#{genFile}", "w") do |ofile|
|
253
|
+
|
254
|
+
# Don't add to list if alias has '.'.
|
255
|
+
# Don't add to list if alias and name are identical.
|
256
|
+
vars = @context.rules.sort {|a, b| a[0].downcase <=> b[0].downcase}
|
257
|
+
vars.each do |ruleAry|
|
258
|
+
rule = ruleAry[1]
|
259
|
+
if (ruleAry[0] != rule.name)
|
260
|
+
if (nil == ruleAry[0].index('.'))
|
261
|
+
ofile << "rule,#{ruleAry[0]},#{rule.name}\n"
|
262
|
+
end # if no period
|
263
|
+
end # if name and alias do not match
|
264
|
+
end # do
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
# Don't add to list if ruleset is powerlookup.
|
270
|
+
# Don't add to list if alias and name are identical.
|
271
|
+
vars = @context.rulesets.sort {|a, b| a[0].downcase <=> b[0].downcase}
|
272
|
+
vars.each do |rulesetAry|
|
273
|
+
ruleset = rulesetAry[1]
|
274
|
+
if ("PL" != ruleset.type)
|
275
|
+
if (rulesetAry[0] != ruleset.name)
|
276
|
+
ofile << "ruleset,#{rulesetAry[0]},#{ruleset.name}\n"
|
277
|
+
end # if not identical
|
278
|
+
end # if not PL ruleset
|
279
|
+
end # do
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
return genFile
|
286
|
+
|
287
|
+
end # generateRenameList
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
#-------------------------------------------------------------------------------------------------------------#
|
293
|
+
# buildLookupList - Create a listing of lookup definitions from the context
|
294
|
+
#
|
295
|
+
#
|
296
|
+
#------------------------------------------------------------------------------------------------------------#
|
297
|
+
def buildLookupList()
|
298
|
+
lkups = Hash.new
|
299
|
+
lkList = ""
|
300
|
+
tpl = GdlTemplate.new
|
301
|
+
|
302
|
+
@context.lookups.each do |lkName, lkup|
|
303
|
+
params = @context.getLookupParamNames(lkName)
|
304
|
+
lkups[lkName] = tpl.lookup(lkName, params["xparam"], params["yparam"])
|
305
|
+
# lkList += tpl.lookup(lkName, params["xparam"], params["yparam"])
|
306
|
+
# lkList += ";\n" # Put each lookup on a seperate line
|
307
|
+
end # do
|
308
|
+
|
309
|
+
sorted = lkups.sort {|a, b| a[0].downcase <=> b[0].downcase}
|
310
|
+
sorted.each do |item|
|
311
|
+
lkList += "#{item[1]};\n"
|
312
|
+
end # do sorted
|
313
|
+
|
314
|
+
return lkList
|
315
|
+
end # def buildLookupList
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
#-------------------------------------------------------------------------------------------------------------#
|
321
|
+
# createOutdir - Create a directory if it does not exist
|
322
|
+
#
|
323
|
+
# outdir - Directory name/path to create
|
324
|
+
#
|
325
|
+
#------------------------------------------------------------------------------------------------------------#
|
326
|
+
def createOutdir(outdir)
|
327
|
+
if( !File.directory?(outdir) )
|
328
|
+
FileUtils.makedirs("#{outdir}")
|
329
|
+
end
|
330
|
+
|
331
|
+
end # def createOutdir
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
#-------------------------------------------------------------------------------------------------------------#
|
337
|
+
# outputFileHeader - output file header
|
338
|
+
#
|
339
|
+
# ofile - output file to write header to
|
340
|
+
# infile - Name of file to create header for
|
341
|
+
#
|
342
|
+
#------------------------------------------------------------------------------------------------------------#
|
343
|
+
def outputFileHeader(ofile, infile)
|
344
|
+
header = <<EOF
|
345
|
+
/* **************************************************************************
|
346
|
+
* File: #{infile}.gdl
|
347
|
+
* Generated guideline
|
348
|
+
*
|
349
|
+
* *************************************************************************/
|
350
|
+
|
351
|
+
|
352
|
+
EOF
|
353
|
+
|
354
|
+
ofile << header
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
#-------------------------------------------------------------------------------------------------------------#
|
360
|
+
# definitionHeader - output collected variables to file
|
361
|
+
#
|
362
|
+
# headerType - Header type (ex: DSM)
|
363
|
+
#
|
364
|
+
#------------------------------------------------------------------------------------------------------------#
|
365
|
+
def definitionHeader(headerType)
|
366
|
+
header = <<EOF
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
// ---------------------------- #{headerType} definitions ----------------------------
|
372
|
+
|
373
|
+
EOF
|
374
|
+
|
375
|
+
header
|
376
|
+
|
377
|
+
end # def definitionHeader
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
#-------------------------------------------------------------------------------------------------------------#
|
383
|
+
# outputPpm - generate a GDL version of a PPM definition based on PPM XML element
|
384
|
+
#
|
385
|
+
# var - XML element to generate output for
|
386
|
+
#
|
387
|
+
# @returns GDL output for PPM definition
|
388
|
+
#
|
389
|
+
#------------------------------------------------------------------------------------------------------------#
|
390
|
+
def outputPpm(var)
|
391
|
+
xVarType = "text"
|
392
|
+
xvarSection = var.attribute('Type').to_s
|
393
|
+
|
394
|
+
case xvarSection
|
395
|
+
when 'APM'
|
396
|
+
varSection = "app"
|
397
|
+
|
398
|
+
when 'PRD'
|
399
|
+
varSection = "prd"
|
400
|
+
|
401
|
+
when 'CRP'
|
402
|
+
varSection = "crd"
|
403
|
+
end
|
404
|
+
|
405
|
+
varAlias = var.attribute('Alias')
|
406
|
+
varName = var.attribute('Name')
|
407
|
+
|
408
|
+
|
409
|
+
out = <<EOF
|
410
|
+
ppm #{xVarType} #{varSection} p#{varName} "#{varAlias}";
|
411
|
+
EOF
|
412
|
+
|
413
|
+
out # Return generated output
|
414
|
+
end # outputPpm
|
415
|
+
|
416
|
+
|
417
|
+
#-------------------------------------------------------------------------------------------------------------#
|
418
|
+
# outputDsm - generate a GDL version of a DSM definition based on DSM XML element
|
419
|
+
#
|
420
|
+
# var - XML element to generate output for
|
421
|
+
#
|
422
|
+
# @returns GDL output for DSM definition
|
423
|
+
#
|
424
|
+
#------------------------------------------------------------------------------------------------------------#
|
425
|
+
def outputDsm(var)
|
426
|
+
xVarType = var.attribute('ProductType').to_s
|
427
|
+
|
428
|
+
case xVarType
|
429
|
+
when '1'
|
430
|
+
varType = "boolean"
|
431
|
+
|
432
|
+
when '2'
|
433
|
+
varType = "date"
|
434
|
+
|
435
|
+
when '3'
|
436
|
+
varType = "money"
|
437
|
+
|
438
|
+
when '4'
|
439
|
+
varType = "numeric"
|
440
|
+
|
441
|
+
when '5'
|
442
|
+
varType = "percentage"
|
443
|
+
|
444
|
+
when '6'
|
445
|
+
varType = "text"
|
446
|
+
end
|
447
|
+
|
448
|
+
varAlias = var.attribute('Alias')
|
449
|
+
varName = var.attribute('Name')
|
450
|
+
|
451
|
+
|
452
|
+
out = <<EOF
|
453
|
+
decision dpm #{varType} #{varName} "#{varAlias}";
|
454
|
+
EOF
|
455
|
+
|
456
|
+
out # Return generated output
|
457
|
+
end # outputDsm
|
458
|
+
|
459
|
+
|
460
|
+
#-------------------------------------------------------------------------------------------------------------#
|
461
|
+
# outputDpm - generate a GDL version of a DPM definition based on DPM XML element
|
462
|
+
#
|
463
|
+
# var - XML element to generate output for
|
464
|
+
#
|
465
|
+
# @returns GDL output for DPM definition
|
466
|
+
#
|
467
|
+
#------------------------------------------------------------------------------------------------------------#
|
468
|
+
def outputDpm(var)
|
469
|
+
xVarType = var.attribute('ProductType').to_s
|
470
|
+
|
471
|
+
case xVarType
|
472
|
+
when '1'
|
473
|
+
varType = "boolean"
|
474
|
+
|
475
|
+
when '2'
|
476
|
+
varType = "date"
|
477
|
+
|
478
|
+
when '3'
|
479
|
+
varType = "money"
|
480
|
+
|
481
|
+
when '4'
|
482
|
+
varType = "numeric"
|
483
|
+
|
484
|
+
when '5'
|
485
|
+
varType = "percentage"
|
486
|
+
|
487
|
+
when '6'
|
488
|
+
varType = "text"
|
489
|
+
end
|
490
|
+
|
491
|
+
varAlias = var.attribute('Alias')
|
492
|
+
varName = var.attribute('Name')
|
493
|
+
|
494
|
+
|
495
|
+
out = <<EOF
|
496
|
+
dpm #{varType} #{varName} "#{varAlias}";
|
497
|
+
EOF
|
498
|
+
|
499
|
+
out # Return generated output
|
500
|
+
end # outputDpm
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
#-------------------------------------------------------------------------------------------------------------#
|
506
|
+
# outputRuleInfo - output collected variables to file
|
507
|
+
#
|
508
|
+
# ofile - output file handle
|
509
|
+
#
|
510
|
+
#------------------------------------------------------------------------------------------------------------#
|
511
|
+
def outputRuleInfo(ofile)
|
512
|
+
|
513
|
+
ofile << definitionHeader("Rule")
|
514
|
+
|
515
|
+
@rules.each_value do |rule|
|
516
|
+
ofile << outputRule(rule)
|
517
|
+
end
|
518
|
+
|
519
|
+
end # def outputRuleInfo
|
520
|
+
|
521
|
+
|
522
|
+
#-------------------------------------------------------------------------------------------------------------#
|
523
|
+
# outputRule - generate a GDL version of a rule definition based on Rule XML element
|
524
|
+
#
|
525
|
+
# rule - XML element to generate output for
|
526
|
+
#
|
527
|
+
# @returns GDL output for Rule definition
|
528
|
+
#
|
529
|
+
#------------------------------------------------------------------------------------------------------------#
|
530
|
+
def outputRule(rule)
|
531
|
+
# arule = root.elements['//Rule'].to_a # returns all 1st level rule children elements
|
532
|
+
ruleParts = rule.elements.to_a
|
533
|
+
puts ""
|
534
|
+
puts "Rule Parts:"
|
535
|
+
puts "#{ruleParts.inspect}"
|
536
|
+
puts ""
|
537
|
+
|
538
|
+
visitor = XmlRuleVisitor.new
|
539
|
+
output = ""
|
540
|
+
visitor.lookupData = @lookupData
|
541
|
+
|
542
|
+
return visitor.visit(rule, output)
|
543
|
+
|
544
|
+
|
545
|
+
end # outputRule
|
546
|
+
end # class GdlDoc
|
547
|
+
|
@@ -0,0 +1,181 @@
|
|
1
|
+
#
|
2
|
+
# File: gdlDocBuilder.rb
|
3
|
+
#
|
4
|
+
# This is a guideline document builder
|
5
|
+
#
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'xmlutils/contextparser'
|
9
|
+
require 'xmlutils/ruleparser'
|
10
|
+
require 'xmlutils/gdldoc'
|
11
|
+
require 'xmlutils/lineparser'
|
12
|
+
|
13
|
+
|
14
|
+
#################################################
|
15
|
+
#
|
16
|
+
# class GdlDocBuilder
|
17
|
+
#
|
18
|
+
#################################################
|
19
|
+
class GdlDocBuilder
|
20
|
+
|
21
|
+
attr_accessor :options
|
22
|
+
attr_accessor :context
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
#-------------------------------------------------------------------------------------------------------------#
|
27
|
+
# initialize - CTor
|
28
|
+
#
|
29
|
+
# options - Document builder options
|
30
|
+
#
|
31
|
+
#------------------------------------------------------------------------------------------------------------#
|
32
|
+
def initialize(options)
|
33
|
+
@options = options
|
34
|
+
@context = GdlContext.new
|
35
|
+
@context.setOptions(@options)
|
36
|
+
end # initialize
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
#-------------------------------------------------------------------------------------------------------------#
|
42
|
+
# createDocument - create a GDL document from an XML document
|
43
|
+
#
|
44
|
+
# srcFile - XML source file
|
45
|
+
#
|
46
|
+
#------------------------------------------------------------------------------------------------------------#
|
47
|
+
def createDocument(srcFile)
|
48
|
+
|
49
|
+
# Setup context object builder
|
50
|
+
ctxBuilder = ContextParser.new(@context)
|
51
|
+
ctxBuilder.setFlag(@options)
|
52
|
+
|
53
|
+
statusMsg "Creating guideline context."
|
54
|
+
|
55
|
+
ctxBuilder.parse(srcFile)
|
56
|
+
|
57
|
+
printMetrics(@context)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
statusMsg "Parsing external variable definitions."
|
62
|
+
|
63
|
+
parseExternalVarDefs(@context)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
statusMsg "Parsing rule data (#{ctxBuilder.context.rules.size.to_s} rules)."
|
68
|
+
|
69
|
+
ruleBuilder = RuleParser.new(@context)
|
70
|
+
ruleBuilder.setFlag(@options)
|
71
|
+
|
72
|
+
@context.rules.each do |key, rule|
|
73
|
+
rule.src = ruleBuilder.parse(rule.xml)
|
74
|
+
print "."
|
75
|
+
end # rules.each
|
76
|
+
puts
|
77
|
+
|
78
|
+
|
79
|
+
# ctxBuilder.dumpResults
|
80
|
+
|
81
|
+
|
82
|
+
# Create output file and output src.
|
83
|
+
statusMsg "Generating document."
|
84
|
+
|
85
|
+
gdlDoc = GdlDoc.new(srcFile, @context)
|
86
|
+
gdlDoc.setOptions(@options)
|
87
|
+
|
88
|
+
genFile = gdlDoc.generate
|
89
|
+
|
90
|
+
statusMsg "Document created: #{genFile}"
|
91
|
+
|
92
|
+
genFile = gdlDoc.generateRenameList
|
93
|
+
|
94
|
+
statusMsg "Rename list document created: #{genFile}"
|
95
|
+
|
96
|
+
end # createDocument
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
#-------------------------------------------------------------------------------------------------------------#
|
102
|
+
# statusMsg - output a status message
|
103
|
+
#
|
104
|
+
# msg - Message to output
|
105
|
+
#
|
106
|
+
#------------------------------------------------------------------------------------------------------------#
|
107
|
+
def statusMsg(msg)
|
108
|
+
|
109
|
+
puts
|
110
|
+
puts "-} #{msg}"
|
111
|
+
puts
|
112
|
+
|
113
|
+
end # statusMsg
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
#-------------------------------------------------------------------------------------------------------------#
|
119
|
+
# printMetrics - Print context metrics
|
120
|
+
#
|
121
|
+
# ctx - Context to generate metrics from
|
122
|
+
#
|
123
|
+
#------------------------------------------------------------------------------------------------------------#
|
124
|
+
def printMetrics(ctx)
|
125
|
+
|
126
|
+
puts " DPM count: #{ctx.dpms.size.to_s} (includes DSMs)"
|
127
|
+
puts " PPM count: #{ctx.ppms.size.to_s}"
|
128
|
+
puts " Lookup count: #{ctx.lookups.size.to_s}"
|
129
|
+
puts " Message count: #{ctx.messages.size.to_s} (includes conditions)"
|
130
|
+
puts " Rule count: #{ctx.rules.size.to_s}"
|
131
|
+
puts " Ruleset count: #{ctx.rulesets.size.to_s}"
|
132
|
+
|
133
|
+
end # printMetrics
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
#-------------------------------------------------------------------------------------------------------------#
|
139
|
+
# parseExternalVarDefs - parse predefined GDL variable definition files.
|
140
|
+
#
|
141
|
+
# ctx - context containing variables to update
|
142
|
+
#
|
143
|
+
#------------------------------------------------------------------------------------------------------------#
|
144
|
+
def parseExternalVarDefs(ctx)
|
145
|
+
puts "No external variable definition files provided." if (!ctx.options[:verbose].nil? && ctx.options[:includes].nil?)
|
146
|
+
return if ctx.options[:includes].nil?
|
147
|
+
|
148
|
+
vp = LineParser.new # Parse externally defined GDL variable definition files.
|
149
|
+
ctx.options[:includes].each do |inc|
|
150
|
+
vp.parse(inc) # TODO: Allow external var def files to be defined in a config file.
|
151
|
+
end # ctx.options.each
|
152
|
+
|
153
|
+
vp.dumpResults if $DEBUG
|
154
|
+
|
155
|
+
puts "Searching for external DPM definitions." if $DEBUG
|
156
|
+
ctx.dpms.each do |key, val|
|
157
|
+
if (vp.dpms.has_key?(key))
|
158
|
+
ctx.dpms[key] = vp.dpms[key]
|
159
|
+
puts "Found match: #{key}" if $DEBUG
|
160
|
+
end # if vp.dpms
|
161
|
+
end # do
|
162
|
+
|
163
|
+
puts "Searching for external DSM definitions." if $DEBUG
|
164
|
+
ctx.dpms.each do |key, val|
|
165
|
+
if (vp.dsms.has_key?("#{key}"))
|
166
|
+
ctx.dpms[key] = vp.dsms[key]
|
167
|
+
puts "Found match: #{key}" if $DEBUG
|
168
|
+
end # if vp.dsms
|
169
|
+
end # do
|
170
|
+
|
171
|
+
puts "Searching for external PPM definitions." if $DEBUG
|
172
|
+
ctx.ppms.each do |key, val|
|
173
|
+
if (vp.ppms.has_key?(key))
|
174
|
+
ctx.ppms[key] = vp.ppms[key]
|
175
|
+
puts "Found match: #{key}" if $DEBUG
|
176
|
+
end # if vp.ppms
|
177
|
+
end # do
|
178
|
+
|
179
|
+
end # parseExternalVarDefs
|
180
|
+
end # class GdlDocBuilder
|
181
|
+
|