<commit_before>module Confetti
  class Config
    include Helpers
    include PhoneGap
    self.extend TemplateHelper

    attr_accessor :package, :version_string, :version_code, :description,
                  :height, :width, :plist_icon_set, :url_scheme_set, :default_min_sdk
    attr_reader :author, :viewmodes, :name, :license, :content,
                :icon_set, :feature_set, :preference_set, :xml_doc,
                :splash_set, :plist_icon_set, :access_set, :plugin_set,
                :url_scheme_set, :platform_set, :allow_navigation_set, :allow_intent_set

    generate_and_write  :android_manifest, :android_strings, :ios_info, 
                        :ios_remote_plist, :windows_phone8_manifest

    # handle bad generate/write calls
    def method_missing(method_name, *args)
      bad_call = /^(generate)|(write)_(.*)$/
      matches = method_name.to_s.match(bad_call)

      if matches
        raise FiletypeError, "#{ matches[3] } not supported"
      else
        super method_name, *args
      end
    end

    def initialize( *args )
      @author           = Author.new
      @name             = Name.new
      @license          = License.new
      @content          = Content.new
      @icon_set         = TypedSet.new Image
      @plist_icon_set   = [] 
      @feature_set      = TypedSet.new Feature
      @platform_set     = TypedSet.new Platform
      @splash_set       = TypedSet.new Image
      @preference_set   = TypedSet.new Preference
      @access_set       = TypedSet.new Access
      @allow_navigation_set = TypedSet.new AllowNavigation
      @allow_intent_set = TypedSet.new AllowIntent
      @url_scheme_set   = TypedSet.new UrlScheme
      @default_min_sdk  = 10

      # defined in PhoneGap module
      @plugin_set       = TypedSet.new Plugin
      @viewmodes        = []

      return if args.empty?

      input = args[0]
      strict = args[1] || false

      if is_file?( input ) || File.extname( input ) == ".xml"
        populate_from_xml input, strict
      elsif input.kind_of?( String )
        populate_from_string input, strict
      end
    end

    def populate_from_xml( xml_file, strict = false )
      begin
        file = File.read(xml_file)
      rescue Errno::ENOENT
        raise FileError, "file #{ xml_file } doesn't exist"
      end
      
      populate file, strict 
    end

    def populate_from_string( xml_str, strict = false )
      populate xml_str, strict
    end

    def populate( config_doc, strict = false )
      
      # confirm valid encoding
      if config_doc && !config_doc.valid_encoding?
        raise XMLError, "malformed config.xml"
      end

      begin
        config_doc = Nokogiri::XML( config_doc ) { |config| 
          strict ? config.nonet.strict : config.nonet.recover
        }.root
      rescue Nokogiri::XML::SyntaxError, TypeError, RuntimeError
        raise XMLError, "malformed config.xml"
      end

      if config_doc.nil?
        raise XMLError, "no doc parsed"
      end

      @xml_doc = config_doc # save reference to doc

      @package = config_doc["id"]
      @version_string = config_doc["version"]
      @version_code = config_doc["versionCode"]

      icon_index = 0
      splash_index = 0<commit_msg>add extra cordova config.xml attributes<commit_after>module Confetti
  class Config
    include Helpers
    include PhoneGap
    self.extend TemplateHelper

    attr_accessor :package, :version_string, :version_code, :description,
                  :height, :width, :plist_icon_set, :url_scheme_set, :default_min_sdk,
                  :android_versioncode, :ios_cfbundleversion, :windows_package_version

    attr_reader :author, :viewmodes, :name, :license, :content,
                :icon_set, :feature_set, :preference_set, :xml_doc,
                :splash_set, :plist_icon_set, :access_set, :plugin_set,
                :url_scheme_set, :platform_set, :allow_navigation_set, :allow_intent_set

    generate_and_write  :android_manifest, :android_strings, :ios_info, 
                        :ios_remote_plist, :windows_phone8_manifest

    # handle bad generate/write calls
    def method_missing(method_name, *args)
      bad_call = /^(generate)|(write)_(.*)$/
      matches = method_name.to_s.match(bad_call)

      if matches
        raise FiletypeError, "#{ matches[3] } not supported"
      else
        super method_name, *args
      end
    end

    def initialize( *args )
      @author           = Author.new
      @name             = Name.new
      @license          = License.new
      @content          = Content.new
      @icon_set         = TypedSet.new Image
      @plist_icon_set   = [] 
      @feature_set      = TypedSet.new Feature
      @platform_set     = TypedSet.new Platform
      @splash_set       = TypedSet.new Image
      @preference_set   = TypedSet.new Preference
      @access_set       = TypedSet.new Access
      @allow_navigation_set = TypedSet.new AllowNavigation
      @allow_intent_set = TypedSet.new AllowIntent
      @url_scheme_set   = TypedSet.new UrlScheme
      @default_min_sdk  = 10

      # defined in PhoneGap module
      @plugin_set       = TypedSet.new Plugin
      @viewmodes        = []

      return if args.empty?

      input = args[0]
      strict = args[1] || false

      if is_file?( input ) || File.extname( input ) == ".xml"
        populate_from_xml input, strict
      elsif input.kind_of?( String )
        populate_from_string input, strict
      end
    end

    def populate_from_xml( xml_file, strict = false )
      begin
        file = File.read(xml_file)
      rescue Errno::ENOENT
        raise FileError, "file #{ xml_file } doesn't exist"
      end
      
      populate file, strict 
    end

    def populate_from_string( xml_str, strict = false )
      populate xml_str, strict
    end

    def populate( config_doc, strict = false )
      
      # confirm valid encoding
      if config_doc && !config_doc.valid_encoding?
        raise XMLError, "malformed config.xml"
      end

      begin
        config_doc = Nokogiri::XML( config_doc ) { |config| 
          strict ? config.nonet.strict : config.nonet.recover
        }.root
      rescue Nokogiri::XML::SyntaxError, TypeError, RuntimeError
        raise XMLError, "malformed config.xml"
      end

      if config_doc.nil?
        raise XMLError, "no doc parsed"
      end

      @xml_doc = config_doc # save reference to doc

      @package                  = config_doc["id"]
      @version_string           = config_doc["version"]
      @version_code             = config_doc["versionCode"]

      @android_versioncode      = config_doc["android-versionCode"] 
      @ios_cfbundleversion      = config_doc["ios-CFBundleVersion"] 
      @windows_package_version  = config_doc["windows-packageVersion"]

      icon_index = 0
      splash_index = 0
{'fraction_non_alphanumeric': 0.08458149779735682, 'fraction_numerical': 0.0023494860499265785, 'mean_word_length': 2.26353617632966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 25}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6400443', 'n_tokens_mistral': 2116, 'n_tokens_neox': 2031, 'n_words': 472}