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 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 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 _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 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
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 _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 _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 _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 _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 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()