def _deserializeContent(self, documentDom, document, deserializationContext): contentNode = documentDom.selectSingleNode(u"/zns:entry/zns:content") #$NON-NLS-1$ # Handle the Case of the Missing Content if not contentNode: xhtmlDoc = loadXhtmlDocumentFromString(u"") #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(u"xml") #$NON-NLS-1$ content.setType(u"application/xhtml+xml") #$NON-NLS-1$ content.setXhtmlDocument(xhtmlDoc) document.setContent(content) return self._processContent(contentNode, deserializationContext) mode = contentNode.getAttribute(u"mode") #$NON-NLS-1$ type = contentNode.getAttribute(u"type") #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(mode) content.setType(type) if mode == u"xml": #$NON-NLS-1$ xhtmlNode = contentNode.selectSingleNode(u"*") #$NON-NLS-1$ xhtmlDoc = loadXhtmlDocumentFromDOM(xhtmlNode) content.setXhtmlDocument(xhtmlDoc) elif mode == u"escaped": #$NON-NLS-1$ htmlText = contentNode.getText() xhtmlDoc = loadXhtmlDocumentFromString(htmlText) content.setXhtmlDocument(xhtmlDoc) else: raise ZBlogAppException(_extstr(u"deserializers.NoContentModeFoundError")) #$NON-NLS-1$ document.setContent(content)
def _visitBodyDispatchElement(self, mshtmlBodyElement): #@UnusedVariable self.mshtmlBodyElement = mshtmlBodyElement eleList = self.mshtmlBodyElement.getElementsByTagName(u"OBJECT") #$NON-NLS-1$ for ele in eleList: if getNoneString(ele.classid) is not None: #$NON-NLS-1$ # Class ID already defined. Skip! continue # 1. Lookup <embed> child element # 2. If child <embed> element is application/x-shockwave-flash, then remove OBJECT elem wrapper # The problem is, IE does not parse <embed> as an element. Instead, it is represented as OBJECT nodes' text. # Work around is to do load the content into ZDOm and select embed elem. content = getNoneString(ele.outerHTML) if not content: continue xhtmlDoc = loadXhtmlDocumentFromString(content) dom = xhtmlDoc.getDom() embed = dom.selectSingleNode(u"//xhtml:embed") #$NON-NLS-1$ #$NON-NLS-1$ if not embed: continue if embed.getAttribute(u"type") == u"application/x-shockwave-flash": #$NON-NLS-1$ #$NON-NLS-2$ embedNode = self.mshtmlDoc.createElement(u"embed") #$NON-NLS-1$ ele.insertAdjacentElement(u"AfterEnd",embedNode) #$NON-NLS-1$ embedEle = getDispElement(embedNode) for attrNode in embed.getAttributes(): embedEle.setAttribute( attrNode.nodeName, attrNode.getText() ) ele.parentNode.removeChild(ele) classes = getSafeString(ele.getAttribute(u"className")).split(u" ") #$NON-NLS-1$ #$NON-NLS-2$ if not u"_Z_RAVEN_OBJECT_WRAPPER_" in classes: #$NON-NLS-1$ classes.append(u"_Z_RAVEN_OBJECT_WRAPPER_") #$NON-NLS-1$ embedEle.setAttribute(u"className", u" ".join(classes).strip() ) #$NON-NLS-2$ #$NON-NLS-1$ return False
def findDependencies(self): u"""findDependencies() -> ZResourceDependency[]""" #$NON-NLS-1$ xhtmlDoc = loadXhtmlDocumentFromString(self.xhtml) self.baseHref = xhtmlDoc.getBaseHref() # Find images for image in xhtmlDoc.getImages(): if image.getSrc(): self.dependencies.append( ZResourceDependency(IZResourceDependencyTypes.IMAGE, image.getSrc())) # Find CSS stylesheets for stylesheet in xhtmlDoc.getStylesheets(): if stylesheet.getHref(): self.dependencies.append( ZResourceDependency(IZResourceDependencyTypes.CSS, stylesheet.getHref())) # Find scripts for script in xhtmlDoc.getScripts(): if script.getSrc(): self.dependencies.append( ZResourceDependency(IZResourceDependencyTypes.SCRIPT, script.getSrc())) # Now find some stuff that the regular analysers miss (in-line CSS) xhtmlDoc.analyse(self) return self.dependencies
def _handleNoThumbnail(self, dndSource): html = u"<p>"; #$NON-NLS-1$ fileNames = dndSource.getData() for fileName in fileNames: frag = self._createNoThumbnailHtmlFragString(fileName) html = html + frag + u"<br/>" #$NON-NLS-1$ html = html + u"</p>" #$NON-NLS-1$ return loadXhtmlDocumentFromString(html)
def _createRavenContent(self, serverContent): # Created and return xhtml content in IZDocumentContent. # content holder. zdocContent = ZXhtmlContent() zdocContent.setType(u"application/xhtml+xml") #$NON-NLS-1$ zdocContent.setMode(u"xml") #$NON-NLS-1$ xhtmlDoc = loadXhtmlDocumentFromString(serverContent) zdocContent.setXhtmlDocument(xhtmlDoc) return zdocContent
def refresh(self): self.templateList.refresh() self.statusBar.refresh() if self.selectedTemplate is not None: document = self.model.getSampleDocument() xhtmlDoc = applyTemplateToDocument(self.selectedTemplate, document, APPLY_TEMPLATE_MODE_FULL) disableTemplatePreviewJavaScript(xhtmlDoc) else: xhtmlDoc = loadXhtmlDocumentFromString(u"Select a template to view a preview of it.") #$NON-NLS-1$ self.preview.setXhtmlDocument(xhtmlDoc, False)
def pasteXhtml(self): # get text from clipboard and insert xhtml content = getTextFromClipboard() if content: xhtmlDoc = loadXhtmlDocumentFromString(content) if xhtmlDoc: html = u"" #$NON-NLS-1$ for node in xhtmlDoc.getBody().selectNodes(u"child::*"): #$NON-NLS-1$ html = html + node.serialize() self._insertHtml(html, 0)
def _getContentBodyNode(self, content): # returns zdom ZNode representing xhtml:body given html string, ZDom or ZHtmlDocument object. bodyNode = None if isinstance(content, basestring): content = loadXhtmlDocumentFromString(content) if isinstance(content, ZXhtmlDocument): bodyNode = content.getBody() elif isinstance(content, ZDom): content.setNamespaceMap(XHTML_NSS_MAP) bodyNode = content.selectSingleNode(u"//xhtml:body") #$NON-NLS-1$ return bodyNode
def pasteXhtml(self): # get text from clipboard and insert xhtml content = getTextFromClipboard() if content: xhtmlDoc = loadXhtmlDocumentFromString(content) if xhtmlDoc: html = u"" #$NON-NLS-1$ for node in xhtmlDoc.getBody().selectNodes( u"child::*"): #$NON-NLS-1$ html = html + node.serialize() self._insertHtml(html, 0)
def appendHtmlFragment(parentNode, htmlFragString): u"""appendHtmlFragment(Node, string) -> Node Deserializes the htmlFragString into an Node and appends it to the parent Node """ #$NON-NLS-1$ try: xhtmlFragDoc = loadXhtmlDocumentFromString(htmlFragString) fragNode = parentNode.ownerDocument.importNode(xhtmlFragDoc.getBody(), True) parentNode.appendChild(fragNode) return parentNode except: return None
def _deserializeContent(self, documentDom, document, deserializationContext): contentNode = documentDom.selectSingleNode( u"/zns:entry/zns:content") #$NON-NLS-1$ # Handle the Case of the Missing Content if not contentNode: xhtmlDoc = loadXhtmlDocumentFromString(u"") #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(u"xml") #$NON-NLS-1$ content.setType(u"application/xhtml+xml") #$NON-NLS-1$ content.setXhtmlDocument(xhtmlDoc) document.setContent(content) return self._processContent(contentNode, deserializationContext) mode = contentNode.getAttribute(u"mode") #$NON-NLS-1$ type = contentNode.getAttribute(u"type") #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(mode) content.setType(type) if mode == u"xml": #$NON-NLS-1$ xhtmlNode = contentNode.selectSingleNode(u"*") #$NON-NLS-1$ xhtmlDoc = loadXhtmlDocumentFromDOM(xhtmlNode) content.setXhtmlDocument(xhtmlDoc) elif mode == u"escaped": #$NON-NLS-1$ htmlText = contentNode.getText() xhtmlDoc = loadXhtmlDocumentFromString(htmlText) content.setXhtmlDocument(xhtmlDoc) else: raise ZBlogAppException( _extstr( u"deserializers.NoContentModeFoundError")) #$NON-NLS-1$ document.setContent(content)
def Drop(self, dataObject, keyState, point, effect): # If we are handling the drop, then do it. if self.handled: handler = self.handlers[0] context = ZDnDContext(self.mshtml) xhtmlDoc = handler.handle(self.dndSource, context) if xhtmlDoc is not None: if isinstance(xhtmlDoc, str) or isinstance(xhtmlDoc, unicode): xhtmlDoc = loadXhtmlDocumentFromString(xhtmlDoc) self.mshtml.onDnDDrop(xhtmlDoc) return S_OK # If we are not handling it, then let IE do the drop. return self.oldDropTarget.Drop(dataObject, keyState, point, effect)
def _createDocument(self): document = ZBlogDocument() document.setTitle(u"RAVEN_TEMPLATE_FETCH_TITLE") #$NON-NLS-1$ document.setCreationTime(ZSchemaDateTime()) document.setLastModifiedTime(ZSchemaDateTime()) xhtmlDoc = loadXhtmlDocumentFromString(u"<p id='_raven_template_body'>RAVEN_TEMPLATE_FETCH_BODY</p>") #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(u"xml") #$NON-NLS-1$ content.setType(u"application/xhtml+xml") #$NON-NLS-1$ content.setXhtmlDocument(xhtmlDoc) document.setContent(content) return document
def _createDocument(self): document = ZBlogDocument() document.setTitle(u"RAVEN_TEMPLATE_FETCH_TITLE") #$NON-NLS-1$ document.setCreationTime(ZSchemaDateTime()) document.setLastModifiedTime(ZSchemaDateTime()) xhtmlDoc = loadXhtmlDocumentFromString( u"<p id='_raven_template_body'>RAVEN_TEMPLATE_FETCH_BODY</p>" ) #$NON-NLS-1$ content = ZXhtmlContent() content.setMode(u"xml") #$NON-NLS-1$ content.setType(u"application/xhtml+xml") #$NON-NLS-1$ content.setXhtmlDocument(xhtmlDoc) document.setContent(content) return document
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
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
def findDependencies(self): u"""findDependencies() -> ZResourceDependency[]""" # $NON-NLS-1$ xhtmlDoc = loadXhtmlDocumentFromString(self.xhtml) self.baseHref = xhtmlDoc.getBaseHref() # Find images for image in xhtmlDoc.getImages(): if image.getSrc(): self.dependencies.append(ZResourceDependency(IZResourceDependencyTypes.IMAGE, image.getSrc())) # Find CSS stylesheets for stylesheet in xhtmlDoc.getStylesheets(): if stylesheet.getHref(): self.dependencies.append(ZResourceDependency(IZResourceDependencyTypes.CSS, stylesheet.getHref())) # Find scripts for script in xhtmlDoc.getScripts(): if script.getSrc(): self.dependencies.append(ZResourceDependency(IZResourceDependencyTypes.SCRIPT, script.getSrc())) # Now find some stuff that the regular analysers miss (in-line CSS) xhtmlDoc.analyse(self) return self.dependencies
def _createXHtmlDocument(self): xhtml = u"""<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce non mauris non purus ultrices tincidunt. Nunc id neque. Curabitur auctor, risus quis semper tincidunt, magna felis egestas orci, ut elementum elit ipsum eget orci. Vivamus non sapien. Nullam a urna. Sed viverra. Aliquam a neque a eros accumsan dapibus. Pellentesque vitae augue vitae est congue convallis. Maecenas dui felis, dictum bibendum, pharetra in, pulvinar eget, diam. Sed consectetuer cursus sapien. Aenean molestie, justo vitae imperdiet tempor, felis dolor pretium massa, eu adipiscing ante purus vitae risus. Etiam ornare erat. Ut bibendum adipiscing nisl. Cras vitae mauris. Suspendisse diam ipsum, sagittis in, dapibus ut, iaculis at, elit. Donec auctor libero volutpat nisl. Proin ornare turpis et odio.</p> <p>In non metus a massa malesuada rutrum. Mauris consequat venenatis dolor. Nullam commodo luctus sapien. Integer quis tortor sit amet tellus scelerisque cursus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Nam at nunc a mi auctor aliquam. Nulla suscipit varius orci. Vestibulum suscipit magna et nisl. Curabitur sem lectus, ullamcorper et, porttitor non, dignissim in, diam. Fusce aliquet. Aenean elit nulla, vulputate eget, interdum id, rhoncus eget, pede. Ut interdum vehicula leo.</p> """ #$NON-NLS-1$ return loadXhtmlDocumentFromString(xhtml)
def _processResponseData(self, resp, txt): txt = ZSimpleTextHTTPRequest._processResponseData(self, resp, txt) txt = string.lstrip(txt) # FIXME (PJ) check resp content-type. If text/plain, then return txt as is isstead of a zdom. xhtmlDoc = loadXhtmlDocumentFromString(txt) return xhtmlDoc
def getXhtmlDocument(self): htmlString = self.getValue() xhtmlDocument = loadXhtmlDocumentFromString(htmlString) return xhtmlDocument
def _handleWithThumbnail(self, dndSource, model): srcFile = dndSource.getData() html = u"<html><body><p>" + self._createWithThumbnailHtmlFragString(srcFile, model) + u"</p></body></html>" #$NON-NLS-1$ #$NON-NLS-2$ return loadXhtmlDocumentFromString(html)
def _handleNoThumbnail(self, dndSource): srcFile = dndSource.getData() html = self._createNoThumbnailHtmlFragString(srcFile) return loadXhtmlDocumentFromString(html)
def _clearHtmlContent(self): self.document = None xhtmlDoc = loadXhtmlDocumentFromString(u"") #$NON-NLS-1$ self.htmlViewer.setXhtmlDocument(xhtmlDoc, False)