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 <comphelper/string.hxx>
15 #include <xmloff/xmlnmspe.hxx>
17 using namespace com::sun::star
;
18 using namespace xmloff::token
;
20 ScXMLCellTextParaContext::ScXMLCellTextParaContext(
21 ScXMLImport
& rImport
, ScXMLTableRowCellContext
& rParent
) :
22 ScXMLImportContext(rImport
),
27 void SAL_CALL
ScXMLCellTextParaContext::endFastElement( sal_Int32
/*nElement*/ )
29 if (!maContent
.isEmpty())
30 mrParentCxt
.PushParagraphSpan(maContent
, OUString());
32 mrParentCxt
.PushParagraphEnd();
35 void SAL_CALL
ScXMLCellTextParaContext::characters( const OUString
& rChars
)
40 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextParaContext::createFastChildContext(
41 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
43 if (!maContent
.isEmpty())
45 mrParentCxt
.PushParagraphSpan(maContent
, OUString());
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);
55 case XML_ELEMENT( TEXT
, XML_SHEET_NAME
):
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);
67 return new SvXMLImportContext(GetImport());
70 void ScXMLCellTextParaContext::PushSpan(const OUString
& rSpan
, const OUString
& rStyleName
)
72 mrParentCxt
.PushParagraphSpan(rSpan
, rStyleName
);
75 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString
& rStyleName
)
77 mrParentCxt
.PushParagraphFieldSheetName(rStyleName
);
80 void ScXMLCellTextParaContext::PushFieldDate(const OUString
& rStyleName
)
82 mrParentCxt
.PushParagraphFieldDate(rStyleName
);
85 void ScXMLCellTextParaContext::PushFieldTitle(const OUString
& rStyleName
)
87 mrParentCxt
.PushParagraphFieldDocTitle(rStyleName
);
90 void ScXMLCellTextParaContext::PushFieldURL(
91 const OUString
& rURL
, const OUString
& rRep
, const OUString
& rStyleName
, const OUString
& rTargetFrame
)
93 mrParentCxt
.PushParagraphFieldURL(rURL
, rRep
, rStyleName
, rTargetFrame
);
96 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
97 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
98 ScXMLImportContext(rImport
),
103 void SAL_CALL
ScXMLCellTextSpanContext::startFastElement( sal_Int32
/*nElement*/,
104 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
106 if ( xAttrList
.is() )
108 sax_fastparser::FastAttributeList
*pAttribList
=
109 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
111 for (auto &aIter
: *pAttribList
)
113 switch (aIter
.getToken())
115 case XML_ELEMENT( TEXT
, XML_STYLE_NAME
):
116 maStyleName
= aIter
.toString();
125 void SAL_CALL
ScXMLCellTextSpanContext::endFastElement( sal_Int32
/*nElement*/ )
127 if (!maContent
.isEmpty())
129 mrParentCxt
.PushSpan(maContent
, maStyleName
);
133 void SAL_CALL
ScXMLCellTextSpanContext::characters( const OUString
& rChars
)
138 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextSpanContext::createFastChildContext(
139 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
141 if (!maContent
.isEmpty())
143 mrParentCxt
.PushSpan(maContent
, maStyleName
);
149 case XML_ELEMENT( TEXT
, XML_SHEET_NAME
):
151 ScXMLCellFieldSheetNameContext
* p
= new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt
);
152 p
->SetStyleName(maStyleName
);
155 case XML_ELEMENT( TEXT
, XML_DATE
):
157 ScXMLCellFieldDateContext
* p
= new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt
);
158 p
->SetStyleName(maStyleName
);
161 case XML_ELEMENT( TEXT
, XML_TITLE
):
163 ScXMLCellFieldTitleContext
* p
= new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt
);
164 p
->SetStyleName(maStyleName
);
167 case XML_ELEMENT( TEXT
, XML_A
):
169 ScXMLCellFieldURLContext
* p
= new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt
);
170 p
->SetStyleName(maStyleName
);
173 case XML_ELEMENT( TEXT
, XML_S
):
175 ScXMLCellFieldSContext
* p
= new ScXMLCellFieldSContext(GetScImport(), mrParentCxt
);
176 p
->SetStyleName(maStyleName
);
183 return new SvXMLImportContext(GetImport());
186 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
187 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
188 ScXMLImportContext(rImport
),
193 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString
& rStyleName
)
195 maStyleName
= rStyleName
;
198 void SAL_CALL
ScXMLCellFieldSheetNameContext::startFastElement( sal_Int32
/*nElement*/,
199 const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
201 // <text:sheet-name> has no attributes (that I'm aware of).
204 void SAL_CALL
ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32
/*nElement*/ )
206 mrParentCxt
.PushFieldSheetName(maStyleName
);
209 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
210 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
211 ScXMLImportContext(rImport
),
216 void ScXMLCellFieldDateContext::SetStyleName(const OUString
& rStyleName
)
218 maStyleName
= rStyleName
;
221 void SAL_CALL
ScXMLCellFieldDateContext::endFastElement( sal_Int32
/*nElement*/ )
223 mrParentCxt
.PushFieldDate(maStyleName
);
226 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
227 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
228 ScXMLImportContext(rImport
),
233 void ScXMLCellFieldTitleContext::SetStyleName(const OUString
& rStyleName
)
235 maStyleName
= rStyleName
;
238 void SAL_CALL
ScXMLCellFieldTitleContext::endFastElement( sal_Int32
/*nElement*/ )
240 mrParentCxt
.PushFieldTitle(maStyleName
);
243 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
244 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
245 ScXMLImportContext(rImport
),
250 void ScXMLCellFieldURLContext::SetStyleName(const OUString
& rStyleName
)
252 maStyleName
= rStyleName
;
255 void SAL_CALL
ScXMLCellFieldURLContext::startFastElement( sal_Int32
/*nElement*/,
256 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
258 if ( xAttrList
.is() )
260 sax_fastparser::FastAttributeList
*pAttribList
=
261 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
263 for (auto &aIter
: *pAttribList
)
265 switch (aIter
.getToken())
267 case XML_ELEMENT( XLINK
, XML_HREF
):
268 maURL
= aIter
.toString();
270 case XML_ELEMENT( XLINK
, XML_TYPE
):
273 case XML_ELEMENT( OFFICE
, XML_TARGET_FRAME_NAME
):
274 maTargetFrame
= aIter
.toString();
283 void SAL_CALL
ScXMLCellFieldURLContext::endFastElement( sal_Int32
/*nElement*/ )
285 mrParentCxt
.PushFieldURL(maURL
, maRep
, maStyleName
, maTargetFrame
);
288 void SAL_CALL
ScXMLCellFieldURLContext::characters( const OUString
& rChars
)
293 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
294 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
295 ScXMLImportContext(rImport
),
296 mrParentCxt(rParent
),
301 void ScXMLCellFieldSContext::SetStyleName(const OUString
& rStyleName
)
303 maStyleName
= rStyleName
;
306 void SAL_CALL
ScXMLCellFieldSContext::startFastElement( sal_Int32
/*nElement*/,
307 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
309 if ( xAttrList
.is() )
311 sax_fastparser::FastAttributeList
*pAttribList
=
312 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
314 for (auto &aIter
: *pAttribList
)
316 switch (aIter
.getToken())
318 case XML_ELEMENT( TEXT
, XML_C
):
319 mnCount
= aIter
.toInt32();
321 mnCount
= 1; // worth a warning?
330 void SAL_CALL
ScXMLCellFieldSContext::endFastElement( sal_Int32
/*nElement*/ )
336 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellFieldSContext::createFastChildContext(
337 sal_Int32
/*nElement*/, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
339 // <text:s> does not have child elements, but ...
346 return new SvXMLImportContext(GetImport());
349 void ScXMLCellFieldSContext::PushSpaces()
354 mrParentCxt
.PushSpan(" ", maStyleName
);
357 OUStringBuffer
aBuf( mnCount
);
358 comphelper::string::padToLength( aBuf
, mnCount
, ' ');
359 mrParentCxt
.PushSpan( aBuf
.makeStringAndClear(), maStyleName
);
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */