Author: jmorliaguet
Date: Sun Apr 30 11:15:16 2006
New Revision: 2988

Removed:
   cpsskins/branches/paris-sprint-2006/standard/io/area.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/box.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/boxgroup.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/color.xml
   cpsskins/branches/paris-sprint-2006/standard/io/color.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/effect.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/layout.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/page.xml
   cpsskins/branches/paris-sprint-2006/standard/io/perspective.xml
   cpsskins/branches/paris-sprint-2006/standard/io/perspective.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/portlet.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/relation.xml
   cpsskins/branches/paris-sprint-2006/standard/io/relation.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/settings.py
   cpsskins/branches/paris-sprint-2006/standard/io/settings.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/storage.py
   cpsskins/branches/paris-sprint-2006/standard/io/storage.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/style.xml
   cpsskins/branches/paris-sprint-2006/standard/io/style.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/theme.xml
   cpsskins/branches/paris-sprint-2006/standard/io/widget.zcml
Modified:
   cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
   cpsskins/branches/paris-sprint-2006/setup/DOM.txt
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/io.py
   cpsskins/branches/paris-sprint-2006/standard/io/configure.zcml
   cpsskins/branches/paris-sprint-2006/standard/io/relation.py
   cpsskins/branches/paris-sprint-2006/standard/io/style.py
Log:

- saving work: implemented a generic exporter for objects (exporting properties
  and child objects), a style exporter, a relation exporter.
  


Modified: cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py (original)
+++ cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py Sun Apr 30 
11:15:16 2006
@@ -24,7 +24,7 @@
 from zope.app import zapi
 from zope.app.testing import ztapi
 from zope.app.testing.functional import FunctionalDocFileSuite
-from zope.interface import alsoProvides, Interfaces
+from zope.interface import alsoProvides, Interface
 from zope.component.interfaces import IFactory
 
 from cpsskins import elements

Modified: cpsskins/branches/paris-sprint-2006/setup/DOM.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/DOM.txt   (original)
+++ cpsskins/branches/paris-sprint-2006/setup/DOM.txt   Sun Apr 30 11:15:16 2006
@@ -26,9 +26,8 @@
 
 doc.toxml() creates an XML representation of the document:
 
-    >>> print doc.toxml()
-    <?xml version="1.0" ?>
-    <themes><theme title="A theme" 
uri="cpsskins://canvas-theme:12345"/></themes>
+    >>> print doc.toxml() # doctest: +NORMALIZE_WHITESPACE
+    <?xml version="1.0" ?><themes><theme title="A theme" 
uri="cpsskins://canvas-theme:12345"/></themes>
 
 
 Exporting nested tree structures

Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/README.txt        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/README.txt        Sun Apr 30 
11:15:16 2006
@@ -490,30 +490,31 @@
 Export of resources
 ===================
 
-Resources can be exported using the IDataExporter adapter.
+Resources can be exported using the IDOMAdapter adapter.
 
-    >>> from zope.publisher.browser import TestRequest
     >>> from zope.component import getMultiAdapter
-    >>> request = TestRequest()
 
-    >>> from cpsskins.setup.interfaces import IDataExporter, IDataImporter
+    >>> from xml.dom.minidom import DOMImplementation
+    >>> dom = DOMImplementation()
+
+    >>> from cpsskins.setup.interfaces import IDOMAdapter
+
+    >>> def toXML(obj, title):
+    ...     document = dom.createDocument(None, title, None)
+    ...     doc = document.documentElement
+    ...     exporter = getMultiAdapter((obj, doc), IDOMAdapter)
+    ...     exporter.setDocument(document)
+    ...     exporter.save()
+    ...     return document.toxml()
+
 
 Export of styles
 ----------------
 
     >>> resource = Style()
     >>> resource[u'div.body'] = {'color': u'red', 'border': u'none'}
-    >>> exporter = getMultiAdapter((resource, request), IDataExporter)
 
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <style uri="cpsskins://format-style:12345">
-      <selector name="div.body">
-        <property name="color" value="red"/>
-        <property name="border" value="none"/>
-      </selector>
-    </style>
-    <BLANKLINE>
+    >>> print toXML(resource, u'styles')
 
 
 Export of relations
