def _normalize_ids_after_move(self, ids=[], forced=0, REQUEST=None): _globals.writeLog( self, "[_normalize_ids_after_move]: %s" % self.absolute_url()) copy_of_prefix = 'copy_of_' id_prefix = REQUEST.get('id_prefix') REQUEST.set('id_prefix', None) ob_ids = copy.copy(self.objectIds(self.dGlobalAttrs.keys())) for ob in self.objectValues(self.dGlobalAttrs.keys()): id = absattr(ob.id) if forced or (id in ids and not copy_of_prefix + id in ob_ids) or ( copy_of_prefix + id in ids): _globals.writeBlock( self, '[_normalize_ids_after_move]: %s(%s)' % (id, ob.meta_id)) if id_prefix: id_prefix = _globals.id_prefix(id_prefix) if id_prefix != _globals.id_prefix(id): new_id = self.getNewId(id_prefix) _globals.writeBlock( self, '[_normalize_ids_after_move]: Rename %s(%s) to %s' % (id, ob.meta_id, new_id)) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) id = new_id # Re-Assign old id. if id.find(copy_of_prefix) == 0: try: new_id = id[len(copy_of_prefix):] self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) except: pass bk_lang = REQUEST.get('lang') for lang in self.getLangIds(): REQUEST.set('lang', lang) if forced == 0: # Object-State and Version-Manager. if not ob.getAutocommit(): ob.setObjStateModified(REQUEST) ob.onChangeObj(REQUEST) # Process referential integrity. ob.onMoveRefObj(REQUEST) REQUEST.set('lang', bk_lang) # Process tree. ob._normalize_ids_after_move(ids=ids, forced=1, REQUEST=REQUEST)
def _normalize_ids_after_copy(self, ids=[], forced=0, REQUEST=None): _globals.writeLog( self, "[_normalize_ids_after_copy]: %s" % self.absolute_url()) copy_of_prefix = 'copy_of_' id_prefix = REQUEST.get('id_prefix') REQUEST.set('id_prefix', None) ob_ids = copy.copy(self.objectIds(self.dGlobalAttrs.keys())) for ob in self.objectValues(self.dGlobalAttrs.keys()): id = absattr(ob.id) if forced or id in ids: _globals.writeBlock( self, '[_normalize_ids_after_copy]: %s(%s)' % (id, ob.meta_id)) if id_prefix: id_prefix = _globals.id_prefix(id_prefix) if id_prefix != _globals.id_prefix(id): new_id = self.getNewId(id_prefix) _globals.writeBlock( self, '[_normalize_ids_after_copy]: Rename %s(%s) to %s' % (id, ob.meta_id, new_id)) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) id = new_id # Assign new id. prefix = _globals.id_prefix(id) if prefix.find(copy_of_prefix) == 0: prefix = prefix[len(copy_of_prefix):] if prefix != id: new_id = self.getNewId(prefix) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) bk_lang = REQUEST.get('lang') for lang in self.getLangIds(): REQUEST.set('lang', lang) if forced == 0: # Object-State and Version-Manager. if not ob.getAutocommit(): ob.setObjStateNew(REQUEST, reset=0) ob.onChangeObj(REQUEST) # Process referential integrity. ob.onCopyRefObj(REQUEST) REQUEST.set('lang', bk_lang) # Process tree. ob._normalize_ids_after_copy(ids=ids, forced=1, REQUEST=REQUEST)
def getObjToXml(self, REQUEST, incl_embedded=False, deep=True, base_path='', data2hex=False): # Check Constraints. root = getattr(self, '__root__', None) if root is not None: return '' ob = self if ob.meta_type == 'ZMSLinkElement' and ob.isEmbedded( REQUEST) and incl_embedded: ob = ob.getRefObj() xml = [] # Start tag. xml.append('<%s' % ob.xmlGetTagName()) id = self.id prefix = _globals.id_prefix(id) if id == prefix: xml.append(' id_fix="%s"' % id) else: xml.append(' id="%s"' % id) if ob.getParentNode() is not None and ob.getParentNode( ).meta_type == 'ZMSCustom': xml.append('\n id_prefix="%s"' % _globals.id_prefix(ob.id)) xml.append('>') # Attributes. keys = ob.getObjAttrs().keys() if ob.getType() == 'ZMSRecordSet': keys = ['active', ob.getMetaobjAttrIds(ob.meta_id)[0]] for key in keys: obj_attr = ob.getObjAttr(key) if obj_attr['xml']: ob_prop = getObjPropertyToXml(ob, base_path, data2hex, obj_attr, REQUEST) if len(ob_prop) > 0: xml.append('\n<%s>%s</%s>' % (key, ob_prop, key)) # Process children. if deep: xml.extend( map( lambda x: getObjToXml(x, REQUEST, incl_embedded, deep, base_path + x.id + '/', data2hex), ob.getChildNodes())) # End tag. xml.append('</%s>\n' % ob.xmlGetTagName()) # Return xml. return ''.join(xml)
def manage_ajaxZMIActions(self, context_id, REQUEST, RESPONSE): """ Returns ZMI actions. @param REQUEST: the triggering request @type REQUEST: C{ZPublisher.HTTPRequest} @param RESPONSE: the response @type RESPONSE: C{ZPublisher.HTTPResponse} """ #-- Get actions. actions = [] container = self objPath = '' context = None if context_id == '': context = container actions.extend(_zmi_actions_util.zmi_actions(self, self)) else: attr_id = _globals.id_prefix(context_id) if context_id in container.objectIds(): context = getattr(container, context_id, None) actions.extend( _zmi_actions_util.zmi_actions(container, context, attr_id)) if context is not None: objPath = context.id + '/' if context is not None: actions.extend(context.filtered_workflow_actions(objPath)) #-- Build json. RESPONSE.setHeader('Content-Type', 'text/plain; charset=utf-8') RESPONSE.setHeader('Cache-Control', 'no-cache') RESPONSE.setHeader('Pragma', 'no-cache') return self.str_json({'id': context_id, 'actions': actions})
def manage_addZMSLinkContainer(self, lang, _sort_id, REQUEST, RESPONSE): """ manage_addZMSLinkContainer """ ##### Create #### id_prefix = _globals.id_prefix(REQUEST.get('id_prefix', 'e')) new_id = self.getNewId(id_prefix) obj = ZMSLinkContainer(new_id, _sort_id + 1) self._setObject(obj.id, obj) obj = getattr(self, obj.id) ##### Object State #### obj.setObjStateNew(REQUEST) ##### Init Coverage #### coverage = self.getDCCoverage(REQUEST) if coverage.find('local.') == 0: obj.setObjProperty('attr_dc_coverage', coverage) else: obj.setObjProperty('attr_dc_coverage', 'global.' + lang) ##### Init Properties #### obj.setObjProperty('active', 1, lang) ##### VersionManager #### obj.onChangeObj(REQUEST) ##### Normalize Sort-IDs #### self.normalizeSortIds(id_prefix) # Return with message. message = self.getZMILangStr('MSG_INSERTED') % obj.display_type(REQUEST) RESPONSE.redirect( '%s/%s/manage_main?lang=%s&manage_tabs_message=%s' % (self.absolute_url(), obj.id, lang, urllib.quote(message)))
def initObjChild(self, id, _sort_id, type, REQUEST): ##### ID #### metaObjAttr = self.getObjChildrenAttr(id) repetitive = metaObjAttr.get('repetitive', 0) == 1 if repetitive: id += str(self.getSequence().nextVal()) ##### Create #### oItem = getattr(self, id, None) if oItem is None or id not in self.objectIds(): if self.dGlobalAttrs.has_key(type): obj = self.dGlobalAttrs[type]['obj_class'](id, _sort_id + 1) else: obj = self.dGlobalAttrs['ZMSCustom']['obj_class'](id, _sort_id + 1, type) self._setObject(obj.id, obj) oItem = getattr(self, id) ##### Object State #### oItem.setObjStateNew(REQUEST) ##### Init Properties #### oItem.setObjStateModified(REQUEST) for lang in self.getLangIds(): oItem.setObjProperty('active', 1, lang) ##### VersionManager #### oItem.onChangeObj(REQUEST) ##### Normalize Sort-IDs #### self.normalizeSortIds(_globals.id_prefix(id)) return oItem
def manage_addZMSCustom(self, meta_id, lang, _sort_id, REQUEST, RESPONSE): """ manage_addZMSCustom """ if REQUEST['btn'] == self.getZMILangStr('BTN_INSERT'): ##### Create #### id_prefix = _globals.id_prefix(REQUEST.get('id_prefix', 'e')) new_id = self.getNewId(id_prefix) obj = ZMSCustom(new_id, _sort_id + 1, meta_id) self._setObject(obj.id, obj) metaObj = self.getMetaobj(meta_id) redirect_self = bool(REQUEST.get('redirect_self', 0)) or REQUEST.get( 'btn', '') == '' or metaObj['type'] == 'ZMSRecordSet' for attr in metaObj['attrs']: attr_type = attr['type'] redirect_self = redirect_self or attr_type in self.getMetaobjIds( ) + ['*'] redirect_self = redirect_self and not REQUEST.get('btn', '') in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK') ] obj = getattr(self, obj.id) ##### Object State #### obj.setObjStateNew(REQUEST) ##### Init Coverage #### coverage = self.getDCCoverage(REQUEST) if coverage.find('local.') == 0: obj.setObjProperty('attr_dc_coverage', coverage) else: obj.setObjProperty('attr_dc_coverage', 'global.' + lang) ##### Init Properties #### obj.manage_changeProperties(lang, REQUEST, RESPONSE) ##### Normalize Sort-IDs #### self.normalizeSortIds(id_prefix) # Return with message. message = self.getZMILangStr('MSG_INSERTED') % obj.display_type( REQUEST) if redirect_self: RESPONSE.redirect( '%s/%s/manage_main?lang=%s&manage_tabs_message=%s' % (self.absolute_url(), obj.id, lang, urllib.quote(message))) else: RESPONSE.redirect( '%s/manage_main?lang=%s&manage_tabs_message=%s#_%s' % (self.absolute_url(), lang, urllib.quote(message), obj.id)) else: RESPONSE.redirect('%s/manage_main?lang=%s' % (self.absolute_url(), lang))
def getSecNo(self): sec_no = '' #-- [ReqBuff]: Fetch buffered value from Http-Request. parentNode = self.getParentNode() if parentNode is None or \ getattr(parentNode,'meta_type',None) not in self.dGlobalAttrs.keys(): return sec_no reqBuffId = 'getSecNo' try: levelnfc = parentNode.fetchReqBuff('%s_levelnfc' % reqBuffId, self.REQUEST, forced=True) if levelnfc > 0: sec_no = parentNode.fetchReqBuff('%s_%s' % (reqBuffId, self.id), self.REQUEST, forced=True) except: levelnfc = parentNode.attr('levelnfc') parentNode.storeReqBuff('%s_levelnfc' % reqBuffId, levelnfc, self.REQUEST) if len(levelnfc) > 0: parent_no = parentNode.getSecNo() sectionizer = _globals.MySectionizer(levelnfc) siblings = parentNode.filteredChildNodes(self.REQUEST) for sibling in siblings: curr_no = '' level = 0 if sibling.isPageElement(): format = sibling.attr('format') if format.find('headline') == 0: level = int( format[len(_globals.id_prefix(format)):]) - 1 elif sibling.isPage(): level = 1 if level > 0: sectionizer.processLevel(level) curr_no = parent_no + str(sectionizer) if self == sibling: sec_no = curr_no #-- [ReqBuff]: Store value in buffer of Http-Request. parentNode.storeReqBuff('%s_%s' % (reqBuffId, sibling.id), curr_no, self.REQUEST) #-- [ReqBuff]: Return value. return sec_no
def manage_addZMSModule(self, lang, _sort_id, custom, REQUEST, RESPONSE): """ Add module. """ meta_id = self.getMetaobjId(custom) metaObj = self.getMetaobj(meta_id) key = self.getMetaobjAttrIds(meta_id)[0] attr = self.getMetaobjAttr(meta_id, key) zexp = attr['custom'] id_prefix = _globals.id_prefix(REQUEST.get('id_prefix', 'e')) new_id = self.getNewId(id_prefix) _fileutil.import_zexp(self, zexp, new_id, id_prefix, _sort_id) # Return with message. message = self.getZMILangStr('MSG_INSERTED') % custom RESPONSE.redirect( '%s/%s/manage_main?lang=%s&manage_tabs_message=%s' % (self.absolute_url(), new_id, lang, urllib.quote(message))) ################################################################################
def manage_addZMSLinkElement(self, lang, _sort_id, REQUEST, RESPONSE): """ manage_addZMSLinkElement """ meta_id = 'ZMSLinkElement' if REQUEST['btn'] == self.getZMILangStr('BTN_INSERT'): ##### Create #### id_prefix = _globals.id_prefix(REQUEST.get('id_prefix','e')) new_id = self.getNewId(id_prefix) obj = ZMSLinkElement(new_id,_sort_id+1) self._setObject(obj.id, obj) redirect_self = bool( REQUEST.get('redirect_self',0)) or REQUEST.get('btn','') == '' for attr in self.getMetaobj(meta_id)['attrs']: attr_type = attr['type'] redirect_self = redirect_self or attr_type in self.getMetaobjIds()+['*'] redirect_self = redirect_self and not REQUEST.get('btn','') in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')] obj = getattr(self,obj.id) ##### Object State #### obj.setObjStateNew(REQUEST) ##### Init Coverage #### obj.setReqProperty('attr_dc_coverage',REQUEST) ##### Init Properties #### obj.manage_changeProperties(lang,REQUEST,RESPONSE) initZMSLinkElement(obj,REQUEST) ##### VersionManager #### obj.onChangeObj(REQUEST) # Return with message. message = self.getZMILangStr('MSG_INSERTED')%obj.display_type(REQUEST) if redirect_self: RESPONSE.redirect('%s/%s/manage_main?lang=%s&manage_tabs_message=%s'%(self.absolute_url(),obj.id,lang,urllib.quote(message))) else: RESPONSE.redirect('%s/manage_main?lang=%s&manage_tabs_message=%s#_%s'%(self.absolute_url(),lang,urllib.quote(message),obj.id)) else: RESPONSE.redirect('%s/manage_main?lang=%s'%(self.absolute_url(),lang))
def addZMSLinkElement(self, title, url, description, REQUEST): lang = REQUEST['lang'] type = 'new' if _zreferableitem.isInternalLink(url): type = 'replace' ##### Create #### id_prefix = _globals.id_prefix(REQUEST.get('id_prefix','e')) new_id = self.getNewId(id_prefix) obj = ZMSLinkElement(new_id) self._setObject(obj.id, obj) obj = getattr(self,obj.id) ##### Object State #### obj.setObjStateNew(REQUEST) ##### Init Metadata (Important: DC.Coverage!) #### obj.setObjProperty("attr_dc_coverage","local."+lang,lang) obj.setObjProperty("attr_dc_description",description,lang) ##### Init Properties #### obj.setObjProperty("titlealt",title,lang) obj.setObjProperty("title",title,lang) obj.setObjProperty("active",1,lang) obj.setObjProperty("attr_ref",url,lang) obj.setObjProperty("attr_type",type,lang) initZMSLinkElement(obj,REQUEST) ##### VersionManager #### obj.onChangeObj(REQUEST) ##### Normalize Sort-IDs #### self.normalizeSortIds(id_prefix) return obj
def manage_addZMSObject(self, meta_type, values, REQUEST): prim_lang = self.getPrimaryLanguage() lang = REQUEST.get('lang', prim_lang) attrs = [] for key in values.keys(): attrs.extend([key, values[key]]) # Get id. if 'id_prefix' in attrs: i = attrs.index('id_prefix') id_prefix = attrs[i + 1] id = self.getNewId(id_prefix) del attrs[i] # Key. del attrs[i] # Value. elif 'id' in attrs: i = attrs.index('id') id = attrs[i + 1] del attrs[i] # Key. del attrs[i] # Value. else: id = self.getNewId() # Get sort id. key = 'sort_id' if key in attrs and attrs.index(key) % 2 == 0: i = attrs.index(key) sort_id = attrs[i + 1] del attrs[i] # Key. del attrs[i] # Value. else: sort_id = 99999 # Create new object. newNode = self.dGlobalAttrs[meta_type]['obj_class'](id, sort_id) self._setObject(newNode.id, newNode) node = getattr(self, newNode.id) # Init meta object. key = 'meta_id' if meta_type == 'ZMSCustom' and key in attrs and attrs.index( key) % 2 == 0: i = attrs.index(key) meta_id = attrs[i + 1] setattr(node, key, meta_id) del attrs[i] # Key. del attrs[i] # Value. # Object state. node.setObjStateNew(REQUEST) # Init properties. key = 'active' if not (key in attrs and attrs.index(key) % 2 == 0): attrs.extend([key, 1]) key = 'attr_dc_coverage' if not (key in attrs and attrs.index(key) % 2 == 0): attrs.extend([key, 'global.%s' % lang]) for i in range(len(attrs) / 2): key = attrs[i * 2] value = attrs[i * 2 + 1] node.setObjProperty(key, value, REQUEST['lang']) # Version manager. node.onChangeObj(REQUEST) # Normalize sort-ids. self.normalizeSortIds(_globals.id_prefix(id)) # Return object. return node
def synchronizeRefs( self, ob_id=None, clients=False, unify_ids=False): _globals.writeBlock(self,'[synchronizeRefs]') # Extend object-tree. def extendObjectTree(home, home_path): message = '' if home not in homes: homes.append( home) home_ob = self for home_id in home_path: if home_ob is not None: home_ob = getattr( home_ob, home_id, None) if home_ob is not None: t1 = time.time() map( lambda x: operator.setitem(obs, x.base_url(), x), _globals.objectTree( home_ob)) message += '[INFO] Load object-tree for '+home+' (in '+str(int((time.time()-t1)*100.0)/100.0)+' secs.)<br/>' else: message += '[ERROR] Can\'t load object-tree for '+home+': not found!<br/>' _globals.writeBlock(self,'[synchronizeRefs]: '+message) return message # Handle internal references. def handleInternalRefs(k,v): message = '' sp = '{$' l = v.split(sp) if len(l) > 1: m = [l[0]] for i in l[1:]: ref = i[:i.find('}')] if ref.startswith('__') and ref.endswith('__'): ref = ref[2:-2] if len( ref.split('@')) == 1: home_path = [ob.getHome().id] home = home_path[-1] else: home_path = ref.split('@')[0].split('/') home = home_path[-1] id = ref.split('@')[-1].split('/')[-1] if len( id) == 0: id = 'content' # Extend object-tree. message += extendObjectTree(home, home_path) f = filter( lambda x: x.find('/%s/content'%home) >= 0 and x.endswith('/%s'%id), obs.keys()) if len( f) == 0: ref = '__%s__'%ref else: if len( f) > 1: if ref.find('@') > 0: ref = ref[ ref.find('@')+1:] g = filter( lambda x: x.find('/%s/content'%home) >= 0 and x.endswith('/%s'%ref), obs.keys()) if len( g) == 1: f = g else: message += '[WARNING] %s: Ambigous reference ref=%s in f=%s'%(ob.absolute_url(),ref,str(f)) else: target = obs[f[0]] ref = ob.getRefObjPath( target)[2:-1] if ob.version_live_id == obj_vers.id: target_ref = target.getRefObjPath( ob) target_ref_by = getattr( target, 'ref_by', []) if target_ref not in target_ref_by: setattr( target, 'ref_by', target_ref_by + [ target_ref]) if ref.startswith('__') and ref.endswith('__'): message += '<a href="%s/manage_main" target="_blank">%s(%s)%s=%s</a><br/>'%(ob.absolute_url(),ob.absolute_url(),ob.meta_type,k,ref) m.append(ref+i[i.find('}'):]) v = sp.join(m) return v, message # Handle relative references. def handleRelativeRefs(k,v): message = '' for sp in ['href="./','src="./']: l = v.split(sp) if len(l) > 1: m = [l[0]] for i in l[1:]: if i.find('"') > 0: ref = i[:i.find('"')] if ref.endswith('/'): ref = ref[:-1] decl_id = ref.split('/')[-1] if getattr(ob.getHome(),decl_id,None) is None: # must not exist as Zope resource filtered_did = filter(lambda x: x['decl_id']==decl_id,did) if len(filtered_did) == 1: # simplest case: decl_id is unique! found = filtered_did[0] req = REQUEST={'lang':found['lang']} target_url = found['abs_url'] target_ref = obs[target_url].getDeclUrl(REQUEST=req) ob_ref = ob.getSelf(ob.PAGES).getDeclUrl(REQUEST=req) ref = self.getRelativeUrl(ob_ref,target_ref) i = ref + i[i.find('"'):] m.append(i) v = sp.join(m) return v, message # Initialize. message = '' t0 = time.time() obs = {} clients = clients or (not self.getPortalMaster() and not self.getPortalClients()) # Initialize object-tree. map( lambda x: operator.setitem(obs, x.base_url(), x), _globals.objectTree( self, clients)) homes = obs.keys() homes = map( lambda x: x[:x.find('/content')], homes) homes = map( lambda x: x[x.rfind('/')+1:], homes) homes = dict.fromkeys(homes).keys() message += 'Load object-tree ['+str(len(obs.keys()))+ '] for '+str(homes)+' (in '+str(int((time.time()-t0)*100.0)/100.0)+' secs.)<br/>' _globals.writeBlock(self,'[synchronizeRefs]: '+message) abs_urls = obs.keys() abs_urls.sort() did = [] if self.getConfProperty('ZMS.pathhandler',0) != 0: for x in obs.keys(): ob = obs[x] for lang in self.getLangIds(): did.append({'decl_id':ob.getDeclId(REQUEST={'lang':lang}),'lang':lang,'abs_url':x}) # Unify object-ids. if unify_ids: did = {} map( lambda x: operator.setitem( did, x.id, did.get(x.id,0)+1), obs.values()) for id in filter( lambda x: did.get(x) > 1 and x[-1] in ['0','1','2','3','4','5','6','7','8','9'], did.keys()): prefix = None keys = map( lambda x: (x.find('/content'),x), filter( lambda x: x.endswith('/'+id), obs.keys())) keys.sort() keys = map( lambda x: x[1], keys) for key in keys: ob = obs[key] if prefix is None: prefix = _globals.id_prefix( id) message += '[INFO] %s: Keep unique object-id \'%s\'<br/>'%(key,id) else: new_id = self.getNewId(prefix) try: ob.getParentNode().manage_renameObject( id=id, new_id=new_id) obs[ ob.base_url()] = ob message += '[INFO] %s: Rename to unique object-id \'%s\'<br/>'%(key,new_id) except: message += _globals.writeError( ob, '%s: Can\'t rename to unique object-id \'%s\'<br/>'%(key,new_id)) # Clear 'ref_by' (reference-by) attributes. for x in filter( lambda x: hasattr( obs[x], 'ref_by'), abs_urls): if clients or True: try: setattr( obs[x], 'ref_by', []) except: pass else: try: ref_by = getattr( obs[x], 'ref_by') ref_by = filter( lambda x: x.find('@')<0, ref_by) setattr( obs[x], 'ref_by', ref_by) except: pass langs = self.getLangIds() for abs_url in abs_urls: ob = obs[ abs_url] # Process recordset. if ob.meta_id!='ZMSLinkElement' and ob.getType()=='ZMSRecordSet': key = ob.getMetaobjAttrIds(ob.meta_id)[0] obj_attr = ob.getObjAttr(key) for lang in langs: for obj_vers in ob.getObjVersions(): v = _objattrs.getobjattr(ob,obj_vers,obj_attr,lang) c = 0 for r in v: for k in r.keys(): v = r[k] o = v if type(v) is str: v, m = handleInternalRefs('%s.%s[%i]'%(key,k,c),v) message += m v, m = handleRelativeRefs('%s.%s[%i]'%(key,k,c),v) message += m if v != o: r[k] = v c += 1 # Process object. else: for key in ob.getObjAttrs().keys(): obj_attr = ob.getObjAttr(key) datatype = obj_attr['datatype_key'] if datatype in _globals.DT_STRINGS: for lang in langs: for obj_vers in ob.getObjVersions(): v = _objattrs.getobjattr(ob,obj_vers,obj_attr,lang) o = v if type(v) is str: v, m = handleInternalRefs(key,v) message += m v, m = handleRelativeRefs(key,v) message += m if v != o: _objattrs.setobjattr(ob,obj_vers,obj_attr,v,lang) message += ' (in '+str(int((time.time()-t0)*100.0)/100.0)+' secs.)' _globals.writeBlock(self,'[synchronizeRefs]: '+message) # Return with desired object. if ob_id is not None: if type( ob_id) is str: home = ob_id.split('@')[0] id = ob_id.split('@')[1] f = filter( lambda x: x.find('/%s/content'%home) > 0 and x.endswith('/%s'%id), abs_urls) if len( f) > 0: return obs[f[0]] return None # Return with message. else: return message
def OnStartElement(self, name, attrs): """ Builder.OnStartElement """ _globals.writeLog( self, "[Builder.OnStartElement(" + str(name) + ")]") name = _globals.unencode( name) attrs = _globals.unencode( attrs) # handle alias if name in self.getMetaobjIds(sort=0) and not self.dGlobalAttrs.has_key(name): attrs['meta_id'] = name name = 'ZMSCustom' # handle alias for zms2go if name == 'ZMS' and self.oRootNode is not None: attrs['meta_id'] = name name = 'ZMSCustom' if self.bInRootTag or \ self.oRoot == None or \ (self.oRoot.id == self.getDocumentElement().id and \ self.dGlobalAttrs.has_key(name) and \ self.dGlobalAttrs[name]['obj_class'] is not None): _globals.writeLog( self, "[Builder.OnStartElement]: " + \ "We are inside the XML root tag OR no root object is set" + \ "-> instanciate node object in any case") if self.dGlobalAttrs.has_key(name) and \ self.dGlobalAttrs[name]['obj_class'] is not None: # class defined for tag! if self.oCurrNode==None and self.oRoot!=None and self.oRoot.id==self.getDocumentElement().id: self.oCurrNode = self.oRoot # create node instance _globals.writeBlock( self, "[Builder.OnStartElement]: create new object <" + str(name) + "> in " + str(self.oCurrNode)) newNode = None if 'id_fix' in attrs.keys(): id = attrs.get( 'id_fix') newNode = getattr(self.oCurrNode,id,None) elif 'id_prefix' in attrs.keys(): prefix = attrs.get( 'id_prefix') id = self.oCurrNode.getNewId(prefix) elif 'id' in attrs.keys(): id = attrs.get( 'id') prefix = _globals.id_prefix(id) id = self.oCurrNode.getNewId(prefix) else: id = self.oCurrNode.getNewId() sort_id = self.oCurrNode.getNewSortId() ##### Create #### if newNode is None: newNode = self.dGlobalAttrs[name]['obj_class'](id,sort_id) self.oCurrNode._setObject(newNode.id, newNode) newNode = getattr(self.oCurrNode,newNode.id) ##### Identify Content-Object #### if newNode.meta_type == 'ZMSCustom': meta_id = attrs.get( 'meta_id') if meta_id not in self.getMetaobjIds( sort=0): _globals.writeError(newNode,'[_builder.OnStartElement]: no object-definition available ('+str(meta_id)+')!') newNode.meta_id = meta_id ##### Object State #### newNode.initializeWorkVersion() obj_attrs = newNode.getObjAttrs() langs = self.getLangIds() for lang in langs: req = {'lang':lang,'preview':'preview'} ##### Object State #### newNode.setObjStateNew(req) ##### Init Properties #### if 'active' in obj_attrs.keys(): newNode.setObjProperty('active',1,lang) if len( langs) == 1: newNode.setObjProperty('change_uid','xml',lang) newNode.setObjProperty('change_dt',time.time(),lang) _globals.writeLog( self, "[Builder.OnStartElement]: object with id " + str(newNode.id) + " of class " + str(newNode.__class__) + " created in " + str(self.oCurrNode.__class__)) if self.oRoot is None: # root object set? self.oRoot = newNode # -> set root node # notify new node newNode.xmlOnStartElement(name, attrs, self.oCurrNode, self.oRoot) # set new node as current node self.oCurrNode = newNode else: # no class defined for tag # -> offer to current object if self.oCurrNode==None: raise ParseError("Unknown tag (" + name + "): no current object available!") # no current object available! if not self.oCurrNode.xmlOnUnknownStartTag(name, attrs): if self._unknownTagName == None: self._unknownTagName = name _globals.writeLog( self, "[Builder.OnStartElement]: Unknown start-tag (" + name + "): current object did not accept tag!") # current object did not accept tag! # raise ParseError("Unknown start-tag (" + name + "): current object did not accept tag!") # current object did not accept tag! else: _globals.writeLog( self, "[Builder.OnStartElement]: " + "we have encountered the XML root tag and a root object is predefined" + \ "-> simply notify root object") self.oRoot.xmlOnStartElement(name, attrs, None, self.oRoot) # set root node as current node self.oCurrNode = self.oRoot # we are inside the XML root now! self.bInRootTag=1 if self.oRootNode is None: self.oRootNode = self.oCurrNode