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/.
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(
45 Reference
<XPropertySet
> & rPropSet
)
46 : XMLIndexSourceBaseContext(rImport
, rPropSet
, UseStyles::None
)
47 , bMainEntryStyleNameOK(false)
49 , bCombineEntries(true)
50 , bCaseSensitive(true)
55 , bCommaSeparated(false)
59 XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
63 void XMLIndexAlphabeticalSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter
& aIter
)
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
);
80 case XML_ELEMENT(TEXT
, XML_IGNORE_CASE
):
81 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
83 bCaseSensitive
= !bTmp
;
87 case XML_ELEMENT(TEXT
, XML_ALPHABETICAL_SEPARATORS
):
88 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
94 case XML_ELEMENT(TEXT
, XML_COMBINE_ENTRIES
):
95 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
97 bCombineEntries
= bTmp
;
101 case XML_ELEMENT(TEXT
, XML_COMBINE_ENTRIES_WITH_DASH
):
102 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
107 case XML_ELEMENT(TEXT
, XML_USE_KEYS_AS_ENTRIES
):
108 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
114 case XML_ELEMENT(TEXT
, XML_COMBINE_ENTRIES_WITH_PP
):
115 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
121 case XML_ELEMENT(TEXT
, XML_CAPITALIZE_ENTRIES
):
122 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
128 case XML_ELEMENT(TEXT
, XML_COMMA_SEPARATED
):
129 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
131 bCommaSeparated
= bTmp
;
135 case XML_ELEMENT(TEXT
, XML_SORT_ALGORITHM
):
136 sAlgorithm
= aIter
.toString();
138 case XML_ELEMENT(STYLE
, XML_RFC_LANGUAGE_TAG
):
139 maLanguageTagODF
.maRfcLanguageTag
= aIter
.toString();
141 case XML_ELEMENT(FO
, XML_LANGUAGE
):
142 maLanguageTagODF
.maLanguage
= aIter
.toString();
144 case XML_ELEMENT(FO
, XML_SCRIPT
):
145 maLanguageTagODF
.maScript
= aIter
.toString();
147 case XML_ELEMENT(FO
, XML_COUNTRY
):
148 maLanguageTagODF
.maCountry
= aIter
.toString();
152 XMLIndexSourceBaseContext::ProcessAttribute(aIter
);
157 void XMLIndexAlphabeticalSourceContext::endFastElement(sal_Int32 nElement
)
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(
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
,
202 aLevelStylePropNameAlphaMap
,
203 aAllowedTokenTypesAlpha
);
207 return XMLIndexSourceBaseContext::createFastChildContext(nElement
,
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */