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 "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(
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"),
63 sIsSortAscending("IsSortAscending"),
64 sSortAlgorithm("SortAlgorithm"),
70 bNumberedEntries(false),
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
++)
86 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
87 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
90 ProcessAttribute(nPrefix
, sLocalName
,
91 xAttrList
->getValueByIndex(nAttr
));
96 void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
98 const OUString
& sLocalName
,
99 const OUString
& sValue
)
101 if( XML_NAMESPACE_TEXT
== nPrefix
)
103 if( IsXMLToken(sLocalName
, XML_PREFIX
) )
107 else if( IsXMLToken(sLocalName
, XML_SUFFIX
) )
111 else if( IsXMLToken(sLocalName
, XML_NUMBERED_ENTRIES
) )
114 if (::sax::Converter::convertBool(bTmp
, sValue
))
116 bNumberedEntries
= bTmp
;
119 else if( IsXMLToken(sLocalName
, XML_SORT_BY_POSITION
) )
122 if (::sax::Converter::convertBool(bTmp
, sValue
))
124 bSortByPosition
= bTmp
;
127 else if( IsXMLToken(sLocalName
, XML_SORT_ALGORITHM
) )
132 else if( XML_NAMESPACE_FO
== nPrefix
)
134 if( IsXMLToken(sLocalName
, XML_LANGUAGE
) )
136 maLanguageTagODF
.maLanguage
= sValue
;
138 else if( IsXMLToken(sLocalName
, XML_SCRIPT
) )
140 maLanguageTagODF
.maScript
= sValue
;
142 else if( IsXMLToken(sLocalName
, XML_COUNTRY
) )
144 maLanguageTagODF
.maCountry
= sValue
;
147 else if( XML_NAMESPACE_STYLE
== nPrefix
)
149 if( IsXMLToken(sLocalName
, XML_RFC_LANGUAGE_TAG
) )
151 maLanguageTagODF
.maRfcLanguageTag
= sValue
;
157 SvXMLImportContext
*XMLIndexBibliographyConfigurationContext::CreateChildContext(
159 const OUString
& rLocalName
,
160 const Reference
<XAttributeList
> & xAttrList
)
163 sal_Bool
bSort(sal_True
);
165 // process children here and use default context!
166 if ( ( nPrefix
== XML_NAMESPACE_TEXT
) &&
167 IsXMLToken( rLocalName
, XML_SORT_KEY
) )
169 sal_Int16 nLength
= xAttrList
->getLength();
170 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
173 sal_uInt16 nPrfx
= GetImport().GetNamespaceMap().
174 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
177 if (nPrfx
== XML_NAMESPACE_TEXT
)
179 if ( IsXMLToken( sLocalName
, XML_KEY
) )
181 sKey
= xAttrList
->getValueByIndex(nAttr
);
183 else if ( IsXMLToken( sLocalName
, XML_SORT_ASCENDING
) )
186 if (::sax::Converter::convertBool(
187 bTmp
, xAttrList
->getValueByIndex(nAttr
)))
197 if (SvXMLUnitConverter::convertEnum(nKey
, sKey
,
198 aBibliographyDataFieldMap
))
202 Sequence
<PropertyValue
> aKey(2);
204 PropertyValue aNameValue
;
205 aNameValue
.Name
= sSortKey
;
206 aAny
<<= (sal_Int16
)nKey
;
207 aNameValue
.Value
= aAny
;
208 aKey
[0] = aNameValue
;
210 PropertyValue aSortValue
;
211 aSortValue
.Name
= sIsSortAscending
;
212 aAny
.setValue(&bSort
, cppu::UnoType
<bool>::get());
213 aSortValue
.Value
= aAny
;
214 aKey
[1] = aSortValue
;
216 aSortKeys
.push_back(aKey
);
220 return SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
,
224 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(bool)
226 // (code almost the same as export...)
228 // insert and block mode is handled in insertStyleFamily
230 // first: get field master
231 // (we'll create one, and get the only master for this type)
232 Reference
<XMultiServiceFactory
> xFactory(GetImport().GetModel(),UNO_QUERY
);
235 Sequence
<OUString
> aServices
= xFactory
->getAvailableServiceNames();
238 sal_Int32
nServiceCount(aServices
.getLength());
239 while (i
< nServiceCount
&& !bFound
)
241 if (aServices
[i
].equals(sFieldMaster_Bibliography
))
242 // here we should use a method which compares in reverse order if available
250 Reference
<XInterface
> xIfc
=
251 xFactory
->createInstance(sFieldMaster_Bibliography
);
254 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
258 xPropSet
->setPropertyValue(sBracketAfter
, aAny
);
261 xPropSet
->setPropertyValue(sBracketBefore
, aAny
);
263 aAny
.setValue(&bNumberedEntries
, cppu::UnoType
<bool>::get());
264 xPropSet
->setPropertyValue(sIsNumberEntries
, aAny
);
266 aAny
.setValue(&bSortByPosition
, cppu::UnoType
<bool>::get());
267 xPropSet
->setPropertyValue(sIsSortByPosition
, aAny
);
269 if( !maLanguageTagODF
.isEmpty() )
271 aAny
<<= maLanguageTagODF
.getLanguageTag().getLocale( false);
272 xPropSet
->setPropertyValue(sLocale
, aAny
);
275 if( !sAlgorithm
.isEmpty() )
278 xPropSet
->setPropertyValue(sSortAlgorithm
, aAny
);
281 sal_Int32 nCount
= aSortKeys
.size();
282 Sequence
<Sequence
<PropertyValue
> > aKeysSeq(nCount
);
283 for(i
= 0; i
< nCount
; i
++)
285 aKeysSeq
[i
] = aSortKeys
[i
];
288 xPropSet
->setPropertyValue(sSortKeys
, aAny
);
290 // else: can't get FieldMaster -> ignore
293 // else: can't even get Factory -> ignore
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */