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 
10 #include "celltextparacontext.hxx"
11 #include "xmlimprt.hxx"
12 #include "xmlcelli.hxx"
13 
14 #include <comphelper/string.hxx>
15 #include <xmloff/xmlnamespace.hxx>
16 #include <xmloff/xmltkmap.hxx>
17 
18 using namespace com::sun::star;
19 using namespace xmloff::token;
20 
22  ScXMLImport& rImport, ScXMLTableRowCellContext& rParent) :
23  ScXMLImportContext(rImport),
24  mrParentCxt(rParent)
25 {
26 }
27 
28 void SAL_CALL ScXMLCellTextParaContext::endFastElement( sal_Int32 /*nElement*/ )
29 {
30  if (!maContent.isEmpty())
32 
34 }
35 
36 void SAL_CALL ScXMLCellTextParaContext::characters( const OUString& rChars )
37 {
38  maContent += rChars;
39 }
40 
41 uno::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);
57  return new ScXMLCellFieldSheetNameContext(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);
66  default:
67  ;
68  }
69 
70  return nullptr;
71 }
72 
73 void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
74 {
75  mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
76 }
77 
78 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
79 {
81 }
82 
83 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
84 {
86 }
87 
88 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
89 {
91 }
92 
94  const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
95 {
96  mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
97 }
98 
100  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
101  ScXMLImportContext(rImport),
102  mrParentCxt(rParent)
103 {
104 }
105 
106 void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
107  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
108 {
109  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
110  {
111  switch (aIter.getToken())
112  {
114  maStyleName = aIter.toString();
115  break;
116  default:
117  ;
118  }
119  }
120 }
121 
122 void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
123 {
125 }
126 
127 void SAL_CALL ScXMLCellTextSpanContext::characters( const OUString& rChars )
128 {
129  maContent += rChars;
130 }
131 
132 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextSpanContext::createFastChildContext(
133  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
134 {
136 
137  switch (nElement)
138  {
140  {
143  return p;
144  }
145  case XML_ELEMENT( TEXT, XML_DATE ):
146  {
149  return p;
150  }
151  case XML_ELEMENT( TEXT, XML_TITLE ):
152  {
155  return p;
156  }
157  case XML_ELEMENT( TEXT, XML_A ):
158  {
161  return p;
162  }
163  case XML_ELEMENT( TEXT, XML_S ):
164  {
167  return p;
168  }
169  default:
170  ;
171  }
172 
173  return nullptr;
174 }
175 
177 {
178  if (!maContent.isEmpty())
179  {
181  maContent.clear();
182  }
183 }
184 
186  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
187  ScXMLImportContext(rImport),
188  mrParentCxt(rParent)
189 {
190 }
191 
192 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
193 {
194  maStyleName = rStyleName;
195 }
196 
197 void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
198 {
200 }
201 
203  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
204  ScXMLImportContext(rImport),
205  mrParentCxt(rParent)
206 {
207 }
208 
209 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
210 {
211  maStyleName = rStyleName;
212 }
213 
214 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
215 {
217 }
218 
220  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
221  ScXMLImportContext(rImport),
222  mrParentCxt(rParent)
223 {
224 }
225 
226 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
227 {
228  maStyleName = rStyleName;
229 }
230 
231 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
232 {
234 }
235 
237  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
238  ScXMLImportContext(rImport),
239  mrParentCxt(rParent)
240 {
241 }
242 
243 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
244 {
245  maStyleName = rStyleName;
246 }
247 
248 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
249  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
250 {
251  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
252  {
253  switch (aIter.getToken())
254  {
255  case XML_ELEMENT( XLINK, XML_HREF ):
256  maURL = aIter.toString();
257  break;
258  case XML_ELEMENT( XLINK, XML_TYPE ):
259  // Ignored for now.
260  break;
262  maTargetFrame = aIter.toString();
263  break;
264  default:
265  ;
266  }
267  }
268 }
269 
270 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
271 {
273 }
274 
275 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
276 {
277  maRep += rChars;
278 }
279 
281  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
282  ScXMLImportContext(rImport),
283  mrParentCxt(rParent),
284  mnCount(1)
285 {
286 }
287 
288 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
289 {
290  maStyleName = rStyleName;
291 }
292 
293 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
294  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
295 {
296  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
297  {
298  switch (aIter.getToken())
299  {
300  case XML_ELEMENT( TEXT, XML_C ):
301  mnCount = aIter.toInt32();
302  if (mnCount <= 0)
303  mnCount = 1; // worth a warning?
304  break;
305  default:
306  ;
307  }
308  }
309 }
310 
311 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
312 {
313  if (mnCount)
314  PushSpaces();
315 }
316 
317 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
318  sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
319 {
320  // <text:s> does not have child elements, but ...
321  if (mnCount)
322  {
323  PushSpaces();
324  mnCount = 0;
325  }
326 
327  return nullptr;
328 }
329 
331 {
332  if (mnCount > 0)
333  {
334  if (mnCount == 1)
336  else
337  {
338  OUStringBuffer aBuf( mnCount);
340  mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
341  }
342  }
343 }
344 
346  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
347  ScXMLImportContext(rImport),
348  mrParentCxt(rParent)
349 {
350 }
351 
352 void SAL_CALL ScXMLCellTextRubyContext::startFastElement( sal_Int32 /*nElement*/,
353  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
354 {
355  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
356  {
357  switch (aIter.getToken())
358  {
360  // This is ruby style instead of text style.
361  break;
362  default:
363  ;
364  }
365  }
366 }
367 
368 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextRubyContext::createFastChildContext(
369  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
370 {
371 
372  switch (nElement)
373  {
374  case XML_ELEMENT( TEXT, XML_RUBY_BASE ):
375  {
377  return p;
378  }
379  case XML_ELEMENT( TEXT, XML_RUBY_TEXT ):
380  {
382  return p;
383  }
384  default:
385  ;
386  }
387 
388  return nullptr;
389 }
390 
392  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
393  ScXMLCellTextSpanContext( rImport, rParent),
394  mrParentCxt(rParent)
395 {
396 }
397 
398 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellRubyBaseContext::createFastChildContext(
399  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
400 {
402 
403  switch (nElement)
404  {
405  case XML_ELEMENT( TEXT, XML_SPAN ):
407  default:
408  ;
409  }
410  return nullptr;
411 }
412 
414  ScXMLImport& rImport, OUString& rRubyText, OUString& rRubyTextStyle) :
415  ScXMLImportContext(rImport),
416  mrRubyText(rRubyText),
417  mrRubyTextStyle(rRubyTextStyle)
418 {
419 }
420 
421 void SAL_CALL ScXMLCellRubyTextContext::startFastElement( sal_Int32 /*nElement*/,
422  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
423 {
424  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
425  {
426  switch (aIter.getToken())
427  {
429  mrRubyTextStyle = aIter.toString();
430  break;
431  default:
432  ;
433  }
434  }
435 }
436 
437 void SAL_CALL ScXMLCellRubyTextContext::characters( const OUString& rChars )
438 {
439  mrRubyText+= rChars;
440 }
441 
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
XML_STYLE_NAME
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
void PushFieldURL(const OUString &rURL, const OUString &rRep, const OUString &rStyleName, const OUString &rTargetFrame)
ScXMLCellTextParaContext & mrParentCxt
void PushParagraphSpan(const OUString &rSpan, const OUString &rStyleName)
Definition: xmlcelli.cxx:313
ScXMLCellRubyBaseContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
aBuf
ScXMLCellFieldTitleContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
ScXMLCellFieldDateContext(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
void SetStyleName(const OUString &rStyleName)
XML_TITLE
void PushFieldSheetName(const OUString &rStyleName)
XML_S
ScXMLCellFieldSheetNameContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void PushParagraphFieldDocTitle(const OUString &rStyleName)
Definition: xmlcelli.cxx:588
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 PushFieldTitle(const OUString &rStyleName)
virtual void SAL_CALL characters(const OUString &aChars) override
XML_TYPE
ScXMLCellTextParaContext & mrParentCxt
ScXMLCellTextParaContext & mrParentCxt
This context handles element inside or .
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLCellRubyTextContext(ScXMLImport &rImport, OUString &rRubyText, OUString &rRubyTextStyle)
virtual void SAL_CALL characters(const OUString &aChars) override
ScXMLCellFieldURLContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
This class exists only to provide GetScImport() to its derived classes.
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCellTextParaContext & mrParentCxt
This context handles element inside .
XML_DATE
XML_SHEET_NAME
ScXMLCellFieldSContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
XML_RUBY_TEXT
This context handles element inside .
ScXMLCellTextParaContext & mrParentCxt
virtual void SAL_CALL characters(const OUString &aChars) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XML_HREF
virtual void SAL_CALL characters(const OUString &aChars) override
ScXMLCellTextSpanContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
XML_SPAN
ScXMLImport & GetScImport()
std::size_t mnCount
void SetStyleName(const OUString &rStyleName)
XML_A
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
This context handles element inside .
ScXMLCellTextParaContext & mrParentCxt
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
This context handles element inside .
XML_RUBY_BASE
ScXMLCellTextParaContext & mrParentCxt
void SetStyleName(const OUString &rStyleName)
ScXMLTableRowCellContext & mrParentCxt
XML_C
void PushParagraphFieldURL(const OUString &rURL, const OUString &rRep, const OUString &rStyleName, const OUString &rTargetFrame)
Definition: xmlcelli.cxx:593
#define XML_ELEMENT(prefix, name)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
void * p
XML_TARGET_FRAME_NAME
void PushParagraphFieldSheetName(const OUString &rStyleName)
Definition: xmlcelli.cxx:582
XML_RUBY
void SetStyleName(const OUString &rStyleName)
void SetStyleName(const OUString &rStyleName)
void PushFieldDate(const OUString &rStyleName)
void PushParagraphFieldDate(const OUString &rStyleName)
Definition: xmlcelli.cxx:577
This context handles element inside .
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
This context handles element inside .
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void PushSpan(const OUString &rSpan, const OUString &rStyleName)
ScXMLCellTextParaContext(ScXMLImport &rImport, ScXMLTableRowCellContext &rParent)
ScXMLCellTextRubyContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
This context handles element inside or .
TEXT
This context handles element inside .
This context handles element inside .
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill= '\0')