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