Bump version to 6.4.0.12
[LibreOffice.git] / xmloff / source / meta / MetaExportComponent.cxx
blobeeb9a97882d776ab5eaf096a49e0947d5384793b
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 <facreg.hxx>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/uno/Exception.hpp>
27 #include <com/sun/star/util/MeasureUnit.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <comphelper/genericpropertyset.hxx>
32 #include <comphelper/propertysetinfo.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <osl/diagnose.h>
35 #include <xmloff/xmlnmspe.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmlmetae.hxx>
39 #include <PropertySetMerger.hxx>
41 #include <unotools/docinfohelper.hxx>
44 using namespace ::com::sun::star;
45 using namespace ::xmloff::token;
47 XMLMetaExportComponent::XMLMetaExportComponent(
48 const css::uno::Reference< css::uno::XComponentContext >& xContext,
49 OUString const & implementationName, SvXMLExportFlags nFlags )
50 : SvXMLExport( util::MeasureUnit::CM, xContext, implementationName, XML_TEXT, nFlags )
54 XMLMetaExportComponent::~XMLMetaExportComponent()
58 void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
60 try
62 SvXMLExport::setSourceDocument( xDoc );
64 catch( lang::IllegalArgumentException& )
66 // allow to use document properties service without model access
67 // this is required for document properties exporter
68 mxDocProps =
69 uno::Reference< document::XDocumentProperties >::query( xDoc );
70 if( !mxDocProps.is() )
71 throw lang::IllegalArgumentException();
75 ErrCode XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
77 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
79 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
81 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
82 try
84 ::comphelper::PropertyMapEntry const aInfoMap[] =
86 { OUString("Class"), 0,
87 ::cppu::UnoType<OUString>::get(),
88 beans::PropertyAttribute::MAYBEVOID, 0},
89 { OUString(), 0, css::uno::Type(), 0, 0 }
91 uno::Reference< beans::XPropertySet > xConvPropSet(
92 ::comphelper::GenericPropertySet_CreateInstance(
93 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
95 xConvPropSet->setPropertyValue("Class", uno::Any(GetXMLToken( XML_TEXT )) );
97 uno::Reference< beans::XPropertySet > xPropSet =
98 getExportInfo().is()
99 ? PropertySetMerger_CreateInstance( getExportInfo(),
100 xConvPropSet )
101 : getExportInfo();
103 uno::Sequence< uno::Any > aArgs( 3 );
104 aArgs[0] <<= xDocHandler;
105 aArgs[1] <<= xPropSet;
106 aArgs[2] <<= GetModel();
108 // get filter component
109 xDocHandler.set(
110 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
111 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
112 uno::UNO_QUERY_THROW );
114 SetDocHandler( xDocHandler );
116 catch( css::uno::Exception& )
118 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!");
123 xDocHandler->startDocument();
125 addChaffWhenEncryptedStorage();
129 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
130 sal_uInt16 nPos = rMap.GetFirstKey();
131 while( USHRT_MAX != nPos )
133 GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
134 nPos = GetNamespaceMap().GetNextKey( nPos );
137 const sal_Char* pVersion = nullptr;
138 switch( getDefaultVersion() )
140 case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
141 case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
142 case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
143 case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
144 case SvtSaveOptions::ODFVER_010: break;
146 default:
147 OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
150 if( pVersion )
151 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
152 OUString::createFromAscii(pVersion) );
154 SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
155 true, true );
157 // NB: office:meta is now written by _ExportMeta
158 ExportMeta_();
160 xDocHandler->endDocument();
161 return ERRCODE_NONE;
164 void XMLMetaExportComponent::ExportMeta_()
166 if (mxDocProps.is()) {
167 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
168 // update generator here
169 mxDocProps->setGenerator(generator);
170 rtl::Reference<SvXMLMetaExport> pMeta = new SvXMLMetaExport(*this, mxDocProps);
171 pMeta->Export();
172 } else {
173 SvXMLExport::ExportMeta_();
177 // methods without content:
178 void XMLMetaExportComponent::ExportAutoStyles_() {}
179 void XMLMetaExportComponent::ExportMasterStyles_() {}
180 void XMLMetaExportComponent::ExportContent_() {}
182 uno::Sequence< OUString > XMLMetaExportOOO_getSupportedServiceNames()
183 throw()
185 return uno::Sequence< OUString > { "com.sun.star.document.XMLMetaExporter" };
188 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
189 XMLMetaExportComponent_get_implementation(
190 css::uno::XComponentContext *context,
191 css::uno::Sequence<css::uno::Any> const &)
193 return cppu::acquire(new XMLMetaExportComponent(context, "XMLMetaExportComponent", SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
196 OUString XMLMetaExportOOO_getImplementationName() throw()
198 return "XMLMetaExportOOo";
201 uno::Reference< uno::XInterface > XMLMetaExportOOO_createInstance(
202 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
204 return static_cast<cppu::OWeakObject*>(new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), XMLMetaExportOOO_getImplementationName(), SvXMLExportFlags::META));
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */