def _importAccount(self, joeyAccountDirName, accountXmlFileName): ravenAccountDirName = self._getRavenAccountDirName(joeyAccountDirName) ravenAccountXmlName = os.path.join(ravenAccountDirName, u"account.xml") #$NON-NLS-1$ os.makedirs(ravenAccountDirName) # Copy over any icons that have been downloaded (or any other resource). fileutil.copyFiles(joeyAccountDirName, ravenAccountDirName) dom = ZDom() dom.load(accountXmlFileName) newDom = dom.transformToXML(self.accountTransformFilename) newDom.setNamespaceMap(ACCOUNT_NSS_MAP) # Encrypt the account password. passwordNode = newDom.selectSingleNode(u"/zns:account/zns:attributes/zns:attribute[@name = 'password']") #$NON-NLS-1$ if passwordNode: password = crypt.encryptPlainText(passwordNode.getText(), PASSWORD_ENCRYPTION_KEY) passwordNode.setText(password) # convert host, port & path combo to a single url attribute; also determine the raven publisher site/type. self._convertApiInfo(newDom) # account id accId = newDom.documentElement.getAttribute(u"account-id") #$NON-NLS-1$ self.validAccounts[accId] = True # convert blog and id format to raven format blogNodeList = newDom.selectNodes(u"/zns:account/zns:blogs/zns:blog") #$NON-NLS-1$ for blogNode in blogNodeList: self._convertAccBlogInfo(accId, blogNode) # Save to disk. newDom.save(ravenAccountXmlName, True) del dom del newDom
def _importBlogPost(self, jbeXmlFileName): ravenXmlFileName = self._getRavenXmlFileName(jbeXmlFileName) jbeHtmlFileName = self._getJbeHtmlFileName(jbeXmlFileName) dom = ZDom() dom.load(jbeXmlFileName) newDom = dom.transformToXML(self.dataTransformFilename) self._attachContent(newDom, jbeHtmlFileName) removeNodeList = [] blogNodeList = [] published = False for blogNode in newDom.selectNodes(u"/zns:entry/zns:blogs/zns:blog"): #$NON-NLS-1$ # since there is atleast one blog associated with the entry, assume the post # is published published = True ravenAccountId = blogNode.getAttribute(u"account-id") #$NON-NLS-1$ joeyBlogId = blogNode.getAttribute(u"blog-id") #$NON-NLS-1$ qid = self._convertBlogId(ravenAccountId, joeyBlogId) if self._hasBlog( qid.getId() ): blogNodeList.append(blogNode) self._convertBlogPostBlogInfo(ravenAccountId, qid.getId(), qid.getServerId(), blogNode) else: removeNodeList.append(blogNode) # remove orphan blog infos for blogNode in removeNodeList: blogNode.parentNode.removeChild(blogNode) # save only if there were any blogs associated with the entry or if the post is a draft (published = false) if not published or (blogNodeList and len(blogNodeList) > 0): newDom.save(ravenXmlFileName, True) del dom del newDom
def _load(self): if not self.registryFile or not os.path.exists(self.registryFile): return mediaStorageDir = os.path.basename(self.registryFile) dom = ZDom() dom.load(self.registryFile) # Legacy handling - old registry file format for fileElem in dom.selectNodes(u"/registry/file"): #$NON-NLS-1$ fileName = fileElem.getText() size = int(fileElem.getAttribute(u"size")) #$NON-NLS-1$ timestamp = ZSchemaDateTime(fileElem.getAttribute(u"timestamp")) #$NON-NLS-1$ url = fileElem.getAttribute(u"url") #$NON-NLS-1$ self.addFile(fileName, size, timestamp, url) # New registry file format for entryElem in dom.selectNodes(u"/registry/entry"): #$NON-NLS-1$ size = int(entryElem.getAttribute(u"size")) #$NON-NLS-1$ timestamp = ZSchemaDateTime(entryElem.getAttribute(u"timestamp")) #$NON-NLS-1$ relativeFileName = entryElem.selectSingleNodeText(u"file") #$NON-NLS-1$ fileName = resolveRelativePath(mediaStorageDir, relativeFileName) url = entryElem.selectSingleNodeText(u"url") #$NON-NLS-1$ embedFragment = entryElem.selectSingleNode(u"embed/*") #$NON-NLS-1$ metaData = entryElem.selectSingleNode(u"metaData/*") #$NON-NLS-1$ uploadResponse = ZUploadResponse(url, embedFragment, metaData) self.addFileEntry(fileName, size, timestamp, uploadResponse)
def _load(self): if not self.registryFile or not os.path.exists(self.registryFile): return mediaStorageDir = os.path.basename(self.registryFile) dom = ZDom() dom.load(self.registryFile) # Legacy handling - old registry file format for fileElem in dom.selectNodes(u"/registry/file"): #$NON-NLS-1$ fileName = fileElem.getText() size = int(fileElem.getAttribute(u"size")) #$NON-NLS-1$ timestamp = ZSchemaDateTime( fileElem.getAttribute(u"timestamp")) #$NON-NLS-1$ url = fileElem.getAttribute(u"url") #$NON-NLS-1$ self.addFile(fileName, size, timestamp, url) # New registry file format for entryElem in dom.selectNodes(u"/registry/entry"): #$NON-NLS-1$ size = int(entryElem.getAttribute(u"size")) #$NON-NLS-1$ timestamp = ZSchemaDateTime( entryElem.getAttribute(u"timestamp")) #$NON-NLS-1$ relativeFileName = entryElem.selectSingleNodeText( u"file") #$NON-NLS-1$ fileName = resolveRelativePath(mediaStorageDir, relativeFileName) url = entryElem.selectSingleNodeText(u"url") #$NON-NLS-1$ embedFragment = entryElem.selectSingleNode( u"embed/*") #$NON-NLS-1$ metaData = entryElem.selectSingleNode(u"metaData/*") #$NON-NLS-1$ uploadResponse = ZUploadResponse(url, embedFragment, metaData) self.addFileEntry(fileName, size, timestamp, uploadResponse)
def _loadProfilesDom(self): domPath = self._getProfilesXmlPath() dom = ZDom() if not os.path.exists(domPath): dom.loadXML(DEFAULT_PROFILES_XML) else: dom.load(domPath) return dom
def _getJoeyUserConfigDom(self): try: configFile = os.path.join(self.pathToSourceProfile, u"joey-user-config.xml") #$NON-NLS-1$ dom = ZDom() dom.load(configFile) return dom except: return None
def _getJoeyLocalFilesDom(self): try: f = os.path.join(self.pathToSourceProfile, u"mediarep\\zlocalfiles.xml") #$NON-NLS-1$ dom = ZDom() dom.load(f) return dom except: return None
def loadStoreEntry(entry, entryXmlPath): u"""loadStoreEntry(ZResourceStoreEntry , string) -> ZResourceStoreEntry """ #$NON-NLS-1$ try: dom = ZDom() dom.load(entryXmlPath) return ZResourceStoreEntryDeserializer().deserialize(entry, dom) except Exception, e: raise e
def loadWordListXML(filePath): u"""loadWordListXML(string) -> string [] Loads the wordlist.xml file at the given path and parses it into a list of strings.""" #$NON-NLS-1$ dom = ZDom() dom.load(filePath) nssMap = { u"ns" : IZAppNamespaces.RAVEN_WORD_LIST_NAMESPACE } #$NON-NLS-1$ nodes = dom.selectNodes(u"/ns:word-list/ns:word", nssMap) #$NON-NLS-1$ return map(_getElementText, nodes)
def loadDictionariesXML(filePath): u"""loadDictionariesXML(string) -> IZSpellCheckDictionaryLanguage [] Loads the dictionaries.xml file at the given path and parses it into a list of IZSpellCheckDictionaryLanguage objects.""" # $NON-NLS-1$ dom = ZDom() dom.load(filePath) nssMap = {u"ns": IZAppNamespaces.RAVEN_DICTIONARIES_NAMESPACE} # $NON-NLS-1$ nodes = dom.selectNodes(u"/ns:dictionaries/ns:dictionary", nssMap) # $NON-NLS-1$ return map(_createSpellCheckDictionaryLanguage, nodes)
def loadWordListXML(filePath): u"""loadWordListXML(string) -> string [] Loads the wordlist.xml file at the given path and parses it into a list of strings.""" #$NON-NLS-1$ dom = ZDom() dom.load(filePath) nssMap = {u"ns": IZAppNamespaces.RAVEN_WORD_LIST_NAMESPACE} #$NON-NLS-1$ nodes = dom.selectNodes(u"/ns:word-list/ns:word", nssMap) #$NON-NLS-1$ return map(_getElementText, nodes)
def _loadBundleStringsFromFile(self, fileName, stringMap): nsMap = { u"zb" : u"http://www.zoundry.com/schemas/2006/06/zbundle.rng" } #$NON-NLS-1$ #$NON-NLS-2$ dom = ZDom() dom.load(fileName) stringElems = dom.selectNodes(u"/zb:string-bundle/zb:string", nsMap) #$NON-NLS-1$ for stringElem in stringElems: key = stringElem.getAttribute(u"name") #$NON-NLS-1$ value = stringElem.getText() stringMap[key] = value
def loadCountryCodes(xmlFilePath): try: dom = ZDom() dom.load(xmlFilePath) deserializer = getI18NDeserializerFactory().getDeserializer(dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom) except Exception, e: raise ZAppFrameworkException(_extstr(u"i18nserviceio.ErrorLoadingCountryCodes"), e) #$NON-NLS-1$
def loadBackgroundTask(taskXmlPath): try: dom = ZDom() dom.load(taskXmlPath) deserializer = getBackgroundTaskDeserializerFactory().getDeserializer(dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom) except Exception, e: raise ZAppFrameworkException(_extstr(u"backgroundtaskio.FailedToLoadTask") % taskXmlPath, e) #$NON-NLS-1$
def loadTemplate(templateDir): try: templateXmlPath = os.path.join(templateDir, u"template.xml") #$NON-NLS-1$ dom = ZDom() dom.load(templateXmlPath) deserializer = getTemplateDeserializerFactory().getDeserializer(dom.documentElement.getNamespaceUri()) return deserializer.deserialize(templateDir, dom) except Exception, e: raise ZBlogAppException(u"Failed to load template: %s" % templateDir, e) #$NON-NLS-1$
def loadAccount(accountDir): try: accountXmlPath = os.path.join(accountDir, u"account.xml") #$NON-NLS-1$ dom = ZDom() dom.load(accountXmlPath) deserializer = getAccountDeserializerFactory().getDeserializer(dom.documentElement.getNamespaceUri()) return deserializer.deserialize(accountDir, dom) except Exception, e: raise ZBlogAppException(_extstr(u"accountio.FailedToLoadAccount") % accountDir, e) #$NON-NLS-1$
def importAccountBlogMediaStores(self, accountXmlPathList): for accountXmlPath in accountXmlPathList: joeyAccountDom = ZDom() joeyAccountDom.load(accountXmlPath) for blogNode in joeyAccountDom.selectNodes(u"//blogs/blog[child::mediarep/text()='publisher']"): #$NON-NLS-1$ try: blogId = blogNode.selectSingleNode(u"id").getText() #$NON-NLS-1$ regList = self._getRegistryEntries(blogId) #@UnusedVariable # FIXME (PJ) create Raven metaweblog media site for blogId. Add regFiles to media store reg. Associate *raven* account with media store except: pass
class ZSystemProperties: u"""Use this class to get and set System Properties.""" #$NON-NLS-1$ def __init__(self, sysPropsFileName): # create a lock for thread synchronization self.lock = ZMutex(u"ZSystemProperties") #$NON-NLS-1$ self.listeners = ZListenerSet() self.sysPropsFileName = sysPropsFileName self.sysPropsDoc = ZDom() self.reloadProperties() # end __init__() def addListener(self, listener): self.listeners.append(listener) # end addListener() def removeListener(self, listener): self.listeners.remove(listener) # end removeListener def _fireEvent(self, key, value): for listener in self.listeners: listener.onSystemPropertyChange(key, value) # end _fireEvent() def reloadProperties(self): self.lock.acquire() try: # Open and parse the system properties file self.sysPropsDoc.load(self.sysPropsFileName) finally: self.lock.release() # end reloadProperties() # Public method - call this to save the system properties. def save(self): u"Public method - call this to save the system properties." #$NON-NLS-1$ self.lock.acquire() self.saveProperties() self.lock.release() self._fireEvent(None, None) # end save() # Note that locking is required prior to calling saveProperties() def saveProperties(self): try: tempSysPropsFileName = self.sysPropsFileName + u".t" #$NON-NLS-1$ self.sysPropsDoc.save(tempSysPropsFileName, True) deleteFile(self.sysPropsFileName) renameFile(tempSysPropsFileName, self.sysPropsFileName) except Exception, e: raise ZException(_extstr(u"sysprops.ErrorSavingPropsFile") % self.sysPropsFileName, e) #$NON-NLS-1$
def loadMediaStorage(mediaStoreXmlPath): try: dom = ZDom() dom.load(mediaStoreXmlPath) deserializer = getMediaStorageDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom) except Exception, e: raise ZBlogAppException(_extstr(u"mediastorageio.FailedToLoadStore"), e) #$NON-NLS-1$
def loadDocument(documentXmlPath): try: dom = ZDom() dom.load(documentXmlPath) dataDir = os.path.dirname(documentXmlPath) context = ZBlogDocumentSerializationContext(dataDir) deserializer = getDocumentDeserializerFactory().getDeserializer(dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom, context) except Exception, e: raise ZBlogAppException(_extstr(u"dataio.DocumentLoadFailedError") % documentXmlPath, e) #$NON-NLS-1$
def loadBackgroundTask(taskXmlPath): try: dom = ZDom() dom.load(taskXmlPath) deserializer = getBackgroundTaskDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom) except Exception, e: raise ZAppFrameworkException( _extstr(u"backgroundtaskio.FailedToLoadTask") % taskXmlPath, e) #$NON-NLS-1$
def loadDictionariesXML(filePath): u"""loadDictionariesXML(string) -> IZSpellCheckDictionaryLanguage [] Loads the dictionaries.xml file at the given path and parses it into a list of IZSpellCheckDictionaryLanguage objects.""" #$NON-NLS-1$ dom = ZDom() dom.load(filePath) nssMap = { u"ns": IZAppNamespaces.RAVEN_DICTIONARIES_NAMESPACE } #$NON-NLS-1$ nodes = dom.selectNodes(u"/ns:dictionaries/ns:dictionary", nssMap) #$NON-NLS-1$ return map(_createSpellCheckDictionaryLanguage, nodes)
def loadLanguageCodes(xmlFilePath): try: dom = ZDom() dom.load(xmlFilePath) deserializer = getI18NDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom) except Exception, e: raise ZAppFrameworkException( _extstr(u"i18nserviceio.ErrorLoadingLanguageCodes"), e) #$NON-NLS-1$
def _loadMerchantRegistry(self): resourceReg = self.applicationModel.getResourceRegistry() merchantsXMLPath = resourceReg.getResourcePath(u"zservice/merchants.xml") #$NON-NLS-1$ dom = ZDom() dom.load(merchantsXMLPath) nodeList = dom.selectNodes(u"//Merchants/Merchant") #$NON-NLS-1$ if not nodeList: return for node in nodeList: merchant = self._createMerchant(node) if merchant: self.merchantRegistry.add(merchant)
def _loadMerchantRegistry(self): resourceReg = self.applicationModel.getResourceRegistry() merchantsXMLPath = resourceReg.getResourcePath( u"zservice/merchants.xml") #$NON-NLS-1$ dom = ZDom() dom.load(merchantsXMLPath) nodeList = dom.selectNodes(u"//Merchants/Merchant") #$NON-NLS-1$ if not nodeList: return for node in nodeList: merchant = self._createMerchant(node) if merchant: self.merchantRegistry.add(merchant)
def loadTemplate(templateDir): try: templateXmlPath = os.path.join(templateDir, u"template.xml") #$NON-NLS-1$ dom = ZDom() dom.load(templateXmlPath) deserializer = getTemplateDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(templateDir, dom) except Exception, e: raise ZBlogAppException(u"Failed to load template: %s" % templateDir, e) #$NON-NLS-1$
def _loadBundle(self, bundleFilename): # Load the file and read in all its string mappings. dom = ZDom() dom.load(bundleFilename) dom.setNamespaceMap(SB_NSS_MAP) nl = dom.selectNodes(u"/sb:string-bundle/sb:string") #$NON-NLS-1$ for n in nl: name = n.getAttribute(u"name") #$NON-NLS-1$ val = n.getText() val = val.replace(u"\\n", u"\n") #$NON-NLS-2$ #$NON-NLS-1$ val = val.replace(u"\\t", u"\t") #$NON-NLS-2$ #$NON-NLS-1$ self.bundleMap[name] = val
def loadAccount(accountDir): try: accountXmlPath = os.path.join(accountDir, u"account.xml") #$NON-NLS-1$ dom = ZDom() dom.load(accountXmlPath) deserializer = getAccountDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(accountDir, dom) except Exception, e: raise ZBlogAppException( _extstr(u"accountio.FailedToLoadAccount") % accountDir, e) #$NON-NLS-1$
def deserialize(self, path): u"""deserialize(string) -> ZSpellChecker""" #$NON-NLS-1$ fpath = os.path.join(path, u"spellchecker.xml") #$NON-NLS-1$ dom = ZDom() dom.load(fpath) dom.setNamespaceMap({ u"ns" : IZAppNamespaces.RAVEN_SPELLCHECKER_NAMESPACE }) #$NON-NLS-1$ spellcheckerElem = dom.documentElement dictionaryLanguage = self._deserializeDictionaryLanguage(spellcheckerElem) provider = self._deserializeProvider(spellcheckerElem, dictionaryLanguage) personalWordList = self._deserializePersonalDictionary(spellcheckerElem) autoCorrections = self._deserializeAutoCorrections(spellcheckerElem) return ZSpellChecker(path, dictionaryLanguage, provider, personalWordList, autoCorrections)
def loadDocument(documentXmlPath): try: dom = ZDom() dom.load(documentXmlPath) dataDir = os.path.dirname(documentXmlPath) context = ZBlogDocumentSerializationContext(dataDir) deserializer = getDocumentDeserializerFactory().getDeserializer( dom.documentElement.getNamespaceUri()) return deserializer.deserialize(dom, context) except Exception, e: raise ZBlogAppException( _extstr(u"dataio.DocumentLoadFailedError") % documentXmlPath, e) #$NON-NLS-1$
def _loadMimeTypes(self, applicationModel): rval = {} mimeTypeFile = applicationModel.getResourceRegistry().getResourcePath(u"mimetypes.xml") #$NON-NLS-1$ mimeTypeDom = ZDom() mimeTypeDom.load(mimeTypeFile) mimeTypeDom.setNamespaceMap({ u"mt" : IZAppNamespaces.RAVEN_MIMETYPES_NAMESPACE }) #$NON-NLS-1$ mimeTypeNodes = mimeTypeDom.selectNodes(u"/mt:mime-types/mt:mime-type") #$NON-NLS-1$ for mimeTypeNode in mimeTypeNodes: type = mimeTypeNode.selectSingleNodeText(u"mt:type") #$NON-NLS-1$ ext = mimeTypeNode.selectSingleNodeText(u"mt:extension") #$NON-NLS-1$ rval[ext] = ZMimeType(type, ext) return rval
def _loadSnapshots(self): self.logger.debug(u"Loading recovery snapshots.") #$NON-NLS-1$ snapshotFiles = getDirectoryListing(self.recoveryDir) snapshots = [] for snapshotFile in snapshotFiles: documentDom = ZDom() documentDom.load(snapshotFile) namespace = documentDom.documentElement.getNamespaceUri() docDeserializer = ZDocumentDeserializerFactory().getDeserializer(namespace) context = ZBlogDocumentSerializationContext(self.recoveryDir) document = docDeserializer.deserialize(documentDom, context) snapshots.append(document) self.logger.debug(u"Recovery snapshot loaded.") #$NON-NLS-1$ return snapshots
def get(self, url): urlHash = self._hashUrl(url) urlDir = os.path.join(self.cacheDir, urlHash) if not os.path.isdir(urlDir): return None urlMetaFile = os.path.join(urlDir, u"meta-data.xml") #$NON-NLS-1$ if not os.path.isfile(urlMetaFile): return None urlMetaDom = ZDom() urlMetaDom.load(urlMetaFile) urlMetaData = ZURLMetaDataReader(urlMetaDom) if url != urlMetaData.getURL(): return None dataFile = os.path.join(urlDir, urlMetaData.getDataFile()) if not os.path.isfile(dataFile): return None return ZCachedHttpConnectionResp(urlMetaData, dataFile)
def importPersonalDictionary(self): joeyConfigDom = self._getJoeyUserConfigDom() if not joeyConfigDom: return try: node = joeyConfigDom.selectSingleNode(u"/joey/user-config/spell-check/language") #$NON-NLS-1$ if not node: return spellcheckLang = getNoneString( node.getText()) if not spellcheckLang: return # FIXME (EPW) we could support other languages... if not spellcheckLang == u"en_US": #$NON-NLS-1$ return # 1) read all words from ZBW personal-dictionary.xml file # 2) create new spellchecker.xml DOM # 3) save new Raven spellchecker file to 'PROFILE\LANG\spellchecker.xml' joeyDictFile = os.path.join(self.pathToJoeyProfile, u"spelling/personal-dictionary.xml") #$NON-NLS-1$ dom = ZDom() dom.load(joeyDictFile) dom.setNamespaceMap(ZBW_PERSONAL_DICTIONARY_NSS_MAP) wordNodeList = dom.selectNodes(u"/pd:personal-dictionary/pd:word") #$NON-NLS-1$ newDom = ZDom() newDom.loadXML(ZBlogWriterDictionaryImporter.SPELLCHECK_TEMPLATE) newDom.setNamespaceMap(RAVEN_SPELLCHECK_NSS_MAP) personalDictElem = newDom.selectSingleNode(u"/spl:spellchecker/spl:personal-dictionary") #$NON-NLS-1$ for wordNode in wordNodeList: word = wordNode.getText() newWordElem = newDom.createElement(u"word", IZBlogAppNamespaces.RAVEN_SPELLCHECKER_NAMESPACE) #$NON-NLS-1$ newWordElem.setText(word) personalDictElem.appendChild(newWordElem) outputDir = os.path.join(self.pathToRavenProfile, u"spellcheck/en_US") #$NON-NLS-1$ os.makedirs(outputDir) outputFile = os.path.join(outputDir, u"spellchecker.xml") #$NON-NLS-1$ newDom.save(outputFile, True) except ZException, ze: # FIXME (EPW) need to report errors in some way ze.printStackTrace()
def _loadMimeTypes(self, applicationModel): rval = {} mimeTypeFile = applicationModel.getResourceRegistry().getResourcePath( u"mimetypes.xml") #$NON-NLS-1$ mimeTypeDom = ZDom() mimeTypeDom.load(mimeTypeFile) mimeTypeDom.setNamespaceMap( {u"mt": IZAppNamespaces.RAVEN_MIMETYPES_NAMESPACE}) #$NON-NLS-1$ mimeTypeNodes = mimeTypeDom.selectNodes( u"/mt:mime-types/mt:mime-type") #$NON-NLS-1$ for mimeTypeNode in mimeTypeNodes: type = mimeTypeNode.selectSingleNodeText(u"mt:type") #$NON-NLS-1$ ext = mimeTypeNode.selectSingleNodeText( u"mt:extension") #$NON-NLS-1$ rval[ext] = ZMimeType(type, ext) return rval
def _getAccountDirList(self): accountDirPath = os.path.join(self.pathToJoeyProfile, u"accounts") #$NON-NLS-1$ fullDirNames = [] try: # get the account.xml ("table of contents") file into a dom accountsTocXmlFileName = os.path.join(accountDirPath, self._getAccountTocXmlFilename() ) #$NON-NLS-1$ if not os.path.exists(accountsTocXmlFileName): return fullDirNames tocDom = ZDom() tocDom.load(accountsTocXmlFileName) accIdNodes = tocDom.selectNodes(u"/blog-accounts/blog-account/@id") #$NON-NLS-1$ for accIdNode in accIdNodes: accId = accIdNode.getText() fullPath = os.path.join(accountDirPath, accId) if os.path.isdir(fullPath): accountXmlFileName = os.path.join(fullPath, u"account.xml") #$NON-NLS-1$ if os.path.isfile(accountXmlFileName): fullDirNames.append( (fullPath, accountXmlFileName) ) except Exception, e: ze = ZException(e) ze.printStackTrace()
class ZXhtmlSchema(IZXhtmlSchema): XS_NSS_MAP = { u"xs": u"http://www.w3.org/2001/XMLSchema" #$NON-NLS-1$ #$NON-NLS-2$ } def __init__(self, xsdFile): self.xsdFile = xsdFile self.dom = None self.elementMap = {} self.complexTypesMap = {} self.simpleTypesMap = {} self.groupsMap = {} self.attributeGroupsMap = {} try: self.dom = ZDom() self.dom.load(self.xsdFile) self.dom.setNamespaceMap(ZXhtmlSchema.XS_NSS_MAP) self._initMaps() except: pass def getSchemaFile(self): u"""Returns the schema xsd filename.""" #$NON-NLS-1$ return self.xsdFile # end getSchemaFile def getDocument(self): u"""Returns the schema xsd ZDom.""" #$NON-NLS-1$ return self.dom # end getDocument() def getAllElementNames(self): u"""Returns list of element names.""" #$NON-NLS-1$ return self.elementMap.keys() # end getAllElementNames() def isMixedType(self, aElementName): u"""Returns true if the element supports mixed typed (e.g. characters and elements).""" #$NON-NLS-1$ rVal = False ele = self._getElement(aElementName) if ele: complexEle = ele.selectSingleNode( u"descendant::xs:complexType") #$NON-NLS-1$ if complexEle: mixed = complexEle.getAttribute(u"mixed") #$NON-NLS-1$ rVal = mixed is not None and mixed.lower( ) == u"true" #$NON-NLS-1$ return rVal # end isMixedType() def getElementDocumentation(self, aElementName): u"""Returns documentation for element. """ #$NON-NLS-1$ rVal = None ele = self._getElement(aElementName) if ele: dEle = ele.selectSingleNode( u"descendant::xs:documentation") #$NON-NLS-1$ if dEle: rVal = dEle.getText() return rVal # end getElementDocumentation def getElementChildren(self, aParentElementName, bMixedTypeOnly=False): u"""Returns list of child element names given parent element name.""" #$NON-NLS-1$ rList = [] parentEle = self._getElement(aParentElementName) if parentEle: eleList = parentEle.selectNodes( u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) # complex tytpe extensions extList = parentEle.selectNodes( u"descendant::xs:extension") #$NON-NLS-1$ for ext in extList: rList.extend( self._getChildrenForComplexType( ext.getAttribute(u"base"), bMixedTypeOnly)) #$NON-NLS-1$ return rList # end getElementChildren() def _getChildrenForComplexType(self, aComplexTypeName, bMixedTypeOnly=False): u"""Returns list of child element names given complexType name.""" #$NON-NLS-1$ rList = [] if self.complexTypesMap.has_key(aComplexTypeName): complexEle = self.complexTypesMap[aComplexTypeName] eleList = complexEle.selectNodes( u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) groupList = complexEle.selectNodes( u"descendant::xs:group") #$NON-NLS-1$ for group in groupList: rList.extend( self._getChildrenForGroup(group.getAttribute(u"ref"), bMixedTypeOnly)) #$NON-NLS-1$ return rList # end _getChildrenForComplexType() def _getChildrenForGroup(self, aGroupName, bMixedTypeOnly=False): u"""Returns list of child element names given group name.""" #$NON-NLS-1$ rList = [] groupEle = self._getGroup(aGroupName) if groupEle: eleList = groupEle.selectNodes( u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) groupList = groupEle.selectNodes( u"descendant::xs:group") #$NON-NLS-1$ for group in groupList: rList.extend( self._getChildrenForGroup(group.getAttribute(u"ref"), bMixedTypeOnly)) #$NON-NLS-1$ return rList # end _getChildrenForGroup() def getElementAttributes(self, aElementName, bRequiredAttrOnly=False): u"""Returns list of attributes given element name.""" #$NON-NLS-1$ rList = [] ele = self._getElement(aElementName) if ele: rList.extend(self._getAttributesForElement(ele, bRequiredAttrOnly)) return rList # end getElementAttributes() def _getAttributesForElement(self, aElement, bRequiredAttrOnly=False): rList = [] # top level attributes attList = aElement.selectNodes( u"descendant::xs:attribute") #$NON-NLS-1$ for att in attList: if self._isSupportAttribute(att, bRequiredAttrOnly): rList.append(att.getAttribute(u"name")) #$NON-NLS-1$ # groups attList = aElement.selectNodes( u"descendant::xs:attributeGroup") #$NON-NLS-1$ for att in attList: rList.extend( self._getAttributesForGroup(att.getAttribute(u"ref"), bRequiredAttrOnly)) #$NON-NLS-1$ return rList # _getAttributesForElement() def _getAttributesForGroup(self, aAttrGroupName, bRequiredAttrOnly=False): rList = [] attGroupEle = self._getAttributeGroup(aAttrGroupName) if attGroupEle: # top level attributes attList = attGroupEle.selectNodes( u"descendant::xs:attribute") #$NON-NLS-1$ for att in attList: if self._isSupportAttribute(att, bRequiredAttrOnly): rList.append(att.getAttribute(u"name")) #$NON-NLS-1$ # groups attList = attGroupEle.selectNodes( u"descendant::xs:attributeGroup") #$NON-NLS-1$ for att in attList: rList.extend( self._getAttributesForGroup( att.getAttribute(u"ref"), bRequiredAttrOnly)) #$NON-NLS-1$ return rList # end _getAttributesForGroup() def _isRequiredAttribute(self, aAttrElement): # Returns true if required. return aAttrElement.getAttribute( u"use").lower() == u"required" #$NON-NLS-1$ #$NON-NLS-2$ # end _isRequiredAttribute() def _isSupportAttribute(self, aAttrElement, bRequiredAttrOnly=False): # skip Script type attributes (onBlur, onFocus) for the Joey editor. if bRequiredAttrOnly and not self._isRequiredAttribute(aAttrElement): return False return aAttrElement.getAttribute( u"type").lower() != u"script" #$NON-NLS-1$ #$NON-NLS-2$ # FIXME (PJ) : also skip for Coords, shape, # end _isSupportAttribute() def _isSupportedAttrGroup(self, aAttrGroupName): # skip events group (mouse up, onClick etc) for the Joey editor. return aAttrGroupName != u"events" #$NON-NLS-1$ # end _isSupportedAttrGroup() def _getElement(self, aElementName): # returns the element given name or None if not found. rVal = None if aElementName: aElementName = aElementName.strip().lower() if self.elementMap.has_key(aElementName): rVal = self.elementMap[aElementName] return rVal # end _getElement() def _getGroup(self, aGroupName): # returns the group element given name or None if not found. rVal = None if self.groupsMap.has_key(aGroupName): rVal = self.groupsMap[aGroupName] return rVal # end _getGroup() def _getAttributeGroup(self, aAttrGroupName): # returns the attribute group element given name or None if not found. rVal = None if aAttrGroupName and self._isSupportedAttrGroup( aAttrGroupName) and self.attributeGroupsMap.has_key( aAttrGroupName): rVal = self.attributeGroupsMap[aAttrGroupName] return rVal # end _getAttributeGroup() def _initMaps(self): u"""Initialized lookup maps.""" #$NON-NLS-1$ self.elementMap = {} eleList = self.getDocument().selectNodes(u"xs:element") #$NON-NLS-1$ for ele in eleList: self.elementMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.complexTypesMap = {} # Eg. Inline, Block, Flow, a.content, pre.content eleList = self.getDocument().selectNodes( u"xs:complexType") #$NON-NLS-1$ for ele in eleList: self.complexTypesMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.simpleTypesMap = {} # Eg ContentType,ContentTypes, URI, UriList eleList = self.getDocument().selectNodes( u"xs:simpleType") #$NON-NLS-1$ for ele in eleList: self.simpleTypesMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.groupsMap = {} # Eg. special.pre, special, fontstyle, phrase, heading, blocktext, block eleList = self.getDocument().selectNodes(u"xs:group") #$NON-NLS-1$ for ele in eleList: self.groupsMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.attributeGroupsMap = {} # Eg. coreattrs,i18n, attrs, events eleList = self.getDocument().selectNodes( u"xs:attributeGroup") #$NON-NLS-1$ for ele in eleList: self.attributeGroupsMap[ele.getAttribute( u"name")] = ele #$NON-NLS-1$
class ZSystemProperties: u"""Use this class to get and set System Properties.""" #$NON-NLS-1$ def __init__(self, sysPropsFileName): # create a lock for thread synchronization self.lock = ZMutex(u"ZSystemProperties") #$NON-NLS-1$ self.listeners = ZListenerSet() self.sysPropsFileName = sysPropsFileName self.sysPropsDoc = ZDom() self.reloadProperties() # end __init__() def addListener(self, listener): self.listeners.append(listener) # end addListener() def removeListener(self, listener): self.listeners.remove(listener) # end removeListener def _fireEvent(self, key, value): for listener in self.listeners: listener.onSystemPropertyChange(key, value) # end _fireEvent() def reloadProperties(self): self.lock.acquire() try: # Open and parse the system properties file self.sysPropsDoc.load(self.sysPropsFileName) finally: self.lock.release() # end reloadProperties() # Public method - call this to save the system properties. def save(self): u"Public method - call this to save the system properties." #$NON-NLS-1$ self.lock.acquire() self.saveProperties() self.lock.release() self._fireEvent(None, None) # end save() # Note that locking is required prior to calling saveProperties() def saveProperties(self): try: tempSysPropsFileName = self.sysPropsFileName + u".t" #$NON-NLS-1$ self.sysPropsDoc.save(tempSysPropsFileName, True) deleteFile(self.sysPropsFileName) renameFile(tempSysPropsFileName, self.sysPropsFileName) except Exception, e: raise ZException( _extstr(u"sysprops.ErrorSavingPropsFile") % self.sysPropsFileName, e) #$NON-NLS-1$
class ZXhtmlSchema(IZXhtmlSchema): XS_NSS_MAP = { u"xs" : u"http://www.w3.org/2001/XMLSchema" #$NON-NLS-1$ #$NON-NLS-2$ } def __init__(self, xsdFile): self.xsdFile = xsdFile self.dom = None self.elementMap = {} self.complexTypesMap = {} self.simpleTypesMap = {} self.groupsMap = {} self.attributeGroupsMap = {} try: self.dom = ZDom() self.dom.load(self.xsdFile) self.dom.setNamespaceMap(ZXhtmlSchema.XS_NSS_MAP) self._initMaps() except: pass def getSchemaFile(self): u"""Returns the schema xsd filename.""" #$NON-NLS-1$ return self.xsdFile # end getSchemaFile def getDocument(self): u"""Returns the schema xsd ZDom.""" #$NON-NLS-1$ return self.dom # end getDocument() def getAllElementNames(self): u"""Returns list of element names.""" #$NON-NLS-1$ return self.elementMap.keys() # end getAllElementNames() def isMixedType(self, aElementName): u"""Returns true if the element supports mixed typed (e.g. characters and elements).""" #$NON-NLS-1$ rVal = False ele = self._getElement(aElementName) if ele: complexEle = ele.selectSingleNode(u"descendant::xs:complexType") #$NON-NLS-1$ if complexEle: mixed = complexEle.getAttribute(u"mixed")#$NON-NLS-1$ rVal = mixed is not None and mixed.lower() == u"true" #$NON-NLS-1$ return rVal # end isMixedType() def getElementDocumentation(self, aElementName): u"""Returns documentation for element. """ #$NON-NLS-1$ rVal = None ele = self._getElement(aElementName) if ele: dEle = ele.selectSingleNode(u"descendant::xs:documentation") #$NON-NLS-1$ if dEle: rVal = dEle.getText() return rVal # end getElementDocumentation def getElementChildren(self, aParentElementName, bMixedTypeOnly=False): u"""Returns list of child element names given parent element name.""" #$NON-NLS-1$ rList = [] parentEle = self._getElement(aParentElementName) if parentEle: eleList = parentEle.selectNodes(u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) # complex tytpe extensions extList = parentEle.selectNodes(u"descendant::xs:extension") #$NON-NLS-1$ for ext in extList: rList.extend( self._getChildrenForComplexType(ext.getAttribute(u"base"), bMixedTypeOnly) ) #$NON-NLS-1$ return rList # end getElementChildren() def _getChildrenForComplexType(self, aComplexTypeName, bMixedTypeOnly=False): u"""Returns list of child element names given complexType name.""" #$NON-NLS-1$ rList = [] if self.complexTypesMap.has_key(aComplexTypeName): complexEle = self.complexTypesMap[aComplexTypeName] eleList = complexEle.selectNodes(u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) groupList = complexEle.selectNodes(u"descendant::xs:group") #$NON-NLS-1$ for group in groupList: rList.extend( self._getChildrenForGroup(group.getAttribute(u"ref"), bMixedTypeOnly) ) #$NON-NLS-1$ return rList # end _getChildrenForComplexType() def _getChildrenForGroup(self, aGroupName, bMixedTypeOnly=False): u"""Returns list of child element names given group name.""" #$NON-NLS-1$ rList = [] groupEle = self._getGroup(aGroupName) if groupEle: eleList = groupEle.selectNodes(u"descendant::xs:element") #$NON-NLS-1$ for ele in eleList: eleName = ele.getAttribute(u"ref") #$NON-NLS-1$ if not bMixedTypeOnly or (bMixedTypeOnly and self.isMixedType(eleName)): rList.append(eleName) groupList = groupEle.selectNodes(u"descendant::xs:group") #$NON-NLS-1$ for group in groupList: rList.extend( self._getChildrenForGroup(group.getAttribute(u"ref"), bMixedTypeOnly) ) #$NON-NLS-1$ return rList # end _getChildrenForGroup() def getElementAttributes(self, aElementName, bRequiredAttrOnly=False): u"""Returns list of attributes given element name.""" #$NON-NLS-1$ rList = [] ele = self._getElement(aElementName) if ele: rList.extend( self._getAttributesForElement(ele, bRequiredAttrOnly) ) return rList # end getElementAttributes() def _getAttributesForElement(self, aElement, bRequiredAttrOnly=False): rList = [] # top level attributes attList = aElement.selectNodes(u"descendant::xs:attribute") #$NON-NLS-1$ for att in attList: if self._isSupportAttribute(att, bRequiredAttrOnly): rList.append(att.getAttribute(u"name"))#$NON-NLS-1$ # groups attList = aElement.selectNodes(u"descendant::xs:attributeGroup") #$NON-NLS-1$ for att in attList: rList.extend( self._getAttributesForGroup(att.getAttribute(u"ref"), bRequiredAttrOnly) ) #$NON-NLS-1$ return rList # _getAttributesForElement() def _getAttributesForGroup(self, aAttrGroupName, bRequiredAttrOnly=False): rList = [] attGroupEle = self._getAttributeGroup(aAttrGroupName) if attGroupEle: # top level attributes attList = attGroupEle.selectNodes(u"descendant::xs:attribute") #$NON-NLS-1$ for att in attList: if self._isSupportAttribute(att, bRequiredAttrOnly): rList.append(att.getAttribute(u"name")) #$NON-NLS-1$ # groups attList = attGroupEle.selectNodes(u"descendant::xs:attributeGroup") #$NON-NLS-1$ for att in attList: rList.extend( self._getAttributesForGroup(att.getAttribute(u"ref"), bRequiredAttrOnly) ) #$NON-NLS-1$ return rList # end _getAttributesForGroup() def _isRequiredAttribute(self, aAttrElement): # Returns true if required. return aAttrElement.getAttribute(u"use").lower() == u"required" #$NON-NLS-1$ #$NON-NLS-2$ # end _isRequiredAttribute() def _isSupportAttribute(self, aAttrElement, bRequiredAttrOnly=False): # skip Script type attributes (onBlur, onFocus) for the Joey editor. if bRequiredAttrOnly and not self._isRequiredAttribute(aAttrElement): return False return aAttrElement.getAttribute(u"type").lower() != u"script" #$NON-NLS-1$ #$NON-NLS-2$ # FIXME (PJ) : also skip for Coords, shape, # end _isSupportAttribute() def _isSupportedAttrGroup(self, aAttrGroupName): # skip events group (mouse up, onClick etc) for the Joey editor. return aAttrGroupName != u"events" #$NON-NLS-1$ # end _isSupportedAttrGroup() def _getElement(self, aElementName): # returns the element given name or None if not found. rVal = None if aElementName: aElementName = aElementName.strip().lower() if self.elementMap.has_key(aElementName): rVal = self.elementMap[aElementName] return rVal # end _getElement() def _getGroup(self, aGroupName): # returns the group element given name or None if not found. rVal = None if self.groupsMap.has_key(aGroupName): rVal = self.groupsMap[aGroupName] return rVal # end _getGroup() def _getAttributeGroup(self, aAttrGroupName): # returns the attribute group element given name or None if not found. rVal = None if aAttrGroupName and self._isSupportedAttrGroup(aAttrGroupName) and self.attributeGroupsMap.has_key(aAttrGroupName): rVal = self.attributeGroupsMap[aAttrGroupName] return rVal # end _getAttributeGroup() def _initMaps(self): u"""Initialized lookup maps.""" #$NON-NLS-1$ self.elementMap = {} eleList = self.getDocument().selectNodes(u"xs:element") #$NON-NLS-1$ for ele in eleList: self.elementMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.complexTypesMap = {} # Eg. Inline, Block, Flow, a.content, pre.content eleList = self.getDocument().selectNodes(u"xs:complexType") #$NON-NLS-1$ for ele in eleList: self.complexTypesMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.simpleTypesMap = {} # Eg ContentType,ContentTypes, URI, UriList eleList = self.getDocument().selectNodes(u"xs:simpleType") #$NON-NLS-1$ for ele in eleList: self.simpleTypesMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.groupsMap = {} # Eg. special.pre, special, fontstyle, phrase, heading, blocktext, block eleList = self.getDocument().selectNodes(u"xs:group") #$NON-NLS-1$ for ele in eleList: self.groupsMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$ self.attributeGroupsMap = {} # Eg. coreattrs,i18n, attrs, events eleList = self.getDocument().selectNodes(u"xs:attributeGroup") #$NON-NLS-1$ for ele in eleList: self.attributeGroupsMap[ele.getAttribute(u"name")] = ele #$NON-NLS-1$