Line data Source code
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/XIndexReplace.hpp>
25 :
26 : #include <sax/tools/converter.hxx>
27 :
28 : #include "XMLIndexTemplateContext.hxx"
29 : #include "XMLIndexTitleTemplateContext.hxx"
30 : #include "XMLIndexTOCStylesContext.hxx"
31 : #include <xmloff/xmlictxt.hxx>
32 : #include <xmloff/xmlimp.hxx>
33 : #include <xmloff/txtimp.hxx>
34 : #include <xmloff/xmlnmspe.hxx>
35 : #include <xmloff/nmspmap.hxx>
36 : #include <xmloff/xmltoken.hxx>
37 : #include <xmloff/xmluconv.hxx>
38 : #include <rtl/ustring.hxx>
39 :
40 :
41 :
42 :
43 : using ::com::sun::star::beans::XPropertySet;
44 : using ::com::sun::star::uno::Reference;
45 : using ::com::sun::star::uno::Any;
46 : using ::com::sun::star::xml::sax::XAttributeList;
47 : using ::xmloff::token::IsXMLToken;
48 : using ::xmloff::token::XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE;
49 : using ::xmloff::token::XML_OUTLINE_LEVEL;
50 :
51 : const sal_Char sAPI_MainEntryCharacterStyleName[] = "MainEntryCharacterStyleName";
52 : const sal_Char sAPI_UseAlphabeticalSeparators[] = "UseAlphabeticalSeparators";
53 : const sal_Char sAPI_UseCombinedEntries[] = "UseCombinedEntries";
54 : const sal_Char sAPI_IsCaseSensitive[] = "IsCaseSensitive";
55 : const sal_Char sAPI_UseKeyAsEntry[] = "UseKeyAsEntry";
56 : const sal_Char sAPI_UseUpperCase[] = "UseUpperCase";
57 : const sal_Char sAPI_UseDash[] = "UseDash";
58 : const sal_Char sAPI_UsePP[] = "UsePP";
59 : const sal_Char sAPI_SortAlgorithm[] = "SortAlgorithm";
60 : const sal_Char sAPI_Locale[] = "Locale";
61 :
62 :
63 0 : TYPEINIT1( XMLIndexAlphabeticalSourceContext, XMLIndexSourceBaseContext );
64 :
65 3 : XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
66 : SvXMLImport& rImport,
67 : sal_uInt16 nPrfx,
68 : const OUString& rLocalName,
69 : Reference<XPropertySet> & rPropSet)
70 : : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, false)
71 : , sMainEntryCharacterStyleName(sAPI_MainEntryCharacterStyleName)
72 : , sUseAlphabeticalSeparators(sAPI_UseAlphabeticalSeparators)
73 : , sUseCombinedEntries(sAPI_UseCombinedEntries)
74 : , sIsCaseSensitive(sAPI_IsCaseSensitive)
75 : , sUseKeyAsEntry(sAPI_UseKeyAsEntry)
76 : , sUseUpperCase(sAPI_UseUpperCase)
77 : , sUseDash(sAPI_UseDash)
78 : , sUsePP(sAPI_UsePP)
79 : , sIsCommaSeparated("IsCommaSeparated")
80 : , sSortAlgorithm(sAPI_SortAlgorithm)
81 : , sLocale(sAPI_Locale)
82 : , bMainEntryStyleNameOK(false)
83 : , bSeparators(false)
84 : , bCombineEntries(true)
85 : , bCaseSensitive(true)
86 : , bEntry(false)
87 : , bUpperCase(false)
88 : , bCombineDash(false)
89 : , bCombinePP(true)
90 3 : , bCommaSeparated(false)
91 : {
92 3 : }
93 :
94 6 : XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
95 : {
96 6 : }
97 :
98 13 : void XMLIndexAlphabeticalSourceContext::ProcessAttribute(
99 : enum IndexSourceParamEnum eParam,
100 : const OUString& rValue)
101 : {
102 13 : bool bTmp(false);
103 :
104 13 : switch (eParam)
105 : {
106 : case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE:
107 : {
108 1 : sMainEntryStyleName = rValue;
109 1 : OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
110 2 : XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
111 : const Reference < ::com::sun::star::container::XNameContainer >&
112 1 : rStyles = GetImport().GetTextImport()->GetTextStyles();
113 1 : bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
114 : }
115 1 : break;
116 :
117 : case XML_TOK_INDEXSOURCE_IGNORE_CASE:
118 0 : if (::sax::Converter::convertBool(bTmp, rValue))
119 : {
120 0 : bCaseSensitive = !bTmp;
121 : }
122 0 : break;
123 :
124 : case XML_TOK_INDEXSOURCE_SEPARATORS:
125 0 : if (::sax::Converter::convertBool(bTmp, rValue))
126 : {
127 0 : bSeparators = bTmp;
128 : }
129 0 : break;
130 :
131 : case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES:
132 0 : if (::sax::Converter::convertBool(bTmp, rValue))
133 : {
134 0 : bCombineEntries = bTmp;
135 : }
136 0 : break;
137 :
138 : case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH:
139 1 : if (::sax::Converter::convertBool(bTmp, rValue))
140 : {
141 1 : bCombineDash = bTmp;
142 : }
143 1 : break;
144 : case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES:
145 0 : if (::sax::Converter::convertBool(bTmp, rValue))
146 : {
147 0 : bEntry = bTmp;
148 : }
149 0 : break;
150 :
151 : case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP:
152 1 : if (::sax::Converter::convertBool(bTmp, rValue))
153 : {
154 1 : bCombinePP = bTmp;
155 : }
156 1 : break;
157 :
158 : case XML_TOK_INDEXSOURCE_CAPITALIZE:
159 1 : if (::sax::Converter::convertBool(bTmp, rValue))
160 : {
161 1 : bUpperCase = bTmp;
162 : }
163 1 : break;
164 :
165 : case XML_TOK_INDEXSOURCE_COMMA_SEPARATED:
166 0 : if (::sax::Converter::convertBool(bTmp, rValue))
167 : {
168 0 : bCommaSeparated = bTmp;
169 : }
170 0 : break;
171 :
172 : case XML_TOK_INDEXSOURCE_SORT_ALGORITHM:
173 3 : sAlgorithm = rValue;
174 3 : break;
175 : case XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG:
176 0 : maLanguageTagODF.maRfcLanguageTag = rValue;
177 0 : break;
178 : case XML_TOK_INDEXSOURCE_LANGUAGE:
179 3 : maLanguageTagODF.maLanguage = rValue;
180 3 : break;
181 : case XML_TOK_INDEXSOURCE_SCRIPT:
182 0 : maLanguageTagODF.maScript = rValue;
183 0 : break;
184 : case XML_TOK_INDEXSOURCE_COUNTRY:
185 3 : maLanguageTagODF.maCountry = rValue;
186 3 : break;
187 :
188 : default:
189 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
190 0 : break;
191 : }
192 13 : }
193 :
194 3 : void XMLIndexAlphabeticalSourceContext::EndElement()
195 : {
196 :
197 3 : Any aAny;
198 :
199 3 : if (bMainEntryStyleNameOK)
200 : {
201 2 : aAny <<= GetImport().GetStyleDisplayName(
202 1 : XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
203 1 : rIndexPropertySet->setPropertyValue(sMainEntryCharacterStyleName,aAny);
204 : }
205 :
206 3 : aAny.setValue(&bSeparators, cppu::UnoType<bool>::get());
207 3 : rIndexPropertySet->setPropertyValue(sUseAlphabeticalSeparators, aAny);
208 :
209 3 : aAny.setValue(&bCombineEntries, cppu::UnoType<bool>::get());
210 3 : rIndexPropertySet->setPropertyValue(sUseCombinedEntries, aAny);
211 :
212 3 : aAny.setValue(&bCaseSensitive, cppu::UnoType<bool>::get());
213 3 : rIndexPropertySet->setPropertyValue(sIsCaseSensitive, aAny);
214 :
215 3 : aAny.setValue(&bEntry, cppu::UnoType<bool>::get());
216 3 : rIndexPropertySet->setPropertyValue(sUseKeyAsEntry, aAny);
217 :
218 3 : aAny.setValue(&bUpperCase, cppu::UnoType<bool>::get());
219 3 : rIndexPropertySet->setPropertyValue(sUseUpperCase, aAny);
220 :
221 3 : aAny.setValue(&bCombineDash, cppu::UnoType<bool>::get());
222 3 : rIndexPropertySet->setPropertyValue(sUseDash, aAny);
223 :
224 3 : aAny.setValue(&bCombinePP, cppu::UnoType<bool>::get());
225 3 : rIndexPropertySet->setPropertyValue(sUsePP, aAny);
226 :
227 3 : aAny.setValue(&bCommaSeparated, cppu::UnoType<bool>::get());
228 3 : rIndexPropertySet->setPropertyValue(sIsCommaSeparated, aAny);
229 :
230 :
231 3 : if (!sAlgorithm.isEmpty())
232 : {
233 3 : aAny <<= sAlgorithm;
234 3 : rIndexPropertySet->setPropertyValue(sSortAlgorithm, aAny);
235 : }
236 :
237 3 : if ( !maLanguageTagODF.isEmpty() )
238 : {
239 3 : aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
240 3 : rIndexPropertySet->setPropertyValue(sLocale, aAny);
241 : }
242 :
243 3 : XMLIndexSourceBaseContext::EndElement();
244 3 : }
245 :
246 15 : SvXMLImportContext* XMLIndexAlphabeticalSourceContext::CreateChildContext(
247 : sal_uInt16 nPrefix,
248 : const OUString& rLocalName,
249 : const Reference<XAttributeList> & xAttrList )
250 : {
251 30 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
252 15 : IsXMLToken( rLocalName, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE ) )
253 : {
254 12 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
255 : nPrefix, rLocalName,
256 : aLevelNameAlphaMap,
257 : XML_OUTLINE_LEVEL,
258 : aLevelStylePropNameAlphaMap,
259 12 : aAllowedTokenTypesAlpha);
260 : }
261 : else
262 : {
263 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
264 : rLocalName,
265 3 : xAttrList);
266 : }
267 : }
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|