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/xmlnmspe.hxx>
16 
17 using namespace com::sun::star;
18 using namespace xmloff::token;
19 
21  ScXMLImport& rImport, ScXMLTableRowCellContext& rParent) :
22  ScXMLImportContext(rImport),
23  mrParentCxt(rParent)
24 {
25 }
26 
27 void SAL_CALL ScXMLCellTextParaContext::endFastElement( sal_Int32 /*nElement*/ )
28 {
29  if (!maContent.isEmpty())
31 
33 }
34 
35 void SAL_CALL ScXMLCellTextParaContext::characters( const OUString& rChars )
36 {
37  maContent += rChars;
38 }
39 
40 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextParaContext::createFastChildContext(
41  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
42 {
43  if (!maContent.isEmpty())
44  {
46  maContent.clear();
47  }
48 
49  switch (nElement)
50  {
51  case XML_ELEMENT( TEXT, XML_S ):
52  return new ScXMLCellFieldSContext(GetScImport(), *this);
53  case XML_ELEMENT( TEXT, XML_SPAN ):
54  return new ScXMLCellTextSpanContext(GetScImport(), *this);
56  return new ScXMLCellFieldSheetNameContext(GetScImport(), *this);
57  case XML_ELEMENT( TEXT, XML_DATE ):
58  return new ScXMLCellFieldDateContext(GetScImport(), *this);
59  case XML_ELEMENT( TEXT, XML_TITLE ):
60  return new ScXMLCellFieldTitleContext(GetScImport(), *this);
61  case XML_ELEMENT( TEXT, XML_A ):
62  return new ScXMLCellFieldURLContext(GetScImport(), *this);
63  default:
64  ;
65  }
66 
67  return nullptr;
68 }
69 
70 void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
71 {
72  mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
73 }
74 
75 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
76 {
78 }
79 
80 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
81 {
83 }
84 
85 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
86 {
88 }
89 
91  const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
92 {
93  mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
94 }
95 
97  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
98  ScXMLImportContext(rImport),
99  mrParentCxt(rParent)
100 {
101 }
102 
103 void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
104  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
105 {
106  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
107  {
108  switch (aIter.getToken())
109  {
111  maStyleName = aIter.toString();
112  break;
113  default:
114  ;
115  }
116  }
117 }
118 
119 void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
120 {
121  if (!maContent.isEmpty())
122  {
124  }
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 {
135  if (!maContent.isEmpty())
136  {
138  maContent.clear();
139  }
140 
141  switch (nElement)
142  {
144  {
147  return p;
148  }
149  case XML_ELEMENT( TEXT, XML_DATE ):
150  {
153  return p;
154  }
155  case XML_ELEMENT( TEXT, XML_TITLE ):
156  {
159  return p;
160  }
161  case XML_ELEMENT( TEXT, XML_A ):
162  {
165  return p;
166  }
167  case XML_ELEMENT( TEXT, XML_S ):
168  {
171  return p;
172  }
173  default:
174  ;
175  }
176 
177  return nullptr;
178 }
179 
181  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
182  ScXMLImportContext(rImport),
183  mrParentCxt(rParent)
184 {
185 }
186 
187 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
188 {
189  maStyleName = rStyleName;
190 }
191 
192 void SAL_CALL ScXMLCellFieldSheetNameContext::startFastElement( sal_Int32 /*nElement*/,
193  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
194 {
195  // <text:sheet-name> has no attributes (that I'm aware of).
196 }
197 
198 void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
199 {
201 }
202 
204  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
205  ScXMLImportContext(rImport),
206  mrParentCxt(rParent)
207 {
208 }
209 
210 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
211 {
212  maStyleName = rStyleName;
213 }
214 
215 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
216 {
218 }
219 
221  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
222  ScXMLImportContext(rImport),
223  mrParentCxt(rParent)
224 {
225 }
226 
227 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
228 {
229  maStyleName = rStyleName;
230 }
231 
232 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
233 {
235 }
236 
238  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
239  ScXMLImportContext(rImport),
240  mrParentCxt(rParent)
241 {
242 }
243 
244 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
245 {
246  maStyleName = rStyleName;
247 }
248 
249 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
250  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
251 {
252  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
253  {
254  switch (aIter.getToken())
255  {
256  case XML_ELEMENT( XLINK, XML_HREF ):
257  maURL = aIter.toString();
258  break;
259  case XML_ELEMENT( XLINK, XML_TYPE ):
260  // Ignored for now.
261  break;
263  maTargetFrame = aIter.toString();
264  break;
265  default:
266  ;
267  }
268  }
269 }
270 
271 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
272 {
274 }
275 
276 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
277 {
278  maRep += rChars;
279 }
280 
282  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
283  ScXMLImportContext(rImport),
284  mrParentCxt(rParent),
285  mnCount(1)
286 {
287 }
288 
289 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
290 {
291  maStyleName = rStyleName;
292 }
293 
294 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
295  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
296 {
297  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
298  {
299  switch (aIter.getToken())
300  {
301  case XML_ELEMENT( TEXT, XML_C ):
302  mnCount = aIter.toInt32();
303  if (mnCount <= 0)
304  mnCount = 1; // worth a warning?
305  break;
306  default:
307  ;
308  }
309  }
310 }
311 
312 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
313 {
314  if (mnCount)
315  PushSpaces();
316 }
317 
318 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
319  sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
320 {
321  // <text:s> does not have child elements, but ...
322  if (mnCount)
323  {
324  PushSpaces();
325  mnCount = 0;
326  }
327 
328  return nullptr;
329 }
330 
332 {
333  if (mnCount > 0)
334  {
335  if (mnCount == 1)
337  else
338  {
339  OUStringBuffer aBuf( mnCount);
341  mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
342  }
343  }
344 }
345 
346 /* 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
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) 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:311
aBuf
ScXMLCellFieldTitleContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
ScXMLCellFieldDateContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
void SetStyleName(const OUString &rStyleName)
XML_TITLE
void PushFieldSheetName(const OUString &rStyleName)
XML_S
ScXMLCellFieldSheetNameContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
void PushParagraphFieldDocTitle(const OUString &rStyleName)
Definition: xmlcelli.cxx:586
void PushFieldTitle(const OUString &rStyleName)
XML_TYPE
ScXMLCellTextParaContext & mrParentCxt
This context handles element inside or .
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
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
This context handles element inside .
XML_DATE
XML_SHEET_NAME
ScXMLCellFieldSContext(ScXMLImport &rImport, ScXMLCellTextParaContext &rParent)
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
ScXMLCellTextParaContext & mrParentCxt
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
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:591
#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:580
void SetStyleName(const OUString &rStyleName)
void SetStyleName(const OUString &rStyleName)
void PushFieldDate(const OUString &rStyleName)
void PushParagraphFieldDate(const OUString &rStyleName)
Definition: xmlcelli.cxx:575
This context handles element inside .
virtual void SAL_CALL endFastElement(sal_Int32 nElement) 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)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
This context handles element inside or .
TEXT
This context handles element inside .
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill= '\0')