1.1 --- a/examples/Common/VerySimple/__init__.py Thu Jul 21 23:53:11 2005 +0000
1.2 +++ b/examples/Common/VerySimple/__init__.py Thu Jul 21 23:53:29 2005 +0000
1.3 @@ -7,6 +7,11 @@
1.4 import XSLForms.Utils
1.5 import os
1.6
1.7 +# Site map imports.
1.8 +
1.9 +from WebStack.Resources.ResourceMap import MapResource
1.10 +from WebStack.Resources.Static import DirectoryResource
1.11 +
1.12 # Resource classes.
1.13
1.14 class VerySimpleResource(XSLForms.Resources.XSLFormsResource):
1.15 @@ -27,6 +32,9 @@
1.16 document_resources = {
1.17 "types" : "structure_types.xml"
1.18 }
1.19 + in_page_resources = {
1.20 + "comments" : ("structure_output_comments.xsl", "comment-node")
1.21 + }
1.22
1.23 def respond_to_form(self, trans, form):
1.24
1.25 @@ -35,6 +43,8 @@
1.26 'form' information.
1.27 """
1.28
1.29 + in_page_resource = self.get_in_page_resource(trans)
1.30 + parameters = form.get_parameters()
1.31 documents = form.get_documents()
1.32
1.33 # Ensure the presence of a document.
1.34 @@ -62,13 +72,31 @@
1.35
1.36 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
1.37
1.38 + # Define the stylesheet parameters.
1.39 +
1.40 + stylesheet_parameters = {}
1.41 +
1.42 # Ensure that an output stylesheet exists.
1.43
1.44 - trans_xsl = self.prepare_output("structure")
1.45 + if in_page_resource in self.in_page_resources.keys():
1.46 + trans_xsl = self.prepare_fragment("structure", in_page_resource)
1.47 + element_path = parameters.get("element-path", [""])[0]
1.48 + stylesheet_parameters["element-path"] = element_path
1.49 + else:
1.50 + trans_xsl = self.prepare_output("structure")
1.51 +
1.52 + # Add information essential for in-page requests.
1.53 +
1.54 + if trans.get_server_port() == "80":
1.55 + stylesheet_parameters["application-url"] = \
1.56 + "http://%s%s" % (trans.get_server_name(), trans.get_path_without_query())
1.57 + else:
1.58 + stylesheet_parameters["application-url"] = \
1.59 + "http://%s:%s%s" % (trans.get_server_name(), trans.get_server_port(), trans.get_path_without_query())
1.60
1.61 # Complete the response.
1.62
1.63 - self.send_output(trans, [trans_xsl], structure)
1.64 + self.send_output(trans, [trans_xsl], structure, stylesheet_parameters)
1.65
1.66 # Site map initialisation.
1.67
1.68 @@ -76,6 +104,22 @@
1.69
1.70 "Return a simple Web site resource."
1.71
1.72 - return VerySimpleResource()
1.73 + # Get the main resource and the directory used by the application.
1.74 +
1.75 + very_simple_resource = VerySimpleResource()
1.76 + directory = very_simple_resource.resource_dir
1.77 +
1.78 + # Make a simple Web site.
1.79 +
1.80 + resource = MapResource({
1.81 + # Static resources:
1.82 + "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}),
1.83 + # Main page:
1.84 + "" : very_simple_resource,
1.85 + # Fragments:
1.86 + "comments" : very_simple_resource
1.87 + })
1.88 +
1.89 + return resource
1.90
1.91 # vim: tabstop=4 expandtab shiftwidth=4