fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / text / XMLIndexBibliographyConfigurationContext.cxx
blobe838485154c1e76b336f36f2a0d6a32b4b3d4b70
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XMLIndexBibliographyConfigurationContext.hxx"
21 #include "XMLIndexBibliographyEntryContext.hxx"
22 #include <xmloff/xmlictxt.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/txtimp.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include "xmloff/xmlnmspe.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.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/lang/XMultiServiceFactory.hpp>
34 using namespace ::com::sun::star::text;
35 using namespace ::com::sun::star::uno;
36 using namespace ::xmloff::token;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::beans::XPropertySet;
41 using ::com::sun::star::lang::XMultiServiceFactory;
43 const sal_Char sAPI_FieldMaster_Bibliography[] =
44 "com.sun.star.text.FieldMaster.Bibliography";
47 TYPEINIT1( XMLIndexBibliographyConfigurationContext, SvXMLStyleContext );
49 XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
50 SvXMLImport& rImport,
51 sal_uInt16 nPrfx,
52 const OUString& rLocalName,
53 const Reference<XAttributeList> & xAttrList) :
54 SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG),
55 sFieldMaster_Bibliography(
56 sAPI_FieldMaster_Bibliography),
57 sBracketBefore("BracketBefore"),
58 sBracketAfter("BracketAfter"),
59 sIsNumberEntries("IsNumberEntries"),
60 sIsSortByPosition("IsSortByPosition"),
61 sSortKeys("SortKeys"),
62 sSortKey("SortKey"),
63 sIsSortAscending("IsSortAscending"),
64 sSortAlgorithm("SortAlgorithm"),
65 sLocale("Locale"),
66 sSuffix(),
67 sPrefix(),
68 sAlgorithm(),
69 aLocale(),
70 bNumberedEntries(sal_False),
71 bSortByPosition(sal_True)
75 XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
79 void XMLIndexBibliographyConfigurationContext::StartElement(
80 const Reference<XAttributeList> & xAttrList)
82 sal_Int16 nLength = xAttrList->getLength();
83 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85 OUString sLocalName;
86 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
87 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
88 &sLocalName );
90 ProcessAttribute(nPrefix, sLocalName,
91 xAttrList->getValueByIndex(nAttr));
92 // else: ignore
96 void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
97 sal_uInt16 nPrefix,
98 OUString sLocalName,
99 OUString sValue)
101 if( XML_NAMESPACE_TEXT == nPrefix )
103 if( IsXMLToken(sLocalName, XML_PREFIX) )
105 sPrefix = sValue;
107 else if( IsXMLToken(sLocalName, XML_SUFFIX) )
109 sSuffix = sValue;
111 else if( IsXMLToken(sLocalName, XML_NUMBERED_ENTRIES) )
113 bool bTmp(false);
114 if (::sax::Converter::convertBool(bTmp, sValue))
116 bNumberedEntries = bTmp;
119 else if( IsXMLToken(sLocalName, XML_SORT_BY_POSITION) )
121 bool bTmp(false);
122 if (::sax::Converter::convertBool(bTmp, sValue))
124 bSortByPosition = bTmp;
127 else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) )
129 sAlgorithm = sValue;
132 else if( XML_NAMESPACE_FO == nPrefix )
134 if( IsXMLToken(sLocalName, XML_LANGUAGE) )
136 aLocale.Language = sValue;
138 else if( IsXMLToken(sLocalName, XML_COUNTRY) )
140 aLocale.Country = sValue;
146 SvXMLImportContext *XMLIndexBibliographyConfigurationContext::CreateChildContext(
147 sal_uInt16 nPrefix,
148 const OUString& rLocalName,
149 const Reference<XAttributeList> & xAttrList )
151 OUString sKey;
152 sal_Bool bSort(sal_True);
154 // process children here and use default context!
155 if ( ( nPrefix == XML_NAMESPACE_TEXT ) &&
156 IsXMLToken( rLocalName, XML_SORT_KEY ) )
158 sal_Int16 nLength = xAttrList->getLength();
159 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
161 OUString sLocalName;
162 sal_uInt16 nPrfx = GetImport().GetNamespaceMap().
163 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
164 &sLocalName );
166 if (nPrfx == XML_NAMESPACE_TEXT)
168 if ( IsXMLToken( sLocalName, XML_KEY ) )
170 sKey = xAttrList->getValueByIndex(nAttr);
172 else if ( IsXMLToken( sLocalName, XML_SORT_ASCENDING ) )
174 bool bTmp(false);
175 if (::sax::Converter::convertBool(
176 bTmp, xAttrList->getValueByIndex(nAttr)))
178 bSort = bTmp;
184 // valid data?
185 sal_uInt16 nKey;
186 if (SvXMLUnitConverter::convertEnum(nKey, sKey,
187 aBibliographyDataFieldMap))
190 Any aAny;
191 Sequence<PropertyValue> aKey(2);
193 PropertyValue aNameValue;
194 aNameValue.Name = sSortKey;
195 aAny <<= (sal_Int16)nKey;
196 aNameValue.Value = aAny;
197 aKey[0] = aNameValue;
199 PropertyValue aSortValue;
200 aSortValue.Name = sIsSortAscending;
201 aAny.setValue(&bSort, ::getBooleanCppuType());
202 aSortValue.Value = aAny;
203 aKey[1] = aSortValue;
205 aSortKeys.push_back(aKey);
209 return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
210 xAttrList);
213 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(sal_Bool)
215 // (code almost the same as export...)
217 // insert and block mode is handled in insertStyleFamily
219 // first: get field master
220 // (we'll create one, and get the only master for this type)
221 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
222 if( xFactory.is() )
224 Sequence<OUString> aServices = xFactory->getAvailableServiceNames();
225 sal_Bool bFound(sal_False);
226 sal_Int32 i(0);
227 sal_Int32 nServiceCount(aServices.getLength());
228 while (i < nServiceCount && !bFound)
230 if (aServices[i].equals(sFieldMaster_Bibliography))
231 // here we should use a method which compares in reverse order if available
232 // #85282#
233 bFound = sal_True;
234 else
235 i++;
237 if (bFound)
239 Reference<XInterface> xIfc =
240 xFactory->createInstance(sFieldMaster_Bibliography);
241 if( xIfc.is() )
243 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
244 Any aAny;
246 aAny <<= sSuffix;
247 xPropSet->setPropertyValue(sBracketAfter, aAny);
249 aAny <<= sPrefix;
250 xPropSet->setPropertyValue(sBracketBefore, aAny);
252 aAny.setValue(&bNumberedEntries, ::getBooleanCppuType());
253 xPropSet->setPropertyValue(sIsNumberEntries, aAny);
255 aAny.setValue(&bSortByPosition, ::getBooleanCppuType());
256 xPropSet->setPropertyValue(sIsSortByPosition, aAny);
258 if( !aLocale.Language.isEmpty() && !aLocale.Country.isEmpty() )
260 aAny <<= aLocale;
261 xPropSet->setPropertyValue(sLocale, aAny);
264 if( !sAlgorithm.isEmpty() )
266 aAny <<= sAlgorithm;
267 xPropSet->setPropertyValue(sSortAlgorithm, aAny);
270 sal_Int32 nCount = aSortKeys.size();
271 Sequence<Sequence<PropertyValue> > aKeysSeq(nCount);
272 for(i = 0; i < nCount; i++)
274 aKeysSeq[i] = aSortKeys[i];
276 aAny <<= aKeysSeq;
277 xPropSet->setPropertyValue(sSortKeys, aAny);
279 // else: can't get FieldMaster -> ignore
282 // else: can't even get Factory -> ignore
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */