'Resource structure introspection method
@param r: the S3Request instance
@param attr: controller attributes'

@staticmethod
def get_struct(r, **attr):

    response = current.response
    json_formats = response.s3.json_formats
    if (r.representation in json_formats):
        as_json = True
        content_type = 'application/json'
    else:
        as_json = False
        content_type = 'text/xml'
    get_vars = r.get_vars
    meta = (str(get_vars.get('meta', False)).lower() == 'true')
    opts = (str(get_vars.get('options', False)).lower() == 'true')
    refs = (str(get_vars.get('references', False)).lower() == 'true')
    stylesheet = r.stylesheet()
    output = r.resource.export_struct(meta=meta, options=opts, references=refs, stylesheet=stylesheet, as_json=as_json)
    if (output is None):
        r.error(400, current.xml.error)
    response.headers['Content-Type'] = content_type
    return output
