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