1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "XMLIndexBibliographyConfigurationContext.hxx"
29cdf0e10cSrcweir #include "XMLIndexBibliographyEntryContext.hxx"
30cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
32cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
33cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
34cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
36cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <rtl/ustring.hxx>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::com::sun::star::text;
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::xmloff::token;
45cdf0e10cSrcweir
46cdf0e10cSrcweir using ::rtl::OUString;
47cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
48cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
49cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
50cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
51cdf0e10cSrcweir
52cdf0e10cSrcweir const sal_Char sAPI_FieldMaster_Bibliography[] =
53cdf0e10cSrcweir "com.sun.star.text.FieldMaster.Bibliography";
54cdf0e10cSrcweir
55cdf0e10cSrcweir
56cdf0e10cSrcweir TYPEINIT1( XMLIndexBibliographyConfigurationContext, SvXMLStyleContext );
57cdf0e10cSrcweir
XMLIndexBibliographyConfigurationContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)58cdf0e10cSrcweir XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
59cdf0e10cSrcweir SvXMLImport& rImport,
60cdf0e10cSrcweir sal_uInt16 nPrfx,
61cdf0e10cSrcweir const OUString& rLocalName,
62cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList) :
63cdf0e10cSrcweir SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG),
64cdf0e10cSrcweir sFieldMaster_Bibliography(
65cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography)),
66cdf0e10cSrcweir sBracketBefore(RTL_CONSTASCII_USTRINGPARAM("BracketBefore")),
67cdf0e10cSrcweir sBracketAfter(RTL_CONSTASCII_USTRINGPARAM("BracketAfter")),
68cdf0e10cSrcweir sIsNumberEntries(RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries")),
69cdf0e10cSrcweir sIsSortByPosition(RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition")),
70cdf0e10cSrcweir sSortKeys(RTL_CONSTASCII_USTRINGPARAM("SortKeys")),
71cdf0e10cSrcweir sSortKey(RTL_CONSTASCII_USTRINGPARAM("SortKey")),
72cdf0e10cSrcweir sIsSortAscending(RTL_CONSTASCII_USTRINGPARAM("IsSortAscending")),
73cdf0e10cSrcweir sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")),
74cdf0e10cSrcweir sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale")),
75cdf0e10cSrcweir sSuffix(),
76cdf0e10cSrcweir sPrefix(),
77cdf0e10cSrcweir sAlgorithm(),
78cdf0e10cSrcweir aLocale(),
79cdf0e10cSrcweir bNumberedEntries(sal_False),
80cdf0e10cSrcweir bSortByPosition(sal_True)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
~XMLIndexBibliographyConfigurationContext()84cdf0e10cSrcweir XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & xAttrList)88cdf0e10cSrcweir void XMLIndexBibliographyConfigurationContext::StartElement(
89cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
92cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir OUString sLocalName;
95cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
96cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
97cdf0e10cSrcweir &sLocalName );
98cdf0e10cSrcweir
99cdf0e10cSrcweir ProcessAttribute(nPrefix, sLocalName,
100cdf0e10cSrcweir xAttrList->getValueByIndex(nAttr));
101cdf0e10cSrcweir // else: ignore
102cdf0e10cSrcweir }
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
ProcessAttribute(sal_uInt16 nPrefix,OUString sLocalName,OUString sValue)105cdf0e10cSrcweir void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
106cdf0e10cSrcweir sal_uInt16 nPrefix,
107cdf0e10cSrcweir OUString sLocalName,
108cdf0e10cSrcweir OUString sValue)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if( XML_NAMESPACE_TEXT == nPrefix )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if( IsXMLToken(sLocalName, XML_PREFIX) )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir sPrefix = sValue;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir else if( IsXMLToken(sLocalName, XML_SUFFIX) )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir sSuffix = sValue;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir else if( IsXMLToken(sLocalName, XML_NUMBERED_ENTRIES) )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir sal_Bool bTmp;
123cdf0e10cSrcweir if( SvXMLUnitConverter::convertBool(bTmp, sValue) )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir bNumberedEntries = bTmp;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir else if( IsXMLToken(sLocalName, XML_SORT_BY_POSITION) )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir sal_Bool bTmp;
131cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sValue))
132cdf0e10cSrcweir {
133cdf0e10cSrcweir bSortByPosition = bTmp;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir }
136cdf0e10cSrcweir else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir sAlgorithm = sValue;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir else if( XML_NAMESPACE_FO == nPrefix )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir if( IsXMLToken(sLocalName, XML_LANGUAGE) )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir aLocale.Language = sValue;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir else if( IsXMLToken(sLocalName, XML_COUNTRY) )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir aLocale.Country = sValue;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir }
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)155cdf0e10cSrcweir SvXMLImportContext *XMLIndexBibliographyConfigurationContext::CreateChildContext(
156cdf0e10cSrcweir sal_uInt16 nPrefix,
157cdf0e10cSrcweir const OUString& rLocalName,
158cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir OUString sKey;
161cdf0e10cSrcweir sal_Bool bSort(sal_True);
162cdf0e10cSrcweir
163cdf0e10cSrcweir // process children here and use default context!
164cdf0e10cSrcweir if ( ( nPrefix == XML_NAMESPACE_TEXT ) &&
165cdf0e10cSrcweir IsXMLToken( rLocalName, XML_SORT_KEY ) )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
168cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir OUString sLocalName;
171cdf0e10cSrcweir sal_uInt16 nPrfx = GetImport().GetNamespaceMap().
172cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
173cdf0e10cSrcweir &sLocalName );
174cdf0e10cSrcweir
175cdf0e10cSrcweir if (nPrfx == XML_NAMESPACE_TEXT)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir if ( IsXMLToken( sLocalName, XML_KEY ) )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir sKey = xAttrList->getValueByIndex(nAttr);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_SORT_ASCENDING ) )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir sal_Bool bTmp;
184cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(
185cdf0e10cSrcweir bTmp, xAttrList->getValueByIndex(nAttr)))
186cdf0e10cSrcweir {
187cdf0e10cSrcweir bSort = bTmp;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir // valid data?
194cdf0e10cSrcweir sal_uInt16 nKey;
195cdf0e10cSrcweir if (SvXMLUnitConverter::convertEnum(nKey, sKey,
196cdf0e10cSrcweir aBibliographyDataFieldMap))
197cdf0e10cSrcweir {
198cdf0e10cSrcweir
199cdf0e10cSrcweir Any aAny;
200cdf0e10cSrcweir Sequence<PropertyValue> aKey(2);
201cdf0e10cSrcweir
202cdf0e10cSrcweir PropertyValue aNameValue;
203cdf0e10cSrcweir aNameValue.Name = sSortKey;
204cdf0e10cSrcweir aAny <<= (sal_Int16)nKey;
205cdf0e10cSrcweir aNameValue.Value = aAny;
206cdf0e10cSrcweir aKey[0] = aNameValue;
207cdf0e10cSrcweir
208cdf0e10cSrcweir PropertyValue aSortValue;
209cdf0e10cSrcweir aSortValue.Name = sIsSortAscending;
210cdf0e10cSrcweir aAny.setValue(&bSort, ::getBooleanCppuType());
211cdf0e10cSrcweir aSortValue.Value = aAny;
212cdf0e10cSrcweir aKey[1] = aSortValue;
213cdf0e10cSrcweir
214cdf0e10cSrcweir aSortKeys.push_back(aKey);
215cdf0e10cSrcweir }
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
219cdf0e10cSrcweir xAttrList);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
CreateAndInsert(sal_Bool)222cdf0e10cSrcweir void XMLIndexBibliographyConfigurationContext::CreateAndInsert(sal_Bool)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir // (code almost the same as export...)
225cdf0e10cSrcweir
226cdf0e10cSrcweir // insert and block mode is handled in insertStyleFamily
227cdf0e10cSrcweir
228cdf0e10cSrcweir // first: get field master
229cdf0e10cSrcweir // (we'll create one, and get the only master for this type)
230cdf0e10cSrcweir Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
231cdf0e10cSrcweir if( xFactory.is() )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir Sequence<rtl::OUString> aServices = xFactory->getAvailableServiceNames();
234cdf0e10cSrcweir sal_Bool bFound(sal_False);
235cdf0e10cSrcweir sal_Int32 i(0);
236cdf0e10cSrcweir sal_Int32 nServiceCount(aServices.getLength());
237cdf0e10cSrcweir while (i < nServiceCount && !bFound)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir if (aServices[i].equals(sFieldMaster_Bibliography))
240cdf0e10cSrcweir // here we should use a methode which compares in reverse order if available
241cdf0e10cSrcweir // #85282#
242cdf0e10cSrcweir bFound = sal_True;
243cdf0e10cSrcweir else
244cdf0e10cSrcweir i++;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir if (bFound)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir Reference<XInterface> xIfc =
249cdf0e10cSrcweir xFactory->createInstance(sFieldMaster_Bibliography);
250cdf0e10cSrcweir if( xIfc.is() )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
253cdf0e10cSrcweir Any aAny;
254cdf0e10cSrcweir
255cdf0e10cSrcweir aAny <<= sSuffix;
256cdf0e10cSrcweir xPropSet->setPropertyValue(sBracketAfter, aAny);
257cdf0e10cSrcweir
258cdf0e10cSrcweir aAny <<= sPrefix;
259cdf0e10cSrcweir xPropSet->setPropertyValue(sBracketBefore, aAny);
260cdf0e10cSrcweir
261cdf0e10cSrcweir aAny.setValue(&bNumberedEntries, ::getBooleanCppuType());
262cdf0e10cSrcweir xPropSet->setPropertyValue(sIsNumberEntries, aAny);
263cdf0e10cSrcweir
264cdf0e10cSrcweir aAny.setValue(&bSortByPosition, ::getBooleanCppuType());
265cdf0e10cSrcweir xPropSet->setPropertyValue(sIsSortByPosition, aAny);
266cdf0e10cSrcweir
267cdf0e10cSrcweir if( (aLocale.Language.getLength() > 0) &&
268cdf0e10cSrcweir (aLocale.Country.getLength() > 0) )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir aAny <<= aLocale;
271cdf0e10cSrcweir xPropSet->setPropertyValue(sLocale, aAny);
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir if( sAlgorithm.getLength() > 0 )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir aAny <<= sAlgorithm;
277cdf0e10cSrcweir xPropSet->setPropertyValue(sSortAlgorithm, aAny);
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir sal_Int32 nCount = aSortKeys.size();
281cdf0e10cSrcweir Sequence<Sequence<PropertyValue> > aKeysSeq(nCount);
282cdf0e10cSrcweir for(i = 0; i < nCount; i++)
283cdf0e10cSrcweir {
284cdf0e10cSrcweir aKeysSeq[i] = aSortKeys[i];
285cdf0e10cSrcweir }
286cdf0e10cSrcweir aAny <<= aKeysSeq;
287cdf0e10cSrcweir xPropSet->setPropertyValue(sSortKeys, aAny);
288cdf0e10cSrcweir }
289cdf0e10cSrcweir // else: can't get FieldMaster -> ignore
290cdf0e10cSrcweir }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir // else: can't even get Factory -> ignore
293cdf0e10cSrcweir }
294