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 
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::endFastElement( sal_Int32 /*nElement*/ )
193 {
195 }
196 
198  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
199  ScXMLImportContext(rImport),
200  mrParentCxt(rParent)
201 {
202 }
203 
204 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
205 {
206  maStyleName = rStyleName;
207 }
208 
209 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
210 {
212 }
213 
215  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
216  ScXMLImportContext(rImport),
217  mrParentCxt(rParent)
218 {
219 }
220 
221 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
222 {
223  maStyleName = rStyleName;
224 }
225 
226 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
227 {
229 }
230 
232  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
233  ScXMLImportContext(rImport),
234  mrParentCxt(rParent)
235 {
236 }
237 
238 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
239 {
240  maStyleName = rStyleName;
241 }
242 
243 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
244  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
245 {
246  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
247  {
248  switch (aIter.getToken())
249  {
250  case XML_ELEMENT( XLINK, XML_HREF ):
251  maURL = aIter.toString();
252  break;
253  case XML_ELEMENT( XLINK, XML_TYPE ):
254  // Ignored for now.
255  break;
257  maTargetFrame = aIter.toString();
258  break;
259  default:
260  ;
261  }
262  }
263 }
264 
265 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
266 {
268 }
269 
270 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
271 {
272  maRep += rChars;
273 }
274 
276  ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
277  ScXMLImportContext(rImport),
278  mrParentCxt(rParent),
279  mnCount(1)
280 {
281 }
282 
283 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
284 {
285  maStyleName = rStyleName;
286 }
287 
288 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
289  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
290 {
291  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
292  {
293  switch (aIter.getToken())
294  {
295  case XML_ELEMENT( TEXT, XML_C ):
296  mnCount = aIter.toInt32();
297  if (mnCount <= 0)
298  mnCount = 1; // worth a warning?
299  break;
300  default:
301  ;
302  }
303  }
304 }
305 
306 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
307 {
308  if (mnCount)
309  PushSpaces();
310 }
311 
312 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
313  sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
314 {
315  // <text:s> does not have child elements, but ...
316  if (mnCount)
317  {
318  PushSpaces();
319  mnCount = 0;
320  }
321 
322  return nullptr;
323 }
324 
326 {
327  if (mnCount > 0)
328  {
329  if (mnCount == 1)
331  else
332  {
333  OUStringBuffer aBuf( mnCount);
335  mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
336  }
337  }
338 }
339 
340 /* 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:312
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:587
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:592
#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:581
void SetStyleName(const OUString &rStyleName)
void SetStyleName(const OUString &rStyleName)
void PushFieldDate(const OUString &rStyleName)
void PushParagraphFieldDate(const OUString &rStyleName)
Definition: xmlcelli.cxx:576
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')