1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
from webob import Response
21
from keystone import utils
22
from keystone.common import template, wsgi
25
class StaticFilesController(wsgi.Controller):
26
"""Controller for contract documents"""
28
def __init__(self, options):
29
self.options = options
32
def get_pdf_contract(self, req, pdf, root="content/"):
35
return template.static_file(resp, req, filepath,
36
root=utils.get_app_root(), mimetype="application/pdf")
39
def get_wadl_contract(self, req, wadl, root):
41
return template.static_file(resp, req, root + wadl,
42
root=utils.get_app_root(), mimetype="application/vnd.sun.wadl+xml")
45
def get_xsd_contract(self, req, xsd, root="content/"):
47
return template.static_file(resp, req, root + "xsd/" + xsd,
48
root=utils.get_app_root(), mimetype="application/xml")
51
def get_xsd_atom_contract(self, req, xsd, root="content/"):
53
return template.static_file(resp, req, root + "xsd/atom/" + xsd,
54
root=utils.get_app_root(), mimetype="application/xml")
57
def get_static_file(self, req, path, file, mimetype=None, root="content/"):
61
if utils.is_xml_response(req):
62
mimetype = "application/xml"
63
elif utils.is_json_response(req):
64
mimetype = "application/json"
66
basename, extension = os.path.splitext(file)
67
if extension == None or extension == '':
68
if mimetype == "application/xml":
69
resp_file = "%s%s%s.xml" % (root, path, file)
70
elif mimetype == "application/json":
71
resp_file = "%s%s%s.json" % (root, path, file)
73
resp_file = root + path + file
75
resp_file = root + path + file
77
return template.static_file(resp, req, resp_file,
78
root=utils.get_app_root(), mimetype=mimetype)