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