[Zope3-checkins] CVS: Packages3/workflow/stateful - definition.py:1.9 xmlexport_template.pt:1.4 xmlimportexport.py:1.8

Ulrich Eck ueck@net-labs.de
Wed, 9 Apr 2003 14:36:01 -0400


Update of /cvs-repository/Packages3/workflow/stateful
In directory cvs.zope.org:/tmp/cvs-serv18601/stateful

Modified Files:
	definition.py xmlexport_template.pt xmlimportexport.py 
Log Message:
added a parameter definition_name to createProcessInstance
that eases the implementation alot and avoids some Wrapper-hacks
updated all tests accordingly

added canImport implementation to stateful/xmlimportexport and tests

cleanup a bit


=== Packages3/workflow/stateful/definition.py 1.8 => 1.9 ===
--- Packages3/workflow/stateful/definition.py:1.8	Fri Mar 28 13:16:37 2003
+++ Packages3/workflow/stateful/definition.py	Wed Apr  9 14:35:30 2003
@@ -23,6 +23,7 @@
 
 from zope.proxy.context import ContextMethod, ContextWrapper
 from zope.proxy.context import getWrapperData, getWrapperContainer
+from zope.proxy.context import getWrapperContext
 
 from zope.app.interfaces.container import IReadContainer
 
@@ -207,9 +208,8 @@
     
     # IProcessDefinition
 
-    def createProcessInstance(self):
-        pd_name = getWrapperData(self)['name']
-        pi_obj = StatefulProcessInstance(pd_name)
+    def createProcessInstance(self, definition_name):
+        pi_obj = StatefulProcessInstance(definition_name)
         ContextWrapper(pi_obj, self).initialize()
         return pi_obj
     createProcessInstance = ContextMethod(createProcessInstance)


=== Packages3/workflow/stateful/xmlexport_template.pt 1.3 => 1.4 ===
--- Packages3/workflow/stateful/xmlexport_template.pt:1.3	Mon Apr  7 13:33:50 2003
+++ Packages3/workflow/stateful/xmlexport_template.pt	Wed Apr  9 14:35:30 2003
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<workflow type="Zope3Workflow"
+<workflow type="StatefulWorkflow"
   xmlns:tal="http://xml.zope.org/namespaces/tal"
   tal:define="wf view/getDefinition"
   tal:attributes="title python:view.getDublinCore(wf).Title()">


=== Packages3/workflow/stateful/xmlimportexport.py 1.7 => 1.8 ===
--- Packages3/workflow/stateful/xmlimportexport.py:1.7	Mon Apr  7 13:33:50 2003
+++ Packages3/workflow/stateful/xmlimportexport.py	Wed Apr  9 14:35:30 2003
@@ -20,6 +20,8 @@
 
 from zope.app.pagetemplate.viewpagetemplatefile \
      import ViewPageTemplateFile
+from zope.app.interfaces.workflow.stateful \
+     import IStatefulProcessDefinition
 from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
 from zope.app.interfaces.workflow import IProcessDefinitionExportHandler
 from zope.component import getAdapter, getServiceManager
@@ -31,9 +33,31 @@
 
 from xml.sax import parse
 from xml.sax.handler import ContentHandler
-from StringIO import StringIO
+
 from zope.app.workflow.stateful.definition import State, Transition
 
+
+
+# basic implementation for a format-checker
+class XMLFormatChecker(ContentHandler):
+
+    def __init__(self):
+        self.__valid = False
+
+    def startElement(self, name, attrs):
+        if name == 'workflow' and attrs.get('type',None) == 'StatefulWorkflow':
+            self.__valid = True
+
+    def endElement(self, name):
+        pass
+
+
+    def isValid(self):
+        return self.__valid
+
+
+
+
 class XMLStatefulImporter(ContentHandler):
     def __init__(self, context, encoding='latin-1'):
         self.context = context
@@ -97,14 +121,18 @@
 
     __implements__ = IProcessDefinitionImportHandler
 
-    def canImport(self, data):
-        return True
+    # XXX Implementation needs more work !!
+    # check if xml-data can be imported and represents a StatefulPD
+    def canImport(self, context, data):
+        checker = XMLFormatChecker()
+        parse(data, checker)
+        return bool(IStatefulProcessDefinition.isImplementedBy(context)) \
+               and checker.isValid()
+    
 
     def doImport(self, context, data):
         # XXX Manually clean ProcessDefinition ??
         context.clear()
-        if not hasattr(data, "read"):
-            data = StringIO(data)
         parse(data, XMLStatefulImporter(context))