# 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.
-