@@ -526,13 +527,7 @@
     >>> relation = MonadicRelation(predicate=Predicate(u'_ A'),
     ...                            first=Actions(u'Actions portlet'))
 
-    >>> exporter = getMultiAdapter((relation, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <relation predicate="_ A">
-      <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
-    </relation>
-    <BLANKLINE>
+    >>> print toXML(relation, u'relations')
 
 Dyadic relations:
 
@@ -543,14 +538,7 @@
     ...                           first=Actions(u'Actions portlet'),
     ...                           second=Breadcrumbs(u'Breadcrumbs portlet'))
 
-    >>> exporter = getMultiAdapter((relation, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <relation predicate="_ B _">
-      <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
-      <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/>
-    </relation>
-    <BLANKLINE>
+    >>> print toXML(relation, u'relations')
 
 Triadic relations:
 
@@ -562,16 +550,7 @@
     ...                            second=Breadcrumbs(u'Breadcrumbs portlet'),
     ...                            third=Slot(slot=u'slotA'))
 
-    >>> exporter = getMultiAdapter((relation, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <relation predicate="_ C _ D _">
-      <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
-      <relate
-          uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/>
-      <relate uri="cpsskins://canvas-slot:slotA"/>
-    </relation>
-    <BLANKLINE>
+    >>> print toXML(relation, u'relations')
 
 
 Export of elements
@@ -593,24 +572,7 @@
     >>> slot = Slot(u'Some slot')
     >>> pageblock[u'cell1'][u'slot'] = slot
 
-    >>> exporter = getMultiAdapter((pageblock, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <pageblock
-        uri="cpsskins://canvas-pageblock:12345"
-        title="Some page block"
-        parent=""
-    />
-    <cell
-        uri="cpsskins://canvas-cell:12345"
-        title="Some cell 1"
-        parent="cpsskins://canvas-pageblock:12345"
-    />
-    <cell
-        uri="cpsskins://canvas-cell:12345"
-        title="Some cell 2"
-        parent="cpsskins://canvas-pageblock:12345"
-    />
+    >>> print toXML(pageblock, u'elements')
 
 
 Export of container elements
@@ -620,9 +582,7 @@
     >>> root = getRootFolder()
     >>> theme = addThemeSkeleton(tmutil)
 
-    >>> exporter = getMultiAdapter((theme, request), IDataExporter)
-
-    to finish
+    >>> print toXML(theme, u'themes')
 
 
 Export of portlets
@@ -630,14 +590,7 @@
 
     >>> portlet = Actions(title=u'Action portlet', category=u'zmi_views')
 
-    >>> exporter = getMultiAdapter((portlet, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <portlet uri="cpsskins://canvas-portlet-standard.actions:12345">
-      <title value="Action portlet"/>
-      <category value="zmi_views"/>
-    </portlet>
-    <BLANKLINE>
+    >>> print toXML(portlet, u'portlets')
 
 
 Export of format elements
@@ -646,17 +599,7 @@
     >>> from cpsskins.standard.formats.effect import Effect
     >>> effect = Effect(width=100, height=80) 
 
-    >>> exporter = getMultiAdapter((effect, request), IDataExporter)
-    >>> print exporter()
-    <?xml version="1.0"?>
-    <effect uri="cpsskins://format-effect:12345">
-      <types value=""/>
-      <format value="PNG"/>
-      <width value="100"/>
-      <height value="80"/>
-      <keep_ratio value="True"/>
-    </effect>
-    <BLANKLINE>
+    >>> print toXML(effect, u'formats')
 
 
 Resolving URIs

Modified: cpsskins/branches/paris-sprint-2006/setup/io.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io.py     Sun Apr 30 11:15:16 2006
@@ -70,8 +70,8 @@
 
         document = self.getDocument()
 
-        element = document.createElement(IType(context).resourcename)
-        element.setAttribute(u'uri', IIdentifiable(context).getURI())
+        element_el = document.createElement(IType(context).resourcename)
+        element_el.setAttribute(u'uri', IIdentifiable(context).getURI())
 
         schema = IType(context).getContentType()
 
@@ -89,12 +89,12 @@
             prop = document.createElement(name)
             prop.setAttribute(u'value', value)
 
-            element.appendChild(prop)
+            element_el.appendChild(prop)
 
         # child nodes
 
         if IItemContainer.providedBy(context):
-            node_child = node.appendChild(element)
+            node_child = node.appendChild(element_el)
             for child in context:
                 exporter = getMultiAdapter((context[child], node_child),
                                             IDOMAdapter)

Modified: cpsskins/branches/paris-sprint-2006/standard/io/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/io/configure.zcml      
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/io/configure.zcml      Sun Apr 
30 11:15:16 2006
@@ -25,4 +25,28 @@
       provides="cpsskins.setup.interfaces.IDOMAdapter"
   />
 
+  <!-- portlets -->
+  <adapter
+      for="cpsskins.elements.interfaces.IPortlet *"
+      factory="cpsskins.setup.io.DOMAdapter"
+      permission="zope.ManageContent"
+      provides="cpsskins.setup.interfaces.IDOMAdapter"
+  />
+
+  <!-- relations -->
+  <adapter
+      for="cpsskins.relations.interfaces.IRelation *"
+      factory="cpsskins.standard.io.relation.DOMAdapter"
+      permission="zope.ManageContent"
+      provides="cpsskins.setup.interfaces.IDOMAdapter"
+  />
+
+  <!-- styles -->
+  <adapter
+      for="cpsskins.standard.formats.style.IStyle *"
+      factory="cpsskins.standard.io.style.DOMAdapter"
+      permission="zope.ManageContent"
+      provides="cpsskins.setup.interfaces.IDOMAdapter"
+  />
+
 </configure>

Modified: cpsskins/branches/paris-sprint-2006/standard/io/relation.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/io/relation.py (original)
+++ cpsskins/branches/paris-sprint-2006/standard/io/relation.py Sun Apr 30 
11:15:16 2006
@@ -17,80 +17,40 @@
 """
 __docformat__ = "reStructuredText"
 
-from xml.dom.minidom import parseString
+import logging
 
-from zope.app import pagetemplate
-from zope.component import adapts, getUtility
-from zope.interface import implements
-
-from cpsskins.elements.interfaces import IIdentifiable
-from cpsskins.relations.interfaces import IRelation
-from cpsskins.relations.predicates import Predicate
-from cpsskins.relations.relations import MonadicRelation, DyadicRelation
-from cpsskins.relations.relations import TriadicRelation
-from cpsskins.setup.io import DataExporter, DataImporter
-from cpsskins.setup.interfaces import IDataExporter, IDataImporter
-from cpsskins.setup.interfaces import IResourceManager
-from cpsskins.utils import getThemeManager
+import zope.schema
 
-class Exporter(DataExporter):
-    """Export a relation.
-    """
-    implements(IDataExporter)
-
-    template = pagetemplate.ViewPageTemplateFile('relation.xml')
-
-    def __call__(self):
-        return self.template()
-
-    def getInfo(self):
-        context = self.context
-        relate_info = []
+from zope.component import adapts, getMultiAdapter
+from zope.interface import implements, Interface
 
-        for relate in context:
-            relate_info.append({
-                'uri': IIdentifiable(relate).getURI(),
-                })
-
-        return {
-            'predicate': str(context),
-            'relates': relate_info,
-            }
+from cpsskins.elements.interfaces import IIdentifiable, IType
+from cpsskins.setup.interfaces import IDOMAdapter
+from cpsskins.setup.io import BaseDOMAdapter
 
-class Importer(DataImporter):
-    """Import a relation.
+class DOMAdapter(BaseDOMAdapter):
+    """DOM adapter for relations
     """
-    implements(IDataImporter)
+    implements(IDOMAdapter)
 
-    def load(self, dom):
+    def save(self):
         context = self.context
-        mapping = self.mapping
-
-        relations = getThemeManager(context).getRelationStorage()
-
-        predicate_str = dom.getAttribute('predicate')
-        predicate = Predicate(predicate_str)
+        node = self.node
 
-        relates_def = dom.getElementsByTagName('relate')
-        relates = []
+        document = self.getDocument()
 
-        resources = getUtility(IResourceManager)
+        relation_el = document.createElement(u'relation')
+        relation_el.setAttribute(u'predicate', str(context))
 
-        for relate_def in relates_def:
-            uri = relate_def.getAttribute('uri')
-            uri = mapping[uri]
-            obj = resources.resolve(uri, self.context)
-            relates.append(obj)
+        for relate in context:
+            relate_el = document.createElement(u'relate')
+            relate_el.setAttribute(u'uri', IIdentifiable(relate).getURI())
+            relation_el.appendChild(relate_el)
 
-        arity = len(relates_def)
+        node.appendChild(relation_el)
 
-        if arity == 1:
-            rel = MonadicRelation(predicate=predicate, first=relates[0])
-        elif arity == 2:
-            rel = DyadicRelation(predicate=predicate, first=relates[0],
-                                 second=relates[1])
-        elif arity == 3:
-            rel = TriadicRelation(predicate=predicate, first=relates[0],
-                                  second=relates[1], third=relates[2])
+    def load(self):
+        context = self.context
+        node = self.node
+        # TODO
 
-        relations.add(rel)

Modified: cpsskins/branches/paris-sprint-2006/standard/io/style.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/io/style.py    (original)
+++ cpsskins/branches/paris-sprint-2006/standard/io/style.py    Sun Apr 30 
11:15:16 2006
@@ -17,54 +17,51 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.app import pagetemplate
 from zope.component import adapts
 from zope.interface import implements
 
 from cpsskins.elements.interfaces import IIdentifiable
 from cpsskins.standard.formats.style import IStyle, Style
-from cpsskins.setup.interfaces import IDataExporter, IDataImporter
-from cpsskins.setup.io import DataImporter, DataExporter
+from cpsskins.setup.interfaces import IDOMAdapter
+from cpsskins.setup.io import BaseDOMAdapter
 
-class Exporter(DataExporter):
-    """Export style resources
+class DOMAdapter(BaseDOMAdapter):
+    """DOM adapter for styles
     """
-    implements(IDataExporter)
+    implements(IDOMAdapter)
 
-    template = pagetemplate.ViewPageTemplateFile('style.xml')
+    def save(self):
+        context = self.context
+        node = self.node
+
+        document = self.getDocument()
+
+        style_el = document.createElement(u'style')
+        style_el.setAttribute(u'uri', IIdentifiable(context).getURI())
+
+        for k, v in context.items():
+            selector_el = document.createElement(u'selector')
+            selector_el.setAttribute(u'value', k)
+            for name, value in v.items():
+                prop_el = document.createElement(u'property')
+                prop_el.setAttribute(u'name', name)
+                prop_el.setAttribute(u'value', value)
+                selector_el.appendChild(prop_el)
+            style_el.appendChild(selector_el)
+
+        node.appendChild(style_el)
+
+    def load(self):
+        context = self.context
+        node = self.node
 
-    def __call__(self):
-        return self.template()
-
-    def getInfo(self):
-        selectors = []
-        for k, v in self.context.items():
-            properties = [{'name': name, 'value': value}
-                         for name, value in v.items()]
-            selectors.append({'name': k, 'properties': properties})
-        return {
-            'uri': IIdentifiable(self.context).getURI(),
-            'selectors': selectors,
-        }
-
-class Importer(DataImporter):
-    """Import style resources.
-    """
-    implements(IDataImporter)
-
-    def load(self, dom):
-        storage = self.context
-
-        style = Style()
-        for style in dom.getElementsByTagName('style'):
-            for sel in style.getElementsByTagName('selector'):
+        for style_el in node.getElementsByTagName('style'):
+            for sel in style_el.getElementsByTagName('selector'):
                 sel_name = sel.getAttribute('name')
                 style_props = {}
                 for prop in sel.getElementsByTagName('property'):
                     name = prop.getAttribute('name')
                     value = prop.getAttribute('value')
                     style_props[name] = value
-                style[sel_name] = style_props
+                context[sel_name] = style_props
 
-        storage.add(style)
-        return style
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to