1.1 --- a/WebStack/Adapters/Webware.py Sun Feb 01 18:45:09 2004 +0000
1.2 +++ b/WebStack/Adapters/Webware.py Sun Feb 01 18:45:34 2004 +0000
1.3 @@ -6,6 +6,76 @@
1.4
1.5 import WebStack.Webware
1.6
1.7 -# NOTE: Implement a servlet factory or other appropriate Webware component.
1.8 +# NOTE: Webware Experimental seems to employ special URLParsers in contexts
1.9 +# NOTE: which are much more compatible with the WebStack approach.
1.10 +
1.11 +from WebKit.ServletFactory import ServletFactory
1.12 +from WebKit.Servlet import Servlet
1.13 +
1.14 +class WebStackServletFactory(ServletFactory):
1.15 +
1.16 + """
1.17 + A servlet factory object producing servlets which provide access to
1.18 + application-specific resources.
1.19 + """
1.20 +
1.21 + def __init__(self, application, resource, file_extensions):
1.22 +
1.23 + """
1.24 + Initialise the servlet factory with the Webware 'application' and the
1.25 + WebStack root application-specific 'resource'. The 'file_extensions'
1.26 + specified indicate for which files this factory is invoked.
1.27 + """
1.28 +
1.29 + ServletFactory.__init__(self, application)
1.30 + self.webstack_resource = resource
1.31 + self.file_extensions = file_extensions
1.32 +
1.33 + def uniqueness(self):
1.34 +
1.35 + """
1.36 + Return "file" uniqueness - probably the most appropriate response.
1.37 + """
1.38 +
1.39 + return "file"
1.40 +
1.41 + def extensions(self):
1.42 +
1.43 + """
1.44 + Return the file extensions supported by this factory.
1.45 + """
1.46 +
1.47 + return self.file_extensions
1.48 +
1.49 + def servletForTransaction(self, trans):
1.50 +
1.51 + """
1.52 + Return a servlet which will provide access to the application-specific
1.53 + resources. The 'trans' object - a Webware transaction - is not given to
1.54 + the servlet since such information is available when the 'respond'
1.55 + method is invoked on the servlet.
1.56 + """
1.57 +
1.58 + return WebStackServlet(self.webstack_resource)
1.59 +
1.60 +class WebStackServlet(Servlet):
1.61 +
1.62 + "A servlet which dispatches transactions to application-specific resources."
1.63 +
1.64 + def __init__(self, resource):
1.65 +
1.66 + "Initialise the servlet with an application-specific 'resource'."
1.67 +
1.68 + self.webstack_resource = resource
1.69 +
1.70 + def respond(self, trans):
1.71 +
1.72 + """
1.73 + Respond to the incoming transaction, 'trans', by dispatching to the
1.74 + application-specific resource.
1.75 + """
1.76 +
1.77 + new_trans = WebStack.Webware.Transaction(trans)
1.78 + self.webstack_resource.respond(new_trans)
1.79
1.80 # vim: tabstop=4 expandtab shiftwidth=4