1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexBibliographyConfigurationContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexBibliographyConfigurationContext.hxx"
36 #include "XMLIndexBibliographyEntryContext.hxx"
37 #include <xmloff/xmlictxt.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/txtimp.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <tools/debug.hxx>
45 #include <rtl/ustring.hxx>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 using namespace ::com::sun::star::text
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::xmloff::token
;
53 using ::rtl::OUString
;
54 using ::com::sun::star::xml::sax::XAttributeList
;
55 using ::com::sun::star::beans::PropertyValue
;
56 using ::com::sun::star::beans::XPropertySet
;
57 using ::com::sun::star::lang::XMultiServiceFactory
;
59 const sal_Char sAPI_FieldMaster_Bibliography
[] =
60 "com.sun.star.text.FieldMaster.Bibliography";
63 TYPEINIT1( XMLIndexBibliographyConfigurationContext
, SvXMLStyleContext
);
65 XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
68 const OUString
& rLocalName
,
69 const Reference
<XAttributeList
> & xAttrList
) :
70 SvXMLStyleContext(rImport
, nPrfx
, rLocalName
, xAttrList
, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG
),
71 sFieldMaster_Bibliography(
72 RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography
)),
73 sBracketBefore(RTL_CONSTASCII_USTRINGPARAM("BracketBefore")),
74 sBracketAfter(RTL_CONSTASCII_USTRINGPARAM("BracketAfter")),
75 sIsNumberEntries(RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries")),
76 sIsSortByPosition(RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition")),
77 sSortKeys(RTL_CONSTASCII_USTRINGPARAM("SortKeys")),
78 sSortKey(RTL_CONSTASCII_USTRINGPARAM("SortKey")),
79 sIsSortAscending(RTL_CONSTASCII_USTRINGPARAM("IsSortAscending")),
80 sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")),
81 sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale")),
86 bNumberedEntries(sal_False
),
87 bSortByPosition(sal_True
)
91 XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
95 void XMLIndexBibliographyConfigurationContext::StartElement(
96 const Reference
<XAttributeList
> & xAttrList
)
98 sal_Int16 nLength
= xAttrList
->getLength();
99 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
102 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
103 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
106 ProcessAttribute(nPrefix
, sLocalName
,
107 xAttrList
->getValueByIndex(nAttr
));
112 void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
117 if( XML_NAMESPACE_TEXT
== nPrefix
)
119 if( IsXMLToken(sLocalName
, XML_PREFIX
) )
123 else if( IsXMLToken(sLocalName
, XML_SUFFIX
) )
127 else if( IsXMLToken(sLocalName
, XML_NUMBERED_ENTRIES
) )
130 if( SvXMLUnitConverter::convertBool(bTmp
, sValue
) )
132 bNumberedEntries
= bTmp
;
135 else if( IsXMLToken(sLocalName
, XML_SORT_BY_POSITION
) )
138 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
140 bSortByPosition
= bTmp
;
143 else if( IsXMLToken(sLocalName
, XML_SORT_ALGORITHM
) )
148 else if( XML_NAMESPACE_FO
== nPrefix
)
150 if( IsXMLToken(sLocalName
, XML_LANGUAGE
) )
152 aLocale
.Language
= sValue
;
154 else if( IsXMLToken(sLocalName
, XML_COUNTRY
) )
156 aLocale
.Country
= sValue
;
162 SvXMLImportContext
*XMLIndexBibliographyConfigurationContext::CreateChildContext(
164 const OUString
& rLocalName
,
165 const Reference
<XAttributeList
> & xAttrList
)
168 sal_Bool
bSort(sal_True
);
170 // process children here and use default context!
171 if ( ( nPrefix
== XML_NAMESPACE_TEXT
) &&
172 IsXMLToken( rLocalName
, XML_SORT_KEY
) )
174 sal_Int16 nLength
= xAttrList
->getLength();
175 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
178 sal_uInt16 nPrfx
= GetImport().GetNamespaceMap().
179 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
182 if (nPrfx
== XML_NAMESPACE_TEXT
)
184 if ( IsXMLToken( sLocalName
, XML_KEY
) )
186 sKey
= xAttrList
->getValueByIndex(nAttr
);
188 else if ( IsXMLToken( sLocalName
, XML_SORT_ASCENDING
) )
191 if (SvXMLUnitConverter::convertBool(
192 bTmp
, xAttrList
->getValueByIndex(nAttr
)))
202 if (SvXMLUnitConverter::convertEnum(nKey
, sKey
,
203 aBibliographyDataFieldMap
))
207 Sequence
<PropertyValue
> aKey(2);
209 PropertyValue aNameValue
;
210 aNameValue
.Name
= sSortKey
;
211 aAny
<<= (sal_Int16
)nKey
;
212 aNameValue
.Value
= aAny
;
213 aKey
[0] = aNameValue
;
215 PropertyValue aSortValue
;
216 aSortValue
.Name
= sIsSortAscending
;
217 aAny
.setValue(&bSort
, ::getBooleanCppuType());
218 aSortValue
.Value
= aAny
;
219 aKey
[1] = aSortValue
;
221 aSortKeys
.push_back(aKey
);
225 return SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
,
229 void XMLIndexBibliographyConfigurationContext::CreateAndInsert(sal_Bool
)
231 // (code almost the same as export...)
233 // insert and block mode is handled in insertStyleFamily
235 // first: get field master
236 // (we'll create one, and get the only master for this type)
237 Reference
<XMultiServiceFactory
> xFactory(GetImport().GetModel(),UNO_QUERY
);
240 Sequence
<rtl::OUString
> aServices
= xFactory
->getAvailableServiceNames();
241 sal_Bool
bFound(sal_False
);
243 sal_Int32
nServiceCount(aServices
.getLength());
244 while (i
< nServiceCount
&& !bFound
)
246 if (aServices
[i
].equals(sFieldMaster_Bibliography
))
247 // here we should use a methode which compares in reverse order if available
255 Reference
<XInterface
> xIfc
=
256 xFactory
->createInstance(sFieldMaster_Bibliography
);
259 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
263 xPropSet
->setPropertyValue(sBracketAfter
, aAny
);
266 xPropSet
->setPropertyValue(sBracketBefore
, aAny
);
268 aAny
.setValue(&bNumberedEntries
, ::getBooleanCppuType());
269 xPropSet
->setPropertyValue(sIsNumberEntries
, aAny
);
271 aAny
.setValue(&bSortByPosition
, ::getBooleanCppuType());
272 xPropSet
->setPropertyValue(sIsSortByPosition
, aAny
);
274 if( (aLocale
.Language
.getLength() > 0) &&
275 (aLocale
.Country
.getLength() > 0) )
278 xPropSet
->setPropertyValue(sLocale
, aAny
);
281 if( sAlgorithm
.getLength() > 0 )
284 xPropSet
->setPropertyValue(sSortAlgorithm
, aAny
);
287 sal_Int32 nCount
= aSortKeys
.size();
288 Sequence
<Sequence
<PropertyValue
> > aKeysSeq(nCount
);
289 for(i
= 0; i
< nCount
; i
++)
291 aKeysSeq
[i
] = aSortKeys
[i
];
294 xPropSet
->setPropertyValue(sSortKeys
, aAny
);
296 // else: can't get FieldMaster -> ignore
299 // else: can't even get Factory -> ignore