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 ::com::sun::star::xml::sax::XAttributeList
;
42 using ::xmloff::token::IsXMLToken
;
43 using ::xmloff::token::XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE
;
44 using ::xmloff::token::XML_OUTLINE_LEVEL
;
46 XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
49 const OUString
& rLocalName
,
50 Reference
<XPropertySet
> & rPropSet
)
51 : XMLIndexSourceBaseContext(rImport
, nPrfx
, rLocalName
, rPropSet
, false)
52 , bMainEntryStyleNameOK(false)
54 , bCombineEntries(true)
55 , bCaseSensitive(true)
60 , bCommaSeparated(false)
64 XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
68 void XMLIndexAlphabeticalSourceContext::ProcessAttribute(
69 enum IndexSourceParamEnum eParam
,
70 const OUString
& rValue
)
76 case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE
:
78 sMainEntryStyleName
= rValue
;
79 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
80 XmlStyleFamily::TEXT_TEXT
, sMainEntryStyleName
);
81 const Reference
< css::container::XNameContainer
>&
82 rStyles
= GetImport().GetTextImport()->GetTextStyles();
83 bMainEntryStyleNameOK
= rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
);
87 case XML_TOK_INDEXSOURCE_IGNORE_CASE
:
88 if (::sax::Converter::convertBool(bTmp
, rValue
))
90 bCaseSensitive
= !bTmp
;
94 case XML_TOK_INDEXSOURCE_SEPARATORS
:
95 if (::sax::Converter::convertBool(bTmp
, rValue
))
101 case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES
:
102 if (::sax::Converter::convertBool(bTmp
, rValue
))
104 bCombineEntries
= bTmp
;
108 case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH
:
109 if (::sax::Converter::convertBool(bTmp
, rValue
))
114 case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES
:
115 if (::sax::Converter::convertBool(bTmp
, rValue
))
121 case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP
:
122 if (::sax::Converter::convertBool(bTmp
, rValue
))
128 case XML_TOK_INDEXSOURCE_CAPITALIZE
:
129 if (::sax::Converter::convertBool(bTmp
, rValue
))
135 case XML_TOK_INDEXSOURCE_COMMA_SEPARATED
:
136 if (::sax::Converter::convertBool(bTmp
, rValue
))
138 bCommaSeparated
= bTmp
;
142 case XML_TOK_INDEXSOURCE_SORT_ALGORITHM
:
145 case XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG
:
146 maLanguageTagODF
.maRfcLanguageTag
= rValue
;
148 case XML_TOK_INDEXSOURCE_LANGUAGE
:
149 maLanguageTagODF
.maLanguage
= rValue
;
151 case XML_TOK_INDEXSOURCE_SCRIPT
:
152 maLanguageTagODF
.maScript
= rValue
;
154 case XML_TOK_INDEXSOURCE_COUNTRY
:
155 maLanguageTagODF
.maCountry
= rValue
;
159 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
164 void XMLIndexAlphabeticalSourceContext::endFastElement(sal_Int32 nElement
)
169 if (bMainEntryStyleNameOK
)
171 aAny
<<= GetImport().GetStyleDisplayName(
172 XmlStyleFamily::TEXT_TEXT
, sMainEntryStyleName
);
173 rIndexPropertySet
->setPropertyValue("MainEntryCharacterStyleName",aAny
);
176 rIndexPropertySet
->setPropertyValue("UseAlphabeticalSeparators", css::uno::Any(bSeparators
));
177 rIndexPropertySet
->setPropertyValue("UseCombinedEntries", css::uno::Any(bCombineEntries
));
178 rIndexPropertySet
->setPropertyValue("IsCaseSensitive", css::uno::Any(bCaseSensitive
));
179 rIndexPropertySet
->setPropertyValue("UseKeyAsEntry", css::uno::Any(bEntry
));
180 rIndexPropertySet
->setPropertyValue("UseUpperCase", css::uno::Any(bUpperCase
));
181 rIndexPropertySet
->setPropertyValue("UseDash", css::uno::Any(bCombineDash
));
182 rIndexPropertySet
->setPropertyValue("UsePP", css::uno::Any(bCombinePP
));
183 rIndexPropertySet
->setPropertyValue("IsCommaSeparated", css::uno::Any(bCommaSeparated
));
186 if (!sAlgorithm
.isEmpty())
188 rIndexPropertySet
->setPropertyValue("SortAlgorithm", css::uno::Any(sAlgorithm
));
191 if ( !maLanguageTagODF
.isEmpty() )
193 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
194 rIndexPropertySet
->setPropertyValue("Locale", aAny
);
197 XMLIndexSourceBaseContext::endFastElement(nElement
);
200 SvXMLImportContextRef
XMLIndexAlphabeticalSourceContext::CreateChildContext(
202 const OUString
& rLocalName
,
203 const Reference
<XAttributeList
> & xAttrList
)
205 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
206 IsXMLToken( rLocalName
, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE
) )
208 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet
,
212 aLevelStylePropNameAlphaMap
,
213 aAllowedTokenTypesAlpha
);
217 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */