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