Esempio n. 1
0
    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
Esempio n. 2
0
 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()
Esempio n. 3
0
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
Esempio n. 4
0
 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
Esempio n. 5
0
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
Esempio n. 6
0
    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)
Esempio n. 7
0
 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)
Esempio n. 8
0
    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
Esempio n. 9
0
 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
Esempio n. 10
0
 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
Esempio n. 11
0
 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
Esempio n. 12
0
    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()
Esempio n. 13
0
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$
Esempio n. 14
0
 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
Esempio n. 15
0
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)
Esempio n. 16
0
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$
Esempio n. 17
0
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
Esempio n. 18
0
    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())
Esempio n. 19
0
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)
Esempio n. 20
0
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)
Esempio n. 21
0
 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
Esempio n. 22
0
 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()
Esempio n. 23
0
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$
Esempio n. 24
0
 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()
Esempio n. 25
0
 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()
Esempio n. 26
0
 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()
Esempio n. 27
0
 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()
Esempio n. 28
0
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$
Esempio n. 29
0
 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()
Esempio n. 30
0
 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
Esempio n. 31
0
    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
Esempio n. 32
0
 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
Esempio n. 33
0
 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
Esempio n. 34
0
 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()
Esempio n. 35
0
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$
Esempio n. 36
0
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$
Esempio n. 37
0
 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
Esempio n. 38
0
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$
Esempio n. 39
0
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$
Esempio n. 40
0
    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
Esempio n. 41
0
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)
Esempio n. 42
0
    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())
Esempio n. 43
0
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$
Esempio n. 44
0
 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)
Esempio n. 45
0
    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())
Esempio n. 46
0
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$
Esempio n. 47
0
    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
Esempio n. 48
0
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$
Esempio n. 49
0
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$
Esempio n. 50
0
 def _createTagsPNode(self, linkFormatterList, listOfWords):
     allSitesHtml = u""  #$NON-NLS-1$
     count = 0
     for formatter in linkFormatterList:
         tagHtml = self._createTagSiteHtml(formatter, listOfWords)
         allSitesHtml = allSitesHtml + tagHtml
         count = count + 1
         if len(linkFormatterList) > 1 and count < len(linkFormatterList):
             allSitesHtml = allSitesHtml + u" <br/>\n "  #$NON-NLS-1$
     html = ZAddTagwordsPrePublishHandler.TAGS_TEMPLATE % allSitesHtml
     html = html.replace(u'&', u'&amp;')  #$NON-NLS-1$ #$NON-NLS-2$
     newDom = ZDom()
     newDom.loadXML(html)
     return newDom.documentElement
Esempio n. 51
0
    def serialize(self, document, serializationContext):
        documentDom = ZDom()
        documentDom.loadXML(u"<entry xmlns='%s' />" %
                            self.namespace)  #$NON-NLS-1$

        entryElem = documentDom.documentElement
        entryElem.setAttribute(u"entry-id", document.getId())  #$NON-NLS-1$
        self._serializeAttributes(document, entryElem)
        self._serializeBlogs(document.getBlogInfoList(), entryElem)
        self._serializePubMetaData(document.getPubMetaDataList(), entryElem)
        self._serializeTagwords(document.getTagwordsList(), entryElem)
        self._serializeContent(document.getContent(), entryElem,
                               serializationContext)
        self._serializeTrackbacks(document.getTrackbacks(), entryElem)
        return documentDom
Esempio n. 52
0
    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
Esempio n. 53
0
    def readDnDSource(self, stgMedium):
        fmtstring = unicode(len(stgMedium.data)) + u"s"  #$NON-NLS-1$
        dataTuple = unpack(fmtstring, stgMedium.data)
        cfhtml = dataTuple[0]
        html = self._decodeCfHtml(cfhtml)
        htmlDom = ZDom()
        rootNode = None
        try:
            htmlDom.loadHTML(html)
            rootNode = htmlDom.selectSingleNode(u"/*")  #$NON-NLS-1$
        except:
            # Probably an encoding problem of some sort - just
            # return None (we are going to let IE handle it anyway)
            pass

        return ZHtmlDnDSource(rootNode)
Esempio n. 54
0
 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)