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 serialize(self, entry): dom = ZDom() dom.loadXML(u"<resource-entry xmlns='%s' />" % self.namespace) #$NON-NLS-1$ root = dom.documentElement root.setAttribute(u"id", entry.getId()) #$NON-NLS-1$ self._serializeAttributes(entry,root) return dom
def _serializeResponseInfo(self, metaFile, connectionRespInfo, dataFilename): dom = ZDom() dom.loadXML(u"""<http-connection-response />""") #$NON-NLS-1$ rootElem = dom.documentElement urlElem = dom.createElement(u"url") #$NON-NLS-1$ urlElem.setText(connectionRespInfo.getURL()) rootElem.appendChild(urlElem) dataFileElem = dom.createElement(u"data-file") #$NON-NLS-1$ dataFileElem.setText(dataFilename) rootElem.appendChild(dataFileElem) respCodeElem = dom.createElement(u"response-code") #$NON-NLS-1$ respCodeElem.setText(unicode(connectionRespInfo.getCode())) rootElem.appendChild(respCodeElem) respMsgElem = dom.createElement(u"response-message") #$NON-NLS-1$ respMsgElem.setText(unicode(connectionRespInfo.getMessage())) rootElem.appendChild(respMsgElem) headersElem = dom.createElement(u"response-headers") #$NON-NLS-1$ rootElem.appendChild(headersElem) for headerName in connectionRespInfo.getHeaders(): headerVal = connectionRespInfo.getHeader(headerName) headerElem = dom.createElement(u"header") #$NON-NLS-1$ headerElem.setAttribute(u"name", headerName) #$NON-NLS-1$ headerElem.setText(headerVal) headersElem.appendChild(headerElem) dom.save(metaFile, True)
def _getAddProductPostDataForUrl(self, productUrl, zoundryServiceId): dom = ZDom(ADD_PRODUCT_REQUEST) dom.selectSingleNode(u"/Request/Authorization/Username").setText( zoundryServiceId) #$NON-NLS-1$ dom.selectSingleNode(u"/Request/AddProducts/Product/Url").setText( productUrl) #$NON-NLS-1$ return dom.serialize(True)
def createHtmlElement(parentElement, elementName, attrMap={}, elementText=None): u"""createHtmlElement(Node, string, map, string) -> Node Creates a element given element name, attribute map and optional element node text. If the parentElement node is None, then element is under new document (zdom). """ #$NON-NLS-1$ element = None elementName = getNoneString(elementName) elementText = getNoneString(elementText) if not elementName: return None dom = None if parentElement: dom = parentElement.ownerDocument else: dom = ZDom() dom.loadXML(ELEMENT_TEMPLATE) parentElement = dom.documentElement try: element = dom.createElement(elementName) parentElement.appendChild(element) for (n, v) in attrMap.iteritems(): if n and v: element.setAttribute(n, v) if elementText: element.setText(elementText) except: pass return element
def _process(self): xhtmlDocument = self._getContext().getXhtmlDocument() pubMetaData = self._getContext().getPubMetaData() if not pubMetaData or not pubMetaData.isAddPoweredBy(): return bodyNode = xhtmlDocument.getDom().selectSingleNode( u"xhtml:body") #$NON-NLS-1$ pNL = bodyNode.selectNodes( u"//xhtml:p[@class='poweredbyzoundry']") #$NON-NLS-1$ if pNL and len(pNL) > 0 and pNL[-1]: # FIXME (PJ) check if the 'Zoundry BW' if so, change to 'Raven'. # grab the last para from the list # do we have a link to Zoundry? aLinkNode = pNL[-1].selectSingleNode( u"xhtml:a[@class='poweredbyzoundry_link']") #$NON-NLS-1$ if aLinkNode: href = aLinkNode.getAttribute(u"href") #$NON-NLS-1$ if href and href.find(u"zoundry.com") != -1: #$NON-NLS-1$ # we already have a link. return # No link. Continue and add a link in a new para to the end of the post xhtml = u'<p class="poweredbyzoundry">Powered by <a class="poweredbyzoundry_link" href="http://www.zoundryraven.com" rel="nofollow">Zoundry Raven</a></p>' #$NON-NLS-1$ newDom = ZDom() newDom.loadXML(xhtml) poweredbyParaNode = xhtmlDocument.getDom().importNode( newDom.documentElement, True) bodyNode.appendChild(poweredbyParaNode)
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 _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 __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()
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 serialize(self, template): templateDom = ZDom() templateDom.loadXML(u"<template xmlns='%s' />" % self.namespace) #$NON-NLS-1$ templateElem = templateDom.documentElement templateElem.setAttribute(u"template-id", template.getId()) #$NON-NLS-1$ self._serializeTemplate(templateElem, template) self._saveDom(templateDom, template.getTemplateDirectory())
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 clone(self): u"""clone() -> ZXhtmlDocument() Returns copy based on cloning the underlying ZDom instance for this document.""" #$NON-NLS-1$ newDom = ZDom() newDom.loadXML(self.dom.serialize()) newDom.setNamespaceMap(XHTML_NSS_MAP) xhtmlDoc = ZXhtmlDocument(newDom) xhtmlDoc.docTypeString = self.docTypeString xhtmlDoc.mRootAbsPath = self.mRootAbsPath return xhtmlDoc
def enableMasterDebugLoggerOutput(self, bEnable): exists = self.outputMap.has_key(u"Master Debug Log File") #$NON-NLS-1$ if not exists and bEnable: dom = ZDom() dom.loadXML(MASTER_DEBUG_FILE_LOGGER_TEMPLATE) self._addLogOutput(dom.documentElement) elif exists and not bEnable: output = self.outputMap.pop(u"Master Debug Log File") #$NON-NLS-1$ if output: output.close()
def enableConsoleDebugLoggerOutput(self, bEnable): exists = self.outputMap.has_key(u"Console Logger") #$NON-NLS-1$ if not exists and bEnable: dom = ZDom() dom.loadXML(CONSOLE_LOGGER_TEMPLATE) self._addLogOutput(dom.documentElement) elif exists and not bEnable: output = self.outputMap.pop(u"Console Logger") #$NON-NLS-1$ if output: output.close()
def enableEclipsePluginLoggerOutput(self, bEnable): exists = self.outputMap.has_key(u"Eclipse Console") #$NON-NLS-1$ if not exists and bEnable: dom = ZDom() dom.loadXML(ECLIPSE_PLUGIN_LOGGER_TEMPLATE) self._addLogOutput(dom.documentElement) elif exists and not bEnable: output = self.outputMap.pop(u"Eclipse Console") #$NON-NLS-1$ if output: output.close()
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 _doHandleError(self, url, dndContext): ZShowInfoMessage( dndContext.getWindow(), _extstr(u"commonvideo.ErrorDiscoveringVideoEmbedInfoMsg"), _extstr(u"commonvideo.ErrorDiscoveringVideoEmbedInfoTitle" )) #$NON-NLS-2$ #$NON-NLS-1$ dom = ZDom() dom.loadXML(u"<a href='' />") #$NON-NLS-1$ dom.documentElement.setAttribute(u"href", url) #$NON-NLS-1$ dom.documentElement.setText(url) return dom.serialize()
def _createDocument(self, rootName = u"root"): #$NON-NLS-1$ u"""Creates the zdom document.""" #$NON-NLS-1$ dom = ZDom() params = { u"prefix" : self.prefix, #$NON-NLS-1$ u"root" : rootName, #$NON-NLS-1$ u"namespace" : self.namespace #$NON-NLS-1$ } xml = u"""<%(prefix)s:%(root)s xmlns:%(prefix)s="%(namespace)s" />""" % params #$NON-NLS-1$ dom.loadHTML(xml) return dom
def _extractEmbedMarkup(self, xhtmlReq): resp = xhtmlReq.getResponse() match = EMBED_PATTERN.search(resp) if match is not None: inputMarkup = match.group(1) dom = ZDom() dom.loadXML(inputMarkup) embedStr = dom.documentElement.getAttribute(u"value") #$NON-NLS-1$ return embedStr else: return None
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 serialize(self, task): taskDom = ZDom() taskDom.loadXML(u"<task xmlns='%s' />" % IZAppNamespaces.RAVEN_TASK_NAMESPACE_2006_05) #$NON-NLS-1$ taskElem = taskDom.documentElement taskElem.setAttribute(u"task-id", task.getId()) #$NON-NLS-1$ taskElem.setAttribute(u"class", unicode(task.__class__)) #$NON-NLS-1$ self._serializeStandardAttributes(task, taskElem) self._serializeError(task, taskElem) self._serializeCustomAttributes(task, taskElem) return taskDom
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 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 _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 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 serialize(self, account): accountDom = ZDom() accountDom.loadXML(u"<account xmlns='%s' />" % self.namespace) #$NON-NLS-1$ accountElem = accountDom.documentElement accountElem.setAttribute(u"type", u"weblog") #$NON-NLS-2$ #$NON-NLS-1$ accountElem.setAttribute(u"account-id", account.getId()) #$NON-NLS-1$ self._serializeAttributes(account, accountElem) self._serializeAPIInfo(account.getAPIInfo(), accountElem) self._serializeBlogs(account.getBlogs(), accountElem) self._saveDom(accountDom, account.getDirectoryPath())
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 serialize(self, store): storeDom = ZDom() storeDom.loadXML(u"<store xmlns='%s' />" % self.namespace) #$NON-NLS-1$ storeElem = storeDom.documentElement storeElem.setAttribute(u"store-id", store.getId()) #$NON-NLS-1$ storeElem.setAttribute(u"media-site-id", store.getMediaSiteId()) #$NON-NLS-1$ storeElem.setAttribute(u"name", store.getName()) #$NON-NLS-1$ self._serializeProperties(store.getProperties(), storeElem) return storeDom