1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "XMLIndexAlphabeticalSourceContext.hxx"
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp>
31cdf0e10cSrcweir #include "XMLIndexTemplateContext.hxx"
32cdf0e10cSrcweir #include "XMLIndexTitleTemplateContext.hxx"
33cdf0e10cSrcweir #include "XMLIndexTOCStylesContext.hxx"
34cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
35cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
36cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
37cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
38cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
39cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
40cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
41cdf0e10cSrcweir #include <tools/debug.hxx>
42cdf0e10cSrcweir #include <rtl/ustring.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using ::rtl::OUString;
48cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
49cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
50cdf0e10cSrcweir using ::com::sun::star::uno::Any;
51cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
52cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
53cdf0e10cSrcweir using ::xmloff::token::XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE;
54cdf0e10cSrcweir using ::xmloff::token::XML_OUTLINE_LEVEL;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir const sal_Char sAPI_MainEntryCharacterStyleName[] = "MainEntryCharacterStyleName";
57cdf0e10cSrcweir const sal_Char sAPI_UseAlphabeticalSeparators[] = "UseAlphabeticalSeparators";
58cdf0e10cSrcweir const sal_Char sAPI_UseCombinedEntries[] = "UseCombinedEntries";
59cdf0e10cSrcweir const sal_Char sAPI_IsCaseSensitive[] = "IsCaseSensitive";
60cdf0e10cSrcweir const sal_Char sAPI_UseKeyAsEntry[] = "UseKeyAsEntry";
61cdf0e10cSrcweir const sal_Char sAPI_UseUpperCase[] = "UseUpperCase";
62cdf0e10cSrcweir const sal_Char sAPI_UseDash[] = "UseDash";
63cdf0e10cSrcweir const sal_Char sAPI_UsePP[] = "UsePP";
64cdf0e10cSrcweir const sal_Char sAPI_SortAlgorithm[] = "SortAlgorithm";
65cdf0e10cSrcweir const sal_Char sAPI_Locale[] = "Locale";
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir TYPEINIT1( XMLIndexAlphabeticalSourceContext, XMLIndexSourceBaseContext );
69cdf0e10cSrcweir 
XMLIndexAlphabeticalSourceContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet)70cdf0e10cSrcweir XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
71cdf0e10cSrcweir 	SvXMLImport& rImport,
72cdf0e10cSrcweir 	sal_uInt16 nPrfx,
73cdf0e10cSrcweir 	const OUString& rLocalName,
74cdf0e10cSrcweir 	Reference<XPropertySet> & rPropSet)
75cdf0e10cSrcweir :	XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_False)
76cdf0e10cSrcweir ,	sMainEntryCharacterStyleName(RTL_CONSTASCII_USTRINGPARAM(sAPI_MainEntryCharacterStyleName))
77cdf0e10cSrcweir ,	sUseAlphabeticalSeparators(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseAlphabeticalSeparators))
78cdf0e10cSrcweir ,	sUseCombinedEntries(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseCombinedEntries))
79cdf0e10cSrcweir ,	sIsCaseSensitive(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsCaseSensitive))
80cdf0e10cSrcweir ,	sUseKeyAsEntry(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseKeyAsEntry))
81cdf0e10cSrcweir ,	sUseUpperCase(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseUpperCase))
82cdf0e10cSrcweir ,	sUseDash(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseDash))
83cdf0e10cSrcweir ,	sUsePP(RTL_CONSTASCII_USTRINGPARAM(sAPI_UsePP))
84cdf0e10cSrcweir ,	sIsCommaSeparated(RTL_CONSTASCII_USTRINGPARAM("IsCommaSeparated"))
85cdf0e10cSrcweir ,	sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM(sAPI_SortAlgorithm))
86cdf0e10cSrcweir ,	sLocale(RTL_CONSTASCII_USTRINGPARAM(sAPI_Locale))
87cdf0e10cSrcweir ,	bMainEntryStyleNameOK(sal_False)
88cdf0e10cSrcweir ,	bSeparators(sal_False)
89cdf0e10cSrcweir ,	bCombineEntries(sal_True)
90cdf0e10cSrcweir ,	bCaseSensitive(sal_True)
91cdf0e10cSrcweir ,	bEntry(sal_False)
92cdf0e10cSrcweir ,	bUpperCase(sal_False)
93cdf0e10cSrcweir ,	bCombineDash(sal_False)
94cdf0e10cSrcweir ,	bCombinePP(sal_True)
95cdf0e10cSrcweir ,	bCommaSeparated(sal_False)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
~XMLIndexAlphabeticalSourceContext()99cdf0e10cSrcweir XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)103cdf0e10cSrcweir void XMLIndexAlphabeticalSourceContext::ProcessAttribute(
104cdf0e10cSrcweir 	enum IndexSourceParamEnum eParam,
105cdf0e10cSrcweir 	const OUString& rValue)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	sal_Bool bTmp;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	switch (eParam)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE:
112cdf0e10cSrcweir 			{
113cdf0e10cSrcweir 				sMainEntryStyleName = rValue;
114cdf0e10cSrcweir 				OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
115cdf0e10cSrcweir 					XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
116cdf0e10cSrcweir 				const Reference < ::com::sun::star::container::XNameContainer >&
117cdf0e10cSrcweir 					rStyles = GetImport().GetTextImport()->GetTextStyles();
118cdf0e10cSrcweir 				bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 			break;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_IGNORE_CASE:
123cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
124cdf0e10cSrcweir 			{
125cdf0e10cSrcweir 				bCaseSensitive = !bTmp;
126cdf0e10cSrcweir 			}
127cdf0e10cSrcweir 			break;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_SEPARATORS:
130cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
131cdf0e10cSrcweir 			{
132cdf0e10cSrcweir 				bSeparators = bTmp;
133cdf0e10cSrcweir 			}
134cdf0e10cSrcweir 			break;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES:
137cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
138cdf0e10cSrcweir 			{
139cdf0e10cSrcweir 				bCombineEntries = bTmp;
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 			break;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH:
144cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
145cdf0e10cSrcweir 			{
146cdf0e10cSrcweir 				bCombineDash = bTmp;
147cdf0e10cSrcweir 			}
148cdf0e10cSrcweir 			break;
149cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES:
150cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
151cdf0e10cSrcweir 			{
152cdf0e10cSrcweir 				bEntry = bTmp;
153cdf0e10cSrcweir 			}
154cdf0e10cSrcweir 			break;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP:
157cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
158cdf0e10cSrcweir 			{
159cdf0e10cSrcweir 				bCombinePP = bTmp;
160cdf0e10cSrcweir 			}
161cdf0e10cSrcweir 			break;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_CAPITALIZE:
164cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
165cdf0e10cSrcweir 			{
166cdf0e10cSrcweir 				bUpperCase = bTmp;
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 			break;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		case XML_TOK_INDEXSOURCE_COMMA_SEPARATED:
171cdf0e10cSrcweir 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
172cdf0e10cSrcweir 			{
173cdf0e10cSrcweir 				bCommaSeparated = bTmp;
174cdf0e10cSrcweir 			}
175cdf0e10cSrcweir 			break;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         case XML_TOK_INDEXSOURCE_SORT_ALGORITHM:
178cdf0e10cSrcweir             sAlgorithm = rValue;
179cdf0e10cSrcweir             break;
180cdf0e10cSrcweir         case XML_TOK_INDEXSOURCE_LANGUAGE:
181cdf0e10cSrcweir             aLocale.Language = rValue;
182cdf0e10cSrcweir             break;
183cdf0e10cSrcweir         case XML_TOK_INDEXSOURCE_COUNTRY:
184cdf0e10cSrcweir             aLocale.Country = rValue;
185cdf0e10cSrcweir             break;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		default:
188cdf0e10cSrcweir 			XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
189cdf0e10cSrcweir 			break;
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
EndElement()193cdf0e10cSrcweir void XMLIndexAlphabeticalSourceContext::EndElement()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	Any aAny;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	if (bMainEntryStyleNameOK)
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		aAny <<= GetImport().GetStyleDisplayName(
201cdf0e10cSrcweir 							XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
202cdf0e10cSrcweir 		rIndexPropertySet->setPropertyValue(sMainEntryCharacterStyleName,aAny);
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	aAny.setValue(&bSeparators, ::getBooleanCppuType());
206cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUseAlphabeticalSeparators, aAny);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	aAny.setValue(&bCombineEntries, ::getBooleanCppuType());
209cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUseCombinedEntries, aAny);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	aAny.setValue(&bCaseSensitive, ::getBooleanCppuType());
212cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sIsCaseSensitive, aAny);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	aAny.setValue(&bEntry, ::getBooleanCppuType());
215cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUseKeyAsEntry, aAny);
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	aAny.setValue(&bUpperCase, ::getBooleanCppuType());
218cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUseUpperCase, aAny);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	aAny.setValue(&bCombineDash, ::getBooleanCppuType());
221cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUseDash, aAny);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	aAny.setValue(&bCombinePP, ::getBooleanCppuType());
224cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sUsePP, aAny);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	aAny.setValue(&bCommaSeparated, ::getBooleanCppuType());
227cdf0e10cSrcweir 	rIndexPropertySet->setPropertyValue(sIsCommaSeparated, aAny);
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     if (sAlgorithm.getLength() > 0)
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         aAny <<= sAlgorithm;
233cdf0e10cSrcweir         rIndexPropertySet->setPropertyValue(sSortAlgorithm, aAny);
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     if ( (aLocale.Language.getLength() > 0) &&
237cdf0e10cSrcweir          (aLocale.Country.getLength() > 0)      )
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         aAny <<= aLocale;
240cdf0e10cSrcweir         rIndexPropertySet->setPropertyValue(sLocale, aAny);
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	XMLIndexSourceBaseContext::EndElement();
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)246cdf0e10cSrcweir SvXMLImportContext* XMLIndexAlphabeticalSourceContext::CreateChildContext(
247cdf0e10cSrcweir 	sal_uInt16 nPrefix,
248cdf0e10cSrcweir 	const OUString& rLocalName,
249cdf0e10cSrcweir 	const Reference<XAttributeList> & xAttrList )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	if ( (XML_NAMESPACE_TEXT == nPrefix) &&
252cdf0e10cSrcweir 		 IsXMLToken( rLocalName, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE ) )
253cdf0e10cSrcweir 	{
254cdf0e10cSrcweir 		return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
255cdf0e10cSrcweir 										   nPrefix, rLocalName,
256cdf0e10cSrcweir 										   aLevelNameAlphaMap,
257cdf0e10cSrcweir 										   XML_OUTLINE_LEVEL,
258cdf0e10cSrcweir 										   aLevelStylePropNameAlphaMap,
259cdf0e10cSrcweir 										   aAllowedTokenTypesAlpha);
260cdf0e10cSrcweir 	}
261cdf0e10cSrcweir 	else
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
264cdf0e10cSrcweir 															 rLocalName,
265cdf0e10cSrcweir 															 xAttrList);
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir }
268