bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / meta / MetaExportComponent.cxx
blobe67f3ba3867114cc8657969527a0b83e15f47902
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/frame/XModel.hpp>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Exception.hpp>
28 #include <com/sun/star/util/MeasureUnit.hpp>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <comphelper/genericpropertyset.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <xmloff/xmlnmspe.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlmetae.hxx>
37 #include "PropertySetMerger.hxx"
39 #include <unotools/docinfohelper.hxx>
42 using namespace ::com::sun::star;
43 using namespace ::xmloff::token;
45 XMLMetaExportComponent::XMLMetaExportComponent(
46 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
47 OUString const & implementationName, SvXMLExportFlags nFlags )
48 : SvXMLExport( util::MeasureUnit::CM, xContext, implementationName, XML_TEXT, nFlags )
52 XMLMetaExportComponent::~XMLMetaExportComponent()
56 void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
58 try
60 SvXMLExport::setSourceDocument( xDoc );
62 catch( lang::IllegalArgumentException& )
64 // allow to use document properties service without model access
65 // this is required for document properties exporter
66 mxDocProps =
67 uno::Reference< document::XDocumentProperties >::query( xDoc );
68 if( !mxDocProps.is() )
69 throw lang::IllegalArgumentException();
73 sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
75 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
77 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
79 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
80 try
82 ::comphelper::PropertyMapEntry const aInfoMap[] =
84 { OUString("Class"), 0,
85 ::cppu::UnoType<OUString>::get(),
86 beans::PropertyAttribute::MAYBEVOID, 0},
87 { OUString(), 0, css::uno::Type(), 0, 0 }
89 uno::Reference< beans::XPropertySet > xConvPropSet(
90 ::comphelper::GenericPropertySet_CreateInstance(
91 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
93 uno::Any aAny;
94 aAny <<= GetXMLToken( XML_TEXT );
95 xConvPropSet->setPropertyValue(
96 OUString("Class"), aAny );
98 uno::Reference< beans::XPropertySet > xPropSet =
99 getExportInfo().is()
100 ? PropertySetMerger_CreateInstance( getExportInfo(),
101 xConvPropSet )
102 : getExportInfo();
104 uno::Sequence< uno::Any > aArgs( 3 );
105 aArgs[0] <<= xDocHandler;
106 aArgs[1] <<= xPropSet;
107 aArgs[2] <<= GetModel();
109 // get filter component
110 xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
111 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
112 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
113 uno::UNO_QUERY_THROW );
115 SetDocHandler( xDocHandler );
117 catch( com::sun::star::uno::Exception& )
119 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
124 xDocHandler->startDocument();
126 addChaffWhenEncryptedStorage();
130 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
131 sal_uInt16 nPos = rMap.GetFirstKey();
132 while( USHRT_MAX != nPos )
134 GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
135 nPos = GetNamespaceMap().GetNextKey( nPos );
138 const sal_Char* pVersion = 0;
139 switch( getDefaultVersion() )
141 case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
142 case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
143 case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
144 case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
145 case SvtSaveOptions::ODFVER_010: break;
147 default:
148 OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
151 if( pVersion )
152 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
153 OUString::createFromAscii(pVersion) );
155 SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
156 true, true );
158 // NB: office:meta is now written by _ExportMeta
159 _ExportMeta();
161 xDocHandler->endDocument();
162 return 0;
165 void XMLMetaExportComponent::_ExportMeta()
167 if (mxDocProps.is()) {
168 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
169 // update generator here
170 mxDocProps->setGenerator(generator);
171 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
172 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
173 pMeta->Export();
174 } else {
175 SvXMLExport::_ExportMeta();
179 // methods without content:
180 void XMLMetaExportComponent::_ExportAutoStyles() {}
181 void XMLMetaExportComponent::_ExportMasterStyles() {}
182 void XMLMetaExportComponent::_ExportContent() {}
185 uno::Sequence< OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
186 throw()
188 const OUString aServiceName(
189 "com.sun.star.document.XMLOasisMetaExporter" );
190 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
191 return aSeq;
194 OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
196 return OUString( "XMLMetaExportComponent" );
199 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
200 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
201 throw( uno::Exception )
203 return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), XMLMetaExportComponent_getImplementationName(), SvXMLExportFlags::META|SvXMLExportFlags::OASIS);
206 uno::Sequence< OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
207 throw()
209 const OUString aServiceName(
210 "com.sun.star.document.XMLMetaExporter" );
211 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
212 return aSeq;
215 OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
217 return OUString( "XMLMetaExportOOo" );
220 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
221 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
222 throw( uno::Exception )
224 return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), XMLMetaExportOOO_getImplementationName(), SvXMLExportFlags::META);
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */