1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/propertyvalue.hxx>
21 #include <XMLIndexBibliographyConfigurationContext.hxx>
22 #include "XMLIndexBibliographyEntryContext.hxx"
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <sal/log.hxx>
29 #include <sax/tools/converter.hxx>
30 #include <rtl/ustring.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <comphelper/sequence.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::xmloff::token
;
39 using ::com::sun::star::xml::sax::XFastAttributeList
;
40 using ::com::sun::star::beans::PropertyValue
;
41 using ::com::sun::star::beans::XPropertySet
;
42 using ::com::sun::star::lang::XMultiServiceFactory
;
45 constexpr OUString
gsFieldMaster_Bibliography(u
"com.sun.star.text.FieldMaster.Bibliography"_ustr
);
46 constexpr OUStringLiteral
gsBracketBefore(u
"BracketBefore");
47 constexpr OUStringLiteral
gsBracketAfter(u
"BracketAfter");
48 constexpr OUStringLiteral
gsIsNumberEntries(u
"IsNumberEntries");
49 constexpr OUStringLiteral
gsIsSortByPosition(u
"IsSortByPosition");
50 constexpr OUStringLiteral
gsSortKeys(u
"SortKeys");
51 constexpr OUString
gsSortKey(u
"SortKey"_ustr
);
52 constexpr OUString
gsIsSortAscending(u
"IsSortAscending"_ustr
);
53 constexpr OUStringLiteral
gsSortAlgorithm(u
"SortAlgorithm");
54 constexpr OUStringLiteral
gsLocale(u
"Locale");
56 XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
57 SvXMLImport
& rImport
) :
58 SvXMLStyleContext(rImport
, XmlStyleFamily::TEXT_BIBLIOGRAPHYCONFIG
),
60 bNumberedEntries(false),
65 XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
69 void XMLIndexBibliographyConfigurationContext::SetAttribute(
71 const OUString
& sValue
)
75 case XML_ELEMENT(TEXT
, XML_PREFIX
):
78 case XML_ELEMENT(TEXT
, XML_SUFFIX
):
81 case XML_ELEMENT(TEXT
, XML_NUMBERED_ENTRIES
):
84 if (::sax::Converter::convertBool(bTmp
, sValue
))
86 bNumberedEntries
= bTmp
;
90 case XML_ELEMENT(TEXT
, XML_SORT_BY_POSITION
):
93 if (::sax::Converter::convertBool(bTmp
, sValue
))
95 bSortByPosition
= bTmp
;
99 case XML_ELEMENT(TEXT
, XML_SORT_ALGORITHM
):
102 case XML_ELEMENT(FO
, XML_LANGUAGE
):
103 maLanguageTagODF
.maLanguage
= sValue
;
105 case XML_ELEMENT(FO
, XML_SCRIPT
):
106 maLanguageTagODF
.maScript
= sValue
;
108 case XML_ELEMENT(FO
, XML_COUNTRY
):
109 maLanguageTagODF
.maCountry
= sValue
;
111 case XML_ELEMENT(STYLE
, XML_RFC_LANGUAGE_TAG
):
112 maLanguageTagODF
.maRfcLanguageTag
= sValue
;
117 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLIndexBibliographyConfigurationContext::createFastChildContext(
119 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
121 // process children here and use default context!
122 if ( nElement
== XML_ELEMENT(TEXT
, XML_SORT_KEY
) )
124 std::string_view sKey
;
127 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
129 switch (aIter
.getToken())
131 case XML_ELEMENT(TEXT
, XML_KEY
):
132 sKey
= aIter
.toView();
134 case XML_ELEMENT(TEXT
, XML_SORT_ASCENDING
):
137 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
142 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
149 if (SvXMLUnitConverter::convertEnum(nKey
, sKey
,
150 aBibliographyDataFieldMap
))
152 Sequence
<PropertyValue
> aKey
154 comphelper::makePropertyValue(gsSortKey
, static_cast<sal_Int16
>(nKey
)),
155 comphelper::makePropertyValue(gsIsSortAscending
, bSort
)
158 aSortKeys
.push_back(aKey
);
165 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(bool)
167 // (code almost the same as export...)
169 // insert and block mode is handled in insertStyleFamily
171 // first: get field master
172 // (we'll create one, and get the only master for this type)
173 Reference
<XMultiServiceFactory
> xFactory(GetImport().GetModel(),UNO_QUERY
);
177 Sequence
<OUString
> aServices
= xFactory
->getAvailableServiceNames();
178 // here we should use a method which compares in reverse order if available
179 if (comphelper::findValue(aServices
, gsFieldMaster_Bibliography
) == -1)
182 Reference
<XInterface
> xIfc
=
183 xFactory
->createInstance(gsFieldMaster_Bibliography
);
187 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
190 xPropSet
->setPropertyValue(gsBracketAfter
, Any(sSuffix
));
191 xPropSet
->setPropertyValue(gsBracketBefore
, Any(sPrefix
));
192 xPropSet
->setPropertyValue(gsIsNumberEntries
, Any(bNumberedEntries
));
193 xPropSet
->setPropertyValue(gsIsSortByPosition
, Any(bSortByPosition
));
195 if( !maLanguageTagODF
.isEmpty() )
197 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
198 xPropSet
->setPropertyValue(gsLocale
, aAny
);
201 if( !sAlgorithm
.isEmpty() )
203 xPropSet
->setPropertyValue(gsSortAlgorithm
, Any(sAlgorithm
));
206 Sequence
<Sequence
<PropertyValue
> > aKeysSeq
= comphelper::containerToSequence(aSortKeys
);
207 xPropSet
->setPropertyValue(gsSortKeys
, Any(aKeysSeq
));
208 // else: can't get FieldMaster -> ignore
209 // else: can't even get Factory -> ignore
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */