bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / meta / MetaExportComponent.cxx
blob72ea7bd85244ff8256327b7c8a5fcb864bfe5dd2
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/frame/XModel.hpp>
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 <comphelper/genericpropertyset.hxx>
30 #include <comphelper/processfactory.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/nmspmap.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 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
46 sal_uInt16 nFlags )
47 : SvXMLExport( util::MeasureUnit::CM, xContext, XML_TEXT, nFlags )
51 XMLMetaExportComponent::~XMLMetaExportComponent()
55 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)
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 sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
74 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
76 if( (getExportFlags() & EXPORT_OASIS) == 0 )
78 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
79 try
81 ::comphelper::PropertyMapEntry aInfoMap[] =
83 { "Class", sizeof("Class")-1, 0,
84 &::getCppuType((OUString*)0),
85 beans::PropertyAttribute::MAYBEVOID, 0},
86 { NULL, 0, 0, NULL, 0, 0 }
88 uno::Reference< beans::XPropertySet > xConvPropSet(
89 ::comphelper::GenericPropertySet_CreateInstance(
90 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
92 uno::Any aAny;
93 aAny <<= GetXMLToken( XML_TEXT );
94 xConvPropSet->setPropertyValue(
95 OUString("Class"), aAny );
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 = uno::Reference< xml::sax::XDocumentHandler >(
110 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
111 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
112 uno::UNO_QUERY_THROW );
114 SetDocHandler( xDocHandler );
116 catch( com::sun::star::uno::Exception& )
118 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
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 = 0;
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 sal_True, sal_True );
157 // NB: office:meta is now written by _ExportMeta
158 _ExportMeta();
160 xDocHandler->endDocument();
161 return 0;
164 void XMLMetaExportComponent::_ExportMeta()
166 if (mxDocProps.is()) {
167 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
168 // update generator here
169 mxDocProps->setGenerator(generator);
170 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
171 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
172 pMeta->Export();
173 } else {
174 SvXMLExport::_ExportMeta();
178 // methods without content:
179 void XMLMetaExportComponent::_ExportAutoStyles() {}
180 void XMLMetaExportComponent::_ExportMasterStyles() {}
181 void XMLMetaExportComponent::_ExportContent() {}
184 uno::Sequence< OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
185 throw()
187 const OUString aServiceName(
188 "com.sun.star.document.XMLOasisMetaExporter" );
189 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
190 return aSeq;
193 OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
195 return OUString( "XMLMetaExportComponent" );
198 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
199 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
200 throw( uno::Exception )
202 return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), EXPORT_META|EXPORT_OASIS);
205 uno::Sequence< OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
206 throw()
208 const OUString aServiceName(
209 "com.sun.star.document.XMLMetaExporter" );
210 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
211 return aSeq;
214 OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
216 return OUString( "XMLMetaExportOOo" );
219 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
220 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
221 throw( uno::Exception )
223 return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), EXPORT_META);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */