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::XFastAttributeList;
43using ::com::sun::star::beans::PropertyValue;
44using ::com::sun::star::beans::XPropertySet;
45using ::com::sun::star::lang::XMultiServiceFactory;
46
47
48constexpr OUStringLiteral gsFieldMaster_Bibliography(u"com.sun.star.text.FieldMaster.Bibliography");
49constexpr OUStringLiteral gsBracketBefore(u"BracketBefore");
50constexpr OUStringLiteral gsBracketAfter(u"BracketAfter");
51constexpr OUStringLiteral gsIsNumberEntries(u"IsNumberEntries");
52constexpr OUStringLiteral gsIsSortByPosition(u"IsSortByPosition");
53constexpr OUStringLiteral gsSortKeys(u"SortKeys");
54constexpr OUStringLiteral gsSortKey(u"SortKey");
55constexpr OUStringLiteral gsIsSortAscending(u"IsSortAscending");
56constexpr OUStringLiteral gsSortAlgorithm(u"SortAlgorithm");
57constexpr OUStringLiteral gsLocale(u"Locale");
58
60 SvXMLImport& rImport) :
62 maLanguageTagODF(),
63 bNumberedEntries(false),
64 bSortByPosition(true)
65{
66}
67
69{
70}
71
73 sal_Int32 nElement,
74 const OUString& sValue)
75{
76 switch (nElement)
77 {
79 sPrefix = sValue;
80 break;
82 sSuffix = sValue;
83 break;
85 {
86 bool bTmp(false);
87 if (::sax::Converter::convertBool(bTmp, sValue))
88 {
89 bNumberedEntries = bTmp;
90 }
91 break;
92 }
94 {
95 bool bTmp(false);
96 if (::sax::Converter::convertBool(bTmp, sValue))
97 {
98 bSortByPosition = bTmp;
99 }
100 break;
101 }
103 sAlgorithm = sValue;
104 break;
105 case XML_ELEMENT(FO, XML_LANGUAGE):
107 break;
108 case XML_ELEMENT(FO, XML_SCRIPT):
109 maLanguageTagODF.maScript = sValue;
110 break;
111 case XML_ELEMENT(FO, XML_COUNTRY):
113 break;
116 break;
117 }
118}
119
120css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexBibliographyConfigurationContext::createFastChildContext(
121 sal_Int32 nElement,
122 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
123{
124 // process children here and use default context!
125 if ( nElement == XML_ELEMENT(TEXT, XML_SORT_KEY) )
126 {
127 std::string_view sKey;
128 bool bSort(true);
129
130 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
131 {
132 switch (aIter.getToken())
133 {
134 case XML_ELEMENT(TEXT, XML_KEY):
135 sKey = aIter.toView();
136 break;
138 {
139 bool bTmp(false);
140 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
141 bSort = bTmp;
142 break;
143 }
144 default:
145 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
146 break;
147 }
148 }
149
150 // valid data?
151 sal_uInt16 nKey;
152 if (SvXMLUnitConverter::convertEnum(nKey, sKey,
154 {
155 Sequence<PropertyValue> aKey
156 {
157 comphelper::makePropertyValue(gsSortKey, static_cast<sal_Int16>(nKey)),
159 };
160
161 aSortKeys.push_back(aKey);
162 }
163 }
164
165 return nullptr;
166}
167
169{
170 // (code almost the same as export...)
171
172 // insert and block mode is handled in insertStyleFamily
173
174 // first: get field master
175 // (we'll create one, and get the only master for this type)
176 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
177 if( !xFactory.is() )
178 return;
179
180 Sequence<OUString> aServices = xFactory->getAvailableServiceNames();
181 // here we should use a method which compares in reverse order if available
183 return;
184
185 Reference<XInterface> xIfc =
186 xFactory->createInstance(gsFieldMaster_Bibliography);
187 if( !xIfc.is() )
188 return;
189
190 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
191 Any aAny;
192
193 xPropSet->setPropertyValue(gsBracketAfter, Any(sSuffix));
194 xPropSet->setPropertyValue(gsBracketBefore, Any(sPrefix));
195 xPropSet->setPropertyValue(gsIsNumberEntries, Any(bNumberedEntries));
196 xPropSet->setPropertyValue(gsIsSortByPosition, Any(bSortByPosition));
197
199 {
200 aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
201 xPropSet->setPropertyValue(gsLocale, aAny);
202 }
203
204 if( !sAlgorithm.isEmpty() )
205 {
206 xPropSet->setPropertyValue(gsSortAlgorithm, Any(sAlgorithm));
207 }
208
209 Sequence<Sequence<PropertyValue> > aKeysSeq = comphelper::containerToSequence(aSortKeys);
210 xPropSet->setPropertyValue(gsSortKeys, Any(aKeysSeq));
211 // else: can't get FieldMaster -> ignore
212 // else: can't even get Factory -> ignore
213}
214
215/* 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