1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import re
17 import logging
18
19 from muntjac.terminal.gwt.server.exceptions import ServletException
20
21 from muntjac.terminal.gwt.server.abstract_application_servlet import \
22 AbstractApplicationServlet
23
24 from muntjac.util import loadClass
25
26
27 logger = logging.getLogger(__name__)
31
32 - def awake(self, transaction):
33 super(ApplicationRunnerServlet, self).awake(transaction)
34
35
36
37 self._defaultPackages = None
38
39 self._request = None
40
41 initParameter = self.getApplicationOrSystemProperty('defaultPackages',
42 None)
43 if initParameter is not None:
44 self._defaultPackages = re.split(',', initParameter)
45
46
53
54
62
63
72
73
76
77
78 @classmethod
80 """Parses application runner URIs.
81
82 If request URL is e.g.
83 http://localhost:8080/muntjac/run/muntjac.demo.calc.Calc then
84
85 - context=muntjac
86 - Runner servlet=run
87 - Muntjac application=muntjac.demo.calc.Calc
88
89 @return: string array containing widgetset URI, application URI and
90 context, runner, application classname
91 """
92 urlParts = re.split('\\/', request.uri())
93 context = None
94
95 uris = URIS()
96 applicationClassname = None
97 contextPath = cls.getContextPath(request)
98 if urlParts[1] == re.sub('\\/', '', contextPath):
99
100 context = urlParts[1]
101
102 if len(urlParts) == 3:
103 raise ValueError, 'No application specified'
104
105 applicationClassname = urlParts[3]
106
107 uris.staticFilesPath = '/' + context
108
109
110
111
112 uris.applicationClassname = applicationClassname
113 else:
114
115 context = ''
116
117 if len(urlParts) == 2:
118 raise ValueError, 'No application specified'
119
120 applicationClassname = urlParts[2]
121
122 uris.staticFilesPath = '/'
123
124
125
126 uris.applicationClassname = applicationClassname
127
128 return uris
129
130
132 appClass = None
133
134 baseName = self.getApplicationRunnerApplicationClassName(self._request)
135
136 try:
137 appClass = loadClass(baseName)
138 return appClass
139 except Exception:
140 if self._defaultPackages is not None:
141 for i in range(len(self._defaultPackages)):
142 try:
143 clsName = self._defaultPackages[i] + '.' + baseName
144 appClass = loadClass(clsName)
145 except TypeError:
146 pass
147 except Exception:
148
149 logger.info('Failed to find application '
150 'class in the default package.')
151
152 if appClass is not None:
153 return appClass
154
155 raise TypeError, 'class not found exception'
156
157
165
166
168 uris = self._getApplicationRunnerURIs(request)
169 staticFilesPath = uris.staticFilesPath
170 if staticFilesPath == '/':
171 staticFilesPath = ''
172 return staticFilesPath
173
174
175 -class URIS(object):
176
178 self.staticFilesPath = None
179
180
181
182 self.applicationClassname = None
183