Author: jmorliaguet Date: Sun Dec 11 15:16:05 2005 New Revision: 2012 Added: cpsskins/branches/jmo-perspectives/io/README.txt (contents, props changed) cpsskins/branches/jmo-perspectives/io/__init__.py (contents, props changed) cpsskins/branches/jmo-perspectives/io/configure.zcml (contents, props changed) cpsskins/branches/jmo-perspectives/io/interfaces.py (contents, props changed) cpsskins/branches/jmo-perspectives/io/perspective.py (contents, props changed) cpsskins/branches/jmo-perspectives/io/perspective.zcml (contents, props changed) cpsskins/branches/jmo-perspectives/io/relation.py (contents, props changed) cpsskins/branches/jmo-perspectives/io/relation.xml (contents, props changed) cpsskins/branches/jmo-perspectives/io/relation.zcml (contents, props changed) cpsskins/branches/jmo-perspectives/io/style.py (contents, props changed) cpsskins/branches/jmo-perspectives/io/style.zcml (contents, props changed) Modified: cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py Log:
- added cpsskins.io package - XML exporters are now views providing IDataExporter instead of being named views Modified: cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py ============================================================================== --- cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py (original) +++ cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py Sun Dec 11 15:16:05 2005 @@ -24,6 +24,7 @@ from cpsskins.setup.interfaces import ISetting, IGlobalSetting from cpsskins.setup.interfaces import IResourceType, IResourceManager, IResource +from cpsskins.io.interfaces import IDataExporter from cpsskins.setup.registration import reloadSetting setting_xml = """<?xml version="1.0"?> @@ -92,7 +93,7 @@ 'attachment; filename=%s' % setting_filename) # export the resource - exporter = getMultiAdapter((resource, request), name=u'exporter') + exporter = getMultiAdapter((resource, request), IDataExporter) # remove the xml header used in the resource resource_xml = exporter().replace('<?xml version="1.0"?>', '') Added: cpsskins/branches/jmo-perspectives/io/README.txt ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/README.txt Sun Dec 11 15:16:05 2005 @@ -0,0 +1,8 @@ + +$id$ + +=============== +IMPORT / EXPORT +=============== + +This package contains XML exporters and importers. Added: cpsskins/branches/jmo-perspectives/io/__init__.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/__init__.py Sun Dec 11 15:16:05 2005 @@ -0,0 +1,19 @@ +############################################################################## +# +# Copyright (c) 2005 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + Added: cpsskins/branches/jmo-perspectives/io/configure.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/configure.zcml Sun Dec 11 15:16:05 2005 @@ -0,0 +1,10 @@ +<configure + xmlns="http://namespaces.zope.org/zope"> + + <include file="perspective.zcml" /> + + <include file="relation.zcml" /> + + <include file="style.zcml" /> + +</configure> Added: cpsskins/branches/jmo-perspectives/io/interfaces.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/interfaces.py Sun Dec 11 15:16:05 2005 @@ -0,0 +1,36 @@ +############################################################################## +# +# Copyright (c) 2005 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from zope.interface import Interface + +class IDataExporter(Interface): + """A data exporter is used to export data to XML + """ + def __call__(): + """Export to XML.""" + + def getInfo(): + """Return some export information (dictionary, ...)""" + +class IDataImporter(Interface): + """A data import is used to import data from XML + """ + def load(xml): + """Load data from XML.""" + Added: cpsskins/branches/jmo-perspectives/io/perspective.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/perspective.py Sun Dec 11 15:16:05 2005 @@ -0,0 +1,56 @@ +############################################################################ +# +# Copyright (c) 2005 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from xml.dom.minidom import parseString + +from zope.app import pagetemplate +from zope.component import adapts +from zope.interface import implements + +from cpsskins.perspectives.interfaces import IPerspective +from cpsskins.io.interfaces import IDataExporter, IDataImporter + +class Exporter(object): + """This view makes it possible to export style resource data + """ + implements(IDataExporter) + + template = pagetemplate.ViewPageTemplateFile('perspective.xml') + + def __call__(self): + return self.template() + +class Importer(object): + """This adapter makes it possible to import style resource data + """ + adapts(IPerspective) + implements(IDataImporter) + + def __init__(self, context): + self.context = context + + def load(self, xml=u''): + context = self.context + dom = parseString(xml) + perspectives = dom.getElementsByTagName('perspective') + if perspectives: + perspective = perspectives[0] + context.name = perspective.getAttribute('name') + context.title = perspective.getAttribute('value') + Added: cpsskins/branches/jmo-perspectives/io/perspective.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/perspective.zcml Sun Dec 11 15:16:05 2005 @@ -0,0 +1,18 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:browser="http://namespaces.zope.org/browser"> + + <!-- XML export --> + <browser:view + provides="cpsskins.io.interfaces.IDataExporter" + for="cpsskins.perspectives.interfaces.IPerspective" + class=".perspective.Exporter" + permission="zope.ManageContent" + /> + + <!-- XML import --> + <adapter + factory=".perspective.Importer" + /> + +</configure> Added: cpsskins/branches/jmo-perspectives/io/relation.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/relation.py Sun Dec 11 15:16:05 2005 @@ -0,0 +1,89 @@ +############################################################################## +# +# Copyright (c) 2005 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from zope.app import zapi, pagetemplate +from zope.component import adapts +from zope.interface import implements + +from cpsskins.relations.interfaces import IRelation +from cpsskins.io.interfaces import IDataExporter, IDataImporter + +class Exporter(object): + """This view is used to exports relations to XML + + >>> from zope.publisher.browser import TestRequest + >>> from zope.component import getMultiAdapter + + >>> from cpsskins.relations import TestRelate as Relate, Predicate + >>> from cpsskins.relations import TriadicRelation + + >>> first = Relate('converter') + >>> second = Relate('text') + >>> third = Relate('html') + >>> predicate = Predicate('_ converts _ into _') + >>> r = TriadicRelation(predicate=predicate, \ + first=first, second=second, third=third) + + >>> request = TestRequest() + >>> exporter = getMultiAdapter((r, request), IDataExporter) + # TODO + + """ + implements(IDataExporter) + + template = pagetemplate.ViewPageTemplateFile('relation.xml') + + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self): + return self.template() + + def getInfo(self): + context = self.context + relate_info = [] + + for r in context: + relate_info.append({ + 'path': zapi.getPath(r), + }) + + return { + 'predicate': str(context), + 'relates': relate_info, + } + +class Importer(object): + + adapts(IRelation) + implements(IDataImporter) + + def load(self, xml=u''): + context = self.context + dom = parseString(xml) + for relation in dom.getElementsByTagName('relation'): + predicate = relation.getAttribute('predicate') + position = 0 + for relate in relation.getElementsByTagName('relate'): + path = relate.getAttribute('path') + obj = traverse(context, path) + context[position] = obj + context._predicate = predicate + Added: cpsskins/branches/jmo-perspectives/io/relation.xml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/relation.xml Sun Dec 11 15:16:05 2005 @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<relation xmlns:tal="http://xml.zope.org/namespaces/tal" + tal:define="info view/getInfo" + tal:attributes="predicate info/predicate"> + <relate tal:repeat="relate info/relates" + tal:attributes="path relate/path" /> +</relation> Added: cpsskins/branches/jmo-perspectives/io/relation.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/relation.zcml Sun Dec 11 15:16:05 2005 @@ -0,0 +1,17 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:browser="http://namespaces.zope.org/browser"> + + <!-- Relations --> + <browser:view + provides="cpsskins.io.interfaces.IDataExporter" + for="cpsskins.relations.interfaces.IRelation" + class=".relation.Exporter" + permission="zope.ManageContent" + /> + + <adapter + factory=".relation.Importer" + /> + +</configure> Added: cpsskins/branches/jmo-perspectives/io/style.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/style.py Sun Dec 11 15:16:05 2005 @@ -0,0 +1,69 @@ +############################################################################## +# +# Copyright (c) 2005 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from xml.dom.minidom import parseString + +from zope.app import zapi, pagetemplate +from zope.app.publisher.browser import BrowserView +from zope.component import adapts +from zope.interface import implements + +from cpsskins.engines.default.formats.style import IStyle +from cpsskins.io.interfaces import IDataExporter, IDataImporter + +class Exporter(object): + """This adapter makes it possible to export style resources + """ + implements(IDataExporter) + + template = pagetemplate.ViewPageTemplateFile('style.xml') + + def __call__(self): + return self.template() + + def getInfo(self): + info = [] + for k, v in self.context.items(): + properties = [{'name': name, 'value': value} + for name, value in v.items()] + info.append({'selector': k, 'properties': properties}) + return info + +class Importer(object): + """This adapter makes it possible to import style resources. + """ + adapts(IStyle) + implements(IDataImporter) + + def __init__(self, context): + self.context = context + + def load(self, xml=u''): + context = self.context + dom = parseString(xml) + for style in dom.getElementsByTagName('style'): + for sel in style.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 + context[sel_name] = style_props + Added: cpsskins/branches/jmo-perspectives/io/style.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/io/style.zcml Sun Dec 11 15:16:05 2005 @@ -0,0 +1,18 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:browser="http://namespaces.zope.org/browser"> + + <!-- XML export --> + <browser:view + provides="cpsskins.io.interfaces.IDataExporter" + for="cpsskins.engines.default.formats.style.IStyle" + class=".style.Exporter" + permission="zope.ManageContent" + /> + + <!-- XML import --> + <adapter + factory=".style.Importer" + /> + +</configure> -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins