Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <officecfg/Office/Common.hxx>
23 : #include <sax/tools/converter.hxx>
24 :
25 : #include <com/sun/star/util/PathSubstitution.hpp>
26 : #include <com/sun/star/util/XStringSubstitution.hpp>
27 : #include <xmloff/DocumentSettingsContext.hxx>
28 : #include <xmloff/xmlimp.hxx>
29 : #include <xmloff/xmltoken.hxx>
30 : #include "xmloff/xmlnmspe.hxx"
31 : #include <xmloff/nmspmap.hxx>
32 : #include <xmloff/xmluconv.hxx>
33 : #include <tools/debug.hxx>
34 : #include <comphelper/processfactory.hxx>
35 :
36 : #include <list>
37 : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
38 : #include <com/sun/star/container/XIndexContainer.hpp>
39 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 : #include <com/sun/star/formula/SymbolDescriptor.hpp>
41 : #include <com/sun/star/util/DateTime.hpp>
42 : #include <com/sun/star/document/XViewDataSupplier.hpp>
43 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
44 : #include <rtl/ustrbuf.hxx>
45 : #include <xmlenums.hxx>
46 :
47 : using namespace com::sun::star;
48 : using namespace ::xmloff::token;
49 :
50 : class XMLMyList
51 : {
52 : std::list<beans::PropertyValue> aProps;
53 : sal_uInt32 nCount;
54 :
55 : // #110680#
56 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory;
57 :
58 : public:
59 : // #110680#
60 : XMLMyList(const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory);
61 : ~XMLMyList();
62 :
63 9093 : void push_back(beans::PropertyValue& aProp) { aProps.push_back(aProp); nCount++; }
64 : uno::Sequence<beans::PropertyValue> GetSequence();
65 : uno::Reference<container::XNameContainer> GetNameContainer();
66 : uno::Reference<container::XIndexContainer> GetIndexContainer();
67 : };
68 :
69 : // #110680#
70 620 : XMLMyList::XMLMyList(const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory)
71 : : nCount(0),
72 620 : mxServiceFactory(xServiceFactory)
73 : {
74 : DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
75 620 : }
76 :
77 : // #110680#
78 620 : XMLMyList::~XMLMyList()
79 : {
80 620 : }
81 :
82 447 : uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
83 : {
84 447 : uno::Sequence<beans::PropertyValue> aSeq;
85 447 : if(nCount)
86 : {
87 : DBG_ASSERT(nCount == aProps.size(), "wrong count of PropertyValue");
88 447 : aSeq.realloc(nCount);
89 447 : beans::PropertyValue* pProps = aSeq.getArray();
90 447 : std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
91 9754 : while (aItr != aProps.end())
92 : {
93 8860 : *pProps = *aItr;
94 8860 : ++pProps;
95 8860 : ++aItr;
96 : }
97 : }
98 447 : return aSeq;
99 : }
100 :
101 62 : uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
102 : {
103 62 : uno::Reference<container::XNameContainer> xNameContainer;
104 :
105 : // #110680#
106 :
107 62 : if( mxServiceFactory.is() )
108 : {
109 62 : rtl::OUString sName("com.sun.star.document.NamedPropertyValues");
110 62 : xNameContainer = uno::Reference<container::XNameContainer>(mxServiceFactory->createInstance(sName), uno::UNO_QUERY);
111 62 : if (xNameContainer.is())
112 : {
113 62 : std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
114 242 : while (aItr != aProps.end())
115 : {
116 118 : xNameContainer->insertByName(aItr->Name, aItr->Value);
117 118 : ++aItr;
118 : }
119 62 : }
120 : }
121 62 : return xNameContainer;
122 : }
123 :
124 111 : uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
125 : {
126 111 : uno::Reference<container::XIndexContainer> xIndexContainer;
127 : // #110680#
128 :
129 111 : if( mxServiceFactory.is() )
130 : {
131 111 : rtl::OUString sName("com.sun.star.document.IndexedPropertyValues");
132 111 : xIndexContainer = uno::Reference<container::XIndexContainer>(mxServiceFactory->createInstance(sName), uno::UNO_QUERY);
133 111 : if (xIndexContainer.is())
134 : {
135 111 : std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
136 111 : sal_uInt32 i(0);
137 337 : while (aItr != aProps.end())
138 : {
139 115 : xIndexContainer->insertByIndex(i, aItr->Value);
140 115 : ++aItr;
141 115 : ++i;
142 : }
143 111 : }
144 : }
145 111 : return xIndexContainer;
146 : }
147 :
148 : //=============================================================================
149 :
150 : class XMLConfigBaseContext : public SvXMLImportContext
151 : {
152 : protected:
153 : XMLMyList maProps;
154 : beans::PropertyValue maProp;
155 : com::sun::star::uno::Any& mrAny;
156 : XMLConfigBaseContext* mpBaseContext;
157 : public:
158 : XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
159 : com::sun::star::uno::Any& rAny,
160 : XMLConfigBaseContext* pBaseContext);
161 : virtual ~XMLConfigBaseContext();
162 :
163 9093 : void AddPropertyValue() { maProps.push_back(maProp); }
164 : };
165 :
166 : //=============================================================================
167 :
168 : class XMLConfigItemContext : public SvXMLImportContext
169 : {
170 : rtl::OUString msType;
171 : rtl::OUString msValue;
172 : uno::Sequence<sal_Int8> maDecoded;
173 : com::sun::star::uno::Any& mrAny;
174 : const rtl::OUString mrItemName;
175 : XMLConfigBaseContext* mpBaseContext;
176 :
177 : public:
178 : XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
179 : const ::com::sun::star::uno::Reference<
180 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
181 : com::sun::star::uno::Any& rAny,
182 : const rtl::OUString& rItemName,
183 : XMLConfigBaseContext* pBaseContext);
184 : virtual ~XMLConfigItemContext();
185 :
186 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
187 : const rtl::OUString& rLocalName,
188 : const ::com::sun::star::uno::Reference<
189 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
190 : virtual void Characters( const ::rtl::OUString& rChars );
191 :
192 : virtual void EndElement();
193 :
194 : virtual void ManipulateConfigItem();
195 : };
196 :
197 : //=============================================================================
198 :
199 : class XMLConfigItemSetContext : public XMLConfigBaseContext
200 : {
201 : public:
202 : XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
203 : const ::com::sun::star::uno::Reference<
204 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
205 : com::sun::star::uno::Any& rAny,
206 : XMLConfigBaseContext* pBaseContext);
207 : virtual ~XMLConfigItemSetContext();
208 :
209 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
210 : const rtl::OUString& rLocalName,
211 : const ::com::sun::star::uno::Reference<
212 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
213 :
214 : virtual void EndElement();
215 : };
216 :
217 : //=============================================================================
218 :
219 : class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
220 : {
221 : public:
222 : XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
223 : const ::com::sun::star::uno::Reference<
224 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
225 : com::sun::star::uno::Any& rAny,
226 : XMLConfigBaseContext* pBaseContext);
227 : virtual ~XMLConfigItemMapNamedContext();
228 :
229 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
230 : const rtl::OUString& rLocalName,
231 : const ::com::sun::star::uno::Reference<
232 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
233 :
234 : virtual void EndElement();
235 : };
236 :
237 : //=============================================================================
238 :
239 : class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
240 : {
241 : private:
242 : rtl::OUString maConfigItemName;
243 :
244 : public:
245 : XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
246 : const rtl::OUString& rLName,
247 : const ::com::sun::star::uno::Reference<
248 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
249 : com::sun::star::uno::Any& rAny,
250 : const rtl::OUString& rConfigItemName,
251 : XMLConfigBaseContext* pBaseContext);
252 : virtual ~XMLConfigItemMapIndexedContext();
253 :
254 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
255 : const rtl::OUString& rLocalName,
256 : const ::com::sun::star::uno::Reference<
257 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
258 :
259 : virtual void EndElement();
260 : };
261 :
262 : //=============================================================================
263 :
264 9093 : SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_uInt16 p_nPrefix,
265 : const rtl::OUString& rLocalName,
266 : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
267 : beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
268 : {
269 9093 : SvXMLImportContext *pContext = 0;
270 :
271 9093 : rProp.Name = rtl::OUString();
272 9093 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
273 26758 : for( sal_Int16 i=0; i < nAttrCount; i++ )
274 : {
275 17665 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
276 17665 : rtl::OUString aLocalName;
277 17665 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(
278 17665 : sAttrName, &aLocalName );
279 17665 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
280 :
281 17665 : if (nPrefix == XML_NAMESPACE_CONFIG)
282 : {
283 17665 : if (IsXMLToken(aLocalName, XML_NAME))
284 8978 : rProp.Name = sValue;
285 : }
286 17665 : }
287 :
288 9093 : if (p_nPrefix == XML_NAMESPACE_CONFIG)
289 : {
290 9093 : if (IsXMLToken(rLocalName, XML_CONFIG_ITEM))
291 8687 : pContext = new XMLConfigItemContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
292 812 : else if((IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET)) ||
293 406 : (IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_ENTRY)) )
294 233 : pContext = new XMLConfigItemSetContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
295 173 : else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_NAMED))
296 62 : pContext = new XMLConfigItemMapNamedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
297 111 : else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_INDEXED))
298 111 : pContext = new XMLConfigItemMapIndexedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
299 : }
300 :
301 9093 : if( !pContext )
302 0 : pContext = new SvXMLImportContext( rImport, p_nPrefix, rLocalName );
303 :
304 9093 : return pContext;
305 : }
306 :
307 : //=============================================================================
308 : namespace
309 : {
310 0 : struct SettingsGroup
311 : {
312 : ::rtl::OUString sGroupName;
313 : uno::Any aSettings;
314 :
315 : SettingsGroup()
316 : :sGroupName()
317 : ,aSettings()
318 : {
319 : }
320 :
321 0 : SettingsGroup( const ::rtl::OUString& _rGroupName, const uno::Any& _rSettings )
322 : :sGroupName( _rGroupName )
323 0 : ,aSettings( _rSettings )
324 : {
325 0 : }
326 : };
327 : }
328 :
329 214 : struct XMLDocumentSettingsContext_Data
330 : {
331 : com::sun::star::uno::Any aViewProps;
332 : com::sun::star::uno::Any aConfigProps;
333 : ::std::list< SettingsGroup > aDocSpecificSettings;
334 : };
335 :
336 : //=============================================================================
337 :
338 107 : XMLDocumentSettingsContext::XMLDocumentSettingsContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
339 : const uno::Reference<xml::sax::XAttributeList>& )
340 : : SvXMLImportContext( rImport, nPrfx, rLName )
341 107 : , m_pData( new XMLDocumentSettingsContext_Data )
342 : {
343 : // here are no attributes
344 107 : }
345 :
346 214 : XMLDocumentSettingsContext::~XMLDocumentSettingsContext()
347 : {
348 214 : }
349 :
350 214 : SvXMLImportContext *XMLDocumentSettingsContext::CreateChildContext( sal_uInt16 p_nPrefix,
351 : const rtl::OUString& rLocalName,
352 : const ::com::sun::star::uno::Reference<
353 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
354 : {
355 214 : SvXMLImportContext *pContext = 0;
356 214 : rtl::OUString sName;
357 :
358 214 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
359 428 : for( sal_Int16 i=0; i < nAttrCount; i++ )
360 : {
361 214 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
362 214 : rtl::OUString aLocalName;
363 214 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
364 214 : sAttrName, &aLocalName );
365 214 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
366 :
367 214 : if (nPrefix == XML_NAMESPACE_CONFIG)
368 : {
369 214 : if (IsXMLToken(aLocalName, XML_NAME))
370 214 : sName = sValue;
371 : }
372 214 : }
373 :
374 214 : if (p_nPrefix == XML_NAMESPACE_CONFIG)
375 : {
376 214 : if (IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET))
377 : {
378 214 : ::rtl::OUString aLocalConfigName;
379 : sal_uInt16 nConfigPrefix =
380 214 : GetImport().GetNamespaceMap().GetKeyByAttrName(
381 214 : sName, &aLocalConfigName );
382 :
383 214 : if( XML_NAMESPACE_OOO == nConfigPrefix )
384 : {
385 214 : if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
386 107 : pContext = new XMLConfigItemSetContext(GetImport(),
387 : p_nPrefix, rLocalName, xAttrList,
388 107 : m_pData->aViewProps, NULL);
389 107 : else if (IsXMLToken(aLocalConfigName,
390 107 : XML_CONFIGURATION_SETTINGS))
391 107 : pContext = new XMLConfigItemSetContext(GetImport(),
392 : p_nPrefix, rLocalName, xAttrList,
393 107 : m_pData->aConfigProps, NULL);
394 : else
395 : {
396 0 : m_pData->aDocSpecificSettings.push_back( SettingsGroup( aLocalConfigName, uno::Any() ) );
397 :
398 : ::std::list< SettingsGroup >::reverse_iterator settingsPos =
399 0 : m_pData->aDocSpecificSettings.rbegin();
400 :
401 0 : pContext = new XMLConfigItemSetContext(GetImport(),
402 : p_nPrefix, rLocalName, xAttrList,
403 0 : settingsPos->aSettings, NULL);
404 : }
405 214 : }
406 : }
407 : }
408 :
409 214 : if( !pContext )
410 0 : pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
411 :
412 214 : return pContext;
413 : }
414 :
415 107 : void XMLDocumentSettingsContext::EndElement()
416 : {
417 107 : uno::Sequence<beans::PropertyValue> aSeqViewProps;
418 107 : if (m_pData->aViewProps >>= aSeqViewProps)
419 : {
420 107 : GetImport().SetViewSettings(aSeqViewProps);
421 107 : sal_Int32 i(aSeqViewProps.getLength() - 1);
422 107 : sal_Bool bFound(sal_False);
423 333 : while((i >= 0) && !bFound)
424 : {
425 119 : if (aSeqViewProps[i].Name.compareToAscii("Views") == 0)
426 : {
427 103 : bFound = sal_True;
428 103 : uno::Reference<container::XIndexAccess> xIndexAccess;
429 103 : if (aSeqViewProps[i].Value >>= xIndexAccess)
430 : {
431 103 : uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
432 103 : if (xViewDataSupplier.is())
433 103 : xViewDataSupplier->setViewData(xIndexAccess);
434 103 : }
435 : }
436 : else
437 16 : i--;
438 : }
439 : }
440 :
441 107 : uno::Sequence<beans::PropertyValue> aSeqConfigProps;
442 107 : if ( m_pData->aConfigProps >>= aSeqConfigProps )
443 : {
444 214 : if (!officecfg::Office::Common::Save::Document::LoadPrinter::get())
445 : {
446 0 : sal_Int32 i = aSeqConfigProps.getLength() - 1;
447 0 : int nFound = 0;
448 :
449 0 : while ( ( i >= 0 ) && nFound < 2 )
450 : {
451 0 : rtl::OUString sProp( aSeqConfigProps[i].Name );
452 :
453 0 : if ( sProp.compareToAscii("PrinterName") == 0 )
454 : {
455 0 : rtl::OUString sEmpty;
456 0 : aSeqConfigProps[i].Value = uno::makeAny( sEmpty );
457 0 : nFound++;
458 : }
459 0 : else if ( sProp.compareToAscii("PrinterSetup") == 0 )
460 : {
461 0 : uno::Sequence< sal_Int8 > aEmpty;
462 0 : aSeqConfigProps[i].Value = uno::makeAny( aEmpty );
463 0 : nFound++;
464 : }
465 :
466 0 : i--;
467 0 : }
468 : }
469 :
470 107 : GetImport().SetConfigurationSettings( aSeqConfigProps );
471 : }
472 :
473 321 : for ( ::std::list< SettingsGroup >::const_iterator settings = m_pData->aDocSpecificSettings.begin();
474 214 : settings != m_pData->aDocSpecificSettings.end();
475 : ++settings
476 : )
477 : {
478 0 : uno::Sequence< beans::PropertyValue > aDocSettings;
479 0 : OSL_VERIFY( settings->aSettings >>= aDocSettings );
480 0 : GetImport().SetDocumentSpecificSettings( settings->sGroupName, aDocSettings );
481 107 : }
482 107 : }
483 :
484 : //=============================================================================
485 :
486 620 : XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
487 : const rtl::OUString& rLName, com::sun::star::uno::Any& rTempAny,
488 : XMLConfigBaseContext* pTempBaseContext)
489 : : SvXMLImportContext( rImport, nPrfx, rLName ),
490 : // #110680#
491 : maProps(rImport.getServiceFactory()),
492 : maProp(),
493 : mrAny(rTempAny),
494 620 : mpBaseContext(pTempBaseContext)
495 : {
496 620 : }
497 :
498 620 : XMLConfigBaseContext::~XMLConfigBaseContext()
499 : {
500 620 : }
501 :
502 : //=============================================================================
503 :
504 447 : XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
505 : const rtl::OUString& rLName,
506 : const ::com::sun::star::uno::Reference<
507 : ::com::sun::star::xml::sax::XAttributeList>&,
508 : com::sun::star::uno::Any& rAny,
509 : XMLConfigBaseContext* pBaseContext)
510 447 : : XMLConfigBaseContext( rImport, nPrfx, rLName, rAny, pBaseContext )
511 : {
512 : // here are no attributes
513 447 : }
514 :
515 894 : XMLConfigItemSetContext::~XMLConfigItemSetContext()
516 : {
517 894 : }
518 :
519 8860 : SvXMLImportContext *XMLConfigItemSetContext::CreateChildContext( sal_uInt16 nPrefix,
520 : const rtl::OUString& rLocalName,
521 : const ::com::sun::star::uno::Reference<
522 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
523 : {
524 8860 : return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
525 : }
526 :
527 447 : void XMLConfigItemSetContext::EndElement()
528 : {
529 447 : mrAny <<= maProps.GetSequence();
530 447 : if (mpBaseContext)
531 233 : mpBaseContext->AddPropertyValue();
532 447 : }
533 :
534 : //=============================================================================
535 :
536 8687 : XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
537 : const ::com::sun::star::uno::Reference<
538 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
539 : com::sun::star::uno::Any& rTempAny,
540 : const rtl::OUString& rTempItemName,
541 : XMLConfigBaseContext* pTempBaseContext)
542 : : SvXMLImportContext(rImport, nPrfx, rLName),
543 : mrAny(rTempAny),
544 : mrItemName(rTempItemName),
545 8687 : mpBaseContext(pTempBaseContext)
546 : {
547 8687 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
548 26061 : for( sal_Int16 i=0; i < nAttrCount; i++ )
549 : {
550 17374 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
551 17374 : rtl::OUString aLocalName;
552 17374 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
553 17374 : sAttrName, &aLocalName );
554 17374 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
555 :
556 17374 : if (nPrefix == XML_NAMESPACE_CONFIG)
557 : {
558 17374 : if (IsXMLToken(aLocalName, XML_TYPE))
559 8687 : msType = sValue;
560 : }
561 17374 : }
562 8687 : }
563 :
564 17374 : XMLConfigItemContext::~XMLConfigItemContext()
565 : {
566 17374 : }
567 :
568 0 : SvXMLImportContext *XMLConfigItemContext::CreateChildContext( sal_uInt16 nPrefix,
569 : const rtl::OUString& rLocalName,
570 : const ::com::sun::star::uno::Reference<
571 : ::com::sun::star::xml::sax::XAttributeList>& )
572 : {
573 0 : SvXMLImportContext* pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
574 0 : return pContext;
575 : }
576 :
577 8317 : void XMLConfigItemContext::Characters( const ::rtl::OUString& rChars )
578 : {
579 8317 : if (IsXMLToken(msType, XML_BASE64BINARY))
580 : {
581 18 : rtl::OUString sTrimmedChars( rChars.trim() );
582 18 : if( !sTrimmedChars.isEmpty() )
583 : {
584 18 : rtl::OUString sChars;
585 18 : if( !msValue.isEmpty() )
586 : {
587 0 : sChars = msValue;
588 0 : sChars += sTrimmedChars;
589 0 : msValue = rtl::OUString();
590 : }
591 : else
592 : {
593 18 : sChars = sTrimmedChars;
594 : }
595 18 : uno::Sequence<sal_Int8> aBuffer((sChars.getLength() / 4) * 3 );
596 : sal_Int32 const nCharsDecoded =
597 18 : ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
598 18 : sal_uInt32 nStartPos(maDecoded.getLength());
599 18 : sal_uInt32 nCount(aBuffer.getLength());
600 18 : maDecoded.realloc(nStartPos + nCount);
601 18 : sal_Int8* pDecoded = maDecoded.getArray();
602 18 : sal_Int8* pBuffer = aBuffer.getArray();
603 4530 : for (sal_uInt32 i = 0; i < nCount; i++, pBuffer++)
604 4512 : pDecoded[nStartPos + i] = *pBuffer;
605 18 : if( nCharsDecoded != sChars.getLength() )
606 0 : msValue = sChars.copy( nCharsDecoded );
607 18 : }
608 : }
609 : else
610 8299 : msValue += rChars;
611 8317 : }
612 :
613 :
614 8687 : void XMLConfigItemContext::EndElement()
615 : {
616 8687 : if (mpBaseContext)
617 : {
618 8687 : if (IsXMLToken(msType, XML_BOOLEAN))
619 : {
620 4299 : sal_Bool bValue(sal_False);
621 4299 : if (IsXMLToken(msValue, XML_TRUE))
622 2267 : bValue = sal_True;
623 4299 : mrAny <<= bValue;
624 : }
625 4388 : else if (IsXMLToken(msType, XML_BYTE))
626 : {
627 0 : sal_Int32 nValue(0);
628 0 : ::sax::Converter::convertNumber(nValue, msValue);
629 0 : mrAny <<= static_cast<sal_Int8>(nValue);
630 : }
631 4388 : else if (IsXMLToken(msType, XML_SHORT))
632 : {
633 905 : sal_Int32 nValue(0);
634 905 : ::sax::Converter::convertNumber(nValue, msValue);
635 905 : mrAny <<= static_cast<sal_Int16>(nValue);
636 : }
637 3483 : else if (IsXMLToken(msType, XML_INT))
638 : {
639 2493 : sal_Int32 nValue(0);
640 2493 : ::sax::Converter::convertNumber(nValue, msValue);
641 2493 : mrAny <<= nValue;
642 : }
643 990 : else if (IsXMLToken(msType, XML_LONG))
644 : {
645 328 : sal_Int64 nValue(msValue.toInt64());
646 328 : mrAny <<= nValue;
647 : }
648 662 : else if (IsXMLToken(msType, XML_DOUBLE))
649 : {
650 0 : double fValue(0.0);
651 0 : ::sax::Converter::convertDouble(fValue, msValue);
652 0 : mrAny <<= fValue;
653 : }
654 662 : else if (IsXMLToken(msType, XML_STRING))
655 : {
656 508 : mrAny <<= msValue;
657 : }
658 154 : else if (IsXMLToken(msType, XML_DATETIME))
659 : {
660 0 : util::DateTime aDateTime;
661 0 : ::sax::Converter::convertDateTime(aDateTime, msValue);
662 0 : mrAny <<= aDateTime;
663 : }
664 154 : else if (IsXMLToken(msType, XML_BASE64BINARY))
665 : {
666 154 : mrAny <<= maDecoded;
667 : }
668 : else {
669 : OSL_FAIL("wrong type");
670 : }
671 :
672 8687 : ManipulateConfigItem();
673 :
674 8687 : mpBaseContext->AddPropertyValue();
675 : }
676 : else {
677 : OSL_FAIL("no BaseContext");
678 : }
679 8687 : }
680 :
681 : /** There are some instances where there is a mismatch between API and
682 : * XML mapping of a setting. In this case, this method allows us to
683 : * manipulate the values accordingly. */
684 8687 : void XMLConfigItemContext::ManipulateConfigItem()
685 : {
686 8687 : if( mrItemName == "PrinterIndependentLayout" )
687 : {
688 41 : rtl::OUString sValue;
689 41 : mrAny >>= sValue;
690 :
691 41 : sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
692 :
693 41 : if( sValue == "enabled" || sValue == "low-resolution" )
694 : {
695 2 : nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
696 : }
697 39 : else if ( sValue == "disabled" )
698 : {
699 6 : nTmp = document::PrinterIndependentLayout::DISABLED;
700 : }
701 : // else: default to high_resolution
702 :
703 41 : mrAny <<= nTmp;
704 : }
705 34536 : else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
706 25890 : || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
707 : {
708 24 : if( GetImport().getServiceFactory().is() ) try
709 : {
710 24 : uno::Reference< uno::XComponentContext > xContext( comphelper::getComponentContext(GetImport().getServiceFactory()) );
711 24 : uno::Reference< util::XStringSubstitution > xStringSubsitution( util::PathSubstitution::create(xContext) );
712 :
713 24 : rtl::OUString aURL;
714 24 : mrAny >>= aURL;
715 24 : aURL = xStringSubsitution->substituteVariables( aURL, sal_False );
716 24 : mrAny <<= aURL;
717 : }
718 0 : catch( uno::Exception& )
719 : {
720 : }
721 : }
722 8687 : }
723 :
724 :
725 : //=============================================================================
726 :
727 62 : XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
728 : const ::com::sun::star::uno::Reference<
729 : ::com::sun::star::xml::sax::XAttributeList>&,
730 : com::sun::star::uno::Any& rAny,
731 : XMLConfigBaseContext* pBaseContext)
732 62 : : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext)
733 : {
734 62 : }
735 :
736 124 : XMLConfigItemMapNamedContext::~XMLConfigItemMapNamedContext()
737 : {
738 124 : }
739 :
740 118 : SvXMLImportContext *XMLConfigItemMapNamedContext::CreateChildContext( sal_uInt16 nPrefix,
741 : const rtl::OUString& rLocalName,
742 : const ::com::sun::star::uno::Reference<
743 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
744 : {
745 118 : return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
746 : }
747 :
748 62 : void XMLConfigItemMapNamedContext::EndElement()
749 : {
750 62 : if (mpBaseContext)
751 : {
752 62 : mrAny <<= maProps.GetNameContainer();
753 62 : mpBaseContext->AddPropertyValue();
754 : }
755 : else {
756 : OSL_FAIL("no BaseContext");
757 : }
758 62 : }
759 :
760 : //=============================================================================
761 :
762 111 : XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
763 : const rtl::OUString& rLName,
764 : const ::com::sun::star::uno::Reference<
765 : ::com::sun::star::xml::sax::XAttributeList>&,
766 : com::sun::star::uno::Any& rAny,
767 : const ::rtl::OUString& rConfigItemName,
768 : XMLConfigBaseContext* pBaseContext)
769 : : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext),
770 111 : maConfigItemName( rConfigItemName )
771 : {
772 111 : }
773 :
774 222 : XMLConfigItemMapIndexedContext::~XMLConfigItemMapIndexedContext()
775 : {
776 222 : }
777 :
778 115 : SvXMLImportContext *XMLConfigItemMapIndexedContext::CreateChildContext( sal_uInt16 nPrefix,
779 : const rtl::OUString& rLocalName,
780 : const ::com::sun::star::uno::Reference<
781 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
782 : {
783 115 : return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
784 : }
785 :
786 111 : void XMLConfigItemMapIndexedContext::EndElement()
787 : {
788 111 : if (mpBaseContext)
789 : {
790 111 : if ( maConfigItemName == "ForbiddenCharacters" )
791 : {
792 8 : uno::Reference< i18n::XForbiddenCharacters > xForbChars;
793 :
794 : // get the forbidden characters from the document
795 8 : uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
796 8 : if( xFac.is() )
797 : {
798 8 : uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
799 8 : if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
800 : {
801 8 : xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
802 8 : }
803 : }
804 :
805 8 : if( xForbChars.is() )
806 : {
807 :
808 8 : uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
809 :
810 8 : const sal_Int32 nCount = xIndex->getCount();
811 8 : uno::Sequence < beans::PropertyValue > aProps;
812 20 : for (sal_Int32 i = 0; i < nCount; i++)
813 : {
814 12 : if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
815 : {
816 12 : beans::PropertyValue *pForChar = aProps.getArray();
817 12 : i18n::ForbiddenCharacters aForbid;
818 12 : lang::Locale aLocale;
819 12 : const rtl::OUString sLanguage ( "Language" );
820 12 : const rtl::OUString sCountry ( "Country" );
821 12 : const rtl::OUString sVariant ( "Variant" );
822 12 : const rtl::OUString sBeginLine ( "BeginLine" );
823 12 : const rtl::OUString sEndLine ( "EndLine" );
824 12 : sal_Bool bHaveLanguage = sal_False, bHaveCountry = sal_False, bHaveVariant = sal_False,
825 12 : bHaveBegin = sal_False, bHaveEnd = sal_False;
826 :
827 72 : for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
828 : {
829 60 : if (pForChar->Name.equals (sLanguage ) )
830 : {
831 12 : pForChar->Value >>= aLocale.Language;
832 12 : bHaveLanguage = sal_True;
833 : }
834 48 : else if (pForChar->Name.equals (sCountry ) )
835 : {
836 12 : pForChar->Value >>= aLocale.Country;
837 12 : bHaveCountry = sal_True;
838 : }
839 36 : else if (pForChar->Name.equals (sVariant ) )
840 : {
841 12 : pForChar->Value >>= aLocale.Variant;
842 12 : bHaveVariant = sal_True;
843 : }
844 24 : else if (pForChar->Name.equals (sBeginLine ) )
845 : {
846 12 : pForChar->Value >>= aForbid.beginLine;
847 12 : bHaveBegin = sal_True;
848 : }
849 12 : else if (pForChar->Name.equals (sEndLine ) )
850 : {
851 12 : pForChar->Value >>= aForbid.endLine;
852 12 : bHaveEnd = sal_True;
853 : }
854 60 : pForChar++;
855 : }
856 :
857 12 : if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
858 : {
859 : try
860 : {
861 12 : xForbChars->setForbiddenCharacters( aLocale, aForbid );
862 : }
863 0 : catch( uno::Exception& )
864 : {
865 : OSL_FAIL( "Exception while importing forbidden characters" );
866 : }
867 12 : }
868 : }
869 8 : }
870 : }
871 : else
872 : {
873 : OSL_FAIL( "could not get the XForbiddenCharacters from document!" );
874 0 : mrAny <<= maProps.GetIndexContainer();
875 8 : }
876 : }
877 103 : else if ( maConfigItemName == "Symbols" )
878 : {
879 0 : uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
880 :
881 0 : const sal_Int32 nCount = xIndex->getCount();
882 0 : uno::Sequence < beans::PropertyValue > aProps;
883 0 : uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
884 :
885 0 : formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
886 :
887 0 : const rtl::OUString sName ( "Name" );
888 0 : const rtl::OUString sExportName ( "ExportName" );
889 0 : const rtl::OUString sFontName ( "FontName" );
890 0 : const rtl::OUString sSymbolSet ( "SymbolSet" );
891 0 : const rtl::OUString sCharacter ( "Character" );
892 0 : const rtl::OUString sCharSet ( "CharSet" );
893 0 : const rtl::OUString sFamily ( "Family" );
894 0 : const rtl::OUString sPitch ( "Pitch" );
895 0 : const rtl::OUString sWeight ( "Weight" );
896 0 : const rtl::OUString sItalic ( "Italic" );
897 0 : sal_Int16 nNumFullEntries = 0;
898 :
899 0 : for ( sal_Int32 i = 0; i < nCount; i++ )
900 : {
901 0 : if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
902 : {
903 0 : sal_Bool bHaveName = sal_False, bHaveExportName = sal_False, bHaveCharSet = sal_False,
904 0 : bHaveFontName = sal_False, bHaveFamily = sal_False, bHavePitch = sal_False,
905 0 : bHaveWeight = sal_False, bHaveItalic = sal_False, bHaveSymbolSet = sal_False,
906 0 : bHaveCharacter = sal_False;
907 0 : beans::PropertyValue *pSymbol = aProps.getArray();
908 :
909 0 : for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
910 : {
911 0 : if (pSymbol->Name.equals ( sName ) )
912 : {
913 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
914 0 : bHaveName = sal_True;
915 : }
916 0 : else if (pSymbol->Name.equals (sExportName ) )
917 : {
918 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
919 0 : bHaveExportName = sal_True;
920 : }
921 0 : else if (pSymbol->Name.equals (sFontName ) )
922 : {
923 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
924 0 : bHaveFontName = sal_True;
925 : }
926 0 : else if (pSymbol->Name.equals (sCharSet ) )
927 : {
928 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
929 0 : bHaveCharSet = sal_True;
930 : }
931 0 : else if (pSymbol->Name.equals (sFamily ) )
932 : {
933 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
934 0 : bHaveFamily = sal_True;
935 : }
936 0 : else if (pSymbol->Name.equals (sPitch ) )
937 : {
938 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
939 0 : bHavePitch = sal_True;
940 : }
941 0 : else if (pSymbol->Name.equals (sWeight ) )
942 : {
943 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
944 0 : bHaveWeight = sal_True;
945 : }
946 0 : else if (pSymbol->Name.equals (sItalic ) )
947 : {
948 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
949 0 : bHaveItalic = sal_True;
950 : }
951 0 : else if (pSymbol->Name.equals (sSymbolSet ) )
952 : {
953 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
954 0 : bHaveSymbolSet = sal_True;
955 : }
956 0 : else if (pSymbol->Name.equals (sCharacter ) )
957 : {
958 0 : pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
959 0 : bHaveCharacter = sal_True;
960 : }
961 0 : pSymbol++;
962 : }
963 0 : if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
964 : && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
965 0 : nNumFullEntries++;
966 : }
967 : }
968 0 : aSymbolList.realloc (nNumFullEntries);
969 0 : mrAny <<= aSymbolList;
970 : }
971 : else
972 : {
973 103 : mrAny <<= maProps.GetIndexContainer();
974 : }
975 111 : mpBaseContext->AddPropertyValue();
976 : }
977 : else {
978 : OSL_FAIL("no BaseContext");
979 : }
980 111 : }
981 :
982 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|