# HG changeset patch # User paulb # Date 1130285229 0 # Node ID 54af5279b35af9335d04660dd8eacedf9552dea8 # Parent 348a80dc3c33b86f4b410a2edc02934757569d5e [project @ 2005-10-26 00:06:50 by paulb] Made XSLForms.Resources a package containing separate resource class modules. diff -r 348a80dc3c33 -r 54af5279b35a XSLForms/PyQt.py --- a/XSLForms/PyQt.py Tue Oct 25 17:52:28 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -#!/usr/bin/env python - -import XSLForms.Prepare -import qt -import qtui -import qtxmldom -import os - -class XSLFormsResource: - - "An XSLForms resource for use with PyQt." - - template_resources = {} - widget_resources = {} - document_resources = {} - - # Helper methods. - # NOTE: Should be moved to a superclass. - - def prepare_document(self, document_identifier): - filename = self.document_resources[document_identifier] - return os.path.abspath(os.path.join(self.resource_dir, filename)) - - def get_document(self, document_identifier): - return qtxmldom.parse(self.prepare_document(document_identifier)) - - def get_elements(self, document_identifier): - doc = self.get_document(document_identifier) - return doc.getElementsByTagName(document_identifier + "-enum") - - def prepare_template(self, template_identifier): - filename = self.template_resources[template_identifier] - return os.path.abspath(os.path.join(self.resource_dir, filename)) - - def prepare_widget(self, template_identifier, widget_identifier, parent=None): - template_path = self.prepare_template(template_identifier) - fragment_name, widget_name = self.widget_resources[widget_identifier] - fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name)) - XSLForms.Prepare.ensure_qt_fragment(template_path, fragment_path, widget_name) - return qtui.QWidgetFactory.create(fragment_path, None, parent) - - def populate_list(self, field, elements): - current_text = field.currentText() - while field.count() > 0: - field.removeItem(0) - item = 0 - set = 0 - for element in elements: - text = element.getAttribute("value") - field.insertItem(text) - if text == current_text: - field.setCurrentItem(item) - set = 1 - item += 1 - if not set: - field.setCurrentItem(0) - - def reset_collection(self, field): - layout = field.layout() - for child in field.children(): - if child is not layout: - layout.remove(child) - child.deleteLater() - -class Factory: - - "A widget factory helper class." - - def __init__(self, ui_filename): - self.ui_filename = ui_filename - self.ui_doc = qtxmldom.parse(ui_filename) - - def connect(self, widget, obj): - - for connection in self.ui_doc.getElementsByTagName("connection"): - sender_name = self.get_text(connection.getElementsByTagName("sender")[0]).encode("utf-8") - signal_name = self.get_text(connection.getElementsByTagName("signal")[0]).encode("utf-8") - slot_name = self.get_text(connection.getElementsByTagName("slot")[0]).encode("utf-8") - - if widget.name() == sender_name: - senders = [widget] - else: - senders = self.find_widgets(widget, sender_name) - - slot = slot_name.split("(")[0] - if hasattr(obj, slot): - signal = qt.SIGNAL(signal_name) - for sender in senders: - qt.QObject.connect(sender, signal, getattr(obj, slot)) - - def find_widgets(self, widget, name): - widgets = [] - found = widget.child(name) - if found: - widgets.append(found) - for child in widget.children(): - widgets += self.find_widgets(child, name) - return widgets - - def get_text(self, node): - node.normalize() - return node.childNodes[0].nodeValue - - def find_widget_element(self, name): - for widget in self.ui_doc.getElementsByTagName("widget"): - for property in widget.getElementsByTagName("property"): - if property.getAttribute("name") == "name": - for cstring in property.getElementsByTagName("cstring"): - found_name = self.get_text(cstring) - if found_name == name: - return widget - return None - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 348a80dc3c33 -r 54af5279b35a XSLForms/Resources.py --- a/XSLForms/Resources.py Tue Oct 25 17:52:28 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,312 +0,0 @@ -#!/usr/bin/env python - -""" -Resources for use with WebStack. - -Copyright (C) 2005 Paul Boddie - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -""" - -import WebStack.Generic -import XSLForms.Fields -import XSLForms.Prepare -import XSLForms.Output -from XSLTools import XSLOutput -import os - -class XSLFormsResource: - - """ - A generic XSLForms resource for use with WebStack. - - When overriding this class, define the following attributes appropriately: - - * template_resources - a dictionary mapping output identifiers to - (template_filename, output_filename) tuples, - indicating the template and stylesheet filenames - to be employed - - * in_page_resources - a dictionary mapping fragment identifiers to - (output_filename, node_identifier) tuples, - indicating the stylesheet filename to be - employed, along with the node identifier used in - the original template and output documents to - mark a region of those documents as the fragment - to be updated upon "in-page" requests - - * init_resources - a dictionary mapping initialiser/input - identifiers to (template_filename, - input_filename) tuples, indicating the template - and initialiser/input stylesheet filenames to be - employed - - * 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 - - All filenames shall be simple leafnames for files residing in the resource's - special resource directory 'resource_dir'. - - The following attributes may also be specified: - - * path_encoding - the assumed encoding of characters in request - paths - - * encoding - the assumed encoding of characters in request - bodies - """ - - path_encoding = "utf-8" - encoding = "utf-8" - template_resources = {} - in_page_resources = {} - transform_resources = {} - document_resources = {} - resource_dir = None - - def clean_parameters(self, parameters): - - """ - Workaround stray zero value characters from Konqueror in XMLHttpRequest - communications. - """ - - for name, values in parameters.items(): - new_values = [] - for value in values: - if value.endswith("\x00"): - new_values.append(value[:-1]) - else: - new_values.append(value) - parameters[name] = new_values - - def prepare_output(self, output_identifier): - - """ - Prepare the output stylesheets using the given 'output_identifier' to - indicate which templates and stylesheets are to be employed in the - production of output from the resource. - - 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] - output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename)) - template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) - XSLForms.Prepare.ensure_stylesheet(template_path, output_path) - return output_path - - def prepare_fragment(self, output_identifier, fragment_identifier): - - """ - Prepare the output stylesheets for the given 'output_identifier' and - 'fragment_identifier', indicating which templates and stylesheets are to - be employed in the production of output from the resource. - - 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) - fragment_filename, node_identifier = self.in_page_resources[fragment_identifier] - fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_filename)) - XSLForms.Prepare.ensure_stylesheet_fragment(output_path, fragment_path, node_identifier) - return fragment_path - - def prepare_parameters(self, parameters): - - """ - Prepare the stylesheet parameters from the given request 'parameters'. - This is most useful when preparing fragments for in-page update output. - """ - - element_path = parameters.get("element-path", [""])[0] - if element_path: - return {"element-path" : element_path} - else: - return {} - - def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, - stylesheet_expressions=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, the optional parameters - as defined in the 'stylesheet_parameters' dictionary, the optional - expressions are defined in the 'stylesheet_expressions' dictionary, and - the optional 'references' to external documents. - """ - - # Sanity check for the filenames list. - - if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): - raise ValueError, stylesheet_filenames - - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, - expressions=stylesheet_expressions, 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, - stylesheet_expressions=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, the optional parameters as defined - in the 'stylesheet_parameters' dictionaryand the optional 'references' - to external documents. - """ - - # Sanity check for the filenames list. - - if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): - raise ValueError, stylesheet_filenames - - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, - expressions=stylesheet_expressions, references=references) - return proc.get_result(document) - - def prepare_initialiser(self, input_identifier): - - """ - Prepare an initialiser/input transformation using the given - 'input_identifier'. - - Return the full path to the input stylesheet for use with 'send_output' - or 'get_result'. - """ - - template_filename, input_filename = self.init_resources[input_identifier] - input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename)) - template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) - XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path) - return input_path - - 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.abspath(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.abspath(os.path.join(self.resource_dir, filename)) - - def get_in_page_resource(self, trans): - - """ - Return the in-page resource being referred to in the given transaction - 'trans'. - """ - - return trans.get_path_info(self.path_encoding).split("/")[-1] - - def respond(self, trans): - - """ - Respond to the request described by the given transaction 'trans'. - """ - - # Only obtain field information according to the stated method. - - method = trans.get_request_method() - in_page_resource = self.get_in_page_resource(trans) - - # Handle typical request methods, processing request information. - - if method == "GET": - - # Get the fields from the request path (URL). - # NOTE: The encoding is actually redundant since WebStack produces - # NOTE: Unicode values. - - form = XSLForms.Fields.Form(encoding=self.path_encoding, values_are_lists=1) - parameters = trans.get_fields_from_path() - form.set_parameters(parameters) - - elif method == "POST": - - # Get the fields from the request body. - # NOTE: The encoding is actually redundant since WebStack produces - # NOTE: Unicode values. - - form = XSLForms.Fields.Form(encoding=self.encoding, values_are_lists=1) - parameters = trans.get_fields_from_body(self.encoding) - - # NOTE: Konqueror workaround. - self.clean_parameters(parameters) - - form.set_parameters(parameters) - - else: - - # Initialise empty containers. - - parameters = {} - documents = {} - - # Call an overridden method with the processed request information. - - self.respond_to_form(trans, form) - - def respond_to_form(self, trans, form): - - """ - Respond to the request described by the given transaction 'trans', using - the given 'form' object to conveniently retrieve field (request - parameter) information and structured form information (as DOM-style XML - documents). - """ - - trans.set_response_code(500) - raise WebStack.Generic.EndOfResponse - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 348a80dc3c33 -r 54af5279b35a XSLForms/Resources/PyQtResources.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/PyQtResources.py Wed Oct 26 00:07:09 2005 +0000 @@ -0,0 +1,114 @@ +#!/usr/bin/env python + +import XSLForms.Prepare +import qt +import qtui +import qtxmldom +import os + +class XSLFormsResource: + + "An XSLForms resource for use with PyQt." + + template_resources = {} + widget_resources = {} + document_resources = {} + + # Helper methods. + # NOTE: Should be moved to a superclass. + + def prepare_document(self, document_identifier): + filename = self.document_resources[document_identifier] + return os.path.abspath(os.path.join(self.resource_dir, filename)) + + def get_document(self, document_identifier): + return qtxmldom.parse(self.prepare_document(document_identifier)) + + def get_elements(self, document_identifier): + doc = self.get_document(document_identifier) + return doc.getElementsByTagName(document_identifier + "-enum") + + def prepare_template(self, template_identifier): + filename = self.template_resources[template_identifier] + return os.path.abspath(os.path.join(self.resource_dir, filename)) + + def prepare_widget(self, template_identifier, widget_identifier, parent=None): + template_path = self.prepare_template(template_identifier) + fragment_name, widget_name = self.widget_resources[widget_identifier] + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name)) + XSLForms.Prepare.ensure_qt_fragment(template_path, fragment_path, widget_name) + return qtui.QWidgetFactory.create(fragment_path, None, parent) + + def populate_list(self, field, elements): + current_text = field.currentText() + while field.count() > 0: + field.removeItem(0) + item = 0 + set = 0 + for element in elements: + text = element.getAttribute("value") + field.insertItem(text) + if text == current_text: + field.setCurrentItem(item) + set = 1 + item += 1 + if not set: + field.setCurrentItem(0) + + def reset_collection(self, field): + layout = field.layout() + for child in field.children(): + if child is not layout: + layout.remove(child) + child.deleteLater() + +class Factory: + + "A widget factory helper class." + + def __init__(self, ui_filename): + self.ui_filename = ui_filename + self.ui_doc = qtxmldom.parse(ui_filename) + + def connect(self, widget, obj): + + for connection in self.ui_doc.getElementsByTagName("connection"): + sender_name = self.get_text(connection.getElementsByTagName("sender")[0]).encode("utf-8") + signal_name = self.get_text(connection.getElementsByTagName("signal")[0]).encode("utf-8") + slot_name = self.get_text(connection.getElementsByTagName("slot")[0]).encode("utf-8") + + if widget.name() == sender_name: + senders = [widget] + else: + senders = self.find_widgets(widget, sender_name) + + slot = slot_name.split("(")[0] + if hasattr(obj, slot): + signal = qt.SIGNAL(signal_name) + for sender in senders: + qt.QObject.connect(sender, signal, getattr(obj, slot)) + + def find_widgets(self, widget, name): + widgets = [] + found = widget.child(name) + if found: + widgets.append(found) + for child in widget.children(): + widgets += self.find_widgets(child, name) + return widgets + + def get_text(self, node): + node.normalize() + return node.childNodes[0].nodeValue + + def find_widget_element(self, name): + for widget in self.ui_doc.getElementsByTagName("widget"): + for property in widget.getElementsByTagName("property"): + if property.getAttribute("name") == "name": + for cstring in property.getElementsByTagName("cstring"): + found_name = self.get_text(cstring) + if found_name == name: + return widget + return None + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 348a80dc3c33 -r 54af5279b35a XSLForms/Resources/WebResources.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/WebResources.py Wed Oct 26 00:07:09 2005 +0000 @@ -0,0 +1,312 @@ +#!/usr/bin/env python + +""" +Resources for use with WebStack. + +Copyright (C) 2005 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import WebStack.Generic +import XSLForms.Fields +import XSLForms.Prepare +import XSLForms.Output +from XSLTools import XSLOutput +import os + +class XSLFormsResource: + + """ + A generic XSLForms resource for use with WebStack. + + When overriding this class, define the following attributes appropriately: + + * template_resources - a dictionary mapping output identifiers to + (template_filename, output_filename) tuples, + indicating the template and stylesheet filenames + to be employed + + * in_page_resources - a dictionary mapping fragment identifiers to + (output_filename, node_identifier) tuples, + indicating the stylesheet filename to be + employed, along with the node identifier used in + the original template and output documents to + mark a region of those documents as the fragment + to be updated upon "in-page" requests + + * init_resources - a dictionary mapping initialiser/input + identifiers to (template_filename, + input_filename) tuples, indicating the template + and initialiser/input stylesheet filenames to be + employed + + * 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 + + All filenames shall be simple leafnames for files residing in the resource's + special resource directory 'resource_dir'. + + The following attributes may also be specified: + + * path_encoding - the assumed encoding of characters in request + paths + + * encoding - the assumed encoding of characters in request + bodies + """ + + path_encoding = "utf-8" + encoding = "utf-8" + template_resources = {} + in_page_resources = {} + transform_resources = {} + document_resources = {} + resource_dir = None + + def clean_parameters(self, parameters): + + """ + Workaround stray zero value characters from Konqueror in XMLHttpRequest + communications. + """ + + for name, values in parameters.items(): + new_values = [] + for value in values: + if value.endswith("\x00"): + new_values.append(value[:-1]) + else: + new_values.append(value) + parameters[name] = new_values + + def prepare_output(self, output_identifier): + + """ + Prepare the output stylesheets using the given 'output_identifier' to + indicate which templates and stylesheets are to be employed in the + production of output from the resource. + + 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] + output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename)) + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) + XSLForms.Prepare.ensure_stylesheet(template_path, output_path) + return output_path + + def prepare_fragment(self, output_identifier, fragment_identifier): + + """ + Prepare the output stylesheets for the given 'output_identifier' and + 'fragment_identifier', indicating which templates and stylesheets are to + be employed in the production of output from the resource. + + 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) + fragment_filename, node_identifier = self.in_page_resources[fragment_identifier] + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_filename)) + XSLForms.Prepare.ensure_stylesheet_fragment(output_path, fragment_path, node_identifier) + return fragment_path + + def prepare_parameters(self, parameters): + + """ + Prepare the stylesheet parameters from the given request 'parameters'. + This is most useful when preparing fragments for in-page update output. + """ + + element_path = parameters.get("element-path", [""])[0] + if element_path: + return {"element-path" : element_path} + else: + return {} + + def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, + stylesheet_expressions=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, the optional parameters + as defined in the 'stylesheet_parameters' dictionary, the optional + expressions are defined in the 'stylesheet_expressions' dictionary, and + the optional 'references' to external documents. + """ + + # Sanity check for the filenames list. + + if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): + raise ValueError, stylesheet_filenames + + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, + expressions=stylesheet_expressions, 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, + stylesheet_expressions=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, the optional parameters as defined + in the 'stylesheet_parameters' dictionaryand the optional 'references' + to external documents. + """ + + # Sanity check for the filenames list. + + if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): + raise ValueError, stylesheet_filenames + + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, + expressions=stylesheet_expressions, references=references) + return proc.get_result(document) + + def prepare_initialiser(self, input_identifier): + + """ + Prepare an initialiser/input transformation using the given + 'input_identifier'. + + Return the full path to the input stylesheet for use with 'send_output' + or 'get_result'. + """ + + template_filename, input_filename = self.init_resources[input_identifier] + input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename)) + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) + XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path) + return input_path + + 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.abspath(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.abspath(os.path.join(self.resource_dir, filename)) + + def get_in_page_resource(self, trans): + + """ + Return the in-page resource being referred to in the given transaction + 'trans'. + """ + + return trans.get_path_info(self.path_encoding).split("/")[-1] + + def respond(self, trans): + + """ + Respond to the request described by the given transaction 'trans'. + """ + + # Only obtain field information according to the stated method. + + method = trans.get_request_method() + in_page_resource = self.get_in_page_resource(trans) + + # Handle typical request methods, processing request information. + + if method == "GET": + + # Get the fields from the request path (URL). + # NOTE: The encoding is actually redundant since WebStack produces + # NOTE: Unicode values. + + form = XSLForms.Fields.Form(encoding=self.path_encoding, values_are_lists=1) + parameters = trans.get_fields_from_path() + form.set_parameters(parameters) + + elif method == "POST": + + # Get the fields from the request body. + # NOTE: The encoding is actually redundant since WebStack produces + # NOTE: Unicode values. + + form = XSLForms.Fields.Form(encoding=self.encoding, values_are_lists=1) + parameters = trans.get_fields_from_body(self.encoding) + + # NOTE: Konqueror workaround. + self.clean_parameters(parameters) + + form.set_parameters(parameters) + + else: + + # Initialise empty containers. + + parameters = {} + documents = {} + + # Call an overridden method with the processed request information. + + self.respond_to_form(trans, form) + + def respond_to_form(self, trans, form): + + """ + Respond to the request described by the given transaction 'trans', using + the given 'form' object to conveniently retrieve field (request + parameter) information and structured form information (as DOM-style XML + documents). + """ + + trans.set_response_code(500) + raise WebStack.Generic.EndOfResponse + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 348a80dc3c33 -r 54af5279b35a XSLForms/Resources/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +""" +XML/XSL-based forms resource classes. + +Copyright (C) 2005 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 348a80dc3c33 -r 54af5279b35a docs/Web-resource.html --- a/docs/Web-resource.html Tue Oct 25 17:52:28 2005 +0000 +++ b/docs/Web-resource.html Wed Oct 26 00:07:09 2005 +0000 @@ -20,14 +20,14 @@ earlier, we now want to edit the __init__.py file and add code which will do most of the work of the form-editing application. Here is the start of this code:

