def setTemplateText(self, text):
        """
        Set the template text; if the template is not HTML, a subclass could override this
        to pre-process the text into HTML before passing it to the default implementation.
        """
        if self.allowEdit:
            self.originalText = text
        # If we have children, remove them all first since we are trashing their DOM
        for child in List(self.children):
            self.remove(child)
        
        DOM.setInnerHTML(self.getElement(), text)
        self.elementsById = {}
        self.links = []
        self.metaTags = {}
        self.forms = []
        self.metaTagList = []
        
        # Make the ids unique and store a pointer to each named element
        for node in DOM.walkChildren(self.getElement()):
            #console.log("Passing node with name %s", node.nodeName)
            if node.nodeName == "META":
                name = node.getAttribute("name")
                content = node.getAttribute("content")
                console.log("Found meta %o name %s content %s", node, name, content)
                self.metaTags[name] = content
                self.metaTagList.append(node)
            elif node.nodeName == "BODY":
                self.body = node
            elif node.nodeName == "TITLE":
                self.title = DOM.getInnerText(node)
            elif node.nodeName == "FORM":
                self.forms.append(node)

            nodeId = DOM.getAttribute(node, "id")
            if nodeId:
                self.elementsById[nodeId] = node
                DOM.setAttribute(node, "id", self.id+":"+node.id)
            nodeHref = DOM.getAttribute(node, "href")
            if nodeHref:
                self.links.append(node)
                
        self.loaded = True
        if self.attached:
            self.attachWidgets()
            self.widgetsAttached = True
            
        if self.allowEdit:
            self.editor = None
            self.editButton = Label("edit "+unescape(self.templateName))
            self.editButton.addStyleName("link")
            self.editButton.addStyleName("ContentPanelEditLink")
            self.editButton.addClickListener(EventDelegate("onClick", self, self.onEditContentClick))
            ComplexPanel.insert(self, self.editButton, self.getElement(), len(self.children))

        self.notifyLoadListeners()
 def onEditContentClick(self, sender):
     if self.editor:
         editor = self.editor
         self.editor = None
         ComplexPanel.remove(self, editor)
         self.editButton.setText("edit "+unescape(self.templateName))
     else:
         self.editor = RichTextEditor(self.originalText)
         self.editor.addSaveListener(self)
         ComplexPanel.insert(self, self.editor, self.getElement(), len(self.children))
         self.editButton.setText("close editor")
 def onError(self, html, statusCode):
     if statusCode == 404 and self.allowEdit:
         self.editor = None
         self.originalText = ""
         DOM.setInnerHTML(self.getElement(), '')
         self.editButton = Label("create "+unescape(self.templateName))
         self.editButton.addStyleName("link")
         self.editButton.addStyleName("ContentPanelEditLink")
         self.editButton.addClickListener(EventDelegate("onClick", self, self.onEditContentClick))
         ComplexPanel.insert(self, self.editButton, self.getElement(), len(self.children))
         return
 def onEditContentClick(self, sender):
     if self.editor:
         editor = self.editor
         self.editor = None
         ComplexPanel.remove(self, editor)
         self.editButton.setText("edit " + unescape(self.templateName))
     else:
         self.editor = RichTextEditor(self.originalText)
         self.editor.addSaveListener(self)
         ComplexPanel.insert(self, self.editor, self.getElement(),
                             len(self.children))
         self.editButton.setText("close editor")
 def onError(self, html, statusCode):
     if statusCode == 404 and self.allowEdit:
         self.editor = None
         self.originalText = ""
         DOM.setInnerHTML(self.getElement(), '')
         self.editButton = Label("create "+unescape(self.templateName))
         self.editButton.addStyleName("link")
         self.editButton.addStyleName("ContentPanelEditLink")
         self.editButton.addClickListener(EventDelegate("onClick", self,
                                          self.onEditContentClick))
         ComplexPanel.insert(self, self.editButton, self.getElement(),
                             len(self.children))
         return
    def setTemplateText(self, text):
        """
        Set the template text; if the template is not HTML, a subclass
        could override this to pre-process the text into HTML before
        passing it to the default implementation.
        """
        if self.allowEdit:
            self.originalText = text
        # If we have children, remove them all first since we are
        # trashing their DOM
        for child in List(self.children):
            self.remove(child)

        DOM.setInnerHTML(self.getElement(), text)
        self.elementsById = {}
        self.links = []
        self.metaTags = {}
        self.forms = []
        self.metaTagList = []

        # Make the ids unique and store a pointer to each named element
        for node in DOM.walkChildren(self.getElement()):
            #console.log("Passing node with name %s", node.nodeName)
            if node.nodeName == "META":
                name = node.getAttribute("name")
                content = node.getAttribute("content")
                console.log("Found meta %o name %s content %s",
                            node, name, content)
                self.metaTags[name] = content
                self.metaTagList.append(node)
            elif node.nodeName == "BODY":
                self.body = node
            elif node.nodeName == "TITLE":
                self.title = DOM.getInnerText(node)
            elif node.nodeName == "FORM":
                self.forms.append(node)

            nodeId = DOM.getAttribute(node, "id")
            if nodeId:
                self.elementsById[nodeId] = node
                DOM.setAttribute(node, "id", self.id + ":" + node.id)
            nodeHref = DOM.getAttribute(node, "href")
            if nodeHref:
                self.links.append(node)

        self.loaded = True
        if self.attached:
            self.attachWidgets()
            self.widgetsAttached = True

        if self.allowEdit:
            self.editor = None
            self.editButton = Label("edit "+unescape(self.templateName))
            self.editButton.addStyleName("link")
            self.editButton.addStyleName("ContentPanelEditLink")
            self.editButton.addClickListener(EventDelegate("onClick", self,
                                             self.onEditContentClick))
            ComplexPanel.insert(self, self.editButton, self.getElement(),
                                len(self.children))

        self.notifyLoadListeners()
 def getSearch(self):
     return unescape(self.location.search)
 def getHash(self):
     return unescape(self.location.hash)