# HG changeset patch # User paulb # Date 1121878927 0 # Node ID 636bc557bc6c595d77337b855876704433f9c630 # Parent 6679351895ce6198616d362ef979f531c36296d8 [project @ 2005-07-20 17:02:07 by paulb] Added convenience methods for transformations along with extra class attributes. diff -r 6679351895ce -r 636bc557bc6c XSLForms/Resources.py --- a/XSLForms/Resources.py Wed Jul 20 16:11:02 2005 +0000 +++ b/XSLForms/Resources.py Wed Jul 20 17:02:07 2005 +0000 @@ -47,6 +47,14 @@ mark a region of those documents as the fragment to be updated upon "in-page" requests + * transform_resources - a dictionary mapping transform identifiers to + lists of stylesheet filenames for use with the + transformation methods + + * document_resources - a dictionary mapping document identifiers to + single filenames for use as source documents or + as references with the transformation methods + * resource_dir - the absolute path of the directory in which stylesheet resources are to reside @@ -66,6 +74,8 @@ encoding = "utf-8" template_resources = {} in_page_resources = {} + transform_resources = {} + document_resources = {} resource_dir = None def get_fields_from_body(self, trans, encoding): @@ -98,6 +108,9 @@ The 'output_identifier' is used as a key to the 'template_resources' dictionary attribute. + + Return the full path to the output stylesheet for use with 'send_output' + or 'get_result'. """ template_filename, output_filename = self.template_resources[output_identifier] @@ -116,6 +129,9 @@ The 'output_identifier' is used as a key to the 'template_resources' dictionary attribute; the 'fragment_identifier' is used as a key to the 'in_page_resources' dictionary attribute. + + Return the full path to the output stylesheet for use with 'send_output' + or 'get_result'. """ output_path = self.prepare_output(output_identifier) @@ -124,18 +140,59 @@ XSLForms.Prepare.ensure_stylesheet_fragment(output_path, fragment_path, node_identifier) return fragment_path - def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None): + def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, references=None): """ Send the output from the resource to the user employing the transaction 'trans', stylesheets having the given 'stylesheet_filenames', the - 'document' upon which the output will be based, and the optional - parameters as defined in the 'stylesheet_parameters' dictionary. + 'document' upon which the output will be based, the optional parameters + as defined in the 'stylesheet_parameters' dictionary, and the optional + 'references' to external documents. + """ + + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references) + proc.send_output(trans.get_response_stream(), trans.get_response_stream_encoding(), + document) + + def get_result(self, stylesheet_filenames, document, stylesheet_parameters=None, references=None): + + """ + Get the result of applying a transformation using stylesheets with the + given 'stylesheet_filenames', the 'document' upon which the result will + be based, the optional parameters as defined in the + 'stylesheet_parameters' dictionary, and the optional 'references' to + external documents. """ - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters) - proc.send_output(trans.get_response_stream(), trans.get_response_stream_encoding(), - document) + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references) + return proc.get_result(document) + + def prepare_transform(self, transform_identifier): + + """ + Prepare a transformation using the given 'transform_identifier'. + + Return a list of full paths to the output stylesheets for use with + 'send_output' or 'get_result'. + """ + + filenames = self.transform_resources[transform_identifier] + paths = [] + for filename in filenames: + paths.append(os.path.join(self.resource_dir, filename)) + return paths + + def prepare_document(self, document_identifier): + + """ + Prepare a document using the given 'document_identifier'. + + Return the full path of the document for use either as the source + document or as a reference with 'send_output' or 'get_result'. + """ + + filename = self.document_resources[document_identifier] + return os.path.join(self.resource_dir, filename) def get_in_page_resource(self, trans):