LibreOffice Module xmloff (master)  1
XMLPageExport.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <xmloff/XMLPageExport.hxx>
21 #include <o3tl/any.hxx>
22 #include <sal/log.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
27 #include <com/sun/star/style/XStyle.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <xmloff/families.hxx>
31 #include <xmloff/xmlexp.hxx>
33 #include <PageMasterStyleMap.hxx>
34 #include "PageMasterPropMapper.hxx"
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::style;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::beans;
42 using namespace ::xmloff::token;
43 
44 static const OUStringLiteral gsIsPhysical( "IsPhysical" );
45 static const OUStringLiteral gsFollowStyle( "FollowStyle" );
46 
47 bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
48 {
49  auto pEntry = std::find_if(aNameVector.cbegin(), aNameVector.cend(),
50  [&rStyleName](const XMLPageExportNameEntry& rEntry) { return rEntry.sStyleName == rStyleName; });
51 
52  if( pEntry != aNameVector.cend() )
53  {
54  rPMName = pEntry->sPageMasterName;
55  return true;
56  }
57 
58  return false;
59 }
60 
62  const Reference < XPropertySet > & rPropSet,
63  OUString& rPageMasterName )
64 {
65  SAL_WARN_IF( !xPageMasterPropSetMapper.is(), "xmloff", "page master family/XMLPageMasterPropSetMapper not found" );
66  if( xPageMasterPropSetMapper.is() )
67  {
68  ::std::vector<XMLPropertyState> aPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
69  if( !aPropStates.empty())
70  {
71  OUString sParent;
72  rPageMasterName = rExport.GetAutoStylePool()->Find( XmlStyleFamily::PAGE_MASTER, sParent, aPropStates );
73  if (rPageMasterName.isEmpty())
74  rPageMasterName = rExport.GetAutoStylePool()->Add(XmlStyleFamily::PAGE_MASTER, sParent, aPropStates);
75  }
76  }
77 }
78 
80  const Reference < XPropertySet > &,
81  bool /*bAutoStyles*/ )
82 {
83 
84 }
85 
87  const Reference< XStyle >& rStyle,
88  bool bAutoStyles )
89 {
90  Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
91  Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
92 
93  // Don't export styles that aren't existing really. This may be the
94  // case for StarOffice Writer's pool styles.
95  if( xPropSetInfo->hasPropertyByName( gsIsPhysical ) )
96  {
97  Any aAny = xPropSet->getPropertyValue( gsIsPhysical );
98  if( !*o3tl::doAccess<bool>(aAny) )
99  return false;
100  }
101 
102  if( bAutoStyles )
103  {
104  XMLPageExportNameEntry aEntry;
105  collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
106  aEntry.sStyleName = rStyle->getName();
107  aNameVector.push_back( aEntry );
108 
109  exportMasterPageContent( xPropSet, true );
110  }
111  else
112  {
113  OUString sName( rStyle->getName() );
114  bool bEncoded = false;
116  GetExport().EncodeStyleName( sName, &bEncoded ) );
117 
118  if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
119  {
120  uno::Any aValue = xPropSet->getPropertyValue( "Hidden" );
121  bool bHidden = false;
122  if ( ( aValue >>= bHidden ) && bHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
124  }
125 
126  if( bEncoded )
128  sName);
129 
130  OUString sPMName;
131  if( findPageMasterName( sName, sPMName ) )
132  GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
133 
134  Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
135  if ( xInfo.is() && xInfo->hasPropertyByName(gsFollowStyle) )
136  {
137  OUString sNextName;
138  xPropSet->getPropertyValue( gsFollowStyle ) >>= sNextName;
139 
140  if( sName != sNextName && !sNextName.isEmpty() )
141  {
143  GetExport().EncodeStyleName( sNextName ) );
144  }
145  }
146 
148  XML_MASTER_PAGE, true, true );
149 
150  exportMasterPageContent( xPropSet, false );
151  }
152 
153  return true;
154 }
155 
157  rExport( rExp )
158 {
165 
168 
169  Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
170  UNO_QUERY );
171  SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
172  "No XStyleFamiliesSupplier from XModel for export!" );
173  if( xFamiliesSupp.is() )
174  {
175  Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
176  SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
177  "getStyleFamilies() from XModel failed for export!" );
178  if( xFamilies.is() )
179  {
180  const OUString aPageStyleName("PageStyles");
181 
182  if( xFamilies->hasByName( aPageStyleName ) )
183  {
184  xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
185 
186  SAL_WARN_IF( !xPageStyles.is(), "xmloff",
187  "Page Styles not found for export!" );
188  }
189  }
190  }
191 }
192 
194 {
195 }
196 
197 void XMLPageExport::exportStyles( bool bUsed, bool bAutoStyles )
198 {
199  if( xPageStyles.is() )
200  {
201  const uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
202  for(const auto& rName : aSeq)
203  {
204  Reference< XStyle > xStyle(xPageStyles->getByName( rName ),uno::UNO_QUERY);
205  if( !bUsed || xStyle->isInUse() )
206  exportStyle( xStyle, bAutoStyles );
207  }
208  }
209 }
210 
212 {
214 }
215 
217 {
218  Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
219  if (xFactory.is())
220  {
221  Reference < XPropertySet > xPropSet (xFactory->createInstance ( "com.sun.star.text.Defaults" ), UNO_QUERY);
222  if (xPropSet.is())
223  {
224  // <style:default-style ...>
226 
227  ::std::vector< XMLPropertyState > aPropStates =
228  xPageMasterExportPropMapper->FilterDefaults( xPropSet );
229 
230  bool bExport = false;
231  rtl::Reference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
232  for( const auto& rProp : aPropStates )
233  {
234  sal_Int16 nContextId = aPropMapper->GetEntryContextId( rProp.mnIndex );
235  if( nContextId == CTF_PM_STANDARD_MODE )
236  {
237  bExport = true;
238  break;
239  }
240  }
241 
242  if( bExport )
243  {
244  assert(GetExport().getSaneDefaultVersion()
246 
247  //<style:default-page-layout>
250  true, true );
251 
252  xPageMasterExportPropMapper->exportXML( GetExport(), aPropStates,
254  }
255  }
256  }
257 }
258 
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
const XMLPropertyMapEntry aXMLPageMasterStyleMap[]
static const OUStringLiteral gsFollowStyle("FollowStyle")
XMLPageExport(SvXMLExport &rExp)
void CheckAttrList()
Definition: xmlexp.cxx:1047
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:926
bool exportStyle(const css::uno::Reference< css::style::XStyle > &rStyle, bool bAutoStyles)
rtl::Reference< XMLPropertyHandlerFactory > xPageMasterPropHdlFactory
const char * sName
virtual ~XMLPageExport() override
virtual void exportMasterPageContent(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyles)
void exportStyles(bool bUsed, bool bAutoStyles)
::std::vector< XMLPageExportNameEntry > aNameVector
void exportAutoStyles()
css::uno::Reference< css::container::XNameAccess > xPageStyles
SvXMLExport & GetExport()
#define XML_STYLE_FAMILY_PAGE_MASTER_PREFIX
Definition: families.hxx:27
void collectPageMasterAutoStyle(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, OUString &rPageMasterName)
void exportDefaultStyle()
#define SAL_WARN_IF(condition, area, stream)
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Definition: xmlexp.hxx:577
Handling of tokens in XML:
rtl::Reference< SvXMLExportPropertyMapper > xPageMasterExportPropMapper
static const OUStringLiteral gsIsPhysical("IsPhysical")
SvXMLExport & rExport
rtl::Reference< XMLPropertySetMapper > xPageMasterPropSetMapper
Sequence< sal_Int8 > aSeq
Reference< XSingleServiceFactory > xFactory
#define CTF_PM_STANDARD_MODE
#define XML_STYLE_FAMILY_PAGE_MASTER_NAME
These defines determine the unique ids for XML style-families used in the SvXMLAutoStylePoolP.
Definition: families.hxx:26
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
SAL_DLLPRIVATE bool findPageMasterName(const OUString &rStyleName, OUString &rPMName) const