LibreOffice Module xmloff (master)  1
DocumentSettingsContext.cxx
Go to the documentation of this file.
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>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <comphelper/base64.hxx>
33 
34 #include <vector>
35 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/formula/SymbolDescriptor.hpp>
39 #include <com/sun/star/frame/XModel.hpp>
40 #include <com/sun/star/util/DateTime.hpp>
41 #include <com/sun/star/document/XViewDataSupplier.hpp>
42 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
43 #include <com/sun/star/document/IndexedPropertyValues.hpp>
44 #include <com/sun/star/document/NamedPropertyValues.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <sal/log.hxx>
47 #include <osl/diagnose.h>
48 #include <tools/diagnose_ex.h>
49 #include <unotools/configmgr.hxx>
50 #include "xmlenums.hxx"
51 
52 using namespace com::sun::star;
53 using namespace ::xmloff::token;
54 
55 namespace {
56 
57 class XMLMyList
58 {
59  std::vector<beans::PropertyValue> aProps;
60  sal_uInt32 nCount;
61 
62  css::uno::Reference< css::uno::XComponentContext > m_xContext;
63 
64 public:
65  explicit XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext);
66 
67  void push_back(beans::PropertyValue const & aProp) { aProps.push_back(aProp); nCount++; }
68  uno::Sequence<beans::PropertyValue> GetSequence();
69  uno::Reference<container::XNameContainer> GetNameContainer();
70  uno::Reference<container::XIndexContainer> GetIndexContainer();
71 };
72 
73 }
74 
75 XMLMyList::XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext)
76 : nCount(0),
77  m_xContext(rxContext)
78 {
79  assert(m_xContext.is());
80 }
81 
82 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
83 {
84  uno::Sequence<beans::PropertyValue> aSeq;
85  if(nCount)
86  {
87  assert(nCount == aProps.size());
88  aSeq.realloc(nCount);
89  beans::PropertyValue* pProps = aSeq.getArray();
90  for (auto const& prop : aProps)
91  {
92  *pProps = prop;
93  ++pProps;
94  }
95  }
96  return aSeq;
97 }
98 
99 uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
100 {
101  uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(m_xContext);
102  for (auto const& prop : aProps)
103  {
104  xNameContainer->insertByName(prop.Name, prop.Value);
105  }
106 
107  return xNameContainer;
108 }
109 
110 uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
111 {
112  uno::Reference<container::XIndexContainer> xIndexContainer = document::IndexedPropertyValues::create(m_xContext);
113  sal_uInt32 i(0);
114  for (auto const& prop : aProps)
115  {
116  xIndexContainer->insertByIndex(i, prop.Value);
117  ++i;
118  }
119 
120  return xIndexContainer;
121 }
122 
123 namespace {
124 
125 class XMLConfigBaseContext : public SvXMLImportContext
126 {
127 protected:
128  XMLMyList maProps;
129  beans::PropertyValue maProp;
130  css::uno::Any& mrAny;
131  XMLConfigBaseContext* mpBaseContext;
132 public:
133  XMLConfigBaseContext(SvXMLImport& rImport,
134  css::uno::Any& rAny,
135  XMLConfigBaseContext* pBaseContext);
136 
137  void AddPropertyValue() { maProps.push_back(maProp); }
138 
139  virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
140  const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
141 };
142 
143 class XMLConfigItemContext : public SvXMLImportContext
144 {
145  OUString msType;
146  css::uno::Any& mrAny;
147  const OUString mrItemName;
148  XMLConfigBaseContext* mpBaseContext;
149  OUStringBuffer maCharBuffer;
150 
151 public:
152  XMLConfigItemContext(SvXMLImport& rImport,
153  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
154  css::uno::Any& rAny,
155  const OUString& rItemName,
156  XMLConfigBaseContext* pBaseContext);
157 
158  virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
159  const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
160 
161  virtual void SAL_CALL characters( const OUString& rChars ) override;
162 
163  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
164 
165  void ManipulateConfigItem();
166 };
167 
168 class XMLConfigItemSetContext : public XMLConfigBaseContext
169 {
170 public:
171  XMLConfigItemSetContext(SvXMLImport& rImport,
172  css::uno::Any& rAny,
173  XMLConfigBaseContext* pBaseContext);
174 
175  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
176  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
177 
178  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
179 };
180 
181 class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
182 {
183 public:
184  XMLConfigItemMapNamedContext(SvXMLImport& rImport,
185  css::uno::Any& rAny,
186  XMLConfigBaseContext* pBaseContext);
187 
188  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
189  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
190 
191  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
192 };
193 
194 class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
195 {
196 private:
197  OUString maConfigItemName;
198 
199 public:
200  XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
201  css::uno::Any& rAny,
202  const OUString& rConfigItemName,
203  XMLConfigBaseContext* pBaseContext);
204 
205  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
206  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
207 
208  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
209 };
210 
211 }
212 
213 static SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_Int32 nElement,
214  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
215  beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
216 {
217  SvXMLImportContext *pContext = nullptr;
218 
219  rProp.Name.clear();
220  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
221  {
222  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_NAME))
223  rProp.Name = aIter.toString();
224  }
225 
226  if (nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM))
227  pContext = new XMLConfigItemContext(rImport, xAttrList, rProp.Value, rProp.Name, pBaseContext);
228  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_SET) ||
229  nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_ENTRY) )
230  pContext = new XMLConfigItemSetContext(rImport, rProp.Value, pBaseContext);
231  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_NAMED))
232  pContext = new XMLConfigItemMapNamedContext(rImport, rProp.Value, pBaseContext);
233  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_INDEXED))
234  pContext = new XMLConfigItemMapIndexedContext(rImport, rProp.Value, rProp.Name, pBaseContext);
235 
236  return pContext;
237 }
238 
240  : SvXMLImportContext( rImport )
241 {
242  // here are no attributes
243 }
244 
246 {
247 }
248 
249 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDocumentSettingsContext::createFastChildContext(
250  sal_Int32 nElement,
251  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
252 {
253  SvXMLImportContext *pContext = nullptr;
254  OUString sName;
255 
256  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
257  {
258  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_NAME))
259  sName = aIter.toString();
260  }
261 
262  if (nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_SET))
263  {
264  OUString aLocalConfigName;
265  sal_uInt16 nConfigPrefix =
267  sName, &aLocalConfigName );
268 
269  if( XML_NAMESPACE_OOO == nConfigPrefix )
270  {
271  if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
272  pContext = new XMLConfigItemSetContext(GetImport(),
273  maViewProps, nullptr);
274  else if (IsXMLToken(aLocalConfigName,
276  pContext = new XMLConfigItemSetContext(GetImport(),
277  maConfigProps, nullptr);
278  else
279  {
280  maDocSpecificSettings.push_back( {aLocalConfigName, uno::Any()} );
281 
282  pContext = new XMLConfigItemSetContext(GetImport(),
283  maDocSpecificSettings.back().aSettings, nullptr);
284  }
285  }
286  }
287 
288  return pContext;
289 }
290 
292 {
293  uno::Sequence<beans::PropertyValue> aSeqViewProps;
294  if (maViewProps >>= aSeqViewProps)
295  {
296  GetImport().SetViewSettings(aSeqViewProps);
297  sal_Int32 i(aSeqViewProps.getLength() - 1);
298  bool bFound(false);
299  while((i >= 0) && !bFound)
300  {
301  if (aSeqViewProps[i].Name == "Views")
302  {
303  bFound = true;
304  uno::Reference<container::XIndexAccess> xIndexAccess;
305  if (aSeqViewProps[i].Value >>= xIndexAccess)
306  {
307  uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
308  if (xViewDataSupplier.is())
309  xViewDataSupplier->setViewData(xIndexAccess);
310  }
311  }
312  else
313  i--;
314  }
315  }
316 
317  uno::Sequence<beans::PropertyValue> aSeqConfigProps;
318  if ( maConfigProps >>= aSeqConfigProps )
319  {
320  if (!utl::ConfigManager::IsFuzzing() && !officecfg::Office::Common::Save::Document::LoadPrinter::get())
321  {
322  sal_Int32 i = aSeqConfigProps.getLength() - 1;
323  int nFound = 0;
324 
325  while ( ( i >= 0 ) && nFound < 2 )
326  {
327  OUString sProp( aSeqConfigProps[i].Name );
328 
329  if ( sProp == "PrinterName" )
330  {
331  aSeqConfigProps[i].Value <<= OUString();
332  nFound++;
333  }
334  else if ( sProp == "PrinterSetup" )
335  {
336  uno::Sequence< sal_Int8 > aEmpty;
337  aSeqConfigProps[i].Value <<= aEmpty;
338  nFound++;
339  }
340 
341  i--;
342  }
343  }
344 
345  GetImport().SetConfigurationSettings( aSeqConfigProps );
346  }
347 
348  for (auto const& settings : maDocSpecificSettings)
349  {
350  uno::Sequence< beans::PropertyValue > aDocSettings;
351  OSL_VERIFY( settings.aSettings >>= aDocSettings );
352  GetImport().SetDocumentSpecificSettings( settings.sGroupName, aDocSettings );
353  }
354 }
355 
356 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport,
357  css::uno::Any& rTempAny,
358  XMLConfigBaseContext* pTempBaseContext)
359  : SvXMLImportContext( rImport ),
360  maProps( rImport.GetComponentContext() ),
361  maProp(),
362  mrAny(rTempAny),
363  mpBaseContext(pTempBaseContext)
364 {
365 }
366 
367 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport,
368  css::uno::Any& rAny,
369  XMLConfigBaseContext* pBaseContext)
370  : XMLConfigBaseContext( rImport, rAny, pBaseContext )
371 {
372  // here are no attributes
373 }
374 
375 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemSetContext::createFastChildContext(
376  sal_Int32 nElement,
377  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
378 {
379  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
380 }
381 
382 void XMLConfigItemSetContext::endFastElement(sal_Int32 )
383 {
384  mrAny <<= maProps.GetSequence();
385  if (mpBaseContext)
386  mpBaseContext->AddPropertyValue();
387 }
388 
389 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport,
390  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
391  css::uno::Any& rTempAny,
392  const OUString& rTempItemName,
393  XMLConfigBaseContext* pTempBaseContext)
394  : SvXMLImportContext(rImport),
395  mrAny(rTempAny),
396  mrItemName(rTempItemName),
397  mpBaseContext(pTempBaseContext)
398 {
399  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
400  {
401  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_TYPE))
402  msType = aIter.toString();
403  }
404 }
405 
406 void XMLConfigItemContext::characters( const OUString& rChars )
407 {
408  maCharBuffer.append(rChars);
409 }
410 
411 void XMLConfigItemContext::endFastElement(sal_Int32 )
412 {
413  OUString sValue;
414  uno::Sequence<sal_Int8> aDecoded;
415  if (IsXMLToken(msType, XML_BASE64BINARY))
416  {
417  OUString sChars = maCharBuffer.makeStringAndClear().trim();
418  if( !sChars.isEmpty() )
419  ::comphelper::Base64::decodeSomeChars( aDecoded, sChars );
420  }
421  else
422  sValue = maCharBuffer.makeStringAndClear();
423 
424  if (mpBaseContext)
425  {
426  if (IsXMLToken(msType, XML_BOOLEAN))
427  {
428  bool bValue(false);
429  if (IsXMLToken(sValue, XML_TRUE))
430  bValue = true;
431  mrAny <<= bValue;
432  }
433  else if (IsXMLToken(msType, XML_BYTE))
434  {
435  sal_Int32 nValue(0);
436  ::sax::Converter::convertNumber(nValue, sValue);
437  mrAny <<= static_cast<sal_Int8>(nValue);
438  }
439  else if (IsXMLToken(msType, XML_SHORT))
440  {
441  sal_Int32 nValue(0);
442  ::sax::Converter::convertNumber(nValue, sValue);
443  mrAny <<= static_cast<sal_Int16>(nValue);
444  }
445  else if (IsXMLToken(msType, XML_INT))
446  {
447  sal_Int32 nValue(0);
448  ::sax::Converter::convertNumber(nValue, sValue);
449  mrAny <<= nValue;
450  }
451  else if (IsXMLToken(msType, XML_LONG))
452  {
453  sal_Int64 nValue(sValue.toInt64());
454  mrAny <<= nValue;
455  }
456  else if (IsXMLToken(msType, XML_DOUBLE))
457  {
458  double fValue(0.0);
459  ::sax::Converter::convertDouble(fValue, sValue);
460  mrAny <<= fValue;
461  }
462  else if (IsXMLToken(msType, XML_STRING))
463  {
464  mrAny <<= sValue;
465  }
466  else if (IsXMLToken(msType, XML_DATETIME))
467  {
468  util::DateTime aDateTime;
469  ::sax::Converter::parseDateTime(aDateTime, sValue);
470  mrAny <<= aDateTime;
471  }
472  else if (IsXMLToken(msType, XML_BASE64BINARY))
473  {
474  mrAny <<= aDecoded;
475  }
476  else {
477  SAL_INFO("xmloff.core",
478  "XMLConfigItemContext: unknown type: " << msType);
479  }
480 
481  ManipulateConfigItem();
482 
483  mpBaseContext->AddPropertyValue();
484  }
485  else {
486  assert(false && "no BaseContext");
487  }
488 }
489 
493 void XMLConfigItemContext::ManipulateConfigItem()
494 {
495  if( mrItemName == "PrinterIndependentLayout" )
496  {
497  OUString sValue;
498  mrAny >>= sValue;
499 
500  sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
501 
502  if( sValue == "enabled" || sValue == "low-resolution" )
503  {
504  nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
505  }
506  else if ( sValue == "disabled" )
507  {
508  nTmp = document::PrinterIndependentLayout::DISABLED;
509  }
510  // else: default to high_resolution
511 
512  mrAny <<= nTmp;
513  }
514  else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
515  || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
516  {
517  try
518  {
519  uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
520  uno::Reference< util::XStringSubstitution > xStringSubstitution( util::PathSubstitution::create(xContext) );
521 
522  OUString aURL;
523  mrAny >>= aURL;
524  aURL = xStringSubstitution->substituteVariables( aURL, false );
525  mrAny <<= aURL;
526  }
527  catch( uno::Exception& )
528  {
529  }
530  }
531 }
532 
533 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport,
534  css::uno::Any& rAny,
535  XMLConfigBaseContext* pBaseContext)
536  : XMLConfigBaseContext(rImport, rAny, pBaseContext)
537 {
538 }
539 
540 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapNamedContext::createFastChildContext(
541  sal_Int32 nElement,
542  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
543 {
544  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
545 }
546 
547 void XMLConfigItemMapNamedContext::endFastElement(sal_Int32 )
548 {
549  if (mpBaseContext)
550  {
551  mrAny <<= maProps.GetNameContainer();
552  mpBaseContext->AddPropertyValue();
553  }
554  else {
555  assert(false && "no BaseContext");
556  }
557 }
558 
559 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
560  css::uno::Any& rAny,
561  const OUString& rConfigItemName,
562  XMLConfigBaseContext* pBaseContext)
563  : XMLConfigBaseContext(rImport, rAny, pBaseContext),
564  maConfigItemName( rConfigItemName )
565 {
566 }
567 
568 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapIndexedContext::createFastChildContext(
569  sal_Int32 nElement,
570  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
571 {
572  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
573 }
574 
575 void XMLConfigItemMapIndexedContext::endFastElement(sal_Int32 )
576 {
577  if (mpBaseContext)
578  {
579  if ( maConfigItemName == "ForbiddenCharacters" )
580  {
581  uno::Reference< i18n::XForbiddenCharacters > xForbChars;
582 
583  // get the forbidden characters from the document
584  uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
585  if( xFac.is() )
586  {
587  uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
588  if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
589  {
590  xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
591  }
592  }
593 
594  if( xForbChars.is() )
595  {
596 
597  uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
598 
599  const sal_Int32 nCount = xIndex->getCount();
600  uno::Sequence < beans::PropertyValue > aProps;
601  for (sal_Int32 i = 0; i < nCount; i++)
602  {
603  if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
604  {
605  /* FIXME-BCP47: this stupid and counterpart in
606  * xmloff/source/core/SettingsExportHelper.cxx
607  * XMLSettingsExportHelper::exportForbiddenCharacters()
608  * */
609 
610  beans::PropertyValue *pForChar = aProps.getArray();
611  i18n::ForbiddenCharacters aForbid;
612  lang::Locale aLocale;
613  bool bHaveLanguage = false, bHaveCountry = false, bHaveVariant = false,
614  bHaveBegin = false, bHaveEnd = false;
615 
616  for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
617  {
618  if (pForChar->Name == "Language")
619  {
620  pForChar->Value >>= aLocale.Language;
621  bHaveLanguage = true;
622  }
623  else if (pForChar->Name == "Country")
624  {
625  pForChar->Value >>= aLocale.Country;
626  bHaveCountry = true;
627  }
628  else if (pForChar->Name == "Variant")
629  {
630  pForChar->Value >>= aLocale.Variant;
631  bHaveVariant = true;
632  }
633  else if (pForChar->Name == "BeginLine")
634  {
635  pForChar->Value >>= aForbid.beginLine;
636  bHaveBegin = true;
637  }
638  else if (pForChar->Name == "EndLine")
639  {
640  pForChar->Value >>= aForbid.endLine;
641  bHaveEnd = true;
642  }
643  pForChar++;
644  }
645 
646  if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
647  {
648  try
649  {
650  xForbChars->setForbiddenCharacters( aLocale, aForbid );
651  }
652  catch (uno::Exception const&)
653  {
654  TOOLS_WARN_EXCEPTION("xmloff.core",
655  "Exception while importing forbidden characters");
656  }
657  }
658  }
659  }
660  }
661  else
662  {
663  SAL_WARN("xmloff.core", "could not get the XForbiddenCharacters from document!");
664  mrAny <<= maProps.GetIndexContainer();
665  }
666  }
667  else if ( maConfigItemName == "Symbols" )
668  {
669  uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
670 
671  const sal_Int32 nCount = xIndex->getCount();
672  uno::Sequence < beans::PropertyValue > aProps;
673  uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
674 
675  formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
676 
677  sal_Int16 nNumFullEntries = 0;
678 
679  for ( sal_Int32 i = 0; i < nCount; i++ )
680  {
681  if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
682  {
683  bool bHaveName = false, bHaveExportName = false, bHaveCharSet = false,
684  bHaveFontName = false, bHaveFamily = false, bHavePitch = false,
685  bHaveWeight = false, bHaveItalic = false, bHaveSymbolSet = false,
686  bHaveCharacter = false;
687  beans::PropertyValue *pSymbol = aProps.getArray();
688 
689  for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
690  {
691  if (pSymbol->Name == "Name")
692  {
693  pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
694  bHaveName = true;
695  }
696  else if (pSymbol->Name == "ExportName")
697  {
698  pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
699  bHaveExportName = true;
700  }
701  else if (pSymbol->Name == "FontName")
702  {
703  pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
704  bHaveFontName = true;
705  }
706  else if (pSymbol->Name == "CharSet")
707  {
708  pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
709  bHaveCharSet = true;
710  }
711  else if (pSymbol->Name == "Family")
712  {
713  pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
714  bHaveFamily = true;
715  }
716  else if (pSymbol->Name == "Pitch")
717  {
718  pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
719  bHavePitch = true;
720  }
721  else if (pSymbol->Name == "Weight")
722  {
723  pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
724  bHaveWeight = true;
725  }
726  else if (pSymbol->Name == "Italic")
727  {
728  pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
729  bHaveItalic = true;
730  }
731  else if (pSymbol->Name == "SymbolSet")
732  {
733  pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
734  bHaveSymbolSet = true;
735  }
736  else if (pSymbol->Name == "Character")
737  {
738  pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
739  bHaveCharacter = true;
740  }
741  pSymbol++;
742  }
743  if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
744  && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
745  nNumFullEntries++;
746  }
747  }
748  aSymbolList.realloc (nNumFullEntries);
749  mrAny <<= aSymbolList;
750  }
751  else
752  {
753  mrAny <<= maProps.GetIndexContainer();
754  }
755  mpBaseContext->AddPropertyValue();
756  }
757  else {
758  assert(false && "no BaseContext");
759  }
760 }
761 
762 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SvXMLImportContext * CreateSettingsContext(SvXMLImport &rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > &xAttrList, beans::PropertyValue &rProp, XMLConfigBaseContext *pBaseContext)
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
URL aURL
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:71
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
constexpr sal_uInt16 XML_NAMESPACE_OOO
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString Name
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
Value
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps)
Definition: xmlimp.cxx:1512
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static bool IsFuzzing()
int nCount
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
const char * sName
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps)
Definition: xmlimp.cxx:1508
static bool parseDateTime(css::util::DateTime &rDateTime, const OUString &rString)
#define TOOLS_WARN_EXCEPTION(area, stream)
int i
::std::vector< SettingsGroup > maDocSpecificSettings
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
const uno::Reference< uno::XComponentContext > m_xContext
virtual ~XMLDocumentSettingsContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
Definition: xmlictxt.cxx:114
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings)
Definition: xmlimp.cxx:1516
Handling of tokens in XML:
#define SAL_INFO(area, stream)
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
static sal_Int32 decodeSomeChars(css::uno::Sequence< sal_Int8 > &aPass, const OUString &sBuffer)
virtual void SAL_CALL characters(const OUString &aChars) override
Definition: xmlictxt.cxx:142
sal_Int16 nValue
XMLDocumentSettingsContext(SvXMLImport &rImport)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)