-
#!/usr/bin/env python

"A very simple example application."

import WebStack.Generic
import XSLForms.Resources
import XSLForms.Utils
import os

# Resource classes.

class VerySimpleResource(XSLForms.Resources.XSLFormsResource):

# To be continued.
+
#!/usr/bin/env python

"A very simple example application."

import WebStack.Generic
import XSLForms.Resources.WebResources
import XSLForms.Utils
import os

# Resource classes.

class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource):

# To be continued.

The above import statements just include in our application everything that it is likely to need from WebStack, XSLForms and the standard library. Then, we define a class inheriting from a special XSLForms class which does some of the tedious Web application housekeeping that we would otherwise need to do ourselves.

We may expand the above class definition as follows:

-
class VerySimpleResource(XSLForms.Resources.XSLFormsResource):

"A very simple resource providing a hierarchy of editable fields."

resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
encoding = "utf-8"
template_resources = {
"structure" : ("structure_template.xhtml", "structure_output.xsl")
}

def respond_to_form(self, trans, form):

"""
Respond to a request having the given transaction 'trans' and the given
'form' information.
"""

# To be continued.
+
class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource):

"A very simple resource providing a hierarchy of editable fields."

resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
encoding = "utf-8"
template_resources = {
"structure" : ("structure_template.xhtml", "structure_output.xsl")
}

