Method: Confetti::Config#to_xml

Defined in:
lib/confetti/config.rb

#to_xmlObject



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/confetti/config.rb', line 307

def to_xml
  doc = REXML::Document.new

  widget = REXML::Element.new( "widget" )
  widget.add_attributes({
    "xmlns" => "http://www.w3.org/ns/widgets",
    "xmlns:gap" =>  "http://phonegap.com/ns/1.0",
    "id" => @package,
    "version" => @version_string
    })

  if !@version_code.nil?
    widget.add_attribute({ "versionCode" => @version_code })
  end

  name = REXML::Element.new( "name" )
  name.text = @name.name
  name.add_attribute({ "shortname" => @name.shortname })

  content = REXML::Element.new( "content" )
  content.add_attributes({
      "src" => @content.src,
      "type" => @content.type
    })

  author = REXML::Element.new( "author" )
  author.text = @author.name
  author.add_attributes({
      "href" => @author.href,
      "email" => @author.email
      })

  description = REXML::Element.new( "description" )
  description.text = @description

  license = REXML::Element.new( "license" )
  license.text = @license.text
  license.add_attribute({ "href" => @license.href })

  icons = []
  @icon_set.each do | icon |
    ico = REXML::Element.new( "icon" )
    attrs = icon.defined_attrs
    ico.add_attributes attrs
    icons << ico
  end

  splashes = []
  @splash_set.each do | splash |
    spl = REXML::Element.new( "gap:splash" )
    attrs = splash.defined_attrs
    spl.add_attributes attrs
    splashes << spl
  end
  
  url_schemes = []
  @url_scheme_set.each do | scheme |
    schm = REXML::Element.new( "gap:url-scheme" )
    schm.add_attributes({"name" => scheme.name }) unless scheme.name.nil?
    schm.add_attributes({"role" => scheme.role }) unless scheme.role.nil?
    scheme.schemes.each{|s| schm.add_element("scheme").add_text(s) }
    url_schemes << schm
  end

  preferences = []
  @preference_set.each do | preference |
    pref = REXML::Element.new( "preference" )
    pref.add_attributes({
        "name" => preference.name,
        "value" => preference.value,
        "readonly" => preference.readonly
        })
    preferences << pref
  end

  features = []
  @feature_set.each do | feature |
    feat = REXML::Element.new( "feature" )
    feat.add_attributes({
        "name" => feature.name,
        "required" => feature.required,
        })

    features << feat 
  end

  platforms = []
  @platform_set.each do | platform |
    plat = REXML::Element.new( "gap:platform" )
    plat.add_attributes({
        "name" => platform.name
        })
    platforms << plat 
  end

  widget.elements.add name 
  widget.elements.add author
  widget.elements.add description 
  widget.elements.add license 
  widget.elements.add content

  icons.each { | icon | widget.elements.add icon }
  splashes.each { | splash | widget.elements.add splash }
  preferences.each { | pref | widget.elements.add pref }
  features.each { | feat | widget.elements.add feat }
  platforms.each { | plat | widget.elements.add plat }
  url_schemes.each { | schm | widget.elements.add schm }

  doc << REXML::XMLDecl.new
  doc.elements.add widget
  doc
end