22 #include <officecfg/Office/Common.hxx>
25 #include <com/sun/star/util/PathSubstitution.hpp>
26 #include <com/sun/star/util/XStringSubstitution.hpp>
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>
47 #include <osl/diagnose.h>
59 std::vector<beans::PropertyValue> aProps;
62 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
65 explicit XMLMyList(
const uno::Reference<uno::XComponentContext>& rxContext);
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();
75 XMLMyList::XMLMyList(
const uno::Reference<uno::XComponentContext>& rxContext)
82 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
84 uno::Sequence<beans::PropertyValue>
aSeq;
87 assert(nCount == aProps.size());
89 beans::PropertyValue* pProps = aSeq.getArray();
90 for (
auto const& prop : aProps)
99 uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
101 uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(
m_xContext);
102 for (
auto const& prop : aProps)
104 xNameContainer->insertByName(prop.Name, prop.Value);
107 return xNameContainer;
110 uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
112 uno::Reference<container::XIndexContainer> xIndexContainer = document::IndexedPropertyValues::create(
m_xContext);
114 for (
auto const& prop : aProps)
116 xIndexContainer->insertByIndex(i, prop.Value);
120 return xIndexContainer;
129 beans::PropertyValue maProp;
130 css::uno::Any& mrAny;
131 XMLConfigBaseContext* mpBaseContext;
135 XMLConfigBaseContext* pBaseContext);
137 void AddPropertyValue() { maProps.push_back(maProp); }
143 css::uno::Any& mrAny;
144 const OUString mrItemName;
145 XMLConfigBaseContext* mpBaseContext;
146 OUStringBuffer maCharBuffer;
150 const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
152 const OUString& rItemName,
153 XMLConfigBaseContext* pBaseContext);
155 virtual void SAL_CALL
characters(
const OUString& rChars )
override;
157 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
159 void ManipulateConfigItem();
162 class XMLConfigItemSetContext :
public XMLConfigBaseContext
167 XMLConfigBaseContext* pBaseContext);
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;
172 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
175 class XMLConfigItemMapNamedContext :
public XMLConfigBaseContext
180 XMLConfigBaseContext* pBaseContext);
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;
185 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
188 class XMLConfigItemMapIndexedContext :
public XMLConfigBaseContext
191 OUString maConfigItemName;
194 XMLConfigItemMapIndexedContext(
SvXMLImport& rImport,
196 const OUString& rConfigItemName,
197 XMLConfigBaseContext* pBaseContext);
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;
202 virtual void SAL_CALL endFastElement(sal_Int32 nElement)
override;
208 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
209 beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
217 rProp.Name = aIter.toString();
221 pContext =
new XMLConfigItemContext(rImport, xAttrList, rProp.Value, rProp.Name, pBaseContext);
224 pContext =
new XMLConfigItemSetContext(rImport, rProp.Value, pBaseContext);
226 pContext =
new XMLConfigItemMapNamedContext(rImport, rProp.Value, pBaseContext);
228 pContext =
new XMLConfigItemMapIndexedContext(rImport, rProp.Value, rProp.Name, pBaseContext);
245 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
253 sName = aIter.toString();
258 OUString aLocalConfigName;
259 sal_uInt16 nConfigPrefix =
261 sName, &aLocalConfigName );
266 pContext =
new XMLConfigItemSetContext(
GetImport(),
270 pContext =
new XMLConfigItemSetContext(
GetImport(),
276 pContext =
new XMLConfigItemSetContext(
GetImport(),
287 uno::Sequence<beans::PropertyValue> aSeqViewProps;
291 sal_Int32
i(aSeqViewProps.getLength() - 1);
293 while((
i >= 0) && !bFound)
295 if (aSeqViewProps[
i].
Name ==
"Views")
298 uno::Reference<container::XIndexAccess> xIndexAccess;
299 if (aSeqViewProps[
i].
Value >>= xIndexAccess)
301 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(
GetImport().GetModel(), uno::UNO_QUERY);
302 if (xViewDataSupplier.is())
303 xViewDataSupplier->setViewData(xIndexAccess);
311 uno::Sequence<beans::PropertyValue> aSeqConfigProps;
316 auto aSeqConfigPropsRange = asNonConstRange(aSeqConfigProps);
317 sal_Int32
i = aSeqConfigProps.getLength() - 1;
320 while ( ( i >= 0 ) && nFound < 2 )
322 OUString sProp( aSeqConfigProps[i].
Name );
324 if ( sProp ==
"PrinterName" )
326 aSeqConfigPropsRange[i].Value <<= OUString();
329 else if ( sProp ==
"PrinterSetup" )
331 uno::Sequence< sal_Int8 > aEmpty;
332 aSeqConfigPropsRange[i].Value <<= aEmpty;
345 uno::Sequence< beans::PropertyValue > aDocSettings;
346 OSL_VERIFY( settings.aSettings >>= aDocSettings );
351 XMLConfigBaseContext::XMLConfigBaseContext(
SvXMLImport& rImport,
352 css::uno::Any& rTempAny,
353 XMLConfigBaseContext* pTempBaseContext)
355 maProps( rImport.GetComponentContext() ),
357 mpBaseContext(pTempBaseContext)
361 XMLConfigItemSetContext::XMLConfigItemSetContext(
SvXMLImport& rImport,
363 XMLConfigBaseContext* pBaseContext)
364 : XMLConfigBaseContext( rImport, rAny, pBaseContext )
369 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemSetContext::createFastChildContext(
371 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
376 void XMLConfigItemSetContext::endFastElement(sal_Int32 )
378 mrAny <<= maProps.GetSequence();
380 mpBaseContext->AddPropertyValue();
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)
390 mrItemName(rTempItemName),
391 mpBaseContext(pTempBaseContext)
396 msType = aIter.toString();
400 void XMLConfigItemContext::characters(
const OUString& rChars )
402 maCharBuffer.append(rChars);
405 void XMLConfigItemContext::endFastElement(sal_Int32 )
408 uno::Sequence<sal_Int8> aDecoded;
411 OUString sChars = maCharBuffer.makeStringAndClear().trim();
412 if( !sChars.isEmpty() )
416 sValue = maCharBuffer.makeStringAndClear();
431 mrAny <<= static_cast<sal_Int8>(
nValue);
437 mrAny <<= static_cast<sal_Int16>(
nValue);
447 sal_Int64
nValue(sValue.toInt64());
462 util::DateTime aDateTime;
472 "XMLConfigItemContext: unknown type: " << msType);
475 ManipulateConfigItem();
477 mpBaseContext->AddPropertyValue();
480 assert(
false &&
"no BaseContext");
487 void XMLConfigItemContext::ManipulateConfigItem()
489 if( mrItemName ==
"PrinterIndependentLayout" )
494 sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
496 if( sValue ==
"enabled" || sValue ==
"low-resolution" )
498 nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
500 else if ( sValue ==
"disabled" )
502 nTmp = document::PrinterIndependentLayout::DISABLED;
508 else if( (mrItemName ==
"ColorTableURL") || (mrItemName ==
"LineEndTableURL") || (mrItemName ==
"HatchTableURL")
509 || (mrItemName ==
"DashTableURL") || (mrItemName ==
"GradientTableURL") || (mrItemName ==
"BitmapTableURL") )
513 uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
514 uno::Reference< util::XStringSubstitution > xStringSubstitution( util::PathSubstitution::create(xContext) );
518 aURL = xStringSubstitution->substituteVariables( aURL,
false );
521 catch( uno::Exception& )
527 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(
SvXMLImport& rImport,
529 XMLConfigBaseContext* pBaseContext)
530 : XMLConfigBaseContext(rImport, rAny, pBaseContext)
534 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapNamedContext::createFastChildContext(
536 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
541 void XMLConfigItemMapNamedContext::endFastElement(sal_Int32 )
545 mrAny <<= maProps.GetNameContainer();
546 mpBaseContext->AddPropertyValue();
549 assert(
false &&
"no BaseContext");
553 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(
SvXMLImport& rImport,
555 const OUString& rConfigItemName,
556 XMLConfigBaseContext* pBaseContext)
557 : XMLConfigBaseContext(rImport, rAny, pBaseContext),
558 maConfigItemName( rConfigItemName )
562 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapIndexedContext::createFastChildContext(
564 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
569 void XMLConfigItemMapIndexedContext::endFastElement(sal_Int32 )
573 if ( maConfigItemName ==
"ForbiddenCharacters" )
575 uno::Reference< i18n::XForbiddenCharacters > xForbChars;
578 uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
581 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance(
"com.sun.star.document.Settings" ), uno::UNO_QUERY );
582 if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
584 xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
588 if( xForbChars.is() )
591 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
593 const sal_Int32
nCount = xIndex->getCount();
594 uno::Sequence < beans::PropertyValue > aProps;
595 for (sal_Int32 i = 0;
i < nCount;
i++)
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;
612 if (pForChar->Name ==
"Language")
614 pForChar->Value >>= aLocale.Language;
615 bHaveLanguage =
true;
617 else if (pForChar->Name ==
"Country")
619 pForChar->Value >>= aLocale.Country;
622 else if (pForChar->Name ==
"Variant")
624 pForChar->Value >>= aLocale.Variant;
627 else if (pForChar->Name ==
"BeginLine")
629 pForChar->Value >>= aForbid.beginLine;
632 else if (pForChar->Name ==
"EndLine")
634 pForChar->Value >>= aForbid.endLine;
640 if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
644 xForbChars->setForbiddenCharacters( aLocale, aForbid );
646 catch (uno::Exception
const&)
649 "Exception while importing forbidden characters");
657 SAL_WARN(
"xmloff.core",
"could not get the XForbiddenCharacters from document!");
658 mrAny <<= maProps.GetIndexContainer();
661 else if ( maConfigItemName ==
"Symbols" )
663 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
665 const sal_Int32 nCount = xIndex->getCount();
666 uno::Sequence < beans::PropertyValue > aProps;
667 uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
669 formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
671 sal_Int16 nNumFullEntries = 0;
673 for ( sal_Int32 i = 0;
i < nCount;
i++ )
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();
685 if (pSymbol->Name ==
"Name")
687 pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
690 else if (pSymbol->Name ==
"ExportName")
692 pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
693 bHaveExportName =
true;
695 else if (pSymbol->Name ==
"FontName")
697 pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
698 bHaveFontName =
true;
700 else if (pSymbol->Name ==
"CharSet")
702 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
705 else if (pSymbol->Name ==
"Family")
707 pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
710 else if (pSymbol->Name ==
"Pitch")
712 pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
715 else if (pSymbol->Name ==
"Weight")
717 pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
720 else if (pSymbol->Name ==
"Italic")
722 pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
725 else if (pSymbol->Name ==
"SymbolSet")
727 pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
728 bHaveSymbolSet =
true;
730 else if (pSymbol->Name ==
"Character")
732 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
733 bHaveCharacter =
true;
737 if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
738 && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
742 aSymbolList.realloc (nNumFullEntries);
743 mrAny <<= aSymbolList;
747 mrAny <<= maProps.GetIndexContainer();
749 mpBaseContext->AddPropertyValue();
752 assert(
false &&
"no BaseContext");
static SvXMLImportContext * CreateSettingsContext(SvXMLImport &rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > &xAttrList, beans::PropertyValue &rProp, XMLConfigBaseContext *pBaseContext)
SvXMLImport & GetImport()
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()
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps)
css::uno::Any maConfigProps
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps)
static std::size_t decodeSomeChars(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
#define TOOLS_WARN_EXCEPTION(area, stream)
::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
css::uno::Any maViewProps
const uno::Reference< uno::XComponentContext > m_xContext
virtual ~XMLDocumentSettingsContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings)
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 ...
Handling of tokens in XML:
#define SAL_INFO(area, stream)
#define XML_ELEMENT(prefix, name)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
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)