Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLIndexBibliographyConfigurationContext.hxx"
30 : : #include "XMLIndexBibliographyEntryContext.hxx"
31 : : #include <xmloff/xmlictxt.hxx>
32 : : #include <xmloff/xmlimp.hxx>
33 : : #include <xmloff/txtimp.hxx>
34 : : #include <xmloff/nmspmap.hxx>
35 : : #include "xmloff/xmlnmspe.hxx"
36 : : #include <xmloff/xmltoken.hxx>
37 : : #include <xmloff/xmluconv.hxx>
38 : : #include <sax/tools/converter.hxx>
39 : : #include <rtl/ustring.hxx>
40 : : #include <com/sun/star/beans/XPropertySet.hpp>
41 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 : :
43 : : using namespace ::com::sun::star::text;
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::xmloff::token;
46 : :
47 : : using ::rtl::OUString;
48 : : using ::com::sun::star::xml::sax::XAttributeList;
49 : : using ::com::sun::star::beans::PropertyValue;
50 : : using ::com::sun::star::beans::XPropertySet;
51 : : using ::com::sun::star::lang::XMultiServiceFactory;
52 : :
53 : : const sal_Char sAPI_FieldMaster_Bibliography[] =
54 : : "com.sun.star.text.FieldMaster.Bibliography";
55 : :
56 : :
57 [ # # ][ # # ]: 0 : TYPEINIT1( XMLIndexBibliographyConfigurationContext, SvXMLStyleContext );
58 : :
59 : 4 : XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
60 : : SvXMLImport& rImport,
61 : : sal_uInt16 nPrfx,
62 : : const OUString& rLocalName,
63 : : const Reference<XAttributeList> & xAttrList) :
64 : : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG),
65 : : sFieldMaster_Bibliography(
66 : : RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography)),
67 : : sBracketBefore(RTL_CONSTASCII_USTRINGPARAM("BracketBefore")),
68 : : sBracketAfter(RTL_CONSTASCII_USTRINGPARAM("BracketAfter")),
69 : : sIsNumberEntries(RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries")),
70 : : sIsSortByPosition(RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition")),
71 : : sSortKeys(RTL_CONSTASCII_USTRINGPARAM("SortKeys")),
72 : : sSortKey(RTL_CONSTASCII_USTRINGPARAM("SortKey")),
73 : : sIsSortAscending(RTL_CONSTASCII_USTRINGPARAM("IsSortAscending")),
74 : : sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")),
75 : : sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale")),
76 : : sSuffix(),
77 : : sPrefix(),
78 : : sAlgorithm(),
79 : : aLocale(),
80 : : bNumberedEntries(sal_False),
81 [ + - ][ + - ]: 4 : bSortByPosition(sal_True)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
82 : : {
83 : 4 : }
84 : :
85 : 4 : XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
86 : : {
87 [ - + ]: 8 : }
88 : :
89 : 4 : void XMLIndexBibliographyConfigurationContext::StartElement(
90 : : const Reference<XAttributeList> & xAttrList)
91 : : {
92 : 4 : sal_Int16 nLength = xAttrList->getLength();
93 [ + + ]: 24 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
94 : : {
95 : 20 : OUString sLocalName;
96 : 20 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
97 [ + - ]: 20 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
98 [ + - + - ]: 40 : &sLocalName );
99 : :
100 : : ProcessAttribute(nPrefix, sLocalName,
101 [ + - ][ + - ]: 20 : xAttrList->getValueByIndex(nAttr));
[ + - ]
102 : : // else: ignore
103 : 20 : }
104 : 4 : }
105 : :
106 : 20 : void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
107 : : sal_uInt16 nPrefix,
108 : : OUString sLocalName,
109 : : OUString sValue)
110 : : {
111 [ + + ]: 20 : if( XML_NAMESPACE_TEXT == nPrefix )
112 : : {
113 [ + + ]: 12 : if( IsXMLToken(sLocalName, XML_PREFIX) )
114 : : {
115 : 4 : sPrefix = sValue;
116 : : }
117 [ + + ]: 8 : else if( IsXMLToken(sLocalName, XML_SUFFIX) )
118 : : {
119 : 4 : sSuffix = sValue;
120 : : }
121 [ - + ]: 4 : else if( IsXMLToken(sLocalName, XML_NUMBERED_ENTRIES) )
122 : : {
123 : 0 : bool bTmp(false);
124 [ # # ][ # # ]: 0 : if (::sax::Converter::convertBool(bTmp, sValue))
125 : : {
126 : 0 : bNumberedEntries = bTmp;
127 : : }
128 : : }
129 [ - + ]: 4 : else if( IsXMLToken(sLocalName, XML_SORT_BY_POSITION) )
130 : : {
131 : 0 : bool bTmp(false);
132 [ # # ][ # # ]: 0 : if (::sax::Converter::convertBool(bTmp, sValue))
133 : : {
134 : 0 : bSortByPosition = bTmp;
135 : : }
136 : : }
137 [ + - ]: 4 : else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) )
138 : : {
139 : 4 : sAlgorithm = sValue;
140 : : }
141 : : }
142 [ + - ]: 8 : else if( XML_NAMESPACE_FO == nPrefix )
143 : : {
144 [ + + ]: 8 : if( IsXMLToken(sLocalName, XML_LANGUAGE) )
145 : : {
146 : 4 : aLocale.Language = sValue;
147 : : }
148 [ + - ]: 4 : else if( IsXMLToken(sLocalName, XML_COUNTRY) )
149 : : {
150 : 4 : aLocale.Country = sValue;
151 : : }
152 : : }
153 : 20 : }
154 : :
155 : :
156 : 0 : SvXMLImportContext *XMLIndexBibliographyConfigurationContext::CreateChildContext(
157 : : sal_uInt16 nPrefix,
158 : : const OUString& rLocalName,
159 : : const Reference<XAttributeList> & xAttrList )
160 : : {
161 : 0 : OUString sKey;
162 : 0 : sal_Bool bSort(sal_True);
163 : :
164 : : // process children here and use default context!
165 [ # # ][ # # ]: 0 : if ( ( nPrefix == XML_NAMESPACE_TEXT ) &&
[ # # ]
166 [ # # ]: 0 : IsXMLToken( rLocalName, XML_SORT_KEY ) )
167 : : {
168 [ # # ][ # # ]: 0 : sal_Int16 nLength = xAttrList->getLength();
169 [ # # ]: 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
170 : : {
171 : 0 : OUString sLocalName;
172 : 0 : sal_uInt16 nPrfx = GetImport().GetNamespaceMap().
173 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
174 [ # # # # ]: 0 : &sLocalName );
175 : :
176 [ # # ]: 0 : if (nPrfx == XML_NAMESPACE_TEXT)
177 : : {
178 [ # # ][ # # ]: 0 : if ( IsXMLToken( sLocalName, XML_KEY ) )
179 : : {
180 [ # # ][ # # ]: 0 : sKey = xAttrList->getValueByIndex(nAttr);
181 : : }
182 [ # # ][ # # ]: 0 : else if ( IsXMLToken( sLocalName, XML_SORT_ASCENDING ) )
183 : : {
184 : 0 : bool bTmp(false);
185 [ # # # # ]: 0 : if (::sax::Converter::convertBool(
186 [ # # ][ # # ]: 0 : bTmp, xAttrList->getValueByIndex(nAttr)))
187 : : {
188 : 0 : bSort = bTmp;
189 : : }
190 : : }
191 : : }
192 : 0 : }
193 : :
194 : : // valid data?
195 : : sal_uInt16 nKey;
196 [ # # ]: 0 : if (SvXMLUnitConverter::convertEnum(nKey, sKey,
197 [ # # ]: 0 : aBibliographyDataFieldMap))
198 : : {
199 : :
200 : 0 : Any aAny;
201 [ # # ]: 0 : Sequence<PropertyValue> aKey(2);
202 : :
203 : 0 : PropertyValue aNameValue;
204 : 0 : aNameValue.Name = sSortKey;
205 [ # # ]: 0 : aAny <<= (sal_Int16)nKey;
206 : 0 : aNameValue.Value = aAny;
207 [ # # ]: 0 : aKey[0] = aNameValue;
208 : :
209 : 0 : PropertyValue aSortValue;
210 : 0 : aSortValue.Name = sIsSortAscending;
211 [ # # ]: 0 : aAny.setValue(&bSort, ::getBooleanCppuType());
212 : 0 : aSortValue.Value = aAny;
213 [ # # ]: 0 : aKey[1] = aSortValue;
214 : :
215 [ # # ][ # # ]: 0 : aSortKeys.push_back(aKey);
216 : : }
217 : : }
218 : :
219 : : return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
220 [ # # ]: 0 : xAttrList);
221 : : }
222 : :
223 : 4 : void XMLIndexBibliographyConfigurationContext::CreateAndInsert(sal_Bool)
224 : : {
225 : : // (code almost the same as export...)
226 : :
227 : : // insert and block mode is handled in insertStyleFamily
228 : :
229 : : // first: get field master
230 : : // (we'll create one, and get the only master for this type)
231 [ + - ]: 4 : Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
232 [ + - ]: 4 : if( xFactory.is() )
233 : : {
234 [ + - ][ + - ]: 4 : Sequence<rtl::OUString> aServices = xFactory->getAvailableServiceNames();
235 : 4 : sal_Bool bFound(sal_False);
236 : 4 : sal_Int32 i(0);
237 : 4 : sal_Int32 nServiceCount(aServices.getLength());
238 [ + - ][ + + ]: 504 : while (i < nServiceCount && !bFound)
[ + + ]
239 : : {
240 [ + - ][ + + ]: 500 : if (aServices[i].equals(sFieldMaster_Bibliography))
241 : : // here we should use a method which compares in reverse order if available
242 : : // #85282#
243 : 4 : bFound = sal_True;
244 : : else
245 : 496 : i++;
246 : : }
247 [ + - ]: 4 : if (bFound)
248 : : {
249 : : Reference<XInterface> xIfc =
250 [ + - ][ + - ]: 4 : xFactory->createInstance(sFieldMaster_Bibliography);
251 [ + - ]: 4 : if( xIfc.is() )
252 : : {
253 [ + - ]: 4 : Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
254 : 4 : Any aAny;
255 : :
256 [ + - ]: 4 : aAny <<= sSuffix;
257 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sBracketAfter, aAny);
258 : :
259 [ + - ]: 4 : aAny <<= sPrefix;
260 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sBracketBefore, aAny);
261 : :
262 [ + - ]: 4 : aAny.setValue(&bNumberedEntries, ::getBooleanCppuType());
263 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sIsNumberEntries, aAny);
264 : :
265 [ + - ]: 4 : aAny.setValue(&bSortByPosition, ::getBooleanCppuType());
266 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sIsSortByPosition, aAny);
267 : :
268 [ + - ][ + - ]: 4 : if( !aLocale.Language.isEmpty() && !aLocale.Country.isEmpty() )
[ + - ]
269 : : {
270 [ + - ]: 4 : aAny <<= aLocale;
271 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sLocale, aAny);
272 : : }
273 : :
274 [ + - ]: 4 : if( !sAlgorithm.isEmpty() )
275 : : {
276 [ + - ]: 4 : aAny <<= sAlgorithm;
277 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sSortAlgorithm, aAny);
278 : : }
279 : :
280 : 4 : sal_Int32 nCount = aSortKeys.size();
281 [ + - ]: 4 : Sequence<Sequence<PropertyValue> > aKeysSeq(nCount);
282 [ - + ]: 4 : for(i = 0; i < nCount; i++)
283 : : {
284 [ # # ][ # # ]: 0 : aKeysSeq[i] = aSortKeys[i];
285 : : }
286 [ + - ]: 4 : aAny <<= aKeysSeq;
287 [ + - ][ + - ]: 4 : xPropSet->setPropertyValue(sSortKeys, aAny);
[ + - ]
288 : 4 : }
289 : : // else: can't get FieldMaster -> ignore
290 [ + - ]: 4 : }
291 : 4 : }
292 : : // else: can't even get Factory -> ignore
293 : 4 : }
294 : :
295 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|