Esempio n. 1
0
    def trim(self):
        xhtmlDoc = loadXhtmlDocumentFromFile(self._getRootFile())
        xhtmlDom = xhtmlDoc.getDom()
        vizzy = ZTemplateBodyFindingVisitor()
        vizzy.visit(xhtmlDom)
        elem = vizzy.getResult()
        if elem is None:
            raise ZException(u"Failed to find Raven template marker content.")  # $NON-NLS-1$

        self._doTrim(elem)
        self._save(xhtmlDom)
Esempio n. 2
0
    def trim(self):
        xhtmlDoc = loadXhtmlDocumentFromFile(self._getRootFile())
        xhtmlDom = xhtmlDoc.getDom()
        vizzy = ZTemplateBodyFindingVisitor()
        vizzy.visit(xhtmlDom)
        elem = vizzy.getResult()
        if elem is None:
            raise ZException(
                u"Failed to find Raven template marker content.")  #$NON-NLS-1$

        self._doTrim(elem)
        self._save(xhtmlDom)
Esempio n. 3
0
 def createXhtmlDocument(self):
     u"""createXhtmlDocument() -> ZXhtmlDocument"""  #$NON-NLS-1$
     file = getSafeString(self.izBlogThisInformation.getFile())
     xhtmlDom = None
     if os.path.exists(file):
         try:
             xhtmlDom = loadXhtmlDocumentFromFile(file)
             return xhtmlDom
         except:
             pass
     # create new doc since file content was not found
     title = getSafeString(self.izBlogThisInformation.getTitle())
     htmlString = u"<html><head><title>%s</title></head><body></body></html>" % title  #$NON-NLS-1$
     xhtmlDoc = loadXhtmlDocumentFromString(htmlString)
     bodyNode = xhtmlDoc.getBody()
     self._createXhtmlContent(bodyNode)
     return xhtmlDoc
Esempio n. 4
0
 def createXhtmlDocument(self):
     u"""createXhtmlDocument() -> ZXhtmlDocument""" #$NON-NLS-1$
     file = getSafeString( self.izBlogThisInformation.getFile() )
     xhtmlDom = None
     if os.path.exists(file):
         try:
             xhtmlDom = loadXhtmlDocumentFromFile(file)
             return xhtmlDom
         except:
             pass
     # create new doc since file content was not found
     title = getSafeString( self.izBlogThisInformation.getTitle() )
     htmlString = u"<html><head><title>%s</title></head><body></body></html>" % title #$NON-NLS-1$
     xhtmlDoc = loadXhtmlDocumentFromString(htmlString)
     bodyNode = xhtmlDoc.getBody()
     self._createXhtmlContent(bodyNode)
     return xhtmlDoc
Esempio n. 5
0
    def _fetchTemplate(self, url, title, bodyStr):
        templateService = getApplicationModel().getService(
            IZBlogAppServiceIDs.TEMPLATE_SERVICE_ID)
        template = templateService.createTemplate()
        templateDir = template.getTemplateDirectory()
        try:
            webPageGetter = ZHttpWebpageGetter(url, templateDir, self)
            webPageGetter.setBasePathToken(
                IZTemplateConstants.TEMPLATE_BASE_TOKEN)
            rootFilePath = webPageGetter.saveAsWebpage()
            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            rootXHtmlDoc = loadXhtmlDocumentFromFile(rootFilePath)
            rootXHtmlDom = rootXHtmlDoc.getDom()
            titleElems = self._findTitleElems(rootXHtmlDom, title)
            if not titleElems:
                return None
            contentElems = self._findContentElems(rootXHtmlDom, bodyStr)
            if not contentElems:
                return None

            indexAllUTFileName = os.path.join(
                templateDir, u"index-all-untrimmed.html")  #$NON-NLS-1$
            rootXHtmlDom.save(indexAllUTFileName)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            for titleElem in titleElems:
                titleElem.removeAllChildren()
                titleMarkerElem = rootXHtmlDom.createElement(
                    u"ravenTitle", titleElem.getNamespaceUri())  #$NON-NLS-1$
                titleElem.appendChild(titleMarkerElem)

            for contentElem in contentElems:
                contentElem.removeAllChildren()
                contentMarkerElem = rootXHtmlDom.createElement(
                    u"ravenBody", contentElem.getNamespaceUri())  #$NON-NLS-1$
                contentElem.appendChild(contentMarkerElem)

            rootFile = makeRelativePath(templateDir, rootFilePath)
            indexAllFileName = u"index-all.html"  #$NON-NLS-1$
            indexBodyOnlyFileName = u"index-body.html"  #$NON-NLS-1$
            indexTitleAndBodyFileName = u"index-titleBody.html"  #$NON-NLS-1$

            template.setRootFileName(rootFile)
            template.setAllFileName(indexAllFileName)
            template.setBodyOnlyFileName(indexBodyOnlyFileName)
            template.setTitleAndBodyFileName(indexTitleAndBodyFileName)

            indexAll = os.path.join(templateDir, indexAllFileName)
            indexTitleAndBody = os.path.join(templateDir,
                                             indexTitleAndBodyFileName)
            indexBodyOnly = os.path.join(templateDir, indexBodyOnlyFileName)

            self.listener.grabFeedback(
                _extstr(u"templategrabber.TemplateDownloaded_Trimming")
            )  #$NON-NLS-1$

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Save the 'all' variant
            rootXHtmlDom.save(indexAll)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Trim the dom - remove everything except the title and body
            self._trimStageOne(titleElems, contentElems)
            rootXHtmlDom.save(indexTitleAndBody)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Trim the dom again - remove everything except the body
            self._trimStageTwo(contentElems)
            rootXHtmlDom.save(indexBodyOnly)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            self.listener.grabFeedback(
                _extstr(
                    u"templategrabber.TemplateTrimmedAndSaved"))  #$NON-NLS-1$

            return template
        except Exception, e:
            getLoggerService().exception(e)
            deleteDirectory(templateDir, True)
            raise e
