Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / XMLIndexAlphabeticalSourceContext.cxx
blobfe6013619daa2f27975e16c556a99f766800db19
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "XMLIndexAlphabeticalSourceContext.hxx"
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <sax/tools/converter.hxx>
28 #include "XMLIndexTemplateContext.hxx"
29 #include <xmloff/xmlictxt.hxx>
30 #include <xmloff/xmlimp.hxx>
31 #include <xmloff/txtimp.hxx>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <rtl/ustring.hxx>
38 using ::com::sun::star::beans::XPropertySet;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Any;
41 using namespace ::xmloff::token;
43 XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
44 SvXMLImport& rImport,
45 Reference<XPropertySet> & rPropSet)
46 : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::None)
47 , bMainEntryStyleNameOK(false)
48 , bSeparators(false)
49 , bCombineEntries(true)
50 , bCaseSensitive(true)
51 , bEntry(false)
52 , bUpperCase(false)
53 , bCombineDash(false)
54 , bCombinePP(true)
55 , bCommaSeparated(false)
59 XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
63 void XMLIndexAlphabeticalSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
65 bool bTmp(false);
67 switch (aIter.getToken())
69 case XML_ELEMENT(TEXT, XML_MAIN_ENTRY_STYLE_NAME):
71 sMainEntryStyleName = aIter.toString();
72 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
73 XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName );
74 const Reference < css::container::XNameContainer >&
75 rStyles = GetImport().GetTextImport()->GetTextStyles();
76 bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
78 break;
80 case XML_ELEMENT(TEXT, XML_IGNORE_CASE):
81 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
83 bCaseSensitive = !bTmp;
85 break;
87 case XML_ELEMENT(TEXT, XML_ALPHABETICAL_SEPARATORS):
88 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
90 bSeparators = bTmp;
92 break;
94 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES):
95 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
97 bCombineEntries = bTmp;
99 break;
101 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_DASH):
102 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
104 bCombineDash = bTmp;
106 break;
107 case XML_ELEMENT(TEXT, XML_USE_KEYS_AS_ENTRIES):
108 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
110 bEntry = bTmp;
112 break;
114 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_PP):
115 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
117 bCombinePP = bTmp;
119 break;
121 case XML_ELEMENT(TEXT, XML_CAPITALIZE_ENTRIES):
122 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
124 bUpperCase = bTmp;
126 break;
128 case XML_ELEMENT(TEXT, XML_COMMA_SEPARATED):
129 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
131 bCommaSeparated = bTmp;
133 break;
135 case XML_ELEMENT(TEXT, XML_SORT_ALGORITHM):
136 sAlgorithm = aIter.toString();
137 break;
138 case XML_ELEMENT(STYLE, XML_RFC_LANGUAGE_TAG):
139 maLanguageTagODF.maRfcLanguageTag = aIter.toString();
140 break;
141 case XML_ELEMENT(FO, XML_LANGUAGE):
142 maLanguageTagODF.maLanguage = aIter.toString();
143 break;
144 case XML_ELEMENT(FO, XML_SCRIPT):
145 maLanguageTagODF.maScript = aIter.toString();
146 break;
147 case XML_ELEMENT(FO, XML_COUNTRY):
148 maLanguageTagODF.maCountry = aIter.toString();
149 break;
151 default:
152 XMLIndexSourceBaseContext::ProcessAttribute(aIter);
153 break;
157 void XMLIndexAlphabeticalSourceContext::endFastElement(sal_Int32 nElement)
160 Any aAny;
162 if (bMainEntryStyleNameOK)
164 aAny <<= GetImport().GetStyleDisplayName(
165 XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName );
166 rIndexPropertySet->setPropertyValue("MainEntryCharacterStyleName",aAny);
169 rIndexPropertySet->setPropertyValue("UseAlphabeticalSeparators", css::uno::Any(bSeparators));
170 rIndexPropertySet->setPropertyValue("UseCombinedEntries", css::uno::Any(bCombineEntries));
171 rIndexPropertySet->setPropertyValue("IsCaseSensitive", css::uno::Any(bCaseSensitive));
172 rIndexPropertySet->setPropertyValue("UseKeyAsEntry", css::uno::Any(bEntry));
173 rIndexPropertySet->setPropertyValue("UseUpperCase", css::uno::Any(bUpperCase));
174 rIndexPropertySet->setPropertyValue("UseDash", css::uno::Any(bCombineDash));
175 rIndexPropertySet->setPropertyValue("UsePP", css::uno::Any(bCombinePP));
176 rIndexPropertySet->setPropertyValue("IsCommaSeparated", css::uno::Any(bCommaSeparated));
179 if (!sAlgorithm.isEmpty())
181 rIndexPropertySet->setPropertyValue("SortAlgorithm", css::uno::Any(sAlgorithm));
184 if ( !maLanguageTagODF.isEmpty() )
186 aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
187 rIndexPropertySet->setPropertyValue("Locale", aAny);
190 XMLIndexSourceBaseContext::endFastElement(nElement);
193 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexAlphabeticalSourceContext::createFastChildContext(
194 sal_Int32 nElement,
195 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
197 if ( nElement == XML_ELEMENT(TEXT, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE) )
199 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
200 aLevelNameAlphaMap,
201 XML_OUTLINE_LEVEL,
202 aLevelStylePropNameAlphaMap,
203 aAllowedTokenTypesAlpha);
205 else
207 return XMLIndexSourceBaseContext::createFastChildContext(nElement,
208 xAttrList);
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */