[ooo-build-commit] scratch/mso-dumper
Kohei Yoshida
kohei at kemper.freedesktop.org
Sat Jan 16 21:42:16 PST 2010
scratch/mso-dumper/src/node.py | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
New commits:
commit 4cc972ed45b3c4122dd09ab91640e66d161834cf
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Sun Jan 17 00:39:45 2010 -0500
[xls-dump] No line breaks or indents when the element has content nodes.
* scratch/mso-dumper/src/node.py:
diff --git a/scratch/mso-dumper/src/node.py b/scratch/mso-dumper/src/node.py
index b1d7910..6f3a7c9 100644
--- a/scratch/mso-dumper/src/node.py
+++ b/scratch/mso-dumper/src/node.py
@@ -17,9 +17,11 @@ class NodeType:
class NodeBase:
def __init__ (self, nodeType = NodeType.Unknown):
self.parent = None
- self.__children = []
self.nodeType = nodeType
+ self.__children = []
+ self.__hasContent = False
+
def appendChild (self, node):
self.__children.append(node)
node.parent = self
@@ -29,9 +31,13 @@ class NodeBase:
self.appendChild(node)
return node
+ def hasContent (self):
+ return self.__hasContent
+
def appendContent (self, text):
node = Content(text)
self.appendChild(node)
+ self.__hasContent = True
return node
def firstChild (self):
@@ -134,15 +140,19 @@ def convertAttrValue (val):
return val
def prettyPrint (fd, node):
- printNode(fd, node, 0)
-
-def printNode (fd, node, level):
- singleIndent = ' '*4
+ printNode(fd, node, 0, True)
+
+def printNode (fd, node, level, breakLine):
+ singleIndent = ''
+ lf = ''
+ if breakLine:
+ singleIndent = ' '*4
+ lf = "\n"
indent = singleIndent*level
if node.nodeType == NodeType.Root:
# root node itself only contains child nodes.
for child in node.getChildNodes():
- printNode(fd, child, level)
+ printNode(fd, child, level, True)
elif node.nodeType == NodeType.Element:
hasChildren = len(node.getChildNodes()) > 0
@@ -160,18 +170,23 @@ def printNode (fd, node, level):
line += " " + key + '="' + encodeString(val) + '"'
if hasChildren:
- line = "<%s>\n"%line
+ breakChildren = breakLine and not node.hasContent()
+ line = "<%s>"%line
+ if breakChildren:
+ line += "\n"
fd.write (indent + line)
for child in node.getChildNodes():
- printNode(fd, child, level+1)
- line = "</%s>\n"%node.name
- fd.write (indent + line)
+ printNode(fd, child, level+1, breakChildren)
+ line = "</%s>%s"%(node.name, lf)
+ if breakChildren:
+ line = indent + line
+ fd.write (line)
else:
- line = "<%s/>\n"%line
+ line = "<%s/>%s"%(line, lf)
fd.write (indent + line)
elif node.nodeType == NodeType.Content:
- content = node.content.strip()
+ content = node.content
content = encodeString(content)
if len(content) > 0:
- fd.write (indent + content + "\n")
+ fd.write (indent + content + lf)
More information about the ooo-build-commit
mailing list