'Old display method, for transition - though still used by API and
test framework. Datatypes should be very careful if overridding this
method and this interface between datatypes and Galaxy will likely
change.
TOOD: Document alternatives to overridding this method (data
providers?).'

def display_data(self, trans, data, preview=False, filename=None, to_ext=None, **kwd):

    composite_extensions = trans.app.datatypes_registry.get_composite_extensions()
    composite_extensions.append('html')
    trans.response.headers['X-Content-Type-Options'] = 'nosniff'
    if isinstance(data, six.string_types):
        return data
    if (filename and (filename != 'index')):
        file_path = trans.app.object_store.get_filename(data.dataset, extra_dir=('dataset_%s_files' % data.dataset.id), alt_name=filename)
        if os.path.exists(file_path):
            if os.path.isdir(file_path):
                tmp_fh = tempfile.NamedTemporaryFile(delete=False)
                tmp_file_name = tmp_fh.name
                dir_items = sorted(os.listdir(file_path))
                (base_path, item_name) = os.path.split(file_path)
                tmp_fh.write(('<html><head><h3>Directory    %s    contents:    %d    items</h3></head>\n' % (item_name, len(dir_items))))
                tmp_fh.write('<body><p/><table    cellpadding="2">\n')
                for (index, fname) in enumerate(dir_items):
                    if ((index % 2) == 0):
                        bgcolor = '#D8D8D8'
                    else:
                        bgcolor = '#FFFFFF'
                    tmp_fh.write(('<tr    bgcolor="%s"><td>%s</td></tr>\n' % (bgcolor, fname)))
                tmp_fh.write('</table></body></html>\n')
                tmp_fh.close()
                return open(tmp_file_name)
            mime = mimetypes.guess_type(file_path)[0]
            if (not mime):
                try:
                    mime = trans.app.datatypes_registry.get_mimetype_by_extension('.'.split(file_path)[(-1)])
                except:
                    mime = 'text/plain'
            self._clean_and_set_mime_type(trans, mime)
            return open(file_path)
        else:
            return paste.httpexceptions.HTTPNotFound(("Could    not    find    '%s'    on    the    extra    files    path    %s." % (filename, file_path)))
    self._clean_and_set_mime_type(trans, data.get_mime())
    trans.log_event(('Display    dataset    id:    %s' % str(data.id)))
    from galaxy import datatypes
    if (to_ext or isinstance(data.datatype, datatypes.binary.Binary)):
        if (data.extension in composite_extensions):
            return self._archive_composite_dataset(trans, data, **kwd)
        else:
            trans.response.headers['Content-Length'] = int(os.stat(data.file_name).st_size)
            filename = self._download_filename(data, to_ext, hdca=kwd.get('hdca', None), element_identifier=kwd.get('element_identifier', None))
            trans.response.set_content_type('application/octet-stream')
            trans.response.headers['Content-Disposition'] = ('attachment;    filename="%s"' % filename)
            return open(data.file_name)
    if (not os.path.exists(data.file_name)):
        raise paste.httpexceptions.HTTPNotFound(('File    Not    Found    (%s).' % data.file_name))
    max_peek_size = 1000000
    if isinstance(data.datatype, datatypes.text.Html):
        max_peek_size = 10000000
    preview = util.string_as_bool(preview)
    if ((not preview) or isinstance(data.datatype, datatypes.images.Image) or (os.stat(data.file_name).st_size < max_peek_size)):
        if (trans.app.config.sanitize_all_html and (trans.response.get_content_type() == 'text/html')):
            if ((not data.creating_job.imported) and (data.creating_job.tool_id in trans.app.config.sanitize_whitelist)):
                return open(data.file_name).read()
            return sanitize_html(open(data.file_name).read()).encode('utf-8')
        return open(data.file_name)
    else:
        trans.response.set_content_type('text/html')
        return trans.stream_template_mako('/dataset/large_file.mako', truncated_data=open(data.file_name).read(max_peek_size), data=data)
