1.1 --- a/examples/Common/Dictionary/__init__.py Sun Feb 17 19:21:57 2008 +0000
1.2 +++ b/examples/Common/Dictionary/__init__.py Sun Feb 17 19:22:28 2008 +0000
1.3 @@ -3,8 +3,8 @@
1.4 "A dictionary example application."
1.5
1.6 import WebStack.Generic
1.7 -import XSLForms.Resources.WebResources
1.8 -import XSLForms.Utils
1.9 +from XSLForms.Resources.WebResources import \
1.10 + XSLFormsResource, output, resources, prepare_resources as xslforms_prepare_resources
1.11 import os
1.12
1.13 # Site map imports.
1.14 @@ -19,13 +19,13 @@
1.15
1.16 # Resource classes.
1.17
1.18 -class DictionaryResource(XSLForms.Resources.WebResources.XSLFormsResource):
1.19 +class DictionaryResource(XSLFormsResource):
1.20
1.21 "A simple resource providing dictionary lookup."
1.22
1.23 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.24 + resource_dir = resources(__file__)
1.25 template_resources = {
1.26 - "words" : ("words_template.xhtml", "words_output.xsl")
1.27 + "words" : output("words_template.xhtml")
1.28 }
1.29 in_page_resources = {
1.30 "matches" : ("words", "words_output_entry.xsl", "matches-node"),
1.31 @@ -38,34 +38,25 @@
1.32
1.33 self.dict = dict
1.34
1.35 - def respond_to_form(self, trans, form):
1.36 -
1.37 - """
1.38 - Respond to a request having the given transaction 'trans' and the given
1.39 - 'form' information.
1.40 - """
1.41 + def select_activity(self, trans, form):
1.42 + form.set_activity("words")
1.43
1.44 - in_page_resource = self.get_in_page_resource(trans)
1.45 - parameters = form.get_parameters()
1.46 - documents = form.get_documents()
1.47 -
1.48 - # Ensure the presence of a document.
1.49 -
1.50 - if documents.has_key("words"):
1.51 - words = documents["words"]
1.52 - else:
1.53 - words = form.new_instance("words")
1.54 + def respond_to_input(self, trans, form):
1.55
1.56 # Add and remove elements according to the selectors found.
1.57
1.58 selectors = form.get_selectors()
1.59 - XSLForms.Utils.remove_elements(selectors.get("remove"))
1.60 - XSLForms.Utils.add_elements(selectors.get("add"), "entry")
1.61 + self.remove_elements(selectors.get("remove"))
1.62 + self.add_elements(selectors.get("add"), "entry")
1.63 +
1.64 + def init_document(self, trans, form):
1.65
1.66 # Ensure all entries have a matches element.
1.67 # Ensure all matches elements have at least one choice.
1.68 # Copy selected matches to their corresponding text field.
1.69
1.70 + words = form.get_document()
1.71 +
1.72 all_entries = words.xpath("words/entry")
1.73
1.74 for entry in all_entries:
1.75 @@ -83,6 +74,9 @@
1.76
1.77 # Find requested search locations.
1.78
1.79 + selectors = form.get_selectors()
1.80 + in_page_resource = self.get_in_page_resource(trans)
1.81 +
1.82 if selectors.has_key("search"):
1.83 entries = selectors["search"]
1.84 elif in_page_resource == "matches":
1.85 @@ -113,27 +107,6 @@
1.86 if word != "" and word.startswith(entry.getAttribute("word")):
1.87 entry.setAttribute("word", word)
1.88
1.89 - # Start the response.
1.90 -
1.91 - trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding))
1.92 -
1.93 - # Ensure that an output stylesheet exists.
1.94 -
1.95 - if in_page_resource in self.in_page_resources.keys():
1.96 - trans_xsl = self.prepare_fragment(in_page_resource)
1.97 - stylesheet_parameters = self.prepare_parameters(parameters)
1.98 - else:
1.99 - trans_xsl = self.prepare_output("words")
1.100 - stylesheet_parameters = {}
1.101 -
1.102 - # Complete the response.
1.103 -
1.104 - self.send_output(trans, [trans_xsl], words, stylesheet_parameters)
1.105 - #from XSLTools import XSLOutput
1.106 - #import sys
1.107 - #proc = XSLOutput.Processor([trans_xsl], parameters=stylesheet_parameters)
1.108 - #proc.send_output(sys.stderr, "iso-8859-1", words)
1.109 -
1.110 # Site map initialisation.
1.111
1.112 def get_site(dict):
1.113 @@ -164,6 +137,6 @@
1.114
1.115 def prepare_resources():
1.116 for cls in [DictionaryResource]:
1.117 - XSLForms.Resources.WebResources.prepare_resources(cls)
1.118 + xslforms_prepare_resources(cls)
1.119
1.120 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/examples/Common/Questionnaire/__init__.py Sun Feb 17 19:21:57 2008 +0000
2.2 +++ b/examples/Common/Questionnaire/__init__.py Sun Feb 17 19:22:28 2008 +0000
2.3 @@ -3,8 +3,8 @@
2.4 "A WebStack questionnaire application."
2.5
2.6 import WebStack.Generic
2.7 -import XSLForms.Resources.WebResources
2.8 -import XSLForms.Utils
2.9 +from XSLForms.Resources.WebResources import \
2.10 + XSLFormsResource, output, resources, prepare_resources as xslforms_prepare_resources
2.11 import os
2.12
2.13 # Site map imports.
2.14 @@ -19,38 +19,27 @@
2.15
2.16 # Resource classes.
2.17
2.18 -class QuestionnaireEditorResource(XSLForms.Resources.WebResources.XSLFormsResource):
2.19 +class QuestionnaireEditorResource(XSLFormsResource):
2.20
2.21 "A resource providing a questionnaire editor."
2.22
2.23 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
2.24 + resource_dir = resources(__file__)
2.25 template_resources = {
2.26 - "question" : ("question_template.xhtml", "question_output.xsl")
2.27 + "questionnaire" : output("question_template.xhtml")
2.28 }
2.29
2.30 - def respond_to_form(self, trans, form):
2.31 + def select_activity(self, trans, form):
2.32 + form.set_activity("questionnaire")
2.33
2.34 - """
2.35 - Respond to a request having the given transaction 'trans' and the given
2.36 - 'form' information.
2.37 - """
2.38 + def respond_to_input(self, trans, form):
2.39
2.40 parameters = form.get_parameters()
2.41 - documents = form.get_documents()
2.42 selectors = form.get_selectors()
2.43 -
2.44 - # Ensure the presence of a document.
2.45 + questionnaire = form.get_document()
2.46
2.47 - if documents.has_key("questionnaire"):
2.48 - questionnaire = documents["questionnaire"]
2.49 - else:
2.50 - questionnaire = form.new_instance("questionnaire")
2.51 -
2.52 - # Add and remove elements according to the selectors found.
2.53 -
2.54 - XSLForms.Utils.remove_elements(selectors.get("remove-question"))
2.55 - XSLForms.Utils.add_elements(selectors.get("add-choice"), "choice")
2.56 - XSLForms.Utils.remove_elements(selectors.get("remove-choice"))
2.57 + self.remove_elements(selectors.get("remove-question"))
2.58 + self.add_elements(selectors.get("add-choice"), "choice")
2.59 + self.remove_elements(selectors.get("remove-choice"))
2.60
2.61 # Add questions using the normal request parameter.
2.62
2.63 @@ -64,23 +53,7 @@
2.64 if parameters.has_key("export"):
2.65 trans.set_content_type(WebStack.Generic.ContentType("text/xml", encoding))
2.66 questionnaire.toStream(trans.get_response_stream(), trans.get_response_stream_encoding())
2.67 -
2.68 - # When not exported, the data is transformed to produce a normal Web
2.69 - # page.
2.70 -
2.71 - else:
2.72 -
2.73 - # Start the response.
2.74 -
2.75 - trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding))
2.76 -
2.77 - # Ensure that an output stylesheet exists.
2.78 -
2.79 - trans_xsl = self.prepare_output("question")
2.80 -
2.81 - # Complete the response.
2.82 -
2.83 - self.send_output(trans, [trans_xsl], questionnaire)
2.84 + raise WebStack.Generic.EndOfResponse
2.85
2.86 # Site map initialisation.
2.87
2.88 @@ -108,6 +81,6 @@
2.89
2.90 def prepare_resources():
2.91 for cls in [QuestionnaireEditorResource]:
2.92 - XSLForms.Resources.WebResources.prepare_resources(cls)
2.93 + xslforms_prepare_resources(cls)
2.94
2.95 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/examples/Common/Recursive/__init__.py Sun Feb 17 19:21:57 2008 +0000
3.2 +++ b/examples/Common/Recursive/__init__.py Sun Feb 17 19:22:28 2008 +0000
3.3 @@ -3,9 +3,8 @@
3.4 "An example of recursive templates."
3.5
3.6 import WebStack.Generic
3.7 -import XSLForms.Resources.WebResources
3.8 -import XSLForms.Utils
3.9 -import os
3.10 +from XSLForms.Resources.WebResources import \
3.11 + XSLFormsResource, input, output, resources, prepare_resources as xslforms_prepare_resources
3.12
3.13 # Site map imports.
3.14
3.15 @@ -17,60 +16,29 @@
3.16
3.17 # Resource classes.
3.18
3.19 -class RecursiveResource(XSLForms.Resources.WebResources.XSLFormsResource):
3.20 +class RecursiveResource(XSLFormsResource):
3.21
3.22 "A resource providing a recursive hierarchy of editable fields."
3.23
3.24 - resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
3.25 + resource_dir = resources(__file__)
3.26 template_resources = {
3.27 - "recursive" : ("recursive_template.xhtml", "recursive_output.xsl")
3.28 + "recursive" : output("recursive_template.xhtml")
3.29 }
3.30 init_resources = {
3.31 - "recursive" : ("recursive_template.xhtml", "recursive_input.xsl")
3.32 + "recursive" : input("recursive_template.xhtml")
3.33 }
3.34
3.35 - def respond_to_form(self, trans, form):
3.36 -
3.37 - """
3.38 - Respond to a request having the given transaction 'trans' and the given
3.39 - 'form' information.
3.40 - """
3.41 + def select_activity(self, trans, form):
3.42 + form.set_activity("recursive")
3.43
3.44 - parameters = form.get_parameters()
3.45 - documents = form.get_documents()
3.46 -
3.47 - # Ensure the presence of a document.
3.48 -
3.49 - if documents.has_key("recursive"):
3.50 - recursive = documents["recursive"]
3.51 - else:
3.52 - recursive = form.new_instance("recursive")
3.53 + def respond_to_input(self, trans, form):
3.54
3.55 # Add and remove elements according to the selectors found.
3.56
3.57 selectors = form.get_selectors()
3.58 - XSLForms.Utils.remove_elements(selectors.get("remove"))
3.59 - XSLForms.Utils.add_elements(selectors.get("add-list"), "list")
3.60 - XSLForms.Utils.add_elements(selectors.get("add-item"), "item")
3.61 -
3.62 - # Initialise the document, adding enumerations/ranges.
3.63 -
3.64 - init_xsl = self.prepare_initialiser("recursive")
3.65 - recursive = self.get_result([init_xsl], recursive)
3.66 - #print recursive.toString("iso-8859-1")
3.67 -
3.68 - # Start the response.
3.69 -
3.70 - trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding))
3.71 -
3.72 - # Ensure that an output stylesheet exists.
3.73 -
3.74 - trans_xsl = self.prepare_output("recursive")
3.75 - stylesheet_parameters = {}
3.76 -
3.77 - # Complete the response.
3.78 -
3.79 - self.send_output(trans, [trans_xsl], recursive, stylesheet_parameters)
3.80 + self.remove_elements(selectors.get("remove"))
3.81 + self.add_elements(selectors.get("add-list"), "list")
3.82 + self.add_elements(selectors.get("add-item"), "item")
3.83
3.84 # Site map initialisation.
3.85