1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "xmltbli.hxx"
12 #include "txtparai.hxx"
14 #include "xmltext.hxx"
16 #include <sal/log.hxx>
18 using namespace com::sun::star
;
20 namespace writerperfect::exp
24 /// Handler for <table:table-row>.
25 class XMLTableRowContext
: public XMLImportContext
28 XMLTableRowContext(XMLImport
& rImport
);
30 rtl::Reference
<XMLImportContext
>
31 CreateChildContext(const OUString
& rName
,
32 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
33 int GetColumn() const;
34 void SetColumn(int nColumn
);
37 startElement(const OUString
& rName
,
38 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
39 void SAL_CALL
endElement(const OUString
& rName
) override
;
45 /// Handler for <table:cell>.
46 class XMLTableCellContext
: public XMLImportContext
49 XMLTableCellContext(XMLImport
& rImport
, XMLTableRowContext
& rRow
);
51 rtl::Reference
<XMLImportContext
>
52 CreateChildContext(const OUString
& rName
,
53 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
56 startElement(const OUString
& rName
,
57 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
58 void SAL_CALL
endElement(const OUString
& rName
) override
;
61 XMLTableRowContext
& m_rRow
;
65 XMLTableCellContext::XMLTableCellContext(XMLImport
& rImport
, XMLTableRowContext
& rRow
)
66 : XMLImportContext(rImport
)
71 rtl::Reference
<XMLImportContext
> XMLTableCellContext::CreateChildContext(
72 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
74 return CreateTextChildContext(GetImport(), rName
);
77 void XMLTableCellContext::startElement(
78 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
80 librevenge::RVNGPropertyList aPropertyList
;
81 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
83 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
84 const OUString
& rAttributeValue
= xAttribs
->getValueByIndex(i
);
86 if (rAttributeName
== "table:style-name")
87 FillStyles(rAttributeValue
, GetImport().GetAutomaticCellStyles(),
88 GetImport().GetCellStyles(), aPropertyList
);
91 OString sName
= OUStringToOString(rAttributeName
, RTL_TEXTENCODING_UTF8
);
92 OString sValue
= OUStringToOString(rAttributeValue
, RTL_TEXTENCODING_UTF8
);
93 aPropertyList
.insert(sName
.getStr(), sValue
.getStr());
96 aPropertyList
.insert("librevenge:column", m_rRow
.GetColumn());
97 GetImport().GetGenerator().openTableCell(aPropertyList
);
98 m_rRow
.SetColumn(m_rRow
.GetColumn() + 1);
101 void XMLTableCellContext::endElement(const OUString
& /*rName*/)
103 GetImport().GetGenerator().closeTableCell();
108 /// Handler for <table:table-column>.
109 class XMLTableColumnContext
: public XMLImportContext
112 XMLTableColumnContext(XMLImport
& rImport
, librevenge::RVNGPropertyListVector
& rColumns
);
115 startElement(const OUString
& rName
,
116 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
119 librevenge::RVNGPropertyListVector
& m_rColumns
;
123 XMLTableColumnContext::XMLTableColumnContext(XMLImport
& rImport
,
124 librevenge::RVNGPropertyListVector
& rColumns
)
125 : XMLImportContext(rImport
)
126 , m_rColumns(rColumns
)
130 void XMLTableColumnContext::startElement(
131 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
133 librevenge::RVNGPropertyList aPropertyList
;
134 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
136 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
137 const OUString
& rAttributeValue
= xAttribs
->getValueByIndex(i
);
139 if (rAttributeName
== "table:style-name")
140 FillStyles(rAttributeValue
, GetImport().GetAutomaticColumnStyles(),
141 GetImport().GetColumnStyles(), aPropertyList
);
143 m_rColumns
.append(aPropertyList
);
146 XMLTableRowContext::XMLTableRowContext(XMLImport
& rImport
)
147 : XMLImportContext(rImport
)
151 rtl::Reference
<XMLImportContext
> XMLTableRowContext::CreateChildContext(
152 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
154 if (rName
== "table:table-cell")
155 return new XMLTableCellContext(GetImport(), *this);
156 if (rName
== "table:covered-table-cell")
159 GetImport().GetGenerator().insertCoveredTableCell(librevenge::RVNGPropertyList());
162 SAL_WARN("writerperfect", "XMLTableRowContext::CreateChildContext: unhandled " << rName
);
166 void XMLTableRowContext::startElement(
167 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
169 librevenge::RVNGPropertyList aPropertyList
;
170 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
172 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
173 const OUString
& rAttributeValue
= xAttribs
->getValueByIndex(i
);
175 if (rAttributeName
== "table:style-name")
176 FillStyles(rAttributeValue
, GetImport().GetAutomaticRowStyles(),
177 GetImport().GetRowStyles(), aPropertyList
);
179 GetImport().GetGenerator().openTableRow(aPropertyList
);
182 void XMLTableRowContext::endElement(const OUString
& /*rName*/)
184 GetImport().GetGenerator().closeTableRow();
187 int XMLTableRowContext::GetColumn() const { return m_nColumn
; }
189 void XMLTableRowContext::SetColumn(int nColumn
) { m_nColumn
= nColumn
; }
191 XMLTableContext::XMLTableContext(XMLImport
& rImport
, bool bTopLevel
)
192 : XMLImportContext(rImport
)
193 , m_bTopLevel(bTopLevel
)
197 rtl::Reference
<XMLImportContext
> XMLTableContext::CreateChildContext(
198 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
200 if (rName
== "table:table-column")
201 // Make sure columns are parsed before we open the table.
202 return new XMLTableColumnContext(GetImport(), m_aColumns
);
206 if (!m_aColumns
.empty())
207 m_aPropertyList
.insert("librevenge:table-columns", m_aColumns
);
208 GetImport().GetGenerator().openTable(m_aPropertyList
);
209 m_bTableOpened
= true;
212 if (rName
== "table:table-row")
213 return new XMLTableRowContext(GetImport());
215 SAL_WARN("writerperfect", "XMLTableContext::CreateChildContext: unhandled " << rName
);
220 void XMLTableContext::startElement(
221 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
223 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
225 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
226 const OUString
& rAttributeValue
= xAttribs
->getValueByIndex(i
);
228 if (rAttributeName
== "table:style-name")
230 FillStyles(rAttributeValue
, GetImport().GetAutomaticTableStyles(),
231 GetImport().GetTableStyles(), m_aPropertyList
);
233 GetImport().HandlePageSpan(m_aPropertyList
);
237 OString sName
= OUStringToOString(rAttributeName
, RTL_TEXTENCODING_UTF8
);
238 OString sValue
= OUStringToOString(rAttributeValue
, RTL_TEXTENCODING_UTF8
);
239 m_aPropertyList
.insert(sName
.getStr(), sValue
.getStr());
244 void XMLTableContext::endElement(const OUString
& /*rName*/)
248 GetImport().GetGenerator().closeTable();
252 } // namespace writerperfect::exp
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */