import (Raggle::OPML)

    # File raggle, line 1111
        def OPML::import(file_name, refresh=nil, lock_title=nil, save_items=nil, force=false)
          begin
            contents = if uri?(file_name)
              begin
                Raggle::Engine::get_url(file_name)[0]
              rescue
                raise "Couldn't get URI \"#{file_name}\"."
              end
            else
              begin
                ret = ''
                file = (file_name == '-') ? $stdin : File::open(file_name)
                ret = file.read
              rescue
                raise "Couldn't open input file \"#{file_name}\"."
              ensure
                file.close
                ret
              end
            end

            if contents && contents.size > 0
              # escape CDATA elements and merge them in to the text
              # (ths fixes REXML's braindead CDATA behavior)
              contents = contents.gsub(/<!\[CDATA\[(.*?)\]\]>/m) do |m|
                $1.dup.escape_html
              end

              dup_added = false
              doc = REXML::Document.new(contents)
              doc.root.elements.each('//outline') do |outline|
                title = outline.attributes['title'] || $config['default_feed_title']
                url = outline.attributes['xmlUrl'] || outline.attributes['xmlurl'] || outline.attributes['url']
                site = outline.attributes['htmlUrl'] || outline.attributes['htmlurl'] || ''
                desc = outline.attributes['description'] || ''
                cat = outline.attributes['category'] || nil
                image = outline.attributes['image'] || nil
                max_items = outline.attributes['max_items'] || nil
                priority = outline.attributes['priority'].to_i || $config['default_feed_priority']
                # the following properties take effect unless overridden on CLI
                if outline.attributes['refresh']: opml_refresh = outline.attributes['refresh'].to_i
                else opml_refresh = nil; end  # fixes clobberation
                frefresh = refresh || opml_refresh || $config['default_feed_refresh']
                fsave_items = save_items || outline.attributes['save_items'] || false
                flock_title = lock_title || outline.attributes['lock_title'] || false

                if url.nil?
                  $stderr.puts "Warning: skipping incomplete OPML entry: #{outline}"
                  next
                end

                if (url =~ /^exec:/)
                  if $wins  # in ncurses mode
                    Interfaces::NcursesInterface::set_status($config['msg_exec_url'])
                    return 1
                  else
                    raise "WARNING!!! EXEC URL IN OPML IMPORT"
                  end
                end

                # build and add feed
                feed = {'title' => title, 'url' => url, 'refresh' => frefresh,
                        'lock_title?' => flock_title, 'save_items?' => fsave_items,
                        'site' => site, 'desc' => desc, 'items' => [],
                        'image' => image, 'category' => cat, 'force' => force,
                        'priority' => priority, 'max_items' => max_items }
                dup_added = true unless Engine::add_feed(feed)
              end
              if $wins  # skip unless using ncurses
                Interfaces::NcursesInterface::populate_feed_win
                Interfaces::NcursesInterface::set_status($config['msg_opml_imported']) unless dup_added
              end
            else
              raise "Empty input file \"#{file_name}\"."
            end
          rescue REXML::ParseException => parse_err
            raise if $wins
            die "Parsing #{file_name} failed: #{parse_err.message}" unless $wins
          rescue => err
            if $wins: Interfaces::NcursesInterface::set_status($config['msg_bad_uri'])
            else die err.message; end
          end
        end