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