Exemplo n.º 1
0
 def endElement(self, elem):
     elem = self.lowerizeInput(elem)
     e = XmlParser.endElement(self, elem)
     currentElem, elemsToReopen = e.onElementEnd(elem)
     # Determine the tag to dump
     startTag, endTag = currentElem.getOdfTags(e)
     if currentElem.isConflictual:
         # Compute the start tag, with potential styles applied
         startTag = e.getTags((currentElem,), start=True)
     if currentElem.isConflictual and e.res.endswith(startTag):
         # We will not dump it, it would constitute a silly empty tag.
         e.res = e.res[:-len(startTag)]
     else:
         # Dump the end tag. But dump some additional stuff if required.
         if elem in XHTML_LISTS:
             if len(e.currentLists) >= 1:
                 # We were in an inner list. So we must close the list-item
                 # tag that surrounds it.
                 endTag = '%s</%s:list-item>' % (endTag, e.textNs)
         if endTag:
             e.dumpString(endTag)
     if elem in IGNORABLE_TAGS:
         e.ignore = False
     if elemsToReopen:
         e.dumpString(e.getTags(elemsToReopen, start=True))
Exemplo n.º 2
0
 def endElement(self, elem):
     elem = self.lowerizeInput(elem)
     e = XmlParser.endElement(self, elem)
     elemsToReopen = e.onElementEnd(elem)
     if HTML_2_ODT.has_key(elem):
         # For "div" elements, we put append a carriage return.
         if elem == 'div':
             e.dumpString('<%s:line-break/>' % e.textNs)
         e.dumpString('</%s:%s>' % (e.textNs, HTML_2_ODT[elem]))
     elif elem == 'a':
         e.dumpString('</%s:a>' % e.textNs)
     elif elem in XHTML_LISTS:
         epilogue = ''
         if len(e.currentLists) >= 1:
             # We were in an inner list. So we must close the list-item tag
             # that surrounds it.
             epilogue = '</%s:list-item>' % e.textNs
         e.dumpString('</%s:list>%s' % (e.textNs, epilogue))
     elif elem == 'li':
         e.dumpString('</%s:list-item>' % e.textNs)
     elif elem == 'table':
         e.dumpString('</%s:table>' % e.tableNs)
     elif elem == 'thead':
         e.dumpString('</%s:table-header-rows>' % e.tableNs)
     elif elem == 'tr':
         e.dumpString('</%s:table-row>' % e.tableNs)
     elif elem in TABLE_CELL_TAGS:
         e.dumpString('</%s:table-cell>' % e.tableNs)
     elif elem in IGNORABLE_TAGS:
         e.ignore = False
     if elemsToReopen:
         e.dumpTags(elemsToReopen)
Exemplo n.º 3
0
    def startElement(self, elem, attrs):
        elem, attrs = self.lowerizeInput(elem, attrs)
        e = XmlParser.startElement(self, elem, attrs)
        currentElem = e.onElementStart(elem, attrs)
        odfTag = currentElem.getOdfTag(e)

        if HTML_2_ODT.has_key(elem):
            e.dumpStyledElement(currentElem, odfTag, attrs)
        elif elem == 'a':
            e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs))
            if attrs.has_key('href'):
                e.dumpString(' %s:href="%s"' % (e.linkNs, attrs['href']))
            e.dumpString('>')
        elif elem in XHTML_LISTS:
            prologue = ''
            if len(e.currentLists) >= 2:
                # It is a list into another list. In this case the inner list
                # must be surrounded by a list-item element.
                prologue = '<%s:list-item>' % e.textNs
            e.dumpString('%s<%s %s:style-name="%s">' % (
                prologue, odfTag, e.textNs, e.listStyles[elem]))
        elif elem in ('li', 'thead', 'tr'):
            e.dumpString('<%s>' % odfTag)
        elif elem == 'table':
            # Here we must call "dumpString" only once
            e.dumpString('<%s %s:style-name="podTable">' % (odfTag, e.tableNs))
        elif elem in TABLE_CELL_TAGS:
            e.dumpString('<%s %s:style-name="%s"' % \
                (odfTag, e.tableNs, DEFAULT_ODT_STYLES[elem]))
            if attrs.has_key('colspan'):
                e.dumpString(' %s:number-columns-spanned="%s"' % \
                             (e.tableNs, attrs['colspan']))
            e.dumpString('>')
        elif elem in IGNORABLE_TAGS:
            e.ignore = True
Exemplo n.º 4
0
 def endElement(self, elem):
     elem = self.lowerizeInput(elem)
     e = XmlParser.endElement(self, elem)
     currentElem, elemsToReopen = e.onElementEnd(elem)
     # Determine the tag to dump
     startTag, endTag = currentElem.getOdfTags(e)
     if currentElem.isConflictual:
         # Compute the start tag, with potential styles applied
         startTag = e.getTags((currentElem, ), start=True)
     if currentElem.isConflictual and e.res.endswith(startTag):
         # We will not dump it, it would constitute a silly empty tag.
         e.res = e.res[:-len(startTag)]
     else:
         # Dump the end tag. But dump some additional stuff if required.
         if elem in XHTML_LISTS:
             if len(e.currentLists) >= 1:
                 # We were in an inner list. So we must close the list-item
                 # tag that surrounds it.
                 endTag = '%s</%s:list-item>' % (endTag, e.textNs)
         if endTag:
             e.dumpString(endTag)
     if elem in IGNORABLE_TAGS:
         e.ignore = False
     if elemsToReopen:
         e.dumpString(e.getTags(elemsToReopen, start=True))
