1.1 --- a/XSLForms/Resources.py Wed Jul 20 16:11:02 2005 +0000
1.2 +++ b/XSLForms/Resources.py Wed Jul 20 17:02:07 2005 +0000
1.3 @@ -47,6 +47,14 @@
1.4 mark a region of those documents as the fragment
1.5 to be updated upon "in-page" requests
1.6
1.7 + * transform_resources - a dictionary mapping transform identifiers to
1.8 + lists of stylesheet filenames for use with the
1.9 + transformation methods
1.10 +
1.11 + * document_resources - a dictionary mapping document identifiers to
1.12 + single filenames for use as source documents or
1.13 + as references with the transformation methods
1.14 +
1.15 * resource_dir - the absolute path of the directory in which
1.16 stylesheet resources are to reside
1.17
1.18 @@ -66,6 +74,8 @@
1.19 encoding = "utf-8"
1.20 template_resources = {}
1.21 in_page_resources = {}
1.22 + transform_resources = {}
1.23 + document_resources = {}
1.24 resource_dir = None
1.25
1.26 def get_fields_from_body(self, trans, encoding):
1.27 @@ -98,6 +108,9 @@
1.28
1.29 The 'output_identifier' is used as a key to the 'template_resources'
1.30 dictionary attribute.
1.31 +
1.32 + Return the full path to the output stylesheet for use with 'send_output'
1.33 + or 'get_result'.
1.34 """
1.35
1.36 template_filename, output_filename = self.template_resources[output_identifier]
1.37 @@ -116,6 +129,9 @@
1.38 The 'output_identifier' is used as a key to the 'template_resources'
1.39 dictionary attribute; the 'fragment_identifier' is used as a key to the
1.40 'in_page_resources' dictionary attribute.
1.41 +
1.42 + Return the full path to the output stylesheet for use with 'send_output'
1.43 + or 'get_result'.
1.44 """
1.45
1.46 output_path = self.prepare_output(output_identifier)
1.47 @@ -124,18 +140,59 @@
1.48 XSLForms.Prepare.ensure_stylesheet_fragment(output_path, fragment_path, node_identifier)
1.49 return fragment_path
1.50
1.51 - def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None):
1.52 + def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, references=None):
1.53
1.54 """
1.55 Send the output from the resource to the user employing the transaction
1.56 'trans', stylesheets having the given 'stylesheet_filenames', the
1.57 - 'document' upon which the output will be based, and the optional
1.58 - parameters as defined in the 'stylesheet_parameters' dictionary.
1.59 + 'document' upon which the output will be based, the optional parameters
1.60 + as defined in the 'stylesheet_parameters' dictionary, and the optional
1.61 + 'references' to external documents.
1.62 + """
1.63 +
1.64 + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references)
1.65 + proc.send_output(trans.get_response_stream(), trans.get_response_stream_encoding(),
1.66 + document)
1.67 +
1.68 + def get_result(self, stylesheet_filenames, document, stylesheet_parameters=None, references=None):
1.69 +
1.70 + """
1.71 + Get the result of applying a transformation using stylesheets with the
1.72 + given 'stylesheet_filenames', the 'document' upon which the result will
1.73 + be based, the optional parameters as defined in the
1.74 + 'stylesheet_parameters' dictionary, and the optional 'references' to
1.75 + external documents.
1.76 """
1.77
1.78 - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters)
1.79 - proc.send_output(trans.get_response_stream(), trans.get_response_stream_encoding(),
1.80 - document)
1.81 + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references)
1.82 + return proc.get_result(document)
1.83 +
1.84 + def prepare_transform(self, transform_identifier):
1.85 +
1.86 + """
1.87 + Prepare a transformation using the given 'transform_identifier'.
1.88 +
1.89 + Return a list of full paths to the output stylesheets for use with
1.90 + 'send_output' or 'get_result'.
1.91 + """
1.92 +
1.93 + filenames = self.transform_resources[transform_identifier]
1.94 + paths = []
1.95 + for filename in filenames:
1.96 + paths.append(os.path.join(self.resource_dir, filename))
1.97 + return paths
1.98 +
1.99 + def prepare_document(self, document_identifier):
1.100 +
1.101 + """
1.102 + Prepare a document using the given 'document_identifier'.
1.103 +
1.104 + Return the full path of the document for use either as the source
1.105 + document or as a reference with 'send_output' or 'get_result'.
1.106 + """
1.107 +
1.108 + filename = self.document_resources[document_identifier]
1.109 + return os.path.join(self.resource_dir, filename)
1.110
1.111 def get_in_page_resource(self, trans):
1.112