CVS: Products/ParsedXML - ExtraDOM.py:1.9 ManageableDOM.py:1.108

Martijn Faassen <[email protected]> Sun, 19 May 2002 11:51:42 -0400
Newsgroups gmane.comp.web.zope.parsed-xml
Message-ID <[email protected]>
Update of /cvs-repository/Products/ParsedXML
In directory cvs.zope.org:/tmp/cvs-serv13557

Modified Files:
	ExtraDOM.py ManageableDOM.py 
Log Message:
Added prettyPrint button. Fixed a bug in ExpatBuilder.


=== Products/ParsedXML/ExtraDOM.py 1.8 => 1.9 ===
         raise Exception, "replacing a document fragment doesn't make sense"
     else:
-        fragment = DOM.ExpatBuilder.parseFragment(file, node.parentNode,
-                                                  namespaces)
+        fragment = DOM.ExpatBuilder.parseFragment(
+            file, node.parentNode, namespaces)
         if fragment.childNodes.length != 1:
             # we could do this, actually, if we wanted
             raise Exception, "replacing a Node with less or more " + \


=== Products/ParsedXML/ManageableDOM.py 1.107 => 1.108 ===
 
     def writeStream(self, stream = None, encoding = None, html = 0,
-                    contentType = None):
+                    contentType = None, prettyPrint=0):
         "Write the XML representation of this object to stream."
         # work thru DOM object to avoid making proxy nodes
         return ExtraDOM.writeStream(self.getDOMObj(), stream, encoding,
-                                    html, contentType)
+                                    html, contentType, prettyPrint=prettyPrint)
     
     def __str__(self):
         "Return the XML representation of this object."
@@ -319,7 +319,7 @@
     # This quotes the relevent refs; when the textarea is sent back the
     # browser unquotes them, so the end result is WYSIWYG.  Yuck!
     # If a browser doesn't do this __str__ should be used.
-    def textareaStr(self):
+    def textareaStr(self, prettyPrint=0):
         """Return the XML representation of this object in a format safe for
         a textarea, with certain entity references quoted."""
         # FIXME
@@ -327,7 +327,8 @@
         # was saved in, but this is too complicated for now, so we just
         # output UTF-8. Unfortunately this is not very pretty in the browser
         # unless you set it to display in UTF-8.
-        outStr = self.writeStream(encoding=None).getvalue().encode('UTF-8')
+        outStr = self.writeStream(
+            encoding=None, prettyPrint=prettyPrint).getvalue().encode('UTF-8')
         outStr = string.replace(outStr, '&amp;', '&amp;amp;')        
         outStr = string.replace(outStr, '&lt;', '&amp;lt;')
         outStr = string.replace(outStr, '&gt;', '&amp;gt;')
@@ -472,6 +473,12 @@
             return self._er(data, title, contentType,
                             SUBMIT, dtpref_cols, dtpref_rows, REQUEST)
 
+        # if we are pretty printing, just redraw the form
+        if SUBMIT == 'PrettyPrint':
+            return self.manage_editForm(
+                self, REQUEST,
+                textareaStr=self.textareaStr(prettyPrint=1))
+                                        
         if (  hasattr(self, 'nodeType')
               and self.nodeType == xml.dom.Node.DOCUMENT_NODE):
             #if we're the main doc