Exemplo n.º 5
0
    def startElement(self, elem, attrs):
        elem, attrs = self.lowerizeInput(elem, attrs)
        e = XmlParser.startElement(self, elem, attrs)
        currentElem = e.onElementStart(elem, attrs)
        odfTag = currentElem.getOdfTag(e)

        if HTML_2_ODT.has_key(elem):
            e.dumpStyledElement(currentElem, odfTag, attrs)
        elif elem == 'a':
            e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs))
            if attrs.has_key('href'):
                e.dumpString(' %s:href="%s"' %
                             (e.linkNs, escapeXml(attrs['href'])))
            e.dumpString('>')
        elif elem in XHTML_LISTS:
            prologue = ''
            if len(e.currentLists) >= 2:
                # It is a list into another list. In this case the inner list
                # must be surrounded by a list-item element.
                prologue = '<%s:list-item>' % e.textNs
            numbering = ''
            if elem == 'ol':
                numbering = ' %s:continue-numbering="false"' % e.textNs
            e.dumpString(
                '%s<%s %s:style-name="%s"%s>' %
                (prologue, odfTag, e.textNs, e.listStyles[elem], numbering))
        elif elem in ('li', 'thead', 'tr'):
            e.dumpString('<%s>' % odfTag)
        elif elem == 'table':
            # Here we must call "dumpString" only once
            table = e.currentTables[-1]
            e.dumpString('<%s %s:name="%s" %s:style-name="podTable">' % \
                         (odfTag, e.tableNs, table.name, e.tableNs))
        elif elem in TABLE_CELL_TAGS:
            e.dumpString('<%s %s:style-name="%s"' % \
                (odfTag, e.tableNs, DEFAULT_ODT_STYLES[elem]))
            if attrs.has_key('colspan'):
                e.dumpString(' %s:number-columns-spanned="%s"' % \
                             (e.tableNs, attrs['colspan']))
            e.dumpString('>')
        elif elem == 'img':
            style = None
            if attrs.has_key('style'): style = attrs['style']
            imgCode = e.renderer.importDocument(at=attrs['src'],
                                                wrapInPara=False,
                                                style=style)
            e.dumpString(imgCode)
        elif elem in IGNORABLE_TAGS:
            e.ignore = True
Exemplo n.º 6
0
    def startElement(self, elem, attrs):
        elem, attrs = self.lowerizeInput(elem, attrs)
        e = XmlParser.startElement(self, elem, attrs)
        currentElem = e.onElementStart(elem, attrs)
        odfTag = currentElem.getOdfTag(e)

        if HTML_2_ODT.has_key(elem):
            e.dumpStyledElement(currentElem, odfTag, attrs)
        elif elem == 'a':
            e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs))
            if attrs.has_key('href'):
                e.dumpString(' %s:href="%s"' % (e.linkNs,
                                                escapeXml(attrs['href'])))
            e.dumpString('>')
        elif elem in XHTML_LISTS:
            prologue = ''
            if len(e.currentLists) >= 2:
                # It is a list into another list. In this case the inner list
                # must be surrounded by a list-item element.
                prologue = '<%s:list-item>' % e.textNs
            numbering = ''
            if elem == 'ol':
                numbering = ' %s:continue-numbering="false"' % e.textNs
            e.dumpString('%s<%s %s:style-name="%s"%s>' % (
                prologue, odfTag, e.textNs, e.listStyles[elem], numbering))
        elif elem in ('li', 'thead', 'tr'):
            e.dumpString('<%s>' % odfTag)
        elif elem == 'table':
            # Here we must call "dumpString" only once
            table = e.currentTables[-1]
            e.dumpString('<%s %s:name="%s" %s:style-name="podTable">' % \
                         (odfTag, e.tableNs, table.name, e.tableNs))
        elif elem in TABLE_CELL_TAGS:
            e.dumpString('<%s %s:style-name="%s"' % \
                (odfTag, e.tableNs, DEFAULT_ODT_STYLES[elem]))
            if attrs.has_key('colspan'):
                e.dumpString(' %s:number-columns-spanned="%s"' % \
                             (e.tableNs, attrs['colspan']))
            e.dumpString('>')
        elif elem == 'img':
            style = None
            if attrs.has_key('style'): style = attrs['style']
            imgCode = e.renderer.importDocument(at=attrs['src'],
                                                wrapInPara=False, style=style)
            e.dumpString(imgCode)
        elif elem in IGNORABLE_TAGS:
            e.ignore = True
Exemplo n.º 7
0
 def __init__(self, env, caller=None):
     XmlParser.__init__(self, env, caller)
Exemplo n.º 8
0
 def __init__(self, env=None, caller=None):
     if not env: env = OdfEnvironment()
     XmlParser.__init__(self, env, caller)
Exemplo n.º 9
0
 def characters(self, content):
     e = XmlParser.characters(self, content)
     if not e.ignore:
         e.currentContent += content
Exemplo n.º 10
0
 def characters(self, content):
     e = XmlParser.characters(self, content)
     if not e.ignore:
         e.currentContent += content
Exemplo n.º 11
0
 def __init__(self, env, caller=None):
     XmlParser.__init__(self, env, caller)
Exemplo n.º 12
0
 def endDocument(self):
     self.res = ' '.join(self.res)
     return XmlParser.endDocument(self)
Exemplo n.º 13
0
 def startDocument(self):
     XmlParser.startDocument(self)
     self.res = []
Exemplo n.º 14
0
 def endDocument(self):
     self.res = ' '.join(self.res)
     return XmlParser.endDocument(self)
Exemplo n.º 15
0
 def startDocument(self):
     XmlParser.startDocument(self)
     self.res = []
Exemplo n.º 16
0
 def characters(self, content):
     e = XmlParser.characters(self, content)
     if e.ignore: return
     e.currentContent += WhitespaceCruncher.crunch(content, e.currentContent)