20#include <officecfg/Office/Common.hxx>
23#include <com/sun/star/container/XChild.hpp>
24#include <com/sun/star/beans/XPropertySetInfo.hpp>
25#include <com/sun/star/embed/ElementModes.hpp>
26#include <com/sun/star/xml/sax/SAXParseException.hpp>
33#include <sfx2/sfxsids.hrc>
39#include <svx/strings.hrc>
46#include <com/sun/star/xml/sax/Parser.hpp>
47#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
48#include <com/sun/star/xml/sax/XFastParser.hpp>
49#include <com/sun/star/document/XFilter.hpp>
50#include <com/sun/star/document/XImporter.hpp>
51#include <com/sun/star/document/XExporter.hpp>
52#include <com/sun/star/lang/XInitialization.hpp>
53#include <com/sun/star/lang/XServiceInfo.hpp>
54#include <com/sun/star/lang/XMultiServiceFactory.hpp>
55#include <com/sun/star/beans/PropertyAttribute.hpp>
56#include <com/sun/star/packages/WrongPasswordException.hpp>
57#include <com/sun/star/packages/zip/ZipIOException.hpp>
59#include <com/sun/star/xml/sax/InputSource.hpp>
60#include <com/sun/star/xml/sax/Writer.hpp>
86#define SD_XML_READERROR ErrCode(1234)
123 const char* mpService;
124 const char* mpStream;
130 const char* mpStyles;
131 const char* mpContent;
132 const char* mpSettings;
142 static XML_SERVICES
const gServices[] =
153 return &gServices[ (bImport ? 0 : 2) + ((nStoreVer ==
SOFFICE_FILEFORMAT_60) ? 4 : 0) + (bDraw ? 1 : 0 ) ];
158 SdFilter( rMedium, rDocShell ), meFilterMode( eFilterMode ), mnStoreVer( nStoreVer )
172 const OUString& rStreamName,
174 const char* pFilterName,
176 const OUString& rName,
177 bool bMustBeSuccessful,
180 DBG_ASSERT(xInputStream.is(),
"input stream missing");
181 DBG_ASSERT(xModelComponent.is(),
"document missing");
182 DBG_ASSERT(rxContext.is(),
"factory missing");
183 DBG_ASSERT(
nullptr != pFilterName,
"I need a service name for the component!");
185 SAL_INFO(
"sd.filter",
"ReadThroughComponent" );
188 xml::sax::InputSource aParserInput;
189 aParserInput.sSystemId = rName;
190 aParserInput.aInputStream = xInputStream;
193 OUString aFilterName(OUString::createFromAscii(pFilterName));
196 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext),
198 SAL_WARN_IF(!xFilter.is(),
"sd.filter",
"Can't instantiate filter component: " << aFilterName);
204 xDocumentHandler.set(xFilter, UNO_QUERY);
205 if (!xFastParser && !xDocumentHandler)
207 SAL_WARN(
"sd",
"service does not implement XFastParser or XDocumentHandler");
211 SAL_INFO(
"sd.filter",
"" << pFilterName <<
" created" );
215 xImporter->setTargetDocument( xModelComponent );
218 SAL_INFO(
"sd.filter",
"parsing stream" );
222 xFastParser->parseStream( aParserInput );
227 xParser->setDocumentHandler( xDocumentHandler );
228 xParser->parseStream( aParserInput );
231 catch (
const xml::sax::SAXParseException& r)
236 xml::sax::SAXException aSaxEx = *
static_cast<xml::sax::SAXException
const *
>(&r);
237 bool bTryChild =
true;
241 xml::sax::SAXException aTmp;
242 if ( aSaxEx.WrappedException >>= aTmp )
248 packages::zip::ZipIOException aBrokenPackage;
249 if ( aSaxEx.WrappedException >>= aBrokenPackage )
257 OUString sErr = OUString::number( r.LineNumber ) +
258 "," + OUString::number( r.ColumnNumber );
260 if (!rStreamName.isEmpty())
266 DialogMask::ButtonsOk | DialogMask::MessageError );
270 DBG_ASSERT( bMustBeSuccessful,
"Warnings are not supported" );
272 DialogMask::ButtonsOk | DialogMask::MessageError );
275 catch (
const xml::sax::SAXException& r)
278 packages::zip::ZipIOException aBrokenPackage;
279 if ( r.WrappedException >>= aBrokenPackage )
288 catch (
const packages::zip::ZipIOException&)
293 catch (
const io::IOException&)
298 catch (
const uno::Exception&)
309 const uno::Reference < embed::XStorage >& xStorage,
311 const char* pStreamName,
313 const char* pFilterName,
315 const OUString& rName,
316 bool bMustBeSuccessful )
319 DBG_ASSERT(
nullptr != pStreamName,
"Please, please, give me a name!");
322 OUString sStreamName = OUString::createFromAscii(pStreamName);
323 bool bContainsStream =
false;
326 bContainsStream = xStorage->isStreamElement(sStreamName);
328 catch (
const container::NoSuchElementException&)
332 if (!bContainsStream )
339 uno::Reference< beans::XPropertySet > xInfoSet;
340 if( rFilterArguments.hasElements() )
341 rFilterArguments.getConstArray()[0] >>= xInfoSet;
342 DBG_ASSERT( xInfoSet.is(),
"missing property set" );
345 xInfoSet->setPropertyValue(
"StreamName",
Any( sStreamName ) );
352 xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
354 if ( !
xStream.is() || ! xProps.is() )
357 Any aAny = xProps->getPropertyValue(
"Encrypted" );
359 bool bEncrypted =
false;
365 return ReadThroughComponent(
366 xInputStream, xModelComponent, sStreamName, rxContext,
367 pFilterName, rFilterArguments,
368 rName, bMustBeSuccessful, bEncrypted );
370 catch (
const packages::WrongPasswordException&)
374 catch (
const packages::zip::ZipIOException&)
378 catch (
const uno::Exception&)
409 pOutliner->SetText(*pOutlParaObj);
410 bool bInconsistent =
false;
411 const sal_Int32 nParaCount = pOutliner->GetParagraphCount();
412 for (sal_Int32 j = 0; j < nParaCount; ++j)
415 const sal_Int16 nExpectedDepth = j;
416 if (nExpectedDepth != pOutliner->GetDepth(j))
419 pOutliner->SetDepth(
p, nExpectedDepth);
420 bInconsistent =
true;
425 SfxItemSet aAttrs(pOutliner->GetParaAttribs(j));
429 pOutliner->SetParaAttribs(j, aAttrs);
430 bInconsistent =
true;
436 SAL_WARN(
"sd.filter",
"Fixing inconsistent outline numbering placeholder preview");
483 uno::Reference< container::XChild > xChild(
mxModel, uno::UNO_QUERY );
486 uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
487 if( xParentSet.is() )
489 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
490 OUString sPropName(
"BuildId" );
491 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
493 xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
498 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
515 sal_Int32 nProgressRange(1000000);
516 OUString aMsg(
SvxResId(RID_SVXSTR_DOC_LOAD));
521 aProgRange <<= nProgressRange;
522 xInfoSet->setPropertyValue(
"ProgressRange" , aProgRange);
526 aProgCurrent <<= sal_Int32(0);
527 xInfoSet->setPropertyValue(
"ProgressCurrent" , aProgCurrent);
535 xInfoSet->setPropertyValue(
"SourceStorage",
Any( xStorage ) );
543 SvXMLGraphicHelperMode::Read );
544 xGraphicStorageHandler = xGraphicHelper.get();
547 SvXMLEmbeddedObjectHelperMode::Read );
548 xObjectResolver = xObjectHelper.get();
554 SAL_INFO_IF(baseURI.isEmpty(),
"sd.filter",
"SdXMLFilter: no base URL");
555 xInfoSet->setPropertyValue(
"BaseURI",
Any(baseURI));
562 if ( pDocHierarchItem )
565 aName =
"dummyObjectName" ;
567 if( !
aName.isEmpty() )
568 xInfoSet->setPropertyValue(
"StreamRelPath",
Any(
aName ) );
572 xInfoSet->setPropertyValue(
"OrganizerMode",
uno::Any(
true));
579 Any *pArgs = aFilterArgs.getArray();
580 *pArgs++ <<= xInfoSet;
581 *pArgs++ <<= xGraphicStorageHandler;
582 *pArgs++ <<= xObjectResolver;
586 pArgs = aEmptyArgs.getArray();
587 *pArgs++ <<= xInfoSet;
598 nWarn = ReadThroughComponent(
599 xStorage, xModelComp,
"meta.xml", rxContext,
601 aEmptyArgs,
aName,
false );
605 nWarn2 = ReadThroughComponent(
606 xStorage, xModelComp,
"settings.xml", rxContext,
607 pServices->mpSettings,
608 aFilterArgs,
aName,
false );
611 nRet = ReadThroughComponent(
612 xStorage, xModelComp,
"styles.xml", rxContext,
614 aFilterArgs,
aName,
true );
617 nRet = ReadThroughComponent(
618 xStorage, xModelComp,
"content.xml", rxContext,
619 pServices->mpContent,
620 aFilterArgs,
aName,
true );
632 xGraphicHelper->dispose();
633 xGraphicHelper.clear();
634 xGraphicStorageHandler =
nullptr;
635 if( xObjectHelper.is() )
636 xObjectHelper->dispose();
637 xObjectHelper.clear();
638 xObjectResolver =
nullptr;
663 ::svx::DropUnusedNamedItems(
mxModel);
668 uno::Reference< beans::XPropertySet > xModelSet(
mxModel, uno::UNO_QUERY );
671 uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
672 static constexpr OUStringLiteral sPropName(
u"BuildId" );
675 xInfoSet->getPropertyValue(sPropName) >>= sBuildId;
677 if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sPropName) )
679 xModelSet->setPropertyValue( sPropName,
Any( sBuildId ) );
682 bool bTransform =
false;
686 if( !sBuildId.isEmpty() )
688 sal_Int32
nIndex = sBuildId.indexOf(
'$');
689 if (sBuildId.indexOf(
';') == -1 &&
nIndex != -1)
696 if( (nBuildId > 0) && (nBuildId < 9316) )
699 else if( (nUPD == 680) || ( nUPD >= 640 && nUPD <= 645 ) )
709 OUString
typeName(pFilter->GetRealTypeName());
710 if(
typeName.startsWith(
"impress_StarImpress" ) ||
711 typeName.startsWith(
"draw_StarDraw" ) )
735 bool bDocRet =
false;
739 SAL_WARN(
"sd.filter",
"Got NO Model in XMLExport");
743 bool bLocked =
mxModel->hasControllersLocked();
749 uno::Reference< lang::XServiceInfo > xServiceInfo(
mxModel, uno::UNO_QUERY );
751 if( !xServiceInfo.is() || !xServiceInfo->supportsService(
"com.sun.star.drawing.GenericDrawingDocument" ) )
753 SAL_WARN(
"sd.filter",
"Model is no DrawingDocument in XMLExport" );
757 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
759 uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext );
779 bool bUsePrettyPrinting = officecfg::Office::Common::Save::Document::PrettyPrinting::get();
780 xInfoSet->setPropertyValue(
"UsePrettyPrinting",
Any( bUsePrettyPrinting ) );
785 OUString sPropName(
"BaseURI" );
788 xInfoSet->setPropertyValue(
"TargetStorage",
Any( xStorage ) );
795 if ( pDocHierarchItem )
798 if( !
aName.isEmpty() )
800 sPropName =
"StreamRelPath";
801 xInfoSet->setPropertyValue( sPropName,
Any(
aName ) );
806 uno::Sequence< beans::PropertyValue > aDescriptor( 1 );
807 beans::PropertyValue* pProps = aDescriptor.getArray();
809 pProps[0].Name =
"FileName";
813 uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
814 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
820 xObjectResolver = xObjectHelper.get();
823 xGraphicStorageHandler = xGraphicHelper.get();
829 sal_Int32 nProgressRange(1000000);
830 OUString aMsg(
SdResId(STR_SAVE_DOC));
835 aProgRange <<= nProgressRange;
836 xInfoSet->setPropertyValue(
"ProgressRange" , aProgRange);
840 aProgCurrent <<= sal_Int32(0);
841 xInfoSet->setPropertyValue(
"ProgressCurrent" , aProgCurrent);
846 XML_SERVICEMAP aServices[5]; sal_uInt16
i = 0;
847 aServices[
i ].mpService = pServiceNames->mpStyles;
848 aServices[
i++].mpStream =
"styles.xml";
850 aServices[
i ].mpService = pServiceNames->mpContent;
851 aServices[
i++].mpStream =
"content.xml";
853 aServices[
i ].mpService = pServiceNames->mpSettings;
854 aServices[
i++].mpStream =
"settings.xml";
858 aServices[
i ].mpService = pServiceNames->mpMeta;
859 aServices[
i++].mpStream =
"meta.xml";
862 aServices[
i].mpService =
nullptr;
863 aServices[
i].mpStream =
nullptr;
865 XML_SERVICEMAP* pServices = aServices;
870 SAL_INFO(
"sd.filter",
"exporting substream " << pServices->mpStream );
872 uno::Reference<io::XOutputStream> xDocOut;
875 const OUString sDocName( OUString::createFromAscii( pServices->mpStream ) );
876 uno::Reference<io::XStream>
xStream =
877 xStorage->openStreamElement( sDocName,
878 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
884 xDocOut =
xStream->getOutputStream();
886 if( !xDocOut.is() || !xProps.is() )
889 xProps->setPropertyValue(
"MediaType",
Any(OUString(
"text/xml")));
892 xProps->setPropertyValue(
"UseCommonStoragePasswordEncryption",
895 xInfoSet->setPropertyValue(
"StreamName",
Any( sDocName ) );
898 xWriter->setOutputStream( xDocOut );
900 uno::Sequence< uno::Any > aArgs( 2 + (
mxStatusIndicator.is() ? 1 : 0 ) + ( xGraphicStorageHandler.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
902 *pArgs++ <<= xInfoSet;
903 if (xGraphicStorageHandler.is())
904 *pArgs++ <<= xGraphicStorageHandler;
905 if (xObjectResolver.is())
906 *pArgs++ <<= xObjectResolver;
912 uno::Reference< document::XFilter > xFilter( xContext->getServiceManager()->createInstanceWithArgumentsAndContext( OUString::createFromAscii( pServices->mpService ), aArgs, xContext ), uno::UNO_QUERY );
915 uno::Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY );
918 xExporter->setSourceDocument(
mxModel );
920 bDocRet = xFilter->filter( aDescriptor );
926 while( bDocRet && pServices->mpService );
932 catch (
const uno::Exception &)
941 xGraphicHelper->dispose();
942 xGraphicHelper.clear();
945 xObjectHelper->dispose();
946 xObjectHelper.clear();
957 uno::Reference<frame::XModel>
xModel(xDocSh->GetModel());
960 uno::Reference<io::XInputStream>
xStream(new ::utl::OSeekableInputStreamWrapper(rStream));
961 uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance(
"com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_SET_THROW);
963 css::uno::Sequence<OUString> aUserData
965 "com.sun.star.comp.filter.OdfFlatXml",
967 "com.sun.star.comp.Impress.XMLOasisImporter",
968 "com.sun.star.comp.Impress.XMLOasisExporter",
975 {
"UserData",
uno::Any(aUserData) },
977 css::uno::Sequence<uno::Any> aOuterArgs{
uno::Any(aAdaptorArgs) };
979 uno::Reference<lang::XInitialization> xInit(xInterface, uno::UNO_QUERY_THROW);
980 xInit->initialize(aOuterArgs);
982 uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW);
986 {
"URL",
uno::Any(OUString(
"private:stream")) },
988 xImporter->setTargetDocument(
xModel);
990 uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW);
995 xDocSh->SetLoading(SfxLoadedFlags::NONE);
996 bool ret = xFilter->filter(aArgs);
997 xDocSh->SetLoading(SfxLoadedFlags::ALL);
1009 xDocSh->DoInitNew();
1010 uno::Reference<frame::XModel>
xModel(xDocSh->GetModel());
1015 uno::Reference<document::XFilter> xFilter(xMultiServiceFactory->createInstance(
"com.sun.star.comp.oox.ppt.PowerPointImport"), uno::UNO_QUERY_THROW);
1017 uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
1023 xImporter->setTargetDocument(
xModel);
1029 xDocSh->SetLoading(SfxLoadedFlags::NONE);
1033 ret = xFilter->filter(aArgs);
1038 xDocSh->SetLoading(SfxLoadedFlags::ALL);
const OUString & GetValue() const
bool anyOf(Args... args) const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
void CreateFirstPages(SdDrawDocument const *pRefDocument=nullptr)
if the document does not contain at least one handout, one slide and one notes page with at least one...
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
SdOutliner * GetInternalOutliner(bool bCreateOutliner=true)
void StopWorkStartupDelay()
SAL_DLLPRIVATE void UpdateAllLinks()
updates all links, only links in this document should by resolved
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
SAL_DLLPRIVATE void NewOrLoadCompleted(DocCreationMode eMode)
::sd::DrawDocShell & mrDocShell
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
css::uno::Reference< css::frame::XModel > mxModel
void CreateStatusIndicator()
The main purpose of this class is searching and replacing as well as spelling of impress documents.
SdrObject * GetPresObj(PresObjKind eObjKind, int nIndex=1, bool bFuzzySearch=false)
returns the nIndex'th object from the given PresObjKind, index starts with 1
virtual ~SdXMLFilter() override
SdXMLFilter(SfxMedium &rMedium, ::sd::DrawDocShell &rDocShell, SdXMLFilterMode eFilterMode=SdXMLFilterMode::Normal, sal_uLong nStoreVer=SOFFICE_FILEFORMAT_8)
bool Import(ErrCode &nError)
SdXMLFilterMode meFilterMode
::comphelper::IEmbeddedHelper * GetPersist() const
bool IsStarDrawPreviewMode() const
void EnableUndo(bool bEnable)
bool IsUndoEnabled() const
void SetOutlinerParaObject(std::optional< OutlinerParaObject > pTextObject)
virtual OutlinerParaObject * GetOutlinerParaObject() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const std::shared_ptr< const SfxFilter > & GetFilter() const
OUString GetBaseURL(bool bForSaving=false)
SfxItemSet & GetItemSet() const
const OUString & GetName() const
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
css::uno::Reference< css::embed::XStorage > GetOutputStorage()
SfxObjectCreateMode GetCreateMode() const
const css::uno::Any & GetValue() const
static rtl::Reference< SvXMLEmbeddedObjectHelper > Create(const css::uno::Reference< css::embed::XStorage > &, ::comphelper::IEmbeddedHelper &rDocPersist, SvXMLEmbeddedObjectHelperMode eCreateMode)
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
css::uno::Type const & get()
SdDrawDocument * GetDoc()
#define DBG_ASSERT(sCon, aError)
OString exceptionToString(const css::uno::Any &caught)
#define TOOLS_WARN_EXCEPTION(area, stream)
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
constexpr TypedWhichId< SvxNumBulletItem > EE_PARA_NUMBULLET(EE_PARA_START+5)
#define ERRCODE_IO_BROKENPACKAGE
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
Reference< XMultiServiceFactory > getProcessServiceFactory()
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Any SAL_CALL getCaughtException()
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
#define ERR_FORMAT_FILE_ROWCOL
#define ERR_FORMAT_ROWCOL
#define WARN_FORMAT_FILE_ROWCOL
OUString SdResId(TranslateId aId)
SAL_DLLPUBLIC_EXPORT bool TestImportFODP(SvStream &rStream)
char const sXML_export_draw_content_oasis_service[]
SAL_DLLPUBLIC_EXPORT bool TestImportPPTX(SvStream &rStream)
char const sXML_import_draw_styles_ooo_service[]
char const sXML_import_draw_settings_oasis_service[]
char const sXML_export_draw_settings_oasis_service[]
char const sXML_import_impress_styles_oasis_service[]
char const sXML_export_impress_content_oasis_service[]
char const sXML_import_draw_meta_oasis_service[]
static XML_SERVICES const * getServices(bool bImport, bool bDraw, sal_uLong nStoreVer)
char const sXML_import_impress_meta_oasis_service[]
char const sXML_import_draw_content_ooo_service[]
char const sXML_import_draw_meta_ooo_service[]
char const sXML_export_impress_settings_oasis_service[]
char const sXML_import_draw_styles_oasis_service[]
char const sXML_import_impress_settings_ooo_service[]
char const sXML_export_impress_styles_oasis_service[]
char const sXML_import_impress_meta_ooo_service[]
char const sXML_import_impress_settings_oasis_service[]
char const sXML_import_impress_content_oasis_service[]
static void fixupOutlinePlaceholderNumberingDepths(SdDrawDocument *pDoc)
char const sXML_import_draw_content_oasis_service[]
char const sXML_export_draw_styles_oasis_service[]
char const sXML_import_impress_content_ooo_service[]
char const sXML_import_draw_settings_ooo_service[]
char const sXML_import_impress_styles_ooo_service[]
char const sXML_export_impress_meta_oasis_service[]
char const sXML_export_draw_meta_oasis_service[]
@ Organizer
only for import, only the styles are loaded
#define ERRCODE_SFX_WRONGPASSWORD
Reference< XModel > xModel