Back to index

plone3  3.1.7
Static Public Attributes | Private Member Functions
ResourceRegistries.exportimport.resourceregistry.ResourceRegistryNodeAdapter Class Reference
Inheritance diagram for ResourceRegistries.exportimport.resourceregistry.ResourceRegistryNodeAdapter:
Inheritance graph
[legend]
Collaboration diagram for ResourceRegistries.exportimport.resourceregistry.ResourceRegistryNodeAdapter:
Collaboration graph
[legend]

List of all members.

Static Public Attributes

string unregister_method = 'unregisterResource'

Private Member Functions

def _exportNode
def _importNode
def _extractResourceInfo
def _initResources

Detailed Description

Definition at line 52 of file resourceregistry.py.


Member Function Documentation

Export the object as a DOM node.

Definition at line 56 of file resourceregistry.py.

00056 
00057     def _exportNode(self):
00058         """
00059         Export the object as a DOM node.
00060         """
00061         node = self._getObjectNode('object')
00062         registry = getToolByName(self.context, self.registry_id)
00063         node.setAttribute('autogroup', str(registry.getAutoGroupingMode()))
00064         #node.setAttribute('xmlns:i18n', I18NURI)
00065         child = self._extractResourceInfo()
00066         node.appendChild(child)
00067         return node

Here is the call graph for this function:

Here is the caller graph for this function:

Extract the information for each of the registered resources.

Definition at line 84 of file resourceregistry.py.

00084 
00085     def _extractResourceInfo(self):
00086         """
00087         Extract the information for each of the registered resources.
00088         """
00089         fragment = self._doc.createDocumentFragment()
00090         registry = getToolByName(self.context, self.registry_id)
00091         resources = registry.getResources()
00092         for resource in resources:
00093             data = resource._data.copy()
00094             child = self._doc.createElement(self.resource_type)
00095             for key, value in data.items():
00096                 if type(value) == type(True) or type(value) == type(0):
00097                     value = str(value)
00098                 child.setAttribute(key, value)
00099             fragment.appendChild(child)
00100         return fragment

Here is the call graph for this function:

Here is the caller graph for this function:

Import the object from the DOM node.

Definition at line 68 of file resourceregistry.py.

00068 
00069     def _importNode(self, node):
00070         """
00071         Import the object from the DOM node.
00072         """
00073         registry = getToolByName(self.context, self.registry_id)
00074         if self.environ.shouldPurge():
00075             registry.clearResources()
00076         
00077         for key, value in node.attributes.items():
00078             key = str(key)
00079             value = value.lower().strip()
00080             if key == 'autogroup':
00081                 registry.setAutoGroupingMode(value in [ 'true', 'yes', '1'])
00082 
00083         self._initResources(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Initialize the registered resources based on the contents of
the provided DOM node.

Definition at line 101 of file resourceregistry.py.

00101 
00102     def _initResources(self, node):
00103         """
00104         Initialize the registered resources based on the contents of
00105         the provided DOM node.
00106         """
00107         registry = getToolByName(self.context, self.registry_id)
00108         reg_method = getattr(registry, self.register_method)
00109         unreg_method = getattr(registry, self.unregister_method)
00110         update_method = getattr(registry, self.update_method)
00111         for child in node.childNodes:
00112             if child.nodeName != self.resource_type:
00113                 continue
00114 
00115             data = {}
00116             method = reg_method
00117             position = None
00118             for key, value in child.attributes.items():
00119                 key = str(key)
00120                 if key == 'update':
00121                     method = update_method
00122                     continue
00123                 if key == 'remove':
00124                     method = unreg_method
00125                     break
00126                 if key in ('position-before', 'insert-before'):
00127                     position = ('Before', value)
00128                     continue
00129                 if key in ('position-after', 'insert-after'):
00130                     position = ('After', value)
00131                     continue
00132                 if key in ('position-top', 'insert-top'):
00133                     position = ('ToTop',)
00134                     continue
00135                 if key in ('position-bottom', 'insert-bottom'):
00136                     position = ('ToBottom',)
00137                     continue
00138                 if key == 'id':
00139                     res_id = str(value)
00140                 elif value.lower() == 'false':
00141                     data[key] = False
00142                 elif value.lower() == 'true':
00143                     data[key] = True
00144                 else:
00145                     try:
00146                         data[key] = int(value)
00147                     except ValueError:
00148                         data[key] = str(value)
00149 
00150             # unreg_method doesn't expect any keyword arguments
00151             # and has to be called separately (this feels dirty..)
00152             if method == unreg_method:
00153                 method(res_id)
00154             elif method == reg_method:
00155                 try:
00156                     data['skipCooking'] = True
00157                     method(res_id, **data)
00158                     del data['skipCooking']
00159                 except ValueError, e:
00160                     # this feels a bit dirty too, but we always want to update
00161                     # if the resource already exists (in which case 'ValueError:
00162                     # Duplicate id ...' is raised.
00163                     method=update_method
00164                     del data['skipCooking']
00165             if method == update_method:
00166                 method(res_id, **data)
00167             if position is not None:
00168                 moveMethod = getattr(registry, 'moveResource' + position[0])
00169                 moveMethod(res_id, *position[1:])
00170 
00171         registry.cookResources()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file resourceregistry.py.


The documentation for this class was generated from the following file: