merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / meta / MetaExportComponent.cxx
blob9ad2b841cf80f8345e02714dd4746b0fa2a75abc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MetaExportComponent.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "MetaExportComponent.hxx"
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include <com/sun/star/uno/Reference.hxx>
40 #ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP
41 #include <com/sun/star/uno/Exception.hpp>
42 #endif
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 // #110680#
46 //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
47 //#include <comphelper/processfactory.hxx>
48 //#endif
49 #include <comphelper/genericpropertyset.hxx>
50 #include <rtl/ustrbuf.hxx>
51 #include "xmlnmspe.hxx"
52 #include <xmloff/nmspmap.hxx>
53 #include <xmloff/xmltoken.hxx>
54 #include <xmloff/xmlmetae.hxx>
55 #include "PropertySetMerger.hxx"
56 #include <tools/debug.hxx>
58 #include <unotools/docinfohelper.hxx>
61 using namespace ::com::sun::star;
62 using namespace ::xmloff::token;
64 // #110680#
65 XMLMetaExportComponent::XMLMetaExportComponent(
66 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
67 sal_uInt16 nFlags )
68 : SvXMLExport( xServiceFactory, MAP_INCH, XML_TEXT, nFlags )
72 XMLMetaExportComponent::~XMLMetaExportComponent()
76 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)
78 try
80 SvXMLExport::setSourceDocument( xDoc );
82 catch( lang::IllegalArgumentException& )
84 // allow to use document properties service without model access
85 // this is required for document properties exporter
86 mxDocProps =
87 uno::Reference< document::XDocumentProperties >::query( xDoc );
88 if( !mxDocProps.is() )
89 throw lang::IllegalArgumentException();
93 sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
95 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
97 if( (getExportFlags() & EXPORT_OASIS) == 0 )
99 uno::Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
100 if( xFactory.is() )
104 ::comphelper::PropertyMapEntry aInfoMap[] =
106 { "Class", sizeof("Class")-1, 0,
107 &::getCppuType((::rtl::OUString*)0),
108 beans::PropertyAttribute::MAYBEVOID, 0},
109 { NULL, 0, 0, NULL, 0, 0 }
111 uno::Reference< beans::XPropertySet > xConvPropSet(
112 ::comphelper::GenericPropertySet_CreateInstance(
113 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
115 uno::Any aAny;
116 aAny <<= GetXMLToken( XML_TEXT );
117 xConvPropSet->setPropertyValue(
118 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Class")), aAny );
120 uno::Reference< beans::XPropertySet > xPropSet =
121 getExportInfo().is()
122 ? PropertySetMerger_CreateInstance( getExportInfo(),
123 xConvPropSet )
124 : getExportInfo();
126 uno::Sequence< uno::Any > aArgs( 3 );
127 aArgs[0] <<= xDocHandler;
128 aArgs[1] <<= xPropSet;
129 aArgs[2] <<= GetModel();
131 // get filter component
132 xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
133 xFactory->createInstanceWithArguments(
134 ::rtl::OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"),
135 aArgs),
136 uno::UNO_QUERY_THROW );
138 SetDocHandler( xDocHandler );
140 catch( com::sun::star::uno::Exception& )
142 OSL_ENSURE( sal_False, "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
148 xDocHandler->startDocument();
150 #if 0
151 GetAttrList().AddAttribute(
152 GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_DC ),
153 GetNamespaceMap().GetNameByKey( XML_NAMESPACE_DC ) );
154 GetAttrList().AddAttribute(
155 GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_META ),
156 GetNamespaceMap().GetNameByKey( XML_NAMESPACE_META ) );
157 GetAttrList().AddAttribute(
158 GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_OFFICE ),
159 GetNamespaceMap().GetNameByKey( XML_NAMESPACE_OFFICE ) );
160 #else
161 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
162 sal_uInt16 nPos = rMap.GetFirstKey();
163 while( USHRT_MAX != nPos )
165 GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
166 nPos = GetNamespaceMap().GetNextKey( nPos );
168 #endif
170 const sal_Char* pVersion = 0;
171 switch( getDefaultVersion() )
173 case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
174 case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
175 case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
176 case SvtSaveOptions::ODFVER_010: break;
178 default:
179 DBG_ERROR("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
182 if( pVersion )
183 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
184 ::rtl::OUString::createFromAscii(pVersion) );
186 SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
187 sal_True, sal_True );
189 // NB: office:meta is now written by _ExportMeta
190 _ExportMeta();
192 xDocHandler->endDocument();
193 return 0;
196 void XMLMetaExportComponent::_ExportMeta()
198 if (mxDocProps.is()) {
199 ::rtl::OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
200 // update generator here
201 mxDocProps->setGenerator(generator);
202 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
203 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
204 pMeta->Export();
205 } else {
206 SvXMLExport::_ExportMeta();
210 // methods without content:
211 void XMLMetaExportComponent::_ExportAutoStyles() {}
212 void XMLMetaExportComponent::_ExportMasterStyles() {}
213 void XMLMetaExportComponent::_ExportContent() {}
216 uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
217 throw()
219 const rtl::OUString aServiceName(
220 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisMetaExporter" ) );
221 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
222 return aSeq;
225 rtl::OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
227 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaExportComponent" ) );
230 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
231 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
232 throw( uno::Exception )
234 // #110680#
235 // return (cppu::OWeakObject*)new XMLMetaExportComponent;
236 return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META|EXPORT_OASIS);
239 uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
240 throw()
242 const rtl::OUString aServiceName(
243 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLMetaExporter" ) );
244 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
245 return aSeq;
248 rtl::OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
250 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaExportOOo" ) );
253 uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
254 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
255 throw( uno::Exception )
257 // #110680#
258 // return (cppu::OWeakObject*)new XMLMetaExportComponent;
259 return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META);