products/CPSRSS

view exportimport.py @ 284:0f9245734ba1

hgbundler made release tag
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Wed, 28 Sep 2011 20:54:53 +0200
parents 9c93ad333884
children
line source
1 # (C) Copyright 2006 Nuxeo SAS <http://nuxeo.com>
2 # Author:
3 # Dragos Ivan <div@nuxeo.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as published
7 # by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 # 02111-1307, USA.
18 #
19 # $Id$
20 """CPSRSS Tool XML Adapter.
21 """
23 from zope.component import adapts
24 from zope.interface import implements
25 from zope.app import zapi
27 from Products.GenericSetup.utils import exportObjects
28 from Products.GenericSetup.utils import importObjects
29 from Products.GenericSetup.utils import XMLAdapterBase
30 from Products.GenericSetup.utils import ObjectManagerHelpers
31 from Products.GenericSetup.utils import PropertyManagerHelpers
33 from Products.CMFCore.utils import getToolByName
35 from Products.GenericSetup.interfaces import INode
36 from Products.GenericSetup.interfaces import IBody
37 from Products.GenericSetup.interfaces import ISetupEnviron
39 from Products.CPSUtil.genericsetup import StrictTextElement
40 from Products.CPSUtil.genericsetup import getExactNodeText
42 from Products.CPSRSS.interfaces import IRSSTool
43 from Products.CPSRSS.interfaces import IRSSChannel
45 from Products.CPSRSS.RSSChannel import RSSChannel_meta_type
46 from Products.CPSRSS.RSSChannel import RSSChannel
48 TOOL = 'portal_rss'
49 NAME = 'rss'
51 def exportRSSTool(context):
52 """Export RSS tool and subobjects as a set of XML files.
53 """
54 site = context.getSite()
55 tool = getToolByName(site, TOOL, None)
56 if tool is None:
57 logger = context.getLogger(NAME)
58 logger.info("Nothing to export.")
59 return
60 exportObjects(tool, '', context)
62 def importRSSTool(context):
63 """Import RSS tool and subobjects from XML files.
64 """
65 site = context.getSite()
66 tool = getToolByName(site, TOOL)
67 importObjects(tool, '', context)
70 class RSSXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
72 """XML im- and exporter for RSS feeds.
73 """
75 adapts(IRSSChannel, ISetupEnviron)
76 implements(IBody)
78 __used_for__ = IRSSChannel
80 _LOGGER_ID = 'rss'
82 def _exportNode(self):
83 """Export the object as a DOM node.
84 """
85 node = self._getObjectNode('object')
86 node.appendChild(self._extractProperties())
88 self._logger.info('%r rss feed exported.' % self.context.getId())
89 return node
91 def _importNode(self, node):
92 """Import the object from the DOM node.
93 """
94 if self.environ.shouldPurge():
95 self._purgeProperties()
97 self._initProperties(node)
99 obj_id = str(node.getAttribute('name'))
100 self._logger.info('%r rss feed imported.' % obj_id)
103 class RSSToolXMLAdapter(XMLAdapterBase, ObjectManagerHelpers,
104 PropertyManagerHelpers):
105 """XML importer and exporter for RSSTool.
106 """
108 adapts(IRSSTool, ISetupEnviron)
109 implements(IBody)
111 _LOGGER_ID = NAME
112 name = NAME
114 def _exportNode(self):
115 """Export the object as a DOM node.
116 """
117 node = self._getObjectNode('object')
118 node.appendChild(self._extractProperties())
119 node.appendChild(self._extractObjects())
121 self._logger.info("RSS tool exported.")
122 return node
124 def _importNode(self, node):
125 """Import the object from the DOM node.
126 """
127 if self.environ.shouldPurge():
128 self._purgeProperties()
129 self._purgeObjects()
131 self._initProperties(node)
132 self._initObjects(node)
134 self._logger.info("RSS tool imported.")