bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / meta / MetaExportComponent.cxx
blobb5ad3177e84bc98f0f7775cd1022184457532bf7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <MetaExportComponent.hxx>
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/uno/Exception.hpp>
25 #include <com/sun/star/util/MeasureUnit.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <comphelper/genericpropertyset.hxx>
30 #include <comphelper/propertysetinfo.hxx>
31 #include <osl/diagnose.h>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/namespacemap.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlmetae.hxx>
36 #include <PropertySetMerger.hxx>
38 #include <unotools/docinfohelper.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
44 XMLMetaExportComponent::XMLMetaExportComponent(
45 const css::uno::Reference< css::uno::XComponentContext >& xContext,
46 OUString const & implementationName, SvXMLExportFlags nFlags )
47 : SvXMLExport( xContext, implementationName, util::MeasureUnit::CM, XML_TEXT, nFlags )
51 XMLMetaExportComponent::~XMLMetaExportComponent()
55 void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
57 try
59 SvXMLExport::setSourceDocument( xDoc );
61 catch( lang::IllegalArgumentException& )
63 // allow to use document properties service without model access
64 // this is required for document properties exporter
65 mxDocProps =
66 uno::Reference< document::XDocumentProperties >::query( xDoc );
67 if( !mxDocProps.is() )
68 throw lang::IllegalArgumentException();
72 ErrCode XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
74 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
76 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
78 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
79 try
81 static const ::comphelper::PropertyMapEntry aInfoMap[] =
83 { OUString("Class"), 0,
84 ::cppu::UnoType<OUString>::get(),
85 beans::PropertyAttribute::MAYBEVOID, 0},
87 uno::Reference< beans::XPropertySet > xConvPropSet(
88 ::comphelper::GenericPropertySet_CreateInstance(
89 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
91 xConvPropSet->setPropertyValue("Class", uno::Any(GetXMLToken( XML_TEXT )) );
93 uno::Reference< beans::XPropertySet > xPropSet =
94 getExportInfo().is()
95 ? PropertySetMerger_CreateInstance( getExportInfo(),
96 xConvPropSet )
97 : getExportInfo();
99 uno::Sequence< uno::Any > aArgs{ uno::Any(xDocHandler), uno::Any(xPropSet),
100 uno::Any(GetModel()) };
102 // get filter component
103 xDocHandler.set(
104 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
105 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
106 uno::UNO_QUERY_THROW );
108 SetDocHandler( xDocHandler );
110 catch( css::uno::Exception& )
112 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!");
117 xDocHandler->startDocument();
119 addChaffWhenEncryptedStorage();
123 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
124 sal_uInt16 nPos = rMap.GetFirstKey();
125 while( USHRT_MAX != nPos )
127 GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
128 nPos = GetNamespaceMap().GetNextKey( nPos );
131 const char*const pVersion = GetODFVersionAttributeValue();
133 if( pVersion )
134 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
135 OUString::createFromAscii(pVersion) );
137 SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
138 true, true );
140 // NB: office:meta is now written by _ExportMeta
141 ExportMeta_();
143 xDocHandler->endDocument();
144 return ERRCODE_NONE;
147 void XMLMetaExportComponent::ExportMeta_()
149 if (mxDocProps.is()) {
150 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
151 // update generator here
152 mxDocProps->setGenerator(generator);
153 rtl::Reference<SvXMLMetaExport> pMeta = new SvXMLMetaExport(*this, mxDocProps);
154 pMeta->Export();
155 } else {
156 SvXMLExport::ExportMeta_();
160 // methods without content:
161 void XMLMetaExportComponent::ExportAutoStyles_() {}
162 void XMLMetaExportComponent::ExportMasterStyles_() {}
163 void XMLMetaExportComponent::ExportContent_() {}
165 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
166 XMLMetaExportComponent_get_implementation(
167 css::uno::XComponentContext *context,
168 css::uno::Sequence<css::uno::Any> const &)
170 return cppu::acquire(new XMLMetaExportComponent(context, "XMLMetaExportComponent", SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
173 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
174 XMLMetaExportOOo_get_implementation(css::uno::XComponentContext* context,
175 css::uno::Sequence<css::uno::Any> const&)
177 return cppu::acquire(
178 new XMLMetaExportComponent(context, "XMLMetaExportOOo", SvXMLExportFlags::META));
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */