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/XIndexReplace.hpp>
26 #include <sax/tools/converter.hxx>
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>
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
;
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";
63 TYPEINIT1( XMLIndexAlphabeticalSourceContext
, XMLIndexSourceBaseContext
);
65 XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
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
)
79 , sIsCommaSeparated("IsCommaSeparated")
80 , sSortAlgorithm(sAPI_SortAlgorithm
)
81 , sLocale(sAPI_Locale
)
82 , bMainEntryStyleNameOK(false)
84 , bCombineEntries(true)
85 , bCaseSensitive(true)
90 , bCommaSeparated(false)
94 XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
98 void XMLIndexAlphabeticalSourceContext::ProcessAttribute(
99 enum IndexSourceParamEnum eParam
,
100 const OUString
& rValue
)
106 case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE
:
108 sMainEntryStyleName
= rValue
;
109 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
110 XML_STYLE_FAMILY_TEXT_TEXT
, sMainEntryStyleName
);
111 const Reference
< ::com::sun::star::container::XNameContainer
>&
112 rStyles
= GetImport().GetTextImport()->GetTextStyles();
113 bMainEntryStyleNameOK
= rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
);
117 case XML_TOK_INDEXSOURCE_IGNORE_CASE
:
118 if (::sax::Converter::convertBool(bTmp
, rValue
))
120 bCaseSensitive
= !bTmp
;
124 case XML_TOK_INDEXSOURCE_SEPARATORS
:
125 if (::sax::Converter::convertBool(bTmp
, rValue
))
131 case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES
:
132 if (::sax::Converter::convertBool(bTmp
, rValue
))
134 bCombineEntries
= bTmp
;
138 case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH
:
139 if (::sax::Converter::convertBool(bTmp
, rValue
))
144 case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES
:
145 if (::sax::Converter::convertBool(bTmp
, rValue
))
151 case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP
:
152 if (::sax::Converter::convertBool(bTmp
, rValue
))
158 case XML_TOK_INDEXSOURCE_CAPITALIZE
:
159 if (::sax::Converter::convertBool(bTmp
, rValue
))
165 case XML_TOK_INDEXSOURCE_COMMA_SEPARATED
:
166 if (::sax::Converter::convertBool(bTmp
, rValue
))
168 bCommaSeparated
= bTmp
;
172 case XML_TOK_INDEXSOURCE_SORT_ALGORITHM
:
175 case XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG
:
176 maLanguageTagODF
.maRfcLanguageTag
= rValue
;
178 case XML_TOK_INDEXSOURCE_LANGUAGE
:
179 maLanguageTagODF
.maLanguage
= rValue
;
181 case XML_TOK_INDEXSOURCE_SCRIPT
:
182 maLanguageTagODF
.maScript
= rValue
;
184 case XML_TOK_INDEXSOURCE_COUNTRY
:
185 maLanguageTagODF
.maCountry
= rValue
;
189 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
194 void XMLIndexAlphabeticalSourceContext::EndElement()
199 if (bMainEntryStyleNameOK
)
201 aAny
<<= GetImport().GetStyleDisplayName(
202 XML_STYLE_FAMILY_TEXT_TEXT
, sMainEntryStyleName
);
203 rIndexPropertySet
->setPropertyValue(sMainEntryCharacterStyleName
,aAny
);
206 aAny
.setValue(&bSeparators
, cppu::UnoType
<bool>::get());
207 rIndexPropertySet
->setPropertyValue(sUseAlphabeticalSeparators
, aAny
);
209 aAny
.setValue(&bCombineEntries
, cppu::UnoType
<bool>::get());
210 rIndexPropertySet
->setPropertyValue(sUseCombinedEntries
, aAny
);
212 aAny
.setValue(&bCaseSensitive
, cppu::UnoType
<bool>::get());
213 rIndexPropertySet
->setPropertyValue(sIsCaseSensitive
, aAny
);
215 aAny
.setValue(&bEntry
, cppu::UnoType
<bool>::get());
216 rIndexPropertySet
->setPropertyValue(sUseKeyAsEntry
, aAny
);
218 aAny
.setValue(&bUpperCase
, cppu::UnoType
<bool>::get());
219 rIndexPropertySet
->setPropertyValue(sUseUpperCase
, aAny
);
221 aAny
.setValue(&bCombineDash
, cppu::UnoType
<bool>::get());
222 rIndexPropertySet
->setPropertyValue(sUseDash
, aAny
);
224 aAny
.setValue(&bCombinePP
, cppu::UnoType
<bool>::get());
225 rIndexPropertySet
->setPropertyValue(sUsePP
, aAny
);
227 aAny
.setValue(&bCommaSeparated
, cppu::UnoType
<bool>::get());
228 rIndexPropertySet
->setPropertyValue(sIsCommaSeparated
, aAny
);
231 if (!sAlgorithm
.isEmpty())
234 rIndexPropertySet
->setPropertyValue(sSortAlgorithm
, aAny
);
237 if ( !maLanguageTagODF
.isEmpty() )
239 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
240 rIndexPropertySet
->setPropertyValue(sLocale
, aAny
);
243 XMLIndexSourceBaseContext::EndElement();
246 SvXMLImportContext
* XMLIndexAlphabeticalSourceContext::CreateChildContext(
248 const OUString
& rLocalName
,
249 const Reference
<XAttributeList
> & xAttrList
)
251 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
252 IsXMLToken( rLocalName
, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE
) )
254 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet
,
258 aLevelStylePropNameAlphaMap
,
259 aAllowedTokenTypesAlpha
);
263 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */