2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-02-06 13:51:28 +00:00
|
|
|
|
|
|
|
#include "MetaExportComponent.hxx"
|
|
|
|
#include <com/sun/star/frame/XModel.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/uno/Exception.hpp>
|
2011-10-11 14:19:09 +02:00
|
|
|
#include <com/sun/star/util/MeasureUnit.hpp>
|
2006-11-01 13:50:39 +00:00
|
|
|
#include <com/sun/star/beans/PropertyAttribute.hpp>
|
|
|
|
#include <comphelper/genericpropertyset.hxx>
|
2013-01-16 17:12:47 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2001-02-06 13:51:28 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <xmloff/xmlnmspe.hxx>
|
2007-06-27 14:18:54 +00:00
|
|
|
#include <xmloff/nmspmap.hxx>
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <xmloff/xmlmetae.hxx>
|
2006-11-01 13:50:39 +00:00
|
|
|
#include "PropertySetMerger.hxx"
|
2001-02-06 13:51:28 +00:00
|
|
|
|
2008-02-26 12:37:31 +00:00
|
|
|
#include <unotools/docinfohelper.hxx>
|
|
|
|
|
2001-02-06 13:51:28 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2001-06-18 14:08:14 +00:00
|
|
|
using namespace ::xmloff::token;
|
2001-02-06 13:51:28 +00:00
|
|
|
|
2004-05-03 12:35:45 +00:00
|
|
|
XMLMetaExportComponent::XMLMetaExportComponent(
|
2013-01-16 17:12:47 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
|
2004-08-20 07:14:39 +00:00
|
|
|
sal_uInt16 nFlags )
|
2013-01-16 17:12:47 +02:00
|
|
|
: SvXMLExport( util::MeasureUnit::CM, xContext, XML_TEXT, nFlags )
|
2001-02-06 13:51:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLMetaExportComponent::~XMLMetaExportComponent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-11-01 13:50:39 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SvXMLExport::setSourceDocument( xDoc );
|
|
|
|
}
|
|
|
|
catch( lang::IllegalArgumentException& )
|
|
|
|
{
|
2008-02-26 12:37:31 +00:00
|
|
|
// allow to use document properties service without model access
|
|
|
|
// this is required for document properties exporter
|
|
|
|
mxDocProps =
|
|
|
|
uno::Reference< document::XDocumentProperties >::query( xDoc );
|
|
|
|
if( !mxDocProps.is() )
|
2006-11-01 13:50:39 +00:00
|
|
|
throw lang::IllegalArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 17:21:14 +00:00
|
|
|
sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
|
2001-02-06 13:51:28 +00:00
|
|
|
{
|
2006-11-01 13:50:39 +00:00
|
|
|
uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
|
|
|
|
|
|
|
|
if( (getExportFlags() & EXPORT_OASIS) == 0 )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
uno::Reference< uno::XComponentContext > xContext = getComponentContext();
|
|
|
|
try
|
2006-11-01 13:50:39 +00:00
|
|
|
{
|
2013-12-11 15:16:51 +01:00
|
|
|
::comphelper::PropertyMapEntry const aInfoMap[] =
|
2006-11-01 13:50:39 +00:00
|
|
|
{
|
2013-12-11 15:16:51 +01:00
|
|
|
{ OUString("Class"), 0,
|
|
|
|
::getCppuType((OUString*)0),
|
2013-01-16 17:12:47 +02:00
|
|
|
beans::PropertyAttribute::MAYBEVOID, 0},
|
2013-12-11 15:16:51 +01:00
|
|
|
{ OUString(), 0, css::uno::Type(), 0, 0 }
|
2013-01-16 17:12:47 +02:00
|
|
|
};
|
|
|
|
uno::Reference< beans::XPropertySet > xConvPropSet(
|
|
|
|
::comphelper::GenericPropertySet_CreateInstance(
|
|
|
|
new ::comphelper::PropertySetInfo( aInfoMap ) ) );
|
|
|
|
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= GetXMLToken( XML_TEXT );
|
|
|
|
xConvPropSet->setPropertyValue(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString("Class"), aAny );
|
2013-01-16 17:12:47 +02:00
|
|
|
|
|
|
|
uno::Reference< beans::XPropertySet > xPropSet =
|
|
|
|
getExportInfo().is()
|
|
|
|
? PropertySetMerger_CreateInstance( getExportInfo(),
|
|
|
|
xConvPropSet )
|
|
|
|
: getExportInfo();
|
|
|
|
|
|
|
|
uno::Sequence< uno::Any > aArgs( 3 );
|
|
|
|
aArgs[0] <<= xDocHandler;
|
|
|
|
aArgs[1] <<= xPropSet;
|
|
|
|
aArgs[2] <<= GetModel();
|
|
|
|
|
|
|
|
// get filter component
|
|
|
|
xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
|
|
|
|
xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
|
|
|
|
"com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
|
|
|
|
uno::UNO_QUERY_THROW );
|
|
|
|
|
|
|
|
SetDocHandler( xDocHandler );
|
|
|
|
}
|
|
|
|
catch( com::sun::star::uno::Exception& )
|
|
|
|
{
|
|
|
|
OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
|
2006-11-01 13:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xDocHandler->startDocument();
|
2011-09-08 13:50:30 +01:00
|
|
|
|
|
|
|
addChaffWhenEncryptedStorage();
|
|
|
|
|
2001-02-06 13:51:28 +00:00
|
|
|
{
|
2010-10-18 19:37:48 +01:00
|
|
|
|
2009-04-23 10:42:05 +00:00
|
|
|
const SvXMLNamespaceMap& rMap = GetNamespaceMap();
|
|
|
|
sal_uInt16 nPos = rMap.GetFirstKey();
|
2006-11-01 13:50:39 +00:00
|
|
|
while( USHRT_MAX != nPos )
|
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
|
2006-11-01 13:50:39 +00:00
|
|
|
nPos = GetNamespaceMap().GetNextKey( nPos );
|
|
|
|
}
|
|
|
|
|
2008-04-15 13:10:55 +00:00
|
|
|
const sal_Char* pVersion = 0;
|
|
|
|
switch( getDefaultVersion() )
|
|
|
|
{
|
2009-09-16 13:55:36 +00:00
|
|
|
case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
|
2012-06-05 03:59:46 +02:00
|
|
|
case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
|
2008-04-15 13:10:55 +00:00
|
|
|
case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
|
|
|
|
case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
|
|
|
|
case SvtSaveOptions::ODFVER_010: break;
|
|
|
|
|
|
|
|
default:
|
2011-03-01 19:07:44 +01:00
|
|
|
OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
|
2008-04-15 13:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( pVersion )
|
|
|
|
AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString::createFromAscii(pVersion) );
|
2001-02-06 14:24:06 +00:00
|
|
|
|
2012-11-03 18:35:52 +01:00
|
|
|
SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
|
|
|
|
sal_True, sal_True );
|
2001-03-02 16:24:39 +00:00
|
|
|
|
2008-02-26 12:37:31 +00:00
|
|
|
// NB: office:meta is now written by _ExportMeta
|
|
|
|
_ExportMeta();
|
2001-02-06 13:51:28 +00:00
|
|
|
}
|
2006-11-01 13:50:39 +00:00
|
|
|
xDocHandler->endDocument();
|
2001-02-06 13:51:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-26 12:37:31 +00:00
|
|
|
void XMLMetaExportComponent::_ExportMeta()
|
|
|
|
{
|
|
|
|
if (mxDocProps.is()) {
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
|
2008-02-26 12:37:31 +00:00
|
|
|
// update generator here
|
|
|
|
mxDocProps->setGenerator(generator);
|
|
|
|
SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
|
|
|
|
uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
|
|
|
|
pMeta->Export();
|
|
|
|
} else {
|
|
|
|
SvXMLExport::_ExportMeta();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-06 13:51:28 +00:00
|
|
|
// methods without content:
|
|
|
|
void XMLMetaExportComponent::_ExportAutoStyles() {}
|
|
|
|
void XMLMetaExportComponent::_ExportMasterStyles() {}
|
|
|
|
void XMLMetaExportComponent::_ExportContent() {}
|
|
|
|
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
uno::Sequence< OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
|
2001-02-06 13:51:28 +00:00
|
|
|
throw()
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString aServiceName(
|
2012-05-29 20:59:45 -05:00
|
|
|
"com.sun.star.document.XMLOasisMetaExporter" );
|
2013-04-07 12:06:47 +02:00
|
|
|
const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
|
2001-02-06 13:51:28 +00:00
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
|
2001-02-06 13:51:28 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString( "XMLMetaExportComponent" );
|
2001-02-06 13:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
|
|
|
|
const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
|
|
|
|
throw( uno::Exception )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), EXPORT_META|EXPORT_OASIS);
|
2004-08-20 07:14:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
uno::Sequence< OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
|
2004-08-20 07:14:39 +00:00
|
|
|
throw()
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString aServiceName(
|
2012-05-29 20:59:45 -05:00
|
|
|
"com.sun.star.document.XMLMetaExporter" );
|
2013-04-07 12:06:47 +02:00
|
|
|
const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
|
2004-08-20 07:14:39 +00:00
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
|
2004-08-20 07:14:39 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString( "XMLMetaExportOOo" );
|
2004-08-20 07:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
|
|
|
|
const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
|
|
|
|
throw( uno::Exception )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
return (cppu::OWeakObject*)new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), EXPORT_META);
|
2001-02-06 13:51:28 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|