Esempio n. 6
0
 def _populateContentWidgets(self):
     xhtmlDoc = loadXhtmlDocumentFromFile(
         getResourceRegistry().getResourcePath(
             u"html/about/credits.html"))  #$NON-NLS-1$
     self.htmlWidget.setXhtmlDocument(xhtmlDoc)
Esempio n. 7
0
    def _fetchTemplate(self, url, title, bodyStr):
        templateService = getApplicationModel().getService(IZBlogAppServiceIDs.TEMPLATE_SERVICE_ID)
        template = templateService.createTemplate()
        templateDir = template.getTemplateDirectory()
        try:
            webPageGetter = ZHttpWebpageGetter(url, templateDir, self)
            webPageGetter.setBasePathToken(IZTemplateConstants.TEMPLATE_BASE_TOKEN)
            rootFilePath = webPageGetter.saveAsWebpage()
            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            rootXHtmlDoc = loadXhtmlDocumentFromFile(rootFilePath)
            rootXHtmlDom = rootXHtmlDoc.getDom()
            titleElems = self._findTitleElems(rootXHtmlDom, title)
            if not titleElems:
                return None
            contentElems = self._findContentElems(rootXHtmlDom, bodyStr)
            if not contentElems:
                return None

            indexAllUTFileName = os.path.join(templateDir, u"index-all-untrimmed.html") #$NON-NLS-1$
            rootXHtmlDom.save(indexAllUTFileName)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            for titleElem in titleElems:
                titleElem.removeAllChildren()
                titleMarkerElem = rootXHtmlDom.createElement(u"ravenTitle", titleElem.getNamespaceUri()) #$NON-NLS-1$
                titleElem.appendChild(titleMarkerElem)

            for contentElem in contentElems:
                contentElem.removeAllChildren()
                contentMarkerElem = rootXHtmlDom.createElement(u"ravenBody", contentElem.getNamespaceUri()) #$NON-NLS-1$
                contentElem.appendChild(contentMarkerElem)

            rootFile = makeRelativePath(templateDir, rootFilePath)
            indexAllFileName = u"index-all.html" #$NON-NLS-1$
            indexBodyOnlyFileName = u"index-body.html" #$NON-NLS-1$
            indexTitleAndBodyFileName = u"index-titleBody.html" #$NON-NLS-1$

            template.setRootFileName(rootFile)
            template.setAllFileName(indexAllFileName)
            template.setBodyOnlyFileName(indexBodyOnlyFileName)
            template.setTitleAndBodyFileName(indexTitleAndBodyFileName)

            indexAll = os.path.join(templateDir, indexAllFileName)
            indexTitleAndBody = os.path.join(templateDir, indexTitleAndBodyFileName)
            indexBodyOnly = os.path.join(templateDir, indexBodyOnlyFileName)

            self.listener.grabFeedback(_extstr(u"templategrabber.TemplateDownloaded_Trimming")) #$NON-NLS-1$

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Save the 'all' variant
            rootXHtmlDom.save(indexAll)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Trim the dom - remove everything except the title and body
            self._trimStageOne(titleElems, contentElems)
            rootXHtmlDom.save(indexTitleAndBody)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            # Trim the dom again - remove everything except the body
            self._trimStageTwo(contentElems)
            rootXHtmlDom.save(indexBodyOnly)

            if self.cancelled:
                raise ZTemplateFetchCancelledException()

            self.listener.grabFeedback(_extstr(u"templategrabber.TemplateTrimmedAndSaved")) #$NON-NLS-1$

            return template
        except Exception, e:
            getLoggerService().exception(e)
            deleteDirectory(templateDir, True)
            raise e
Esempio n. 8
0
 def _populateContentWidgets(self):
     xhtmlDoc = loadXhtmlDocumentFromFile(getResourceRegistry().getResourcePath(u"html/about/credits.html")) #$NON-NLS-1$
     self.htmlWidget.setXhtmlDocument(xhtmlDoc)