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