1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include "MetaExportComponent.hxx" 27cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 31cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP 34cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp> 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir // #110680# 39cdf0e10cSrcweir //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ 40cdf0e10cSrcweir //#include <comphelper/processfactory.hxx> 41cdf0e10cSrcweir //#endif 42cdf0e10cSrcweir #include <comphelper/genericpropertyset.hxx> 43cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 44cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 45cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 46cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 47cdf0e10cSrcweir #include <xmloff/xmlmetae.hxx> 48cdf0e10cSrcweir #include "PropertySetMerger.hxx" 49cdf0e10cSrcweir #include <tools/debug.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <unotools/docinfohelper.hxx> 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir using namespace ::com::sun::star; 55cdf0e10cSrcweir using namespace ::xmloff::token; 56cdf0e10cSrcweir 57cdf0e10cSrcweir // #110680# 58cdf0e10cSrcweir XMLMetaExportComponent::XMLMetaExportComponent( 59cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, 60cdf0e10cSrcweir sal_uInt16 nFlags ) 61cdf0e10cSrcweir : SvXMLExport( xServiceFactory, MAP_INCH, XML_TEXT, nFlags ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir XMLMetaExportComponent::~XMLMetaExportComponent() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir 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) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir try 72cdf0e10cSrcweir { 73cdf0e10cSrcweir SvXMLExport::setSourceDocument( xDoc ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir catch( lang::IllegalArgumentException& ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // allow to use document properties service without model access 78cdf0e10cSrcweir // this is required for document properties exporter 79cdf0e10cSrcweir mxDocProps = 80cdf0e10cSrcweir uno::Reference< document::XDocumentProperties >::query( xDoc ); 81cdf0e10cSrcweir if( !mxDocProps.is() ) 82cdf0e10cSrcweir throw lang::IllegalArgumentException(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir if( (getExportFlags() & EXPORT_OASIS) == 0 ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory(); 93cdf0e10cSrcweir if( xFactory.is() ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir try 96cdf0e10cSrcweir { 97cdf0e10cSrcweir ::comphelper::PropertyMapEntry aInfoMap[] = 98cdf0e10cSrcweir { 99cdf0e10cSrcweir { "Class", sizeof("Class")-1, 0, 100cdf0e10cSrcweir &::getCppuType((::rtl::OUString*)0), 101cdf0e10cSrcweir beans::PropertyAttribute::MAYBEVOID, 0}, 102cdf0e10cSrcweir { NULL, 0, 0, NULL, 0, 0 } 103cdf0e10cSrcweir }; 104cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xConvPropSet( 105cdf0e10cSrcweir ::comphelper::GenericPropertySet_CreateInstance( 106cdf0e10cSrcweir new ::comphelper::PropertySetInfo( aInfoMap ) ) ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir uno::Any aAny; 109cdf0e10cSrcweir aAny <<= GetXMLToken( XML_TEXT ); 110cdf0e10cSrcweir xConvPropSet->setPropertyValue( 111cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Class")), aAny ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet = 114cdf0e10cSrcweir getExportInfo().is() 115cdf0e10cSrcweir ? PropertySetMerger_CreateInstance( getExportInfo(), 116cdf0e10cSrcweir xConvPropSet ) 117cdf0e10cSrcweir : getExportInfo(); 118cdf0e10cSrcweir 119cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 3 ); 120cdf0e10cSrcweir aArgs[0] <<= xDocHandler; 121cdf0e10cSrcweir aArgs[1] <<= xPropSet; 122cdf0e10cSrcweir aArgs[2] <<= GetModel(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir // get filter component 125cdf0e10cSrcweir xDocHandler = uno::Reference< xml::sax::XDocumentHandler >( 126cdf0e10cSrcweir xFactory->createInstanceWithArguments( 127cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"), 128cdf0e10cSrcweir aArgs), 129cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir SetDocHandler( xDocHandler ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir catch( com::sun::star::uno::Exception& ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir OSL_ENSURE( sal_False, "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n"); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir xDocHandler->startDocument(); 142cdf0e10cSrcweir { 143cdf0e10cSrcweir #if 0 144cdf0e10cSrcweir GetAttrList().AddAttribute( 145cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_DC ), 146cdf0e10cSrcweir GetNamespaceMap().GetNameByKey( XML_NAMESPACE_DC ) ); 147cdf0e10cSrcweir GetAttrList().AddAttribute( 148cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_META ), 149cdf0e10cSrcweir GetNamespaceMap().GetNameByKey( XML_NAMESPACE_META ) ); 150cdf0e10cSrcweir GetAttrList().AddAttribute( 151cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByKey( XML_NAMESPACE_OFFICE ), 152cdf0e10cSrcweir GetNamespaceMap().GetNameByKey( XML_NAMESPACE_OFFICE ) ); 153cdf0e10cSrcweir #else 154cdf0e10cSrcweir const SvXMLNamespaceMap& rMap = GetNamespaceMap(); 155cdf0e10cSrcweir sal_uInt16 nPos = rMap.GetFirstKey(); 156cdf0e10cSrcweir while( USHRT_MAX != nPos ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) ); 159cdf0e10cSrcweir nPos = GetNamespaceMap().GetNextKey( nPos ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir #endif 162cdf0e10cSrcweir 163cdf0e10cSrcweir const sal_Char* pVersion = 0; 164cdf0e10cSrcweir switch( getDefaultVersion() ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break; 167cdf0e10cSrcweir case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break; 168cdf0e10cSrcweir case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break; 169cdf0e10cSrcweir case SvtSaveOptions::ODFVER_010: break; 170cdf0e10cSrcweir 171cdf0e10cSrcweir default: 172cdf0e10cSrcweir DBG_ERROR("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!"); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir if( pVersion ) 176cdf0e10cSrcweir AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION, 177cdf0e10cSrcweir ::rtl::OUString::createFromAscii(pVersion) ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META, 180cdf0e10cSrcweir sal_True, sal_True ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir // NB: office:meta is now written by _ExportMeta 183cdf0e10cSrcweir _ExportMeta(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir xDocHandler->endDocument(); 186cdf0e10cSrcweir return 0; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir void XMLMetaExportComponent::_ExportMeta() 190cdf0e10cSrcweir { 191cdf0e10cSrcweir if (mxDocProps.is()) { 192cdf0e10cSrcweir ::rtl::OUString generator( ::utl::DocInfoHelper::GetGeneratorString() ); 193cdf0e10cSrcweir // update generator here 194cdf0e10cSrcweir mxDocProps->setGenerator(generator); 195cdf0e10cSrcweir SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps); 196cdf0e10cSrcweir uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta); 197cdf0e10cSrcweir pMeta->Export(); 198cdf0e10cSrcweir } else { 199cdf0e10cSrcweir SvXMLExport::_ExportMeta(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir // methods without content: 204cdf0e10cSrcweir void XMLMetaExportComponent::_ExportAutoStyles() {} 205cdf0e10cSrcweir void XMLMetaExportComponent::_ExportMasterStyles() {} 206cdf0e10cSrcweir void XMLMetaExportComponent::_ExportContent() {} 207cdf0e10cSrcweir 208cdf0e10cSrcweir 209cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames() 210cdf0e10cSrcweir throw() 211cdf0e10cSrcweir { 212cdf0e10cSrcweir const rtl::OUString aServiceName( 213cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisMetaExporter" ) ); 214cdf0e10cSrcweir const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); 215cdf0e10cSrcweir return aSeq; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir rtl::OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw() 219cdf0e10cSrcweir { 220cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaExportComponent" ) ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance( 224cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & rSMgr) 225cdf0e10cSrcweir throw( uno::Exception ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir // #110680# 228cdf0e10cSrcweir // return (cppu::OWeakObject*)new XMLMetaExportComponent; 229cdf0e10cSrcweir return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META|EXPORT_OASIS); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames() 233cdf0e10cSrcweir throw() 234cdf0e10cSrcweir { 235cdf0e10cSrcweir const rtl::OUString aServiceName( 236cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLMetaExporter" ) ); 237cdf0e10cSrcweir const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); 238cdf0e10cSrcweir return aSeq; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir rtl::OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaExportOOo" ) ); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance( 247cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & rSMgr) 248cdf0e10cSrcweir throw( uno::Exception ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir // #110680# 251cdf0e10cSrcweir // return (cppu::OWeakObject*)new XMLMetaExportComponent; 252cdf0e10cSrcweir return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255