Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / xmllinebreakcontext.cxx
blob67b56c2d32c8c2e3aa2118db84f63c6e2a67c556
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "xmllinebreakcontext.hxx"
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/frame/XModel.hpp>
14 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
15 #include <com/sun/star/text/XTextContent.hpp>
17 #include <xmloff/xmlement.hxx>
18 #include <xmloff/xmlimp.hxx>
19 #include <xmloff/xmlnamespace.hxx>
20 #include <xmloff/xmluconv.hxx>
22 using namespace com::sun::star;
23 using namespace xmloff::token;
25 namespace
27 const SvXMLEnumMapEntry<sal_Int16> pXML_LineBreakClear_Enum[] = {
28 { XML_NONE, 0 }, { XML_LEFT, 1 }, { XML_RIGHT, 2 }, { XML_ALL, 3 }, { XML_TOKEN_INVALID, 0 }
32 SvXMLLineBreakContext::SvXMLLineBreakContext(SvXMLImport& rImport, XMLTextImportHelper& rHelper)
33 : SvXMLImportContext(rImport)
34 , m_rHelper(rHelper)
38 void SvXMLLineBreakContext::startFastElement(
39 sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
41 const uno::Reference<frame::XModel>& xModel = GetImport().GetModel();
42 uno::Reference<lang::XMultiServiceFactory> xFactory(xModel, uno::UNO_QUERY);
43 if (!xFactory.is())
44 return;
46 uno::Reference<text::XTextContent> xLineBreak(
47 xFactory->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY);
49 sal_Int16 eClear = 0;
50 OUString aClear = xAttrList->getValue(XML_ELEMENT(LO_EXT, XML_CLEAR));
51 if (SvXMLUnitConverter::convertEnum(eClear, aClear, pXML_LineBreakClear_Enum))
53 uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, uno::UNO_QUERY);
54 xLineBreakProps->setPropertyValue("Clear", uno::Any(eClear));
57 m_rHelper.InsertTextContent(xLineBreak);
60 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */