/src/libreoffice/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include "XMLIndexAlphabeticalSourceContext.hxx" |
22 | | |
23 | | #include <com/sun/star/beans/XPropertySet.hpp> |
24 | | #include <com/sun/star/container/XNameContainer.hpp> |
25 | | |
26 | | #include <sax/tools/converter.hxx> |
27 | | |
28 | | #include "XMLIndexTemplateContext.hxx" |
29 | | #include <xmloff/xmlimp.hxx> |
30 | | #include <xmloff/txtimp.hxx> |
31 | | #include <xmloff/xmlnamespace.hxx> |
32 | | #include <xmloff/xmltoken.hxx> |
33 | | #include <xmloff/xmluconv.hxx> |
34 | | #include <rtl/ustring.hxx> |
35 | | |
36 | | |
37 | | using ::com::sun::star::beans::XPropertySet; |
38 | | using ::com::sun::star::uno::Reference; |
39 | | using ::com::sun::star::uno::Any; |
40 | | using namespace ::xmloff::token; |
41 | | |
42 | | XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext( |
43 | | SvXMLImport& rImport, |
44 | | Reference<XPropertySet> & rPropSet) |
45 | 0 | : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::None) |
46 | 0 | , bMainEntryStyleNameOK(false) |
47 | 0 | , bSeparators(false) |
48 | 0 | , bCombineEntries(true) |
49 | 0 | , bCaseSensitive(true) |
50 | 0 | , bEntry(false) |
51 | 0 | , bUpperCase(false) |
52 | 0 | , bCombineDash(false) |
53 | 0 | , bCombinePP(true) |
54 | 0 | , bCommaSeparated(false) |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext() |
59 | 0 | { |
60 | 0 | } |
61 | | |
62 | | void XMLIndexAlphabeticalSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter) |
63 | 0 | { |
64 | 0 | bool bTmp(false); |
65 | |
|
66 | 0 | switch (aIter.getToken()) |
67 | 0 | { |
68 | 0 | case XML_ELEMENT(TEXT, XML_MAIN_ENTRY_STYLE_NAME): |
69 | 0 | { |
70 | 0 | sMainEntryStyleName = aIter.toString(); |
71 | 0 | OUString sDisplayStyleName = GetImport().GetStyleDisplayName( |
72 | 0 | XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName ); |
73 | 0 | const Reference < css::container::XNameContainer >& |
74 | 0 | rStyles = GetImport().GetTextImport()->GetTextStyles(); |
75 | 0 | bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName ); |
76 | 0 | } |
77 | 0 | break; |
78 | | |
79 | 0 | case XML_ELEMENT(TEXT, XML_IGNORE_CASE): |
80 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
81 | 0 | { |
82 | 0 | bCaseSensitive = !bTmp; |
83 | 0 | } |
84 | 0 | break; |
85 | | |
86 | 0 | case XML_ELEMENT(TEXT, XML_ALPHABETICAL_SEPARATORS): |
87 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
88 | 0 | { |
89 | 0 | bSeparators = bTmp; |
90 | 0 | } |
91 | 0 | break; |
92 | | |
93 | 0 | case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES): |
94 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
95 | 0 | { |
96 | 0 | bCombineEntries = bTmp; |
97 | 0 | } |
98 | 0 | break; |
99 | | |
100 | 0 | case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_DASH): |
101 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
102 | 0 | { |
103 | 0 | bCombineDash = bTmp; |
104 | 0 | } |
105 | 0 | break; |
106 | 0 | case XML_ELEMENT(TEXT, XML_USE_KEYS_AS_ENTRIES): |
107 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
108 | 0 | { |
109 | 0 | bEntry = bTmp; |
110 | 0 | } |
111 | 0 | break; |
112 | | |
113 | 0 | case XML_ELEMENT(TEXT, XML_COMBINE_ENTRIES_WITH_PP): |
114 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
115 | 0 | { |
116 | 0 | bCombinePP = bTmp; |
117 | 0 | } |
118 | 0 | break; |
119 | | |
120 | 0 | case XML_ELEMENT(TEXT, XML_CAPITALIZE_ENTRIES): |
121 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
122 | 0 | { |
123 | 0 | bUpperCase = bTmp; |
124 | 0 | } |
125 | 0 | break; |
126 | | |
127 | 0 | case XML_ELEMENT(TEXT, XML_COMMA_SEPARATED): |
128 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView())) |
129 | 0 | { |
130 | 0 | bCommaSeparated = bTmp; |
131 | 0 | } |
132 | 0 | break; |
133 | | |
134 | 0 | case XML_ELEMENT(TEXT, XML_SORT_ALGORITHM): |
135 | 0 | sAlgorithm = aIter.toString(); |
136 | 0 | break; |
137 | 0 | case XML_ELEMENT(STYLE, XML_RFC_LANGUAGE_TAG): |
138 | 0 | maLanguageTagODF.maRfcLanguageTag = aIter.toString(); |
139 | 0 | break; |
140 | 0 | case XML_ELEMENT(FO, XML_LANGUAGE): |
141 | 0 | maLanguageTagODF.maLanguage = aIter.toString(); |
142 | 0 | break; |
143 | 0 | case XML_ELEMENT(FO, XML_SCRIPT): |
144 | 0 | maLanguageTagODF.maScript = aIter.toString(); |
145 | 0 | break; |
146 | 0 | case XML_ELEMENT(FO, XML_COUNTRY): |
147 | 0 | maLanguageTagODF.maCountry = aIter.toString(); |
148 | 0 | break; |
149 | | |
150 | 0 | default: |
151 | 0 | XMLIndexSourceBaseContext::ProcessAttribute(aIter); |
152 | 0 | break; |
153 | 0 | } |
154 | 0 | } |
155 | | |
156 | | void XMLIndexAlphabeticalSourceContext::endFastElement(sal_Int32 nElement) |
157 | 0 | { |
158 | |
|
159 | 0 | Any aAny; |
160 | |
|
161 | 0 | if (bMainEntryStyleNameOK) |
162 | 0 | { |
163 | 0 | aAny <<= GetImport().GetStyleDisplayName( |
164 | 0 | XmlStyleFamily::TEXT_TEXT, sMainEntryStyleName ); |
165 | 0 | rIndexPropertySet->setPropertyValue(u"MainEntryCharacterStyleName"_ustr,aAny); |
166 | 0 | } |
167 | |
|
168 | 0 | rIndexPropertySet->setPropertyValue(u"UseAlphabeticalSeparators"_ustr, css::uno::Any(bSeparators)); |
169 | 0 | rIndexPropertySet->setPropertyValue(u"UseCombinedEntries"_ustr, css::uno::Any(bCombineEntries)); |
170 | 0 | rIndexPropertySet->setPropertyValue(u"IsCaseSensitive"_ustr, css::uno::Any(bCaseSensitive)); |
171 | 0 | rIndexPropertySet->setPropertyValue(u"UseKeyAsEntry"_ustr, css::uno::Any(bEntry)); |
172 | 0 | rIndexPropertySet->setPropertyValue(u"UseUpperCase"_ustr, css::uno::Any(bUpperCase)); |
173 | 0 | rIndexPropertySet->setPropertyValue(u"UseDash"_ustr, css::uno::Any(bCombineDash)); |
174 | 0 | rIndexPropertySet->setPropertyValue(u"UsePP"_ustr, css::uno::Any(bCombinePP)); |
175 | 0 | rIndexPropertySet->setPropertyValue(u"IsCommaSeparated"_ustr, css::uno::Any(bCommaSeparated)); |
176 | | |
177 | |
|
178 | 0 | if (!sAlgorithm.isEmpty()) |
179 | 0 | { |
180 | 0 | rIndexPropertySet->setPropertyValue(u"SortAlgorithm"_ustr, css::uno::Any(sAlgorithm)); |
181 | 0 | } |
182 | |
|
183 | 0 | if ( !maLanguageTagODF.isEmpty() ) |
184 | 0 | { |
185 | 0 | aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false); |
186 | 0 | rIndexPropertySet->setPropertyValue(u"Locale"_ustr, aAny); |
187 | 0 | } |
188 | |
|
189 | 0 | XMLIndexSourceBaseContext::endFastElement(nElement); |
190 | 0 | } |
191 | | |
192 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexAlphabeticalSourceContext::createFastChildContext( |
193 | | sal_Int32 nElement, |
194 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
195 | 0 | { |
196 | 0 | if ( nElement == XML_ELEMENT(TEXT, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE) ) |
197 | 0 | { |
198 | 0 | return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, |
199 | 0 | aLevelNameAlphaMap, |
200 | 0 | XML_OUTLINE_LEVEL, |
201 | 0 | aLevelStylePropNameAlphaMap, |
202 | 0 | aAllowedTokenTypesAlpha); |
203 | 0 | } |
204 | 0 | else |
205 | 0 | { |
206 | 0 | return XMLIndexSourceBaseContext::createFastChildContext(nElement, |
207 | 0 | xAttrList); |
208 | 0 | } |
209 | 0 | } |
210 | | |
211 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |