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::XAttributeList
;
43 using ::com::sun::star::xml::sax::XFastAttributeList
;
44 using ::com::sun::star::beans::PropertyValue
;
45 using ::com::sun::star::beans::XPropertySet
;
46 using ::com::sun::star::lang::XMultiServiceFactory
;
49 constexpr OUStringLiteral
gsFieldMaster_Bibliography(u
"com.sun.star.text.FieldMaster.Bibliography");
50 constexpr OUStringLiteral
gsBracketBefore(u
"BracketBefore");
51 constexpr OUStringLiteral
gsBracketAfter(u
"BracketAfter");
52 constexpr OUStringLiteral
gsIsNumberEntries(u
"IsNumberEntries");
53 constexpr OUStringLiteral
gsIsSortByPosition(u
"IsSortByPosition");
54 constexpr OUStringLiteral
gsSortKeys(u
"SortKeys");
55 constexpr OUStringLiteral
gsSortKey(u
"SortKey");
56 constexpr OUStringLiteral
gsIsSortAscending(u
"IsSortAscending");
57 constexpr OUStringLiteral
gsSortAlgorithm(u
"SortAlgorithm");
58 constexpr OUStringLiteral
gsLocale(u
"Locale");
60 XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
61 SvXMLImport
& rImport
) :
62 SvXMLStyleContext(rImport
, XmlStyleFamily::TEXT_BIBLIOGRAPHYCONFIG
),
64 bNumberedEntries(false),
69 XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
73 void XMLIndexBibliographyConfigurationContext::SetAttribute(
75 const OUString
& sValue
)
79 case XML_ELEMENT(TEXT
, XML_PREFIX
):
82 case XML_ELEMENT(TEXT
, XML_SUFFIX
):
85 case XML_ELEMENT(TEXT
, XML_NUMBERED_ENTRIES
):
88 if (::sax::Converter::convertBool(bTmp
, sValue
))
90 bNumberedEntries
= bTmp
;
94 case XML_ELEMENT(TEXT
, XML_SORT_BY_POSITION
):
97 if (::sax::Converter::convertBool(bTmp
, sValue
))
99 bSortByPosition
= bTmp
;
103 case XML_ELEMENT(TEXT
, XML_SORT_ALGORITHM
):
106 case XML_ELEMENT(FO
, XML_LANGUAGE
):
107 maLanguageTagODF
.maLanguage
= sValue
;
109 case XML_ELEMENT(FO
, XML_SCRIPT
):
110 maLanguageTagODF
.maScript
= sValue
;
112 case XML_ELEMENT(FO
, XML_COUNTRY
):
113 maLanguageTagODF
.maCountry
= sValue
;
115 case XML_ELEMENT(STYLE
, XML_RFC_LANGUAGE_TAG
):
116 maLanguageTagODF
.maRfcLanguageTag
= sValue
;
121 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLIndexBibliographyConfigurationContext::createFastChildContext(
123 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
125 // process children here and use default context!
126 if ( nElement
== XML_ELEMENT(TEXT
, XML_SORT_KEY
) )
128 std::string_view sKey
;
131 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
133 switch (aIter
.getToken())
135 case XML_ELEMENT(TEXT
, XML_KEY
):
136 sKey
= aIter
.toView();
138 case XML_ELEMENT(TEXT
, XML_SORT_ASCENDING
):
141 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
146 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
153 if (SvXMLUnitConverter::convertEnum(nKey
, sKey
,
154 aBibliographyDataFieldMap
))
156 Sequence
<PropertyValue
> aKey
158 comphelper::makePropertyValue(gsSortKey
, static_cast<sal_Int16
>(nKey
)),
159 comphelper::makePropertyValue(gsIsSortAscending
, bSort
)
162 aSortKeys
.push_back(aKey
);
169 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(bool)
171 // (code almost the same as export...)
173 // insert and block mode is handled in insertStyleFamily
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
);
181 Sequence
<OUString
> aServices
= xFactory
->getAvailableServiceNames();
182 // here we should use a method which compares in reverse order if available
183 if (comphelper::findValue(aServices
, gsFieldMaster_Bibliography
) == -1)
186 Reference
<XInterface
> xIfc
=
187 xFactory
->createInstance(gsFieldMaster_Bibliography
);
191 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
194 xPropSet
->setPropertyValue(gsBracketAfter
, Any(sSuffix
));
195 xPropSet
->setPropertyValue(gsBracketBefore
, Any(sPrefix
));
196 xPropSet
->setPropertyValue(gsIsNumberEntries
, Any(bNumberedEntries
));
197 xPropSet
->setPropertyValue(gsIsSortByPosition
, Any(bSortByPosition
));
199 if( !maLanguageTagODF
.isEmpty() )
201 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
202 xPropSet
->setPropertyValue(gsLocale
, aAny
);
205 if( !sAlgorithm
.isEmpty() )
207 xPropSet
->setPropertyValue(gsSortAlgorithm
, Any(sAlgorithm
));
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
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */