commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8049 - in trunk: gnue-common/src/definitions gnue-designer/src/b


From: btami
Subject: [gnue] r8049 - in trunk: gnue-common/src/definitions gnue-designer/src/base
Date: Wed, 12 Oct 2005 02:49:27 -0500 (CDT)

Author: btami
Date: 2005-10-12 02:49:26 -0500 (Wed, 12 Oct 2005)
New Revision: 8049

Modified:
   trunk/gnue-common/src/definitions/GParser.py
   trunk/gnue-common/src/definitions/GParserHelpers.py
   trunk/gnue-designer/src/base/Instance.py
Log:
fixed the 'designer looses comments on save' bug

Modified: trunk/gnue-common/src/definitions/GParser.py
===================================================================
--- trunk/gnue-common/src/definitions/GParser.py        2005-10-12 04:45:47 UTC 
(rev 8048)
+++ trunk/gnue-common/src/definitions/GParser.py        2005-10-12 07:49:26 UTC 
(rev 8049)
@@ -35,6 +35,7 @@
 from gnue.common.utils.FileUtils import openResource
 
 try:
+  from xml.sax.handler import property_lexical_handler
   from xml.sax import saxutils
   import xml.sax
 except ImportError:
@@ -54,7 +55,7 @@
 
 from gnue.common.apps import errors
 from gnue.common.formatting import GTypecast
-from gnue.common.definitions.GParserHelpers import GContent
+from gnue.common.definitions.GParserHelpers import GContent, GComment
 
 
 #######################################################
@@ -128,8 +129,13 @@
 
   # Tell the parser to use our handler
   parser.setContentHandler(dh)
-  
+
   try:
+    parser.setProperty(property_lexical_handler, dh)
+  except Exception, e:
+    print e
+
+  try:
     parser.parse (stream)
 
   except xml.sax.SAXParseException, e:
@@ -149,6 +155,8 @@
               'got'     : object._type}
     raise MarkupError, (tmsg, url)
 
+  object.rootComments = dh.getRootComments()
+
   dh.finalValidation ()
 
   # Set the root object's attributes
@@ -169,7 +177,6 @@
   # able to collect it
   dh.parser = None
 
-
   return object
 #######################################################
 #
@@ -240,6 +247,7 @@
     self._singleInstanceTags = []
     self._tagCounts = {}
     self.url = None
+    self.rootComments = []
 
   #
   # Called by client code to get the "root" node
@@ -467,7 +475,7 @@
   # text (not part of a tag) is encountered.
   #
   def characters(self, text):
-
+ 
     if self.xmlStack[0] != None:
 
       # Masqueraging namespace elements, then keep content
@@ -507,7 +515,36 @@
     assert gDebug (7, "</%s>" % name)
 
 
+  #  lexical handler stuff
+  def comment(self, text):
+    if self.root is None:
+      self.rootComments.append(text)
+    else:
+      if self.xmlStack[0] != None:
+        GComment(self.xmlStack[0], text)
 
+  def startCDATA(self):
+    pass
+  
+  def endCDATA(self):
+    pass
+      
+  def startDTD(self, name, public_id, system_id):
+    pass
+          
+  def endDTD(self):
+    pass
+
+  def startEntity(self, name):
+    pass
+
+  def endEntity(self, name):
+    pass
+
+  def getRootComments(self):
+    return self.rootComments
+
+
 class GImportItem(GObj):
   def __init__(self, parent=None, type="GCImport-Item"):
     GObj.__init__(self, parent, type=type)

Modified: trunk/gnue-common/src/definitions/GParserHelpers.py
===================================================================
--- trunk/gnue-common/src/definitions/GParserHelpers.py 2005-10-12 04:45:47 UTC 
(rev 8048)
+++ trunk/gnue-common/src/definitions/GParserHelpers.py 2005-10-12 07:49:26 UTC 
(rev 8049)
@@ -335,3 +335,33 @@
 
   def merge (self, other):
     return
+
+
+# =============================================================================
+# Base class for xml comment
+# =============================================================================
+
+class GComment (ParserObj):
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
+  def __init__ (self, parent, comment = None):
+
+    ParserObj.__init__ (self, parent, '_comment_')
+    self._comment = comment
+
+  def dumpXML (self, lookupDict, treeDump = None, gap = "",
+               escape = 1, textEncoding = '<locale>', xmlnamespaces = {},
+               stripPrefixes = None):
+
+    if textEncoding == '<locale>':
+      textEncoding = gConfig ('textEncoding')
+
+    if type (self._comment) == StringType:
+      xmlString = '%s' % unicode (self._comment, textEncoding)
+    else:
+      xmlString = self._comment
+
+    return '<!--%s-->\n' % xmlString

Modified: trunk/gnue-designer/src/base/Instance.py
===================================================================
--- trunk/gnue-designer/src/base/Instance.py    2005-10-12 04:45:47 UTC (rev 
8048)
+++ trunk/gnue-designer/src/base/Instance.py    2005-10-12 07:49:26 UTC (rev 
8049)
@@ -533,9 +533,17 @@
     fileHandle.write('<?xml version="1.0" encoding="%s"?>\n\n' % \
            gConfig('textEncoding'))
 
+    for comment in self.rootObject.rootComments:
+      if comment.find(TITLE) > 0:
+        self.rootObject.rootComments.remove(comment)
+      
     fileHandle.write('<!--  %s (%s)\n%s      Saved on: %s  -->\n\n' \
        % (TITLE, VERSION, (len(self.wizardName) and ("      Created by " + 
self.wizardName + "\n") or ""),\
           time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))))
+
+    fileHandle.write(''.join(["<!--%s-->\n\n" % 
comment.encode(gConfig('textEncoding')) \
+                     for comment in self.rootObject.rootComments]))
+    
     
fileHandle.write(self.rootObject.dumpXML(treeDump=True).encode(gConfig('textEncoding')))
     fileHandle.close()
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]