1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexAlphabeticalSourceContext.cxx,v $
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(
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
)
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
)
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
);
129 case XML_TOK_INDEXSOURCE_IGNORE_CASE
:
130 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
132 bCaseSensitive
= !bTmp
;
136 case XML_TOK_INDEXSOURCE_SEPARATORS
:
137 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
143 case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES
:
144 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
146 bCombineEntries
= bTmp
;
150 case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH
:
151 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
156 case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES
:
157 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
163 case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP
:
164 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
170 case XML_TOK_INDEXSOURCE_CAPITALIZE
:
171 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
177 case XML_TOK_INDEXSOURCE_COMMA_SEPARATED
:
178 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
180 bCommaSeparated
= bTmp
;
184 case XML_TOK_INDEXSOURCE_SORT_ALGORITHM
:
187 case XML_TOK_INDEXSOURCE_LANGUAGE
:
188 aLocale
.Language
= rValue
;
190 case XML_TOK_INDEXSOURCE_COUNTRY
:
191 aLocale
.Country
= rValue
;
195 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
200 void XMLIndexAlphabeticalSourceContext::EndElement()
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)
240 rIndexPropertySet
->setPropertyValue(sSortAlgorithm
, aAny
);
243 if ( (aLocale
.Language
.getLength() > 0) &&
244 (aLocale
.Country
.getLength() > 0) )
247 rIndexPropertySet
->setPropertyValue(sLocale
, aAny
);
250 XMLIndexSourceBaseContext::EndElement();
253 SvXMLImportContext
* XMLIndexAlphabeticalSourceContext::CreateChildContext(
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
,
265 aLevelStylePropNameAlphaMap
,
266 aAllowedTokenTypesAlpha
);
270 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,