def respond_to_form(self, trans, form):

"""
Respond to a request having the given transaction 'trans' and the given
'form' information.
"""

# To be continued.

The class is started with some attribute definitions:

  • The resource_dir attribute is used to locate @@ -132,4 +132,4 @@ using the usual WebStack techniques. However, more advanced templates can be designed, and we shall consider multiple-choice fields in the next activity in the development process.

    - \ No newline at end of file + diff -r 348a80dc3c33 -r 54af5279b35a docs/XSLForms-resource.html --- a/docs/XSLForms-resource.html Tue Oct 25 17:52:28 2005 +0000 +++ b/docs/XSLForms-resource.html Wed Oct 26 00:07:09 2005 +0000 @@ -11,7 +11,7 @@ from this class, XSLFormsResource, you can derive your own application-specific resources and use the class's API to obtain, manipulate and present form data. Although the -supplied API documentation provides details of the class's API, specifically in the XSLForms.Resources module, this document attempts to explain how the API is used in practice.

    Resource Structure

    The structure of a Web resource derived from XSLFormsResource should look like this:

    class MyResource(XSLForms.Resources.XSLFormsResource):

    [Resource definitions]

    def respond_to_form(self, trans, form):
    [Examine the form data, see if the user has added or removed anything.]
    [Perform additional processing and initialise the form data.]
    [Produce some kind of response to show the user the updated form data.]

    Since XSLFormsResource builds on WebStack's resource mechanisms, we do have the transaction object, trans, available. However, most of the information we need to access and manipulate is generally available through the form object.

    Defining Resources

    Classes derived from XSLFormsResource +supplied API documentation provides details of the class's API, specifically in the XSLForms.Resources.WebResources module, this document attempts to explain how the API is used in practice.

    Resource Structure

    The structure of a Web resource derived from XSLFormsResource should look like this:

    class MyResource(XSLForms.Resources.WebResources.XSLFormsResource):

    [Resource definitions]

    def respond_to_form(self, trans, form):
    [Examine the form data, see if the user has added or removed anything.]
    [Perform additional processing and initialise the form data.]
    [Produce some kind of response to show the user the updated form data.]

    Since XSLFormsResource builds on WebStack's resource mechanisms, we do have the transaction object, trans, available. However, most of the information we need to access and manipulate is generally available through the form object.

    Defining Resources

    Classes derived from XSLFormsResource support the concept of resources which are used to produce output, support processing and to provide access to useful information. At the class level it is essential to define at least some of these resources @@ -19,7 +19,7 @@ XSLForms relies on template files residing in the filesystem, along with other files, we need to define where such files can be found (as described in the "Creating Applications: Create -a Directory" document). Consequently, it is the convention that all resource classes define such information as follows:

    class ConfiguratorResource(XSLForms.Resources.XSLFormsResource):

    resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")

    All +a Directory" document). Consequently, it is the convention that all resource classes define such information as follows:

    class ConfiguratorResource(XSLForms.Resources.WebResources.XSLFormsResource):

    resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")

    All filenames, defined in the various resource sections (as described below) must be stated without leading path information - in other words, as "leafnames" rather than "pathnames". Thus, an example of @@ -204,4 +204,4 @@ enough flexibility when introducing additional information into a transformation. An alternative approach involves copying data into the document to be processed and then to supply references to the data in -its new location within the document.

    \ No newline at end of file +its new location within the document.

    diff -r 348a80dc3c33 -r 54af5279b35a docs/in-page-updates.html --- a/docs/in-page-updates.html Tue Oct 25 17:52:28 2005 +0000 +++ b/docs/in-page-updates.html Wed Oct 26 00:07:09 2005 +0000 @@ -169,10 +169,10 @@ pages from our application. Some standard WebStack resources can be used to help with this, and we add some imports at the top of our source file:

    -
    #!/usr/bin/env python

    "A very simple example application."

    import WebStack.Generic
    import XSLForms.Resources
    import XSLForms.Utils
    import os

    # Site map imports.

    from WebStack.Resources.ResourceMap import MapResource
    from WebStack.Resources.Static import DirectoryResource
    +
    #!/usr/bin/env python

    "A very simple example application."

    import WebStack.Generic
    import XSLForms.Resources.WebResources
    import XSLForms.Utils
    import os

    # Site map imports.

    from WebStack.Resources.ResourceMap import MapResource
    from WebStack.Resources.Static import DirectoryResource

    Then, we define the resource class as before, but with an additional attribute:

    -
    # Resource classes.

    class VerySimpleResource(XSLForms.Resources.XSLFormsResource):

    "A very simple resource providing a hierarchy of editable fields."

    resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
    encoding = "utf-8"
    template_resources = {
    "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")
    }
    init_resources = {
    "structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl")
    }
    transform_resources = {
    "comments" : ["structure_comments.xsl"]
    }
    document_resources = {
    "types" : "structure_types.xml"
    }
    in_page_resources = {
    "comments" : ("structure_output_comments.xsl", "comment-node")
    }
    +
    # Resource classes.

    class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource):

    "A very simple resource providing a hierarchy of editable fields."

    resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
    encoding = "utf-8"
    template_resources = {
    "structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl")
    }
    init_resources = {
    "structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl")
    }
    transform_resources = {
    "comments" : ["structure_comments.xsl"]
    }
    document_resources = {
    "types" : "structure_types.xml"
    }
    in_page_resources = {
    "comments" : ("structure_output_comments.xsl", "comment-node")
    }

    This new attribute provides information about the in-page request to retrieve comment regions of the Web form, and it consists of the stylesheet filename that will be generated to produce the page @@ -220,4 +220,4 @@ script file; otherwise it gets a Web page showing either all of the form (if a normal request is received), or a part of the form (if an in-page request is received).

    - \ No newline at end of file + diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/Candidate/__init__.py --- a/examples/Common/Candidate/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/Candidate/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -3,7 +3,7 @@ "A job candidate editing application." import WebStack.Generic -import XSLForms.Resources +import XSLForms.Resources.WebResources import XSLForms.Utils import os @@ -14,7 +14,7 @@ # Resource classes. -class CandidateResource(XSLForms.Resources.XSLFormsResource): +class CandidateResource(XSLForms.Resources.WebResources.XSLFormsResource): "A resource providing editing facilities for a job candidate profile." diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/Configurator/__init__.py --- a/examples/Common/Configurator/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/Configurator/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -4,7 +4,7 @@ import WebStack.Generic import XSLForms.Utils -import XSLForms.Resources +import XSLForms.Resources.WebResources import os # Site map imports. @@ -14,7 +14,7 @@ # Resource classes. -class ConfiguratorResource(XSLForms.Resources.XSLFormsResource): +class ConfiguratorResource(XSLForms.Resources.WebResources.XSLFormsResource): "A resource providing a system configurator." diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/Dictionary/__init__.py --- a/examples/Common/Dictionary/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/Dictionary/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -3,7 +3,7 @@ "A dictionary example application." import WebStack.Generic -import XSLForms.Resources +import XSLForms.Resources.WebResources import XSLForms.Utils import os @@ -14,7 +14,7 @@ # Resource classes. -class DictionaryResource(XSLForms.Resources.XSLFormsResource): +class DictionaryResource(XSLForms.Resources.WebResources.XSLFormsResource): "A simple resource providing dictionary lookup." diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/PEP241/__init__.py --- a/examples/Common/PEP241/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/PEP241/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -3,7 +3,7 @@ "A WebStack application for a PEP 241 repository." import WebStack.Generic -import XSLForms.Resources +import XSLForms.Resources.WebResources import XSLForms.Utils import os @@ -14,7 +14,7 @@ # Resource classes. -class PEP241Resource(XSLForms.Resources.XSLFormsResource): +class PEP241Resource(XSLForms.Resources.WebResources.XSLFormsResource): "A resource providing repository browsing." diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/QtConfigurator/__init__.py --- a/examples/Common/QtConfigurator/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/QtConfigurator/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -169,16 +169,16 @@ def get_resource_class(resource_type): if resource_type == "PyQt": - import XSLForms.PyQt + import XSLForms.Resources.PyQtResources import QtConfigurator.Forms - class Configurator(ConfiguratorResource, QtConfigurator.Forms.Configurator, XSLForms.PyQt.XSLFormsResource): + class Configurator(ConfiguratorResource, QtConfigurator.Forms.Configurator, XSLForms.Resources.PyQtResources.XSLFormsResource): def __init__(self, *args, **kw): QtConfigurator.Forms.Configurator.__init__(self, *args, **kw) - self.factory = XSLForms.PyQt.Factory(self.prepare_template("configuration")) + self.factory = XSLForms.Resources.PyQtResources.Factory(self.prepare_template("configuration")) ConfiguratorResource.__init__(self, *args, **kw) else: - import XSLForms.Resources - class Configurator(ConfiguratorResource, XSLForms.PyQtWeb.XSLFormsResource): + import XSLForms.Resources.PyQtWebResources + class Configurator(ConfiguratorResource, XSLForms.Resources.PyQtWebResources.XSLFormsResource): def __init__(self, *args, **kw): ConfiguratorResource.__init__(self, *args, **kw) diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/Questionnaire/__init__.py --- a/examples/Common/Questionnaire/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/Questionnaire/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -3,7 +3,7 @@ "A WebStack questionnaire application." import WebStack.Generic -import XSLForms.Resources +import XSLForms.Resources.WebResources import XSLForms.Utils import os @@ -14,7 +14,7 @@ # Resource classes. -class QuestionnaireEditorResource(XSLForms.Resources.XSLFormsResource): +class QuestionnaireEditorResource(XSLForms.Resources.WebResources.XSLFormsResource): "A resource providing a questionnaire editor." diff -r 348a80dc3c33 -r 54af5279b35a examples/Common/VerySimple/__init__.py --- a/examples/Common/VerySimple/__init__.py Tue Oct 25 17:52:28 2005 +0000 +++ b/examples/Common/VerySimple/__init__.py Wed Oct 26 00:07:09 2005 +0000 @@ -3,7 +3,7 @@ "A very simple example application." import WebStack.Generic -import XSLForms.Resources +import XSLForms.Resources.WebResources import XSLForms.Utils import os @@ -14,7 +14,7 @@ # Resource classes. -class VerySimpleResource(XSLForms.Resources.XSLFormsResource): +class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource): "A very simple resource providing a hierarchy of editable fields."