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