23#include <officecfg/Office/Common.hxx>
26#include <com/sun/star/util/PathSubstitution.hpp>
27#include <com/sun/star/util/XStringSubstitution.hpp>
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/frame/XModel.hpp>
42#include <com/sun/star/util/DateTime.hpp>
43#include <com/sun/star/document/XViewDataSupplier.hpp>
44#include <com/sun/star/document/PrinterIndependentLayout.hpp>
45#include <com/sun/star/document/NamedPropertyValues.hpp>
46#include <com/sun/star/beans/XPropertySet.hpp>
49#include <osl/diagnose.h>
61 std::vector<beans::PropertyValue> aProps;
64 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
67 explicit XMLMyList(uno::Reference<uno::XComponentContext> xContext);
69 void push_back(beans::PropertyValue
const & aProp) { aProps.push_back(aProp);
nCount++; }
70 uno::Sequence<beans::PropertyValue> GetSequence();
71 uno::Reference<container::XNameContainer> GetNameContainer();
72 uno::Reference<container::XIndexContainer> GetIndexContainer();
77XMLMyList::XMLMyList(uno::Reference<uno::XComponentContext> xContext)
84uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
86 uno::Sequence<beans::PropertyValue>
aSeq;
89 assert(nCount == aProps.size());
91 beans::PropertyValue* pProps =
aSeq.getArray();
92 for (
auto const& prop : aProps)
101uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
103 uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(
m_xContext);
104 for (
auto const& prop : aProps)
106 xNameContainer->insertByName(prop.Name, prop.Value);
109 return xNameContainer;
112uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
116 for (
auto const& prop : aProps)
118 xIndexContainer->insertByIndex(i, prop.Value);
122 return xIndexContainer;
131 beans::PropertyValue maProp;
132 css::uno::Any& mrAny;
133 XMLConfigBaseContext* mpBaseContext;
135 XMLConfigBaseContext(SvXMLImport& rImport,
137 XMLConfigBaseContext* pBaseContext);
139 void AddPropertyValue() { maProps.push_back(maProp); }
145 css::uno::Any& mrAny;
146 const OUString mrItemName;
147 XMLConfigBaseContext* mpBaseContext;
148 OUStringBuffer maCharBuffer;
151 XMLConfigItemContext(SvXMLImport& rImport,
152 const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
155 XMLConfigBaseContext* pBaseContext);
157 virtual void SAL_CALL
characters(
const OUString& rChars )
override;
159 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
161 void ManipulateConfigItem();
164class XMLConfigItemSetContext :
public XMLConfigBaseContext
167 XMLConfigItemSetContext(SvXMLImport& rImport,
169 XMLConfigBaseContext* pBaseContext);
171 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
172 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
174 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
177class XMLConfigItemMapNamedContext :
public XMLConfigBaseContext
180 XMLConfigItemMapNamedContext(SvXMLImport& rImport,
182 XMLConfigBaseContext* pBaseContext);
184 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
185 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
187 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
190class XMLConfigItemMapIndexedContext :
public XMLConfigBaseContext
193 OUString maConfigItemName;
196 XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
198 OUString aConfigItemName,
199 XMLConfigBaseContext* pBaseContext);
201 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
202 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
204 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
210 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
211 beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
219 rProp.Name = aIter.toString();
223 pContext =
new XMLConfigItemContext(rImport, xAttrList, rProp.Value, rProp.Name, pBaseContext);
226 pContext =
new XMLConfigItemSetContext(rImport, rProp.Value, pBaseContext);
228 pContext =
new XMLConfigItemMapNamedContext(rImport, rProp.Value, pBaseContext);
230 pContext =
new XMLConfigItemMapIndexedContext(rImport, rProp.Value, rProp.Name, pBaseContext);
247 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
255 sName = aIter.toString();
260 OUString aLocalConfigName;
261 sal_uInt16 nConfigPrefix =
262 GetImport().GetNamespaceMap().GetKeyByAttrValueQName(
263 sName, &aLocalConfigName );
268 pContext =
new XMLConfigItemSetContext(
GetImport(),
272 pContext =
new XMLConfigItemSetContext(
GetImport(),
278 pContext =
new XMLConfigItemSetContext(
GetImport(),
289 uno::Sequence<beans::PropertyValue> aSeqViewProps;
292 GetImport().SetViewSettings(aSeqViewProps);
293 sal_Int32
i(aSeqViewProps.getLength() - 1);
295 while((
i >= 0) && !bFound)
297 if (aSeqViewProps[
i].
Name ==
"Views")
300 uno::Reference<container::XIndexAccess> xIndexAccess;
301 if (aSeqViewProps[
i].
Value >>= xIndexAccess)
303 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(
GetImport().GetModel(), uno::UNO_QUERY);
304 if (xViewDataSupplier.is())
305 xViewDataSupplier->setViewData(xIndexAccess);
313 uno::Sequence<beans::PropertyValue> aSeqConfigProps;
318 auto aSeqConfigPropsRange = asNonConstRange(aSeqConfigProps);
319 sal_Int32
i = aSeqConfigProps.getLength() - 1;
322 while ( (
i >= 0 ) && nFound < 2 )
324 OUString sProp( aSeqConfigProps[
i].
Name );
326 if ( sProp ==
"PrinterName" )
328 aSeqConfigPropsRange[
i].Value <<= OUString();
331 else if ( sProp ==
"PrinterSetup" )
333 uno::Sequence< sal_Int8 > aEmpty;
334 aSeqConfigPropsRange[
i].Value <<= aEmpty;
342 GetImport().SetConfigurationSettings( aSeqConfigProps );
347 uno::Sequence< beans::PropertyValue > aDocSettings;
348 OSL_VERIFY( settings.aSettings >>= aDocSettings );
349 GetImport().SetDocumentSpecificSettings( settings.sGroupName, aDocSettings );
353XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport,
354 css::uno::Any& rTempAny,
355 XMLConfigBaseContext* pTempBaseContext)
357 maProps( rImport.GetComponentContext() ),
359 mpBaseContext(pTempBaseContext)
363XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport,
365 XMLConfigBaseContext* pBaseContext)
366 : XMLConfigBaseContext( rImport, rAny, pBaseContext )
371css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemSetContext::createFastChildContext(
373 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
378void XMLConfigItemSetContext::endFastElement(sal_Int32 )
380 mrAny <<= maProps.GetSequence();
382 mpBaseContext->AddPropertyValue();
385XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport,
386 const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
387 css::uno::Any& rTempAny,
388 OUString aTempItemName,
389 XMLConfigBaseContext* pTempBaseContext)
392 mrItemName(
std::move(aTempItemName)),
393 mpBaseContext(pTempBaseContext)
398 msType = aIter.toString();
402void XMLConfigItemContext::characters(
const OUString& rChars )
404 maCharBuffer.append(rChars);
407void XMLConfigItemContext::endFastElement(sal_Int32 )
410 uno::Sequence<sal_Int8> aDecoded;
413 std::u16string_view sChars =
o3tl::trim(maCharBuffer);
414 if( !sChars.empty() )
416 maCharBuffer.setLength(0);
419 sValue = maCharBuffer.makeStringAndClear();
434 mrAny <<= static_cast<sal_Int8>(nValue);
440 mrAny <<= static_cast<sal_Int16>(nValue);
450 sal_Int64
nValue(sValue.toInt64());
465 util::DateTime aDateTime;
469 SAL_WARN(
"xmloff.core",
"XMLConfigItemContext: broken DateTime '" << sValue <<
"'");
477 "XMLConfigItemContext: unknown type: " << msType);
480 ManipulateConfigItem();
482 mpBaseContext->AddPropertyValue();
485 assert(
false &&
"no BaseContext");
492void XMLConfigItemContext::ManipulateConfigItem()
494 if( mrItemName ==
"PrinterIndependentLayout" )
499 sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
501 if( sValue ==
"enabled" || sValue ==
"low-resolution" )
503 nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
505 else if ( sValue ==
"disabled" )
507 nTmp = document::PrinterIndependentLayout::DISABLED;
513 else if( (mrItemName ==
"ColorTableURL") || (mrItemName ==
"LineEndTableURL") || (mrItemName ==
"HatchTableURL")
514 || (mrItemName ==
"DashTableURL") || (mrItemName ==
"GradientTableURL") || (mrItemName ==
"BitmapTableURL") )
518 uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
519 uno::Reference< util::XStringSubstitution > xStringSubstitution( util::PathSubstitution::create(xContext) );
523 aURL = xStringSubstitution->substituteVariables( aURL,
false );
526 catch( uno::Exception& )
532XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport,
534 XMLConfigBaseContext* pBaseContext)
535 : XMLConfigBaseContext(rImport, rAny, pBaseContext)
539css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapNamedContext::createFastChildContext(
541 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
546void XMLConfigItemMapNamedContext::endFastElement(sal_Int32 )
550 mrAny <<= maProps.GetNameContainer();
551 mpBaseContext->AddPropertyValue();
554 assert(
false &&
"no BaseContext");
558XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
560 OUString aConfigItemName,
561 XMLConfigBaseContext* pBaseContext)
562 : XMLConfigBaseContext(rImport, rAny, pBaseContext),
563 maConfigItemName(
std::move( aConfigItemName ))
567css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapIndexedContext::createFastChildContext(
569 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
574void XMLConfigItemMapIndexedContext::endFastElement(sal_Int32 )
578 if ( maConfigItemName ==
"ForbiddenCharacters" )
580 uno::Reference< i18n::XForbiddenCharacters > xForbChars;
583 uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
586 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(
"com.sun.star.document.Settings" ), uno::UNO_QUERY );
587 if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
589 xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
593 if( xForbChars.is() )
596 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
598 const sal_Int32
nCount = xIndex->getCount();
599 uno::Sequence < beans::PropertyValue > aProps;
600 for (sal_Int32 i = 0;
i <
nCount;
i++)
609 beans::PropertyValue *pForChar = aProps.getArray();
610 i18n::ForbiddenCharacters aForbid;
611 lang::Locale aLocale;
612 bool bHaveLanguage =
false, bHaveCountry =
false, bHaveVariant =
false,
613 bHaveBegin =
false, bHaveEnd =
false;
617 if (pForChar->Name ==
"Language")
619 pForChar->Value >>= aLocale.Language;
620 bHaveLanguage =
true;
622 else if (pForChar->Name ==
"Country")
624 pForChar->Value >>= aLocale.Country;
627 else if (pForChar->Name ==
"Variant")
629 pForChar->Value >>= aLocale.Variant;
632 else if (pForChar->Name ==
"BeginLine")
634 pForChar->Value >>= aForbid.beginLine;
637 else if (pForChar->Name ==
"EndLine")
639 pForChar->Value >>= aForbid.endLine;
645 if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
649 xForbChars->setForbiddenCharacters( aLocale, aForbid );
651 catch (uno::Exception
const&)
654 "Exception while importing forbidden characters");
662 SAL_WARN(
"xmloff.core",
"could not get the XForbiddenCharacters from document!");
663 mrAny <<= maProps.GetIndexContainer();
666 else if ( maConfigItemName ==
"Symbols" )
668 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
670 const sal_Int32
nCount = xIndex->getCount();
671 uno::Sequence < beans::PropertyValue > aProps;
672 uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
674 formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
676 sal_Int16 nNumFullEntries = 0;
678 for ( sal_Int32 i = 0;
i <
nCount;
i++ )
682 bool bHaveName =
false, bHaveExportName =
false, bHaveCharSet =
false,
683 bHaveFontName =
false, bHaveFamily =
false, bHavePitch =
false,
684 bHaveWeight =
false, bHaveItalic =
false, bHaveSymbolSet =
false,
685 bHaveCharacter =
false;
686 beans::PropertyValue *pSymbol = aProps.getArray();
690 if (pSymbol->Name ==
"Name")
692 pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
695 else if (pSymbol->Name ==
"ExportName")
697 pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
698 bHaveExportName =
true;
700 else if (pSymbol->Name ==
"FontName")
702 pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
703 bHaveFontName =
true;
705 else if (pSymbol->Name ==
"CharSet")
707 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
710 else if (pSymbol->Name ==
"Family")
712 pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
715 else if (pSymbol->Name ==
"Pitch")
717 pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
720 else if (pSymbol->Name ==
"Weight")
722 pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
725 else if (pSymbol->Name ==
"Italic")
727 pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
730 else if (pSymbol->Name ==
"SymbolSet")
732 pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
733 bHaveSymbolSet =
true;
735 else if (pSymbol->Name ==
"Character")
737 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
738 bHaveCharacter =
true;
742 if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
743 && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
747 aSymbolList.realloc (nNumFullEntries);
748 mrAny <<= aSymbolList;
752 mrAny <<= maProps.GetIndexContainer();
754 mpBaseContext->AddPropertyValue();
757 assert(
false &&
"no BaseContext");
static SvXMLImportContext * CreateSettingsContext(SvXMLImport &rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > &xAttrList, beans::PropertyValue &rProp, XMLConfigBaseContext *pBaseContext)
const uno::Reference< uno::XComponentContext > m_xContext
This class deliberately does not support XWeak, to improve performance when loading large documents.
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 ...
SvXMLImport & GetImport()
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
css::uno::Any maConfigProps
::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
virtual ~XMLDocumentSettingsContext() override
css::uno::Any maViewProps
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 ...
XMLDocumentSettingsContext(SvXMLImport &rImport)
static std::size_t decodeSomeChars(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_CONFIG_ITEM_MAP_NAMED
@ XML_CONFIGURATION_SETTINGS
@ XML_CONFIG_ITEM_MAP_ENTRY
@ XML_CONFIG_ITEM_MAP_INDEXED
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
@ XML_SYMBOL_DESCRIPTOR_MAX
@ XML_FORBIDDEN_CHARACTER_MAX
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_OOO