1.1 --- a/XSLForms/Resources/WebResources.py Sat Mar 04 18:49:38 2006 +0000
1.2 +++ b/XSLForms/Resources/WebResources.py Sat Mar 04 18:50:16 2006 +0000
1.3 @@ -41,12 +41,14 @@
1.4 to be employed
1.5
1.6 * in_page_resources - a dictionary mapping fragment identifiers to
1.7 - (output_filename, node_identifier) tuples,
1.8 - indicating the stylesheet filename to be
1.9 - employed, along with the node identifier used in
1.10 - the original template and output documents to
1.11 - mark a region of those documents as the fragment
1.12 - to be updated upon "in-page" requests
1.13 + (output_identifier, output_filename,
1.14 + node_identifier) tuples, indicating the output
1.15 + identifier for which the fragment applies, the
1.16 + stylesheet filename to be employed, along with
1.17 + the node identifier used in the original
1.18 + template and output documents to mark a region
1.19 + of those documents as the fragment to be updated
1.20 + upon "in-page" requests
1.21
1.22 * init_resources - a dictionary mapping initialiser/input
1.23 identifiers to (template_filename,
1.24 @@ -114,32 +116,25 @@
1.25 or 'get_result'.
1.26 """
1.27
1.28 - template_filename, output_filename = self.template_resources[output_identifier]
1.29 - output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename))
1.30 - template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.31 - XSLForms.Prepare.ensure_stylesheet(template_path, output_path)
1.32 + template_path, output_path = prepare_output(self, output_identifier)
1.33 return output_path
1.34
1.35 - def prepare_fragment(self, output_identifier, fragment_identifier):
1.36 + def prepare_fragment(self, fragment_identifier):
1.37
1.38 """
1.39 - Prepare the output stylesheets for the given 'output_identifier' and
1.40 - 'fragment_identifier', indicating which templates and stylesheets are to
1.41 - be employed in the production of output from the resource.
1.42 + Prepare the output stylesheets for the given 'fragment_identifier',
1.43 + indicating which templates and stylesheets are to be employed in the
1.44 + production of output from the resource.
1.45
1.46 - The 'output_identifier' is used as a key to the 'template_resources'
1.47 - dictionary attribute; the 'fragment_identifier' is used as a key to the
1.48 - 'in_page_resources' dictionary attribute.
1.49 + The 'fragment_identifier' is used as a key to the 'in_page_resources'
1.50 + dictionary attribute which in turn obtains an 'output_identifier', which
1.51 + is used as a key to the 'template_resources' dictionary attribute.
1.52
1.53 Return the full path to the output stylesheet for use with 'send_output'
1.54 or 'get_result'.
1.55 """
1.56
1.57 - template_filename, output_filename = self.template_resources[output_identifier]
1.58 - template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.59 - fragment_filename, node_identifier = self.in_page_resources[fragment_identifier]
1.60 - fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_filename))
1.61 - XSLForms.Prepare.ensure_stylesheet_fragment(template_path, fragment_path, node_identifier)
1.62 + template_path, fragment_path = prepare_fragment(self, fragment_identifier)
1.63 return fragment_path
1.64
1.65 def prepare_parameters(self, parameters):
1.66 @@ -210,10 +205,7 @@
1.67 or 'get_result'.
1.68 """
1.69
1.70 - template_filename, input_filename = self.init_resources[input_identifier]
1.71 - input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename))
1.72 - template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.73 - XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path, init_enumerations)
1.74 + template_path, input_path = prepare_initialiser(self, input_identifier, init_enumerations)
1.75 return input_path
1.76
1.77 def prepare_transform(self, transform_identifier):
1.78 @@ -308,4 +300,61 @@
1.79 out.write("Resource not fully defined to respond.")
1.80 raise WebStack.Generic.EndOfResponse
1.81
1.82 +def prepare_output(self, output_identifier):
1.83 +
1.84 + """
1.85 + Prepare the output stylesheet for the resource class or object 'self'
1.86 + corresponding to the given 'output_identifier'. Return the template path
1.87 + and the output stylesheet path in a 2-tuple.
1.88 + """
1.89 +
1.90 + template_filename, output_filename = self.template_resources[output_identifier]
1.91 + output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename))
1.92 + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.93 + XSLForms.Prepare.ensure_stylesheet(template_path, output_path)
1.94 + return template_path, output_path
1.95 +
1.96 +def prepare_fragment(self, fragment_identifier):
1.97 +
1.98 + """
1.99 + Prepare the output stylesheet for the resource class or object 'self'
1.100 + corresponding to the given 'fragment_identifier'. Return the template path
1.101 + and the output stylesheet path in a 2-tuple.
1.102 + """
1.103 +
1.104 + output_identifier, fragment_filename, node_identifier = self.in_page_resources[fragment_identifier]
1.105 + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_filename))
1.106 + template_filename, output_filename = self.template_resources[output_identifier]
1.107 + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.108 + XSLForms.Prepare.ensure_stylesheet_fragment(template_path, fragment_path, node_identifier)
1.109 + return template_path, fragment_path
1.110 +
1.111 +def prepare_initialiser(self, input_identifier, init_enumerations):
1.112 +
1.113 + """
1.114 + Prepare the initialising stylesheet for the resource class or object 'self'
1.115 + corresponding to the given 'input_identifier' and 'init_enumerations' flag.
1.116 + Return the template path and the initialising stylesheet path in a 2-tuple.
1.117 + """
1.118 +
1.119 + template_filename, input_filename = self.init_resources[input_identifier]
1.120 + input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename))
1.121 + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.122 + XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path, init_enumerations)
1.123 + return template_path, input_path
1.124 +
1.125 +def prepare_resources(cls):
1.126 +
1.127 + "Prepare the resources associated with the class 'cls'."
1.128 +
1.129 + for output_identifier in cls.template_resources.keys():
1.130 + prepare_output(cls, output_identifier)
1.131 + for fragment_identifier in cls.in_page_resources.keys():
1.132 + prepare_fragment(cls, fragment_identifier)
1.133 +
1.134 + # NOTE: Using init_enumerations=1 here.
1.135 +
1.136 + for input_identifier in cls.init_resources.keys():
1.137 + prepare_initialiser(cls, input_identifier, 1)
1.138 +
1.139 # vim: tabstop=4 expandtab shiftwidth=4