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 "celltextparacontext.hxx"
11 #include "xmlimprt.hxx"
12 #include "xmlcelli.hxx"
14 #include <xmloff/nmspmap.hxx>
15 #include <comphelper/string.hxx>
17 #include <com/sun/star/xml/sax/XAttributeList.hpp>
19 using namespace com::sun::star
;
21 ScXMLCellTextParaContext::ScXMLCellTextParaContext(
22 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLTableRowCellContext
& rParent
) :
23 ScXMLImportContext(rImport
, nPrefix
, rLName
),
28 void ScXMLCellTextParaContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
32 void ScXMLCellTextParaContext::EndElement()
34 if (!maContent
.isEmpty())
35 mrParentCxt
.PushParagraphSpan(maContent
, OUString());
37 mrParentCxt
.PushParagraphEnd();
40 void ScXMLCellTextParaContext::Characters(const OUString
& rChars
)
45 SvXMLImportContext
* ScXMLCellTextParaContext::CreateChildContext(
46 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
48 if (!maContent
.isEmpty())
50 mrParentCxt
.PushParagraphSpan(maContent
, OUString());
54 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetCellTextParaElemTokenMap();
55 switch (rTokenMap
.Get(nPrefix
, rLocalName
))
57 case XML_TOK_CELL_TEXT_S
:
58 return new ScXMLCellFieldSContext(GetScImport(), nPrefix
, rLocalName
, *this);
59 case XML_TOK_CELL_TEXT_SPAN
:
60 return new ScXMLCellTextSpanContext(GetScImport(), nPrefix
, rLocalName
, *this);
61 case XML_TOK_CELL_TEXT_SHEET_NAME
:
62 return new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix
, rLocalName
, *this);
63 case XML_TOK_CELL_TEXT_DATE
:
64 return new ScXMLCellFieldDateContext(GetScImport(), nPrefix
, rLocalName
, *this);
65 case XML_TOK_CELL_TEXT_TITLE
:
66 return new ScXMLCellFieldTitleContext(GetScImport(), nPrefix
, rLocalName
, *this);
67 case XML_TOK_CELL_TEXT_URL
:
68 return new ScXMLCellFieldURLContext(GetScImport(), nPrefix
, rLocalName
, *this);
73 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
76 void ScXMLCellTextParaContext::PushSpan(const OUString
& rSpan
, const OUString
& rStyleName
)
78 mrParentCxt
.PushParagraphSpan(rSpan
, rStyleName
);
81 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString
& rStyleName
)
83 mrParentCxt
.PushParagraphFieldSheetName(rStyleName
);
86 void ScXMLCellTextParaContext::PushFieldDate(const OUString
& rStyleName
)
88 mrParentCxt
.PushParagraphFieldDate(rStyleName
);
91 void ScXMLCellTextParaContext::PushFieldTitle(const OUString
& rStyleName
)
93 mrParentCxt
.PushParagraphFieldDocTitle(rStyleName
);
96 void ScXMLCellTextParaContext::PushFieldURL(
97 const OUString
& rURL
, const OUString
& rRep
, const OUString
& rStyleName
)
99 mrParentCxt
.PushParagraphFieldURL(rURL
, rRep
, rStyleName
);
102 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
103 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
104 ScXMLImportContext(rImport
, nPrefix
, rLName
),
109 void ScXMLCellTextSpanContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
115 sal_Int16 nAttrCount
= xAttrList
->getLength();
117 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetCellTextSpanAttrTokenMap();
118 for (sal_Int16 i
= 0; i
< nAttrCount
; ++i
)
120 sal_uInt16 nAttrPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
121 xAttrList
->getNameByIndex(i
), &aLocalName
);
123 const OUString
& rAttrValue
= xAttrList
->getValueByIndex(i
);
124 sal_uInt16 nToken
= rTokenMap
.Get(nAttrPrefix
, aLocalName
);
127 case XML_TOK_CELL_TEXT_SPAN_ATTR_STYLE_NAME
:
128 maStyleName
= rAttrValue
;
136 void ScXMLCellTextSpanContext::EndElement()
138 if (!maContent
.isEmpty())
140 mrParentCxt
.PushSpan(maContent
, maStyleName
);
144 void ScXMLCellTextSpanContext::Characters(const OUString
& rChars
)
149 SvXMLImportContext
* ScXMLCellTextSpanContext::CreateChildContext(
150 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
152 if (!maContent
.isEmpty())
154 mrParentCxt
.PushSpan(maContent
, maStyleName
);
158 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetCellTextSpanElemTokenMap();
159 switch (rTokenMap
.Get(nPrefix
, rLocalName
))
161 case XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME
:
163 ScXMLCellFieldSheetNameContext
* p
= new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix
, rLocalName
, mrParentCxt
);
164 p
->SetStyleName(maStyleName
);
167 case XML_TOK_CELL_TEXT_SPAN_ELEM_DATE
:
169 ScXMLCellFieldDateContext
* p
= new ScXMLCellFieldDateContext(GetScImport(), nPrefix
, rLocalName
, mrParentCxt
);
170 p
->SetStyleName(maStyleName
);
173 case XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE
:
175 ScXMLCellFieldTitleContext
* p
= new ScXMLCellFieldTitleContext(GetScImport(), nPrefix
, rLocalName
, mrParentCxt
);
176 p
->SetStyleName(maStyleName
);
179 case XML_TOK_CELL_TEXT_SPAN_ELEM_URL
:
181 ScXMLCellFieldURLContext
* p
= new ScXMLCellFieldURLContext(GetScImport(), nPrefix
, rLocalName
, mrParentCxt
);
182 p
->SetStyleName(maStyleName
);
185 case XML_TOK_CELL_TEXT_SPAN_ELEM_S
:
187 ScXMLCellFieldSContext
* p
= new ScXMLCellFieldSContext(GetScImport(), nPrefix
, rLocalName
, mrParentCxt
);
188 p
->SetStyleName(maStyleName
);
195 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
198 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
199 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
200 ScXMLImportContext(rImport
, nPrefix
, rLName
),
205 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString
& rStyleName
)
207 maStyleName
= rStyleName
;
210 void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
212 // <text:sheet-name> has no attributes (that I'm aware of).
215 void ScXMLCellFieldSheetNameContext::EndElement()
217 mrParentCxt
.PushFieldSheetName(maStyleName
);
220 void ScXMLCellFieldSheetNameContext::Characters(const OUString
& /*rChars*/)
224 SvXMLImportContext
* ScXMLCellFieldSheetNameContext::CreateChildContext(
225 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
227 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
230 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
231 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
232 ScXMLImportContext(rImport
, nPrefix
, rLName
),
237 void ScXMLCellFieldDateContext::SetStyleName(const OUString
& rStyleName
)
239 maStyleName
= rStyleName
;
242 void ScXMLCellFieldDateContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
246 void ScXMLCellFieldDateContext::EndElement()
248 mrParentCxt
.PushFieldDate(maStyleName
);
251 void ScXMLCellFieldDateContext::Characters(const OUString
& /*rChars*/)
255 SvXMLImportContext
* ScXMLCellFieldDateContext::CreateChildContext(
256 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
258 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
261 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
262 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
263 ScXMLImportContext(rImport
, nPrefix
, rLName
),
268 void ScXMLCellFieldTitleContext::SetStyleName(const OUString
& rStyleName
)
270 maStyleName
= rStyleName
;
273 void ScXMLCellFieldTitleContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
277 void ScXMLCellFieldTitleContext::EndElement()
279 mrParentCxt
.PushFieldTitle(maStyleName
);
282 void ScXMLCellFieldTitleContext::Characters(const OUString
& /*rChars*/)
286 SvXMLImportContext
* ScXMLCellFieldTitleContext::CreateChildContext(
287 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
289 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
292 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
293 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
294 ScXMLImportContext(rImport
, nPrefix
, rLName
),
299 void ScXMLCellFieldURLContext::SetStyleName(const OUString
& rStyleName
)
301 maStyleName
= rStyleName
;
304 void ScXMLCellFieldURLContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
310 sal_Int16 nAttrCount
= xAttrList
->getLength();
312 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetCellTextURLAttrTokenMap();
313 for (sal_Int16 i
= 0; i
< nAttrCount
; ++i
)
315 sal_uInt16 nAttrPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
316 xAttrList
->getNameByIndex(i
), &aLocalName
);
318 const OUString
& rAttrValue
= xAttrList
->getValueByIndex(i
);
319 sal_uInt16 nToken
= rTokenMap
.Get(nAttrPrefix
, aLocalName
);
322 case XML_TOK_CELL_TEXT_URL_ATTR_UREF
:
325 case XML_TOK_CELL_TEXT_URL_ATTR_TYPE
:
334 void ScXMLCellFieldURLContext::EndElement()
336 mrParentCxt
.PushFieldURL(maURL
, maRep
, maStyleName
);
339 void ScXMLCellFieldURLContext::Characters(const OUString
& rChars
)
344 SvXMLImportContext
* ScXMLCellFieldURLContext::CreateChildContext(
345 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
347 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
350 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
351 ScXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLName
, ScXMLCellTextParaContext
& rParent
) :
352 ScXMLImportContext(rImport
, nPrefix
, rLName
),
353 mrParentCxt(rParent
),
358 void ScXMLCellFieldSContext::SetStyleName(const OUString
& rStyleName
)
360 maStyleName
= rStyleName
;
363 void ScXMLCellFieldSContext::StartElement(const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
369 sal_Int16 nAttrCount
= xAttrList
->getLength();
371 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetCellTextSAttrTokenMap();
372 for (sal_Int16 i
= 0; i
< nAttrCount
; ++i
)
374 sal_uInt16 nAttrPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
375 xAttrList
->getNameByIndex(i
), &aLocalName
);
377 const OUString
& rAttrValue
= xAttrList
->getValueByIndex(i
);
378 sal_uInt16 nToken
= rTokenMap
.Get(nAttrPrefix
, aLocalName
);
381 case XML_TOK_CELL_TEXT_S_ATTR_C
:
382 mnCount
= rAttrValue
.toInt32();
384 mnCount
= 1; // worth a warning?
392 void ScXMLCellFieldSContext::EndElement()
398 SvXMLImportContext
* ScXMLCellFieldSContext::CreateChildContext(
399 sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& /*xAttrList*/)
401 // <text:s> does not have child elements, but ...
408 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
411 void ScXMLCellFieldSContext::PushSpaces()
416 mrParentCxt
.PushSpan(" ", maStyleName
);
419 OUStringBuffer
aBuf( mnCount
);
420 comphelper::string::padToLength( aBuf
, mnCount
, ' ');
421 mrParentCxt
.PushSpan( aBuf
.makeStringAndClear(), maStyleName
);
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */