~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/controllers/staticfiles.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
from webob import Response
 
19
import os
 
20
 
 
21
from keystone import utils
 
22
from keystone.common import template, wsgi
 
23
 
 
24
 
 
25
class StaticFilesController(wsgi.Controller):
 
26
    """Controller for contract documents"""
 
27
 
 
28
    def __init__(self, options):
 
29
        self.options = options
 
30
 
 
31
    @utils.wrap_error
 
32
    def get_pdf_contract(self, req, pdf, root="content/"):
 
33
        resp = Response()
 
34
        filepath = root + pdf
 
35
        return template.static_file(resp, req, filepath,
 
36
            root=utils.get_app_root(), mimetype="application/pdf")
 
37
 
 
38
    @utils.wrap_error
 
39
    def get_wadl_contract(self, req, wadl, root):
 
40
        resp = Response()
 
41
        return template.static_file(resp, req, root + wadl,
 
42
            root=utils.get_app_root(), mimetype="application/vnd.sun.wadl+xml")
 
43
 
 
44
    @utils.wrap_error
 
45
    def get_xsd_contract(self, req, xsd, root="content/"):
 
46
        resp = Response()
 
47
        return template.static_file(resp, req, root + "xsd/" + xsd,
 
48
            root=utils.get_app_root(), mimetype="application/xml")
 
49
 
 
50
    @utils.wrap_error
 
51
    def get_xsd_atom_contract(self, req, xsd, root="content/"):
 
52
        resp = Response()
 
53
        return template.static_file(resp, req, root + "xsd/atom/" + xsd,
 
54
            root=utils.get_app_root(), mimetype="application/xml")
 
55
 
 
56
    @utils.wrap_error
 
57
    def get_static_file(self, req, path, file, mimetype=None, root="content/"):
 
58
        resp = Response()
 
59
 
 
60
        if mimetype == None:
 
61
            if utils.is_xml_response(req):
 
62
                mimetype = "application/xml"
 
63
            elif utils.is_json_response(req):
 
64
                mimetype = "application/json"
 
65
 
 
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)
 
72
            else:
 
73
                resp_file = root + path + file
 
74
        else:
 
75
            resp_file = root + path + file
 
76
 
 
77
        return template.static_file(resp, req, resp_file,
 
78
            root=utils.get_app_root(), mimetype=mimetype)