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