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/txtimp.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <sal/log.hxx>
31 #include <sax/tools/converter.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>
36 #include <comphelper/sequence.hxx>
38 using namespace ::com::sun::star::text
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::xmloff::token
;
42 using ::com::sun::star::xml::sax::XFastAttributeList
;
43 using ::com::sun::star::beans::PropertyValue
;
44 using ::com::sun::star::beans::XPropertySet
;
45 using ::com::sun::star::lang::XMultiServiceFactory
;
48 constexpr OUString
gsFieldMaster_Bibliography(u
"com.sun.star.text.FieldMaster.Bibliography"_ustr
);
49 constexpr OUStringLiteral
gsBracketBefore(u
"BracketBefore");
50 constexpr OUStringLiteral
gsBracketAfter(u
"BracketAfter");
51 constexpr OUStringLiteral
gsIsNumberEntries(u
"IsNumberEntries");
52 constexpr OUStringLiteral
gsIsSortByPosition(u
"IsSortByPosition");
53 constexpr OUStringLiteral
gsSortKeys(u
"SortKeys");
54 constexpr OUString
gsSortKey(u
"SortKey"_ustr
);
55 constexpr OUString
gsIsSortAscending(u
"IsSortAscending"_ustr
);
56 constexpr OUStringLiteral
gsSortAlgorithm(u
"SortAlgorithm");
57 constexpr OUStringLiteral
gsLocale(u
"Locale");
59 XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
60 SvXMLImport
& rImport
) :
61 SvXMLStyleContext(rImport
, XmlStyleFamily::TEXT_BIBLIOGRAPHYCONFIG
),
63 bNumberedEntries(false),
68 XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
72 void XMLIndexBibliographyConfigurationContext::SetAttribute(
74 const OUString
& sValue
)
78 case XML_ELEMENT(TEXT
, XML_PREFIX
):
81 case XML_ELEMENT(TEXT
, XML_SUFFIX
):
84 case XML_ELEMENT(TEXT
, XML_NUMBERED_ENTRIES
):
87 if (::sax::Converter::convertBool(bTmp
, sValue
))
89 bNumberedEntries
= bTmp
;
93 case XML_ELEMENT(TEXT
, XML_SORT_BY_POSITION
):
96 if (::sax::Converter::convertBool(bTmp
, sValue
))
98 bSortByPosition
= bTmp
;
102 case XML_ELEMENT(TEXT
, XML_SORT_ALGORITHM
):
105 case XML_ELEMENT(FO
, XML_LANGUAGE
):
106 maLanguageTagODF
.maLanguage
= sValue
;
108 case XML_ELEMENT(FO
, XML_SCRIPT
):
109 maLanguageTagODF
.maScript
= sValue
;
111 case XML_ELEMENT(FO
, XML_COUNTRY
):
112 maLanguageTagODF
.maCountry
= sValue
;
114 case XML_ELEMENT(STYLE
, XML_RFC_LANGUAGE_TAG
):
115 maLanguageTagODF
.maRfcLanguageTag
= sValue
;
120 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLIndexBibliographyConfigurationContext::createFastChildContext(
122 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
124 // process children here and use default context!
125 if ( nElement
== XML_ELEMENT(TEXT
, XML_SORT_KEY
) )
127 std::string_view sKey
;
130 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
132 switch (aIter
.getToken())
134 case XML_ELEMENT(TEXT
, XML_KEY
):
135 sKey
= aIter
.toView();
137 case XML_ELEMENT(TEXT
, XML_SORT_ASCENDING
):
140 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
145 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
152 if (SvXMLUnitConverter::convertEnum(nKey
, sKey
,
153 aBibliographyDataFieldMap
))
155 Sequence
<PropertyValue
> aKey
157 comphelper::makePropertyValue(gsSortKey
, static_cast<sal_Int16
>(nKey
)),
158 comphelper::makePropertyValue(gsIsSortAscending
, bSort
)
161 aSortKeys
.push_back(aKey
);
168 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(bool)
170 // (code almost the same as export...)
172 // insert and block mode is handled in insertStyleFamily
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
);
180 Sequence
<OUString
> aServices
= xFactory
->getAvailableServiceNames();
181 // here we should use a method which compares in reverse order if available
182 if (comphelper::findValue(aServices
, gsFieldMaster_Bibliography
) == -1)
185 Reference
<XInterface
> xIfc
=
186 xFactory
->createInstance(gsFieldMaster_Bibliography
);
190 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
193 xPropSet
->setPropertyValue(gsBracketAfter
, Any(sSuffix
));
194 xPropSet
->setPropertyValue(gsBracketBefore
, Any(sPrefix
));
195 xPropSet
->setPropertyValue(gsIsNumberEntries
, Any(bNumberedEntries
));
196 xPropSet
->setPropertyValue(gsIsSortByPosition
, Any(bSortByPosition
));
198 if( !maLanguageTagODF
.isEmpty() )
200 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
201 xPropSet
->setPropertyValue(gsLocale
, aAny
);
204 if( !sAlgorithm
.isEmpty() )
206 xPropSet
->setPropertyValue(gsSortAlgorithm
, Any(sAlgorithm
));
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
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */