CVS: Products/ParsedXML - helpers.py:1.1 CHANGES.txt:1.22 ManageableDOM.py:1.118 ParsedXML.py:1.46 PrettyPrinter.py:1.7

Martijn Faassen <[email protected]> Wed, 28 Apr 2004 08:09:21 -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-serv32332

Modified Files:
	CHANGES.txt ManageableDOM.py ParsedXML.py PrettyPrinter.py 
Added Files:
	helpers.py 
Log Message:
ZMI UI now in UTF-8, more sanity for encodings.
Some cleanups of UI, added new helpers.py module which contains
add_and_edit functionality.


=== Added File Products/ParsedXML/helpers.py ===
import urllib

def add_and_edit(self, id, REQUEST, screen='manage_main'):
    """Helper function to point to the object's management screen if
    'Add and Edit' button is pressed.
    id -- id of the object we just added
    """
    if REQUEST is None:
        return
    try:
        u = self.DestinationURL()
    except:
        u = REQUEST['URL1']
    if REQUEST.has_key('submit_edit'):
        u = "%s/%s" % (u, urllib.quote(id))
        REQUEST.RESPONSE.redirect(u+'/'+screen)
    else:
        REQUEST.RESPONSE.redirect(u+'/manage_main')


=== Products/ParsedXML/CHANGES.txt 1.21 => 1.22 ===
--- Products/ParsedXML/CHANGES.txt:1.21	Tue Apr 27 14:13:17 2004
+++ Products/ParsedXML/CHANGES.txt	Wed Apr 28 08:09:13 2004
@@ -2,24 +2,42 @@
 
   ParsedXML under development
 
-    Misc
-
-      - Updated license to ZPL 2.0.
+    Features Added
 
       - Switched the test suite over to use ZopeTestCase.
 
+      - Updated UI so that the XML edit screen is the first screen
+        seen, not the DOM screen.
+
+      - UI is UTF-8 by default now, the same as the default encoding
+        of the XML. XML 'encoding' setting in the XML declaration
+        other than UTF-8 are supported by the upload, but the XML text
+        will be converted to unicode internally and will display as
+        UTF-8, the default encoding.
+
+        You can also use the encoding in the XML declaration in the
+        edit entry, but you will be unlikely to get it right as the
+        interactions between various encodings becomes rather
+        complex. If you have XML text in a non-UTF-8 encoding upload
+        it as a file rather than copy and paste it.
+
+    Bugs Fixed
+
       - Cleaned out tests so they all pass. This was done
         (unfortunately) by disabling some failing tests.
 
-      - Removed old Printer.py module (PrettyPrinter works better and
-        has more functionality).
+      - Some encoding issues should be more sane now.
+
+    Misc
+
+      - Updated license to ZPL 2.0.
 
       - get rid of unused HTML writing support.
 
-      - get rid of obsolete delegation through StrIO module to get StringIO.
+      - Removed old Printer.py module (PrettyPrinter works better and
+        has more functionality).
 
-      - Updated UI so that the XML edit screen is the first screen
-        seen, not the DOM screen.
+      - get rid of obsolete delegation through StrIO module to get StringIO.
 
   ParsedXML 1.3.1
 


=== Products/ParsedXML/ManageableDOM.py 1.117 => 1.118 ===
--- Products/ParsedXML/ManageableDOM.py:1.117	Tue Apr 27 14:13:17 2004
+++ Products/ParsedXML/ManageableDOM.py	Wed Apr 28 08:09:13 2004
@@ -22,6 +22,7 @@
 from OFS.Traversable import Traversable
 from DateTime import DateTime # for manage_edit cookie expire
 import marshal # for ftp
+from Globals import DTMLFile
 
 import DOMProxy
 import DOM
@@ -231,7 +232,7 @@
 
 class DOMIO:
     "Mixin class for DOM classes to provide parsing, writing."
-
+    
     def writeStream(self, stream=None, encoding=None, prettyPrint=0):
         "Write the XML representation of this object to stream."
         # work thru DOM object to avoid making proxy nodes
@@ -298,14 +299,13 @@
 class DOMManageable(DOMIO, DOMPublishable, App.Management.Tabs):
     "Mixin class for DOM classes to provide Zope management interfaces."
 
