2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-10-11 06:51:24 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
2008-04-10 21:31:00 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-10-11 06:51:24 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2007-06-27 14:33:37 +00:00
|
|
|
#include <xmloff/XMLPageExport.hxx>
|
2000-10-11 06:51:24 +00:00
|
|
|
#include <tools/debug.hxx>
|
2010-04-16 23:04:00 +02:00
|
|
|
#include "xmloff/xmlnmspe.hxx"
|
2007-06-27 14:33:37 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2000-10-11 06:51:24 +00:00
|
|
|
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
|
|
|
|
#include <com/sun/star/style/XStyle.hpp>
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#include <com/sun/star/container/XIndexReplace.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2007-06-27 14:33:37 +00:00
|
|
|
#include <xmloff/families.hxx>
|
|
|
|
#include <xmloff/xmlexp.hxx>
|
2000-10-19 12:42:08 +00:00
|
|
|
#include "PageMasterPropHdlFactory.hxx"
|
2007-06-27 14:33:37 +00:00
|
|
|
#include <xmloff/PageMasterStyleMap.hxx>
|
2000-10-18 10:32:20 +00:00
|
|
|
#include "PageMasterPropMapper.hxx"
|
2000-10-19 12:42:08 +00:00
|
|
|
#include "PageMasterExportPropMapper.hxx"
|
2000-10-20 04:36:28 +00:00
|
|
|
#include "PageMasterExportPropMapper.hxx"
|
2000-10-11 06:51:24 +00:00
|
|
|
|
2008-03-12 09:47:53 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2000-10-11 06:51:24 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::style;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::beans;
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-10-11 06:51:24 +00:00
|
|
|
|
2000-10-19 04:32:52 +00:00
|
|
|
|
|
|
|
//______________________________________________________________________________
|
|
|
|
|
|
|
|
sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
|
2000-10-11 06:51:24 +00:00
|
|
|
{
|
2000-10-19 04:32:52 +00:00
|
|
|
for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
|
2011-07-30 23:51:40 +02:00
|
|
|
pEntry != aNameVector.end(); ++pEntry )
|
2000-10-18 10:32:20 +00:00
|
|
|
{
|
2000-10-19 04:32:52 +00:00
|
|
|
if( pEntry->sStyleName == rStyleName )
|
2000-10-18 10:32:20 +00:00
|
|
|
{
|
2000-10-19 04:32:52 +00:00
|
|
|
rPMName = pEntry->sPageMasterName;
|
|
|
|
return sal_True;
|
2000-10-18 10:32:20 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-19 04:32:52 +00:00
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLPageExport::collectPageMasterAutoStyle(
|
|
|
|
const Reference < XPropertySet > & rPropSet,
|
|
|
|
OUString& rPageMasterName )
|
|
|
|
{
|
2000-11-07 12:33:09 +00:00
|
|
|
DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
|
|
|
|
if( xPageMasterPropSetMapper.is() )
|
2000-10-19 04:32:52 +00:00
|
|
|
{
|
2000-11-07 12:33:09 +00:00
|
|
|
::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
|
2007-07-06 08:44:13 +00:00
|
|
|
if( !xPropStates.empty())
|
2000-10-19 12:42:08 +00:00
|
|
|
{
|
|
|
|
OUString sParent;
|
|
|
|
rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
|
2012-01-25 21:59:48 -02:00
|
|
|
if (rPageMasterName.isEmpty())
|
2000-10-19 12:42:08 +00:00
|
|
|
rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
|
|
|
|
}
|
2000-10-19 04:32:52 +00:00
|
|
|
}
|
2000-10-11 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XMLPageExport::exportMasterPageContent(
|
2006-06-19 17:30:11 +00:00
|
|
|
const Reference < XPropertySet > &,
|
|
|
|
sal_Bool /*bAutoStyles*/ )
|
2000-10-11 06:51:24 +00:00
|
|
|
{
|
2000-10-18 10:32:20 +00:00
|
|
|
|
2000-10-11 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool XMLPageExport::exportStyle(
|
|
|
|
const Reference< XStyle >& rStyle,
|
|
|
|
sal_Bool bAutoStyles )
|
|
|
|
{
|
|
|
|
Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
|
|
|
|
Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
|
|
|
|
|
|
|
|
// Don't export styles that aren't existing really. This may be the
|
|
|
|
// case for StarOffice Writer's pool styles.
|
|
|
|
if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
|
|
|
|
{
|
2007-07-06 08:44:13 +00:00
|
|
|
Any aAny = xPropSet->getPropertyValue( sIsPhysical );
|
2000-10-11 06:51:24 +00:00
|
|
|
if( !*(sal_Bool *)aAny.getValue() )
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bAutoStyles )
|
|
|
|
{
|
2000-10-19 04:32:52 +00:00
|
|
|
XMLPageExportNameEntry aEntry;
|
|
|
|
collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
|
|
|
|
aEntry.sStyleName = rStyle->getName();
|
|
|
|
aNameVector.push_back( aEntry );
|
|
|
|
|
2000-10-11 06:51:24 +00:00
|
|
|
exportMasterPageContent( xPropSet, sal_True );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OUString sName( rStyle->getName() );
|
2004-07-13 07:23:05 +00:00
|
|
|
sal_Bool bEncoded = sal_False;
|
|
|
|
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
|
|
|
|
GetExport().EncodeStyleName( sName, &bEncoded ) );
|
|
|
|
|
|
|
|
if( bEncoded )
|
|
|
|
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
|
|
|
|
sName);
|
2000-10-11 06:51:24 +00:00
|
|
|
|
2000-10-19 04:32:52 +00:00
|
|
|
OUString sPMName;
|
|
|
|
if( findPageMasterName( sName, sPMName ) )
|
2004-07-13 07:23:05 +00:00
|
|
|
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
|
2000-10-19 04:32:52 +00:00
|
|
|
|
2007-07-06 08:44:13 +00:00
|
|
|
Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
|
|
|
|
if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
|
2000-10-11 06:51:24 +00:00
|
|
|
{
|
2007-07-06 08:44:13 +00:00
|
|
|
OUString sNextName;
|
|
|
|
xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
|
|
|
|
|
2012-01-25 21:59:48 -02:00
|
|
|
if( sName != sNextName && !sNextName.isEmpty() )
|
2007-07-06 08:44:13 +00:00
|
|
|
{
|
|
|
|
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
|
|
|
|
GetExport().EncodeStyleName( sNextName ) );
|
|
|
|
}
|
2000-10-11 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
|
2001-06-29 20:07:26 +00:00
|
|
|
XML_MASTER_PAGE, sal_True, sal_True );
|
2000-10-11 06:51:24 +00:00
|
|
|
|
|
|
|
exportMasterPageContent( xPropSet, sal_False );
|
|
|
|
}
|
|
|
|
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
|
|
|
|
rExport( rExp ),
|
|
|
|
sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
|
|
|
|
sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) )
|
|
|
|
{
|
2000-11-07 12:33:09 +00:00
|
|
|
xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
|
|
|
|
xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
|
|
|
|
(XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
|
|
|
|
xPageMasterPropHdlFactory );
|
|
|
|
xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
|
|
|
|
xPageMasterPropSetMapper, rExp);
|
2000-10-19 12:42:08 +00:00
|
|
|
|
|
|
|
rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ),
|
2000-11-07 12:33:09 +00:00
|
|
|
xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False );
|
2000-10-19 12:42:08 +00:00
|
|
|
|
2000-10-11 06:51:24 +00:00
|
|
|
Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
|
|
|
|
UNO_QUERY );
|
|
|
|
DBG_ASSERT( xFamiliesSupp.is(),
|
|
|
|
"No XStyleFamiliesSupplier from XModel for export!" );
|
|
|
|
if( xFamiliesSupp.is() )
|
|
|
|
{
|
|
|
|
Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
|
|
|
|
DBG_ASSERT( xFamiliesSupp.is(),
|
|
|
|
"getStyleFamilies() from XModel failed for export!" );
|
|
|
|
if( xFamilies.is() )
|
|
|
|
{
|
|
|
|
const OUString aPageStyleName(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ));
|
|
|
|
|
|
|
|
if( xFamilies->hasByName( aPageStyleName ) )
|
|
|
|
{
|
2007-07-06 08:44:13 +00:00
|
|
|
xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
|
2000-10-11 06:51:24 +00:00
|
|
|
|
|
|
|
DBG_ASSERT( xPageStyles.is(),
|
|
|
|
"Page Styles not found for export!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLPageExport::~XMLPageExport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles )
|
|
|
|
{
|
|
|
|
if( xPageStyles.is() )
|
|
|
|
{
|
2007-07-06 08:44:13 +00:00
|
|
|
uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames();
|
|
|
|
const ::rtl::OUString* pIter = aSeq.getConstArray();
|
|
|
|
const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
|
|
|
|
for(;pIter != pEnd;++pIter)
|
2000-10-11 06:51:24 +00:00
|
|
|
{
|
2007-07-06 08:44:13 +00:00
|
|
|
Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
|
2000-10-11 06:51:24 +00:00
|
|
|
if( !bUsed || xStyle->isInUse() )
|
|
|
|
exportStyle( xStyle, bAutoStyles );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-20 04:36:28 +00:00
|
|
|
void XMLPageExport::exportAutoStyles()
|
|
|
|
{
|
2001-10-25 19:57:03 +00:00
|
|
|
rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
|
|
|
|
, rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
|
|
|
|
rExport.GetNamespaceMap()
|
|
|
|
);
|
2000-10-20 04:36:28 +00:00
|
|
|
}
|
2008-03-07 15:17:58 +00:00
|
|
|
|
|
|
|
void XMLPageExport::exportDefaultStyle()
|
|
|
|
{
|
|
|
|
Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
|
|
|
|
if (xFactory.is())
|
|
|
|
{
|
|
|
|
OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
|
|
|
|
Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
|
|
|
|
if (xPropSet.is())
|
|
|
|
{
|
|
|
|
// <style:default-style ...>
|
|
|
|
GetExport().CheckAttrList();
|
|
|
|
|
|
|
|
::std::vector< XMLPropertyState > xPropStates =
|
|
|
|
xPageMasterExportPropMapper->FilterDefaults( xPropSet );
|
|
|
|
|
|
|
|
sal_Bool bExport = sal_False;
|
|
|
|
UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
|
|
|
|
for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
|
|
|
|
{
|
|
|
|
XMLPropertyState *pProp = &(*aIter);
|
|
|
|
sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
|
|
|
|
if( nContextId == CTF_PM_STANDARD_MODE )
|
|
|
|
{
|
|
|
|
bExport = sal_True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bExport )
|
|
|
|
{
|
2012-01-31 17:32:42 +01:00
|
|
|
assert(GetExport().getDefaultVersion()
|
|
|
|
>= SvtSaveOptions::ODFVER_012);
|
|
|
|
|
2008-03-07 15:17:58 +00:00
|
|
|
//<style:default-page-layout>
|
|
|
|
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
|
|
|
|
XML_DEFAULT_PAGE_LAYOUT,
|
|
|
|
sal_True, sal_True );
|
|
|
|
|
|
|
|
xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
|
|
|
|
XML_EXPORT_FLAG_IGN_WS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|