LibreOffice Module sc (master) 1
celltextparacontext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11#include "xmlimprt.hxx"
12#include "xmlcelli.hxx"
13
14#include <comphelper/string.hxx>
16#include <xmloff/xmltoken.hxx>
17
18using namespace com::sun::star;
19using namespace xmloff::token;
20
22 ScXMLImport& rImport, ScXMLTableRowCellContext& rParent) :
23 ScXMLImportContext(rImport),
24 mrParentCxt(rParent)
25{
26}
27
28void SAL_CALL ScXMLCellTextParaContext::endFastElement( sal_Int32 /*nElement*/ )
29{
30 if (!maContent.isEmpty())
32
34}
35
36void SAL_CALL ScXMLCellTextParaContext::characters( const OUString& rChars )
37{
38 maContent += rChars;
39}
40
41uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextParaContext::createFastChildContext(
42 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
43{
44 if (!maContent.isEmpty())
45 {
47 maContent.clear();
48 }
49
50 switch (nElement)
51 {
52 case XML_ELEMENT( TEXT, XML_S ):
53 return new ScXMLCellFieldSContext(GetScImport(), *this);
54 case XML_ELEMENT( TEXT, XML_SPAN ):
55 return new ScXMLCellTextSpanContext(GetScImport(), *this);
58 case XML_ELEMENT( TEXT, XML_DATE ):
59 return new ScXMLCellFieldDateContext(GetScImport(), *this);
60 case XML_ELEMENT( TEXT, XML_TITLE ):
61 return new ScXMLCellFieldTitleContext(GetScImport(), *this);
62 case XML_ELEMENT( TEXT, XML_A ):
63 return new ScXMLCellFieldURLContext(GetScImport(), *this);
64 case XML_ELEMENT( TEXT, XML_RUBY ):
65 return new ScXMLCellTextRubyContext(GetScImport(), *this);
67 maContent += "\t";
68 break;
70 maContent += "\x0a";
71 break;
75 // TODO: ooo95423-1 [file.ods] and tdf#116079-3 have these bookmarks.
76 // Is this valid, and how can we prevent losing these?
77 break;
78 default:
79 SAL_WARN("sc","unknown text element["<<nElement<<"]["<<SvXMLImport::getNameFromToken(nElement )<<"] lost");
80 }
81
82 return nullptr;
83}
84
85void ScXMLCellTextParaContext::PushSpan(std::u16string_view aSpan, const OUString& rStyleName)
86{
87 mrParentCxt.PushParagraphSpan(aSpan, rStyleName);
88}
89
90void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
91{
93}
94
95void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
96{
98}
99
100void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
101{
103}
104
106 const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
107{
108 mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
109}
110
112 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
113 ScXMLImportContext(rImport),
114 mrParentCxt(rParent)
115{
116}
117
118void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
119 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
120{
121 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
122 {
123 switch (aIter.getToken())
124 {
126 maStyleName = aIter.toString();
127 break;
128 default:
129 ;
130 }
131 }
132}
133
134void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
135{
137}
138
139void SAL_CALL ScXMLCellTextSpanContext::characters( const OUString& rChars )
140{
141 maContent += rChars;
142}
143
144uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextSpanContext::createFastChildContext(
145 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
146{
148
149 switch (nElement)
150 {
152 {
154 p->SetStyleName(maStyleName);
155 return p;
156 }
157 case XML_ELEMENT( TEXT, XML_DATE ):
158 {
160 p->SetStyleName(maStyleName);
161 return p;
162 }
163 case XML_ELEMENT( TEXT, XML_TITLE ):
164 {
166 p->SetStyleName(maStyleName);
167 return p;
168 }
169 case XML_ELEMENT( TEXT, XML_A ):
170 {
172 p->SetStyleName(maStyleName);
173 return p;
174 }
175 case XML_ELEMENT( TEXT, XML_S ):
176 {
178 p->SetStyleName(maStyleName);
179 return p;
180 }
181 default:
182 ;
183 }
184
185 return nullptr;
186}
187
189{
190 if (!maContent.isEmpty())
191 {
193 maContent.clear();
194 }
195}
196
198 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
199 ScXMLImportContext(rImport),
200 mrParentCxt(rParent)
201{
202}
203
204void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
205{
206 maStyleName = rStyleName;
207}
208
209void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
210{
212}
213
215 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
216 ScXMLImportContext(rImport),
217 mrParentCxt(rParent)
218{
219}
220
221void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
222{
223 maStyleName = rStyleName;
224}
225
226void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
227{
229}
230
232 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
233 ScXMLImportContext(rImport),
234 mrParentCxt(rParent)
235{
236}
237
238void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
239{
240 maStyleName = rStyleName;
241}
242
243void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
244{
246}
247
249 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
250 ScXMLImportContext(rImport),
251 mrParentCxt(rParent)
252{
253}
254
255void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
256{
257 maStyleName = rStyleName;
258}
259
260void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
261 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
262{
263 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
264 {
265 switch (aIter.getToken())
266 {
267 case XML_ELEMENT( XLINK, XML_HREF ):
268 maURL = aIter.toString();
269 break;
270 case XML_ELEMENT( XLINK, XML_TYPE ):
271 // Ignored for now.
272 break;
274 maTargetFrame = aIter.toString();
275 break;
276 default:
277 ;
278 }
279 }
280}
281
282void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
283{
285}
286
287void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
288{
289 maRep += rChars;
290}
291
293 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
294 ScXMLImportContext(rImport),
295 mrParentCxt(rParent),
296 mnCount(1)
297{
298}
299
300void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
301{
302 maStyleName = rStyleName;
303}
304
305void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
306 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
307{
308 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
309 {
310 switch (aIter.getToken())
311 {
312 case XML_ELEMENT( TEXT, XML_C ):
313 mnCount = aIter.toInt32();
314 if (mnCount <= 0)
315 mnCount = 1; // worth a warning?
316 break;
317 default:
318 ;
319 }
320 }
321}
322
323void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
324{
325 if (mnCount)
326 PushSpaces();
327}
328
329uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
330 sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
331{
332 // <text:s> does not have child elements, but ...
333 if (mnCount)
334 {
335 PushSpaces();
336 mnCount = 0;
337 }
338
339 return nullptr;
340}
341
343{
344 if (mnCount > 0)
345 {
346 if (mnCount == 1)
348 else
349 {
350 OUStringBuffer aBuf( mnCount);
352 mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
353 }
354 }
355}
356
358 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
359 ScXMLImportContext(rImport),
360 mrParentCxt(rParent)
361{
362}
363
364void SAL_CALL ScXMLCellTextRubyContext::startFastElement( sal_Int32 /*nElement*/,
365 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
366{
367 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
368 {
369 switch (aIter.getToken())
370 {
372 // This is ruby style instead of text style.
373 break;
374 default:
375 ;
376 }
377 }
378}
379
380uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextRubyContext::createFastChildContext(
381 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
382{
383
384 switch (nElement)
385 {
387 {
389 return p;
390 }
392 {
394 return p;
395 }
396 default:
397 ;
398 }
399
400 return nullptr;
401}
402
404 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
405 ScXMLCellTextSpanContext( rImport, rParent),
406 mrParentCxt(rParent)
407{
408}
409
410uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellRubyBaseContext::createFastChildContext(
411 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
412{
414
415 switch (nElement)
416 {
417 case XML_ELEMENT( TEXT, XML_SPAN ):
419 default:
420 ;
421 }
422 return nullptr;
423}
424
426 ScXMLImport& rImport, OUString& rRubyText, OUString& rRubyTextStyle) :
427 ScXMLImportContext(rImport),
428 mrRubyText(rRubyText),
429 mrRubyTextStyle(rRubyTextStyle)
430{
431}
432
433void SAL_CALL ScXMLCellRubyTextContext::startFastElement( sal_Int32 /*nElement*/,
434 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
435{
436 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
437 {
438 switch (aIter.getToken())
439 {
441 mrRubyTextStyle = aIter.toString();
442 break;
443 default:
444 ;
445 }
446 }
447}
448
449void SAL_CALL ScXMLCellRubyTextContext::characters( const OUString& rChars )
450{
451 mrRubyText+= rChars;
452}
453
454/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This context handles <text:date> element inside <text:p>.
void SetStyleName(const OUString &rStyleName)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLCellFieldDateContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
ScXMLCellTextParaContext & mrParentCxt
This context handles <text:s> element inside <text:p> or <text:span>.
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLCellFieldSContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void SetStyleName(const OUString &rStyleName)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCellTextParaContext & mrParentCxt
This context handles <text:sheet-name> element inside <text:p>.
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLCellFieldSheetNameContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
ScXMLCellTextParaContext & mrParentCxt
void SetStyleName(const OUString &rStyleName)
This context handles <text:title> element inside <text:p>.
ScXMLCellTextParaContext & mrParentCxt
void SetStyleName(const OUString &rStyleName)
ScXMLCellFieldTitleContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
This context handles <text:a> element inside <text:p> or <text:span>.
virtual void SAL_CALL characters(const OUString &aChars) override
ScXMLCellFieldURLContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLCellTextParaContext & mrParentCxt
void SetStyleName(const OUString &rStyleName)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
This context handles <text:ruby-base> element inside <text:ruby>.
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCellTextParaContext & mrParentCxt
ScXMLCellRubyBaseContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
This context handles <text:ruby-text> element inside <text:ruby>.
ScXMLCellRubyTextContext(ScXMLImport &rImport, OUString &rRubyText, OUString &rRubyTextStyle)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL characters(const OUString &aChars) override
This context handles <text:p> element inside <table:table-cell>.
void PushFieldTitle(const OUString &rStyleName)
void PushFieldURL(const OUString &rURL, const OUString &rRep, const OUString &rStyleName, const OUString &rTargetFrame)
void PushFieldSheetName(const OUString &rStyleName)
virtual void SAL_CALL characters(const OUString &aChars) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void PushSpan(std::u16string_view aSpan, const OUString &rStyleName)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
void PushFieldDate(const OUString &rStyleName)
ScXMLCellTextParaContext(ScXMLImport &rImport, ScXMLTableRowCellContext &rParent)
ScXMLTableRowCellContext & mrParentCxt
This context handles <text:ruby> element inside <text:p>.
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCellTextRubyContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCellTextParaContext & mrParentCxt
This context handles <text:span> element inside <text:p>.
ScXMLCellTextParaContext & mrParentCxt
ScXMLCellTextSpanContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL characters(const OUString &aChars) override
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
void PushParagraphFieldDocTitle(const OUString &rStyleName)
Definition: xmlcelli.cxx:587
void PushParagraphFieldSheetName(const OUString &rStyleName)
Definition: xmlcelli.cxx:581
void PushParagraphSpan(std::u16string_view rSpan, const OUString &rStyleName)
Definition: xmlcelli.cxx:313
void PushParagraphFieldDate(const OUString &rStyleName)
Definition: xmlcelli.cxx:576
void PushParagraphFieldURL(const OUString &rURL, const OUString &rRep, const OUString &rStyleName, const OUString &rTargetFrame)
Definition: xmlcelli.cxx:592
std::size_t mnCount
float u
void * p
#define SAL_WARN(area, stream)
aBuf
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill='\0')
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_LINE_BREAK
XML_C
XML_S
XML_SHEET_NAME
XML_HREF
XML_SPAN
XML_TARGET_FRAME_NAME
XML_BOOKMARK_START
XML_RUBY_TEXT
XML_RUBY_BASE
XML_TITLE
XML_STYLE_NAME
XML_BOOKMARK
XML_TAB
XML_BOOKMARK_END
XML_DATE
XML_RUBY
XML_A
XML_TYPE
TEXT
#define XML_ELEMENT(prefix, name)