-    manage_editForm = Globals.HTMLFile('dtml/transEdit',globals())
-    #pretty_html = Globals.HTMLFile('dtml/pretty',globals())
-    manage_DOMTree = Globals.HTMLFile('dtml/DOMTree',globals())
-    try: 
-        manage_DOMTree._setName('manage_DOMTree')
-    except AttributeError:
-        pass # _setName only exists in Zope 2.4+
-    manage_main = manage_DOMTree
+    # the UI of ParsedXML is UTF-8
+    management_page_charset = 'UTF-8'
+    
+    manage_editForm = Globals.DTMLFile('dtml/transEdit', globals(),
+                                       __name__='manage_editForm')
+    manage_DOMTree = Globals.DTMLFile('dtml/DOMTree', globals(),
+                                      __name__='manage_DOMTree')
  
     manage_options = (
         {'label':'Edit', 'action':'manage_editForm',
@@ -388,17 +388,17 @@
                 self, REQUEST,
                 textareaStr=self.textareaStr(prettyPrint=1))
                                         
-        if (  hasattr(self, 'nodeType')
-              and self.nodeType == xml.dom.Node.DOCUMENT_NODE):
+        if (hasattr(self, 'nodeType')
+            and self.nodeType == xml.dom.Node.DOCUMENT_NODE):
             #if we're the main doc
             self.title = str(title)
             if contentType:
                 self.contentType = str(contentType)
-            self.noNamespaces = not useNamespaces
-                    
-        text=StringIO(data)
+            self.noNamespaces = not useNamespaces        
+        
+        f = StringIO(data)
         try:
-            newNode = self.parseXML(text) # self not in doc if this succeeds
+            newNode = self.parseXML(f) # self not in doc if this succeeds
         except expat.error, e:
             get_transaction().abort()
             if REQUEST:
@@ -433,11 +433,11 @@
                 return Globals.MessageDialog(
                     title  = 'XML Parsing Error',
                     message = err,
-                    action = 'manage_main')
+                    action = 'manage_editForm')
             raise
         if REQUEST:
-            return newNode.manage_main(self, REQUEST,
-                                       manage_tabs_message='Saved changes.')
+            return newNode.manage_editForm(self, REQUEST,
+                                           manage_tabs_message='Saved changes.')
 
 Globals.default__class_init__(DOMManageable) # activate perms
 


=== Products/ParsedXML/ParsedXML.py 1.45 => 1.46 ===
--- Products/ParsedXML/ParsedXML.py:1.45	Tue Apr 27 14:08:20 2004
+++ Products/ParsedXML/ParsedXML.py	Wed Apr 28 08:09:13 2004
@@ -21,12 +21,14 @@
 from Acquisition import Implicit
 from OFS.Cache import Cacheable
 import Globals
+from Globals import DTMLFile
 
 from ManageableDOM import ManageableDocument, DOMManageable, \
      theDOMImplementation
 from StringIO import StringIO
 from xml.parsers import expat
 import DOM, ExtraDOM
+import helpers
 
 from types import FileType, StringType
 from urllib import quote
@@ -39,11 +41,11 @@
          'your XML document for well-formedness and try '
          'to upload it again after modification.<br><br>')
 
-def manage_addParsedXML(self,id,title='',file='',
-                        useNamespaces = 1, contentType = "text/xml",
-                        REQUEST=None,submit=None):
+def manage_addParsedXML(context, id, title='', file='',
+                        useNamespaces=1, contentType="text/xml",
+                        REQUEST=None):
     "Add a Parsed XML instance with optional file content."
-
+    
     if not file or not isinstance(file, StringType):
         file ='<?xml version = "1.0"?><emptydocumentElement/>'
     try:
@@ -58,15 +60,11 @@
                 action='manage_main')
         raise
     ob.title = str(title)
-    id = self._setObject(id, ob)
-    if REQUEST is not None:
-        try: u=self.DestinationURL()
-        except: u=REQUEST['URL1']
-        if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
-        REQUEST.RESPONSE.redirect(u+'/manage_main')
-
+    context._setObject(id, ob)
+    helpers.add_and_edit(context, id, REQUEST, 'manage_editForm')
 
-manage_addParsedXMLForm = Globals.DTMLFile('dtml/documentAdd', globals())
+manage_addParsedXMLForm = DTMLFile('dtml/documentAdd', globals(),
+                                   __name__='manage_addParsedXMLForm')
 
 
 def createDOMDocument(XMLstring = None, namespaces = 1):
@@ -86,13 +84,14 @@
      
     meta_type = 'Parsed XML'
 
-    manage_editForm = Globals.HTMLFile('dtml/persEdit',globals())
+    manage_editForm = DTMLFile('dtml/persEdit', globals(),
+                               __name__='manage_editForm')
     
     manage_options = (DOMManageable.manage_options +
                       RoleManager.manage_options +
                       Cacheable.manage_options)
 
-    __ac_permissions__ = (('View management screens', ('manage_main',),
+    __ac_permissions__ = (('View management screens', ('manage_editForm',),
                            ('Manager',)),
                           ('View DOM hierarchy', ('manage_DOMTree',),
                            ('Manager',)),


=== Products/ParsedXML/PrettyPrinter.py 1.6 => 1.7 ===
--- Products/ParsedXML/PrettyPrinter.py:1.6	Tue Apr 27 14:08:20 2004
+++ Products/ParsedXML/PrettyPrinter.py	Wed Apr 28 08:09:13 2004
@@ -12,7 +12,6 @@
 #
 ##############################################################################
 import re
-import string
 from DOM.Core import Node, XMLNS_NS, XML_NS
 import sys
 from StringIO import StringIO
@@ -163,10 +162,10 @@
         f.write('-->')
 
     def renderDocument(self, f, node):    
-        f.write('<?xml version="1.0"')
-        if self.encoding:
-            f.write(' encoding="%s"' % self.encoding)
-        f.write(' ?>\n')
+        f.write('<?xml version="1.0" ?>\n')
+        #if self.encoding:
+        #    f.write(' encoding="%s"' % self.encoding)
+        #f.write(' ?>\n')
         for child in node.childNodes:
             self.render(f, child)
         f.write('\n')