LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / xmloff / source / text / XMLIndexAlphabeticalSourceContext.cxx
blobdf1385d95b0e39da6619eb479de656b3e48a9252
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 ::com::sun::star::xml::sax::XAttributeList;
42 using ::xmloff::token::IsXMLToken;
43 using namespace ::xmloff::token;
45 XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
46 SvXMLImport& rImport,
47 Reference<XPropertySet> & rPropSet)
48 : XMLIndexSourceBaseContext(rImport, rPropSet, false)
49 , bMainEntryStyleNameOK(false)
50 , bSeparators(false)
51 , bCombineEntries(true)
52 , bCaseSensitive(true)
53 , bEntry(false)
54 , bUpperCase(false)
55 , bCombineDash(false)
56 , bCombinePP(true)
57 , bCommaSeparated(false)
61 XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
65 void XMLIndexAlphabeticalSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
67 bool bTmp(false);
69 switch (aIter.getToken())
71 case XML_ELEMENT(TEXT, XML_MAIN_ENTRY_STYLE_NAME):
73 sMainEntryStyleName = aIter.toString();
74 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
75 XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName );
76 const Reference < css::container::XNameContainer >&
77 rStyles = GetImport().GetTextImport()->GetTextStyles();
78 bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
80 break;
82 case XML_ELEMENT(TEXT, XML_IGNORE_CASE):
83 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
85 bCaseSensitive = !bTmp;
87 break;
89 case XML_ELEMENT(TEXT, XML_ALPHABETICAL_SEPARATORS):
90 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
92 bSeparators = bTmp;
94 break;
96 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES):
97 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
99 bCombineEntries = bTmp;
101 break;
103 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_DASH):
104 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
106 bCombineDash = bTmp;
108 break;
109 case XML_ELEMENT(TEXT, XML_USE_KEYS_AS_ENTRIES):
110 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
112 bEntry = bTmp;
114 break;
116 case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_PP):
117 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
119 bCombinePP = bTmp;
121 break;
123 case XML_ELEMENT(TEXT, XML_CAPITALIZE_ENTRIES):
124 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
126 bUpperCase = bTmp;
128 break;
130 case XML_ELEMENT(TEXT, XML_COMMA_SEPARATED):
131 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
133 bCommaSeparated = bTmp;
135 break;
137 case XML_ELEMENT(TEXT, XML_SORT_ALGORITHM):
138 sAlgorithm = aIter.toString();
139 break;
140 case XML_ELEMENT(STYLE, XML_RFC_LANGUAGE_TAG):
141 maLanguageTagODF.maRfcLanguageTag = aIter.toString();
142 break;
143 case XML_ELEMENT(FO, XML_LANGUAGE):
144 maLanguageTagODF.maLanguage = aIter.toString();
145 break;
146 case XML_ELEMENT(FO, XML_SCRIPT):
147 maLanguageTagODF.maScript = aIter.toString();
148 break;
149 case XML_ELEMENT(FO, XML_COUNTRY):
150 maLanguageTagODF.maCountry = aIter.toString();
151 break;
153 default:
154 XMLIndexSourceBaseContext::ProcessAttribute(aIter);
155 break;
159 void XMLIndexAlphabeticalSourceContext::endFastElement(sal_Int32 nElement)
162 Any aAny;
164 if (bMainEntryStyleNameOK)
166 aAny <<= GetImport().GetStyleDisplayName(
167 XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName );
168 rIndexPropertySet->setPropertyValue("MainEntryCharacterStyleName",aAny);
171 rIndexPropertySet->setPropertyValue("UseAlphabeticalSeparators", css::uno::Any(bSeparators));
172 rIndexPropertySet->setPropertyValue("UseCombinedEntries", css::uno::Any(bCombineEntries));
173 rIndexPropertySet->setPropertyValue("IsCaseSensitive", css::uno::Any(bCaseSensitive));
174 rIndexPropertySet->setPropertyValue("UseKeyAsEntry", css::uno::Any(bEntry));
175 rIndexPropertySet->setPropertyValue("UseUpperCase", css::uno::Any(bUpperCase));
176 rIndexPropertySet->setPropertyValue("UseDash", css::uno::Any(bCombineDash));
177 rIndexPropertySet->setPropertyValue("UsePP", css::uno::Any(bCombinePP));
178 rIndexPropertySet->setPropertyValue("IsCommaSeparated", css::uno::Any(bCommaSeparated));
181 if (!sAlgorithm.isEmpty())
183 rIndexPropertySet->setPropertyValue("SortAlgorithm", css::uno::Any(sAlgorithm));
186 if ( !maLanguageTagODF.isEmpty() )
188 aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
189 rIndexPropertySet->setPropertyValue("Locale", aAny);
192 XMLIndexSourceBaseContext::endFastElement(nElement);
195 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexAlphabeticalSourceContext::createFastChildContext(
196 sal_Int32 nElement,
197 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
199 if ( nElement == XML_ELEMENT(TEXT, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE) )
201 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
202 aLevelNameAlphaMap,
203 XML_OUTLINE_LEVEL,
204 aLevelStylePropNameAlphaMap,
205 aAllowedTokenTypesAlpha);
207 else
209 return XMLIndexSourceBaseContext::createFastChildContext(nElement,
210 xAttrList);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */