LibreOffice Module xmloff (master) 1
XMLIndexBibliographyConfigurationContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
23#include <xmloff/xmlictxt.hxx>
24#include <xmloff/xmlimp.hxx>
25#include <xmloff/txtimp.hxx>
28#include <xmloff/xmltoken.hxx>
29#include <xmloff/xmluconv.hxx>
30#include <sal/log.hxx>
32#include <rtl/ustring.hxx>
33#include <com/sun/star/beans/XPropertySet.hpp>
34#include <com/sun/star/frame/XModel.hpp>
35#include <com/sun/star/lang/XMultiServiceFactory.hpp>
37
38using namespace ::com::sun::star::text;
39using namespace ::com::sun::star::uno;
40using namespace ::xmloff::token;
41
42using ::com::sun::star::xml::sax::XAttributeList;
43using ::com::sun::star::xml::sax::XFastAttributeList;
44using ::com::sun::star::beans::PropertyValue;
45using ::com::sun::star::beans::XPropertySet;
46using ::com::sun::star::lang::XMultiServiceFactory;
47
48
49constexpr OUStringLiteral gsFieldMaster_Bibliography(u"com.sun.star.text.FieldMaster.Bibliography");
50constexpr OUStringLiteral gsBracketBefore(u"BracketBefore");
51constexpr OUStringLiteral gsBracketAfter(u"BracketAfter");
52constexpr OUStringLiteral gsIsNumberEntries(u"IsNumberEntries");
53constexpr OUStringLiteral gsIsSortByPosition(u"IsSortByPosition");
54constexpr OUStringLiteral gsSortKeys(u"SortKeys");
55constexpr OUStringLiteral gsSortKey(u"SortKey");
56constexpr OUStringLiteral gsIsSortAscending(u"IsSortAscending");
57constexpr OUStringLiteral gsSortAlgorithm(u"SortAlgorithm");
58constexpr OUStringLiteral gsLocale(u"Locale");
59
61 SvXMLImport& rImport) :
63 maLanguageTagODF(),
64 bNumberedEntries(false),
65 bSortByPosition(true)
66{
67}
68
70{
71}
72
74 sal_Int32 nElement,
75 const OUString& sValue)
76{
77 switch (nElement)
78 {
80 sPrefix = sValue;
81 break;
83 sSuffix = sValue;
84 break;
86 {
87 bool bTmp(false);
88 if (::sax::Converter::convertBool(bTmp, sValue))
89 {
90 bNumberedEntries = bTmp;
91 }
92 break;
93 }
95 {
96 bool bTmp(false);
97 if (::sax::Converter::convertBool(bTmp, sValue))
98 {
99 bSortByPosition = bTmp;
100 }
101 break;
102 }
104 sAlgorithm = sValue;
105 break;
106 case XML_ELEMENT(FO, XML_LANGUAGE):
108 break;
109 case XML_ELEMENT(FO, XML_SCRIPT):
110 maLanguageTagODF.maScript = sValue;
111 break;
112 case XML_ELEMENT(FO, XML_COUNTRY):
114 break;
117 break;
118 }
119}
120
121css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexBibliographyConfigurationContext::createFastChildContext(
122 sal_Int32 nElement,
123 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
124{
125 // process children here and use default context!
126 if ( nElement == XML_ELEMENT(TEXT, XML_SORT_KEY) )
127 {
128 std::string_view sKey;
129 bool bSort(true);
130
131 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
132 {
133 switch (aIter.getToken())
134 {
135 case XML_ELEMENT(TEXT, XML_KEY):
136 sKey = aIter.toView();
137 break;
139 {
140 bool bTmp(false);
141 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
142 bSort = bTmp;
143 break;
144 }
145 default:
146 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
147 break;
148 }
149 }
150
151 // valid data?
152 sal_uInt16 nKey;
153 if (SvXMLUnitConverter::convertEnum(nKey, sKey,
155 {
156 Sequence<PropertyValue> aKey
157 {
158 comphelper::makePropertyValue(gsSortKey, static_cast<sal_Int16>(nKey)),
160 };
161
162 aSortKeys.push_back(aKey);
163 }
164 }
165
166 return nullptr;
167}
168
170{
171 // (code almost the same as export...)
172
173 // insert and block mode is handled in insertStyleFamily
174
175 // first: get field master
176 // (we'll create one, and get the only master for this type)
177 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
178 if( !xFactory.is() )
179 return;
180
181 Sequence<OUString> aServices = xFactory->getAvailableServiceNames();
182 // here we should use a method which compares in reverse order if available
184 return;
185
186 Reference<XInterface> xIfc =
187 xFactory->createInstance(gsFieldMaster_Bibliography);
188 if( !xIfc.is() )
189 return;
190
191 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
192 Any aAny;
193
194 xPropSet->setPropertyValue(gsBracketAfter, Any(sSuffix));
195 xPropSet->setPropertyValue(gsBracketBefore, Any(sPrefix));
196 xPropSet->setPropertyValue(gsIsNumberEntries, Any(bNumberedEntries));
197 xPropSet->setPropertyValue(gsIsSortByPosition, Any(bSortByPosition));
198
200 {
201 aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
202 xPropSet->setPropertyValue(gsLocale, aAny);
203 }
204
205 if( !sAlgorithm.isEmpty() )
206 {
207 xPropSet->setPropertyValue(gsSortAlgorithm, Any(sAlgorithm));
208 }
209
210 Sequence<Sequence<PropertyValue> > aKeysSeq = comphelper::containerToSequence(aSortKeys);
211 xPropSet->setPropertyValue(gsSortKeys, Any(aKeysSeq));
212 // else: can't get FieldMaster -> ignore
213 // else: can't even get Factory -> ignore
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsSortKeys(u"SortKeys")
constexpr OUStringLiteral gsBracketAfter(u"BracketAfter")
constexpr OUStringLiteral gsIsSortAscending(u"IsSortAscending")
constexpr OUStringLiteral gsBracketBefore(u"BracketBefore")
constexpr OUStringLiteral gsLocale(u"Locale")
constexpr OUStringLiteral gsFieldMaster_Bibliography(u"com.sun.star.text.FieldMaster.Bibliography")
constexpr OUStringLiteral gsIsSortByPosition(u"IsSortByPosition")
constexpr OUStringLiteral gsIsNumberEntries(u"IsNumberEntries")
constexpr OUStringLiteral gsSortKey(u"SortKey")
constexpr OUStringLiteral gsSortAlgorithm(u"SortAlgorithm")
const SvXMLEnumMapEntry< sal_uInt16 > aBibliographyDataFieldMap[]
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
::std::vector< css::uno::Sequence< css::beans::PropertyValue > > aSortKeys
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
static bool convertBool(bool &rBool, std::u16string_view rString)
Reference< XSingleServiceFactory > xFactory
XmlStyleFamily
Definition: families.hxx:50
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
LanguageTag getLanguageTag() const
Best call this only once per instance, it recreates a LanguageTag instance on every call.
bool isEmpty() const
OUString maRfcLanguageTag
TEXT
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97