LibreOffice Module xmloff (master)  1
XMLTextMasterPageExport.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/xmlnamespace.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <com/sun/star/text/XText.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <xmloff/xmlexp.hxx>
26 #include <sal/log.hxx>
27 
28 
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::text;
32 using namespace ::com::sun::star::beans;
33 using namespace ::xmloff::token;
34 
35 const OUStringLiteral gsHeaderText( u"HeaderText" );
36 const OUStringLiteral gsHeaderOn( u"HeaderIsOn" );
37 const OUStringLiteral gsHeaderShareContent( u"HeaderIsShared" );
38 const OUStringLiteral gsHeaderTextFirst( u"HeaderTextFirst" );
39 const OUStringLiteral gsHeaderTextLeft( u"HeaderTextLeft" );
40 const OUStringLiteral gsFirstShareContent( u"FirstIsShared" );
41 const OUStringLiteral gsFooterText( u"FooterText" );
42 const OUStringLiteral gsFooterOn( u"FooterIsOn" );
43 const OUStringLiteral gsFooterShareContent( u"FooterIsShared" );
44 const OUStringLiteral gsFooterTextFirst( u"FooterTextFirst" );
45 const OUStringLiteral gsFooterTextLeft( u"FooterTextLeft" );
46 
48  XMLPageExport( rExp )
49 {
50 }
51 
53 {
54 }
55 
56 
58  const Reference< XText >& rText,
59  bool bAutoStyles, bool bExportParagraph )
60 {
61  SAL_WARN_IF( !rText.is(), "xmloff", "There is the text" );
62 
63  // tracked changes (autostyles + changes list)
64  GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText);
65  GetExport().GetTextParagraphExport()->exportTrackedChanges(rText,
66  bAutoStyles);
67  if( bAutoStyles )
69  ->collectTextAutoStyles( rText, true, bExportParagraph );
70  else
71  {
72  GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
73  GetExport().GetTextParagraphExport()->exportText( rText, true, bExportParagraph );
74  }
75 
76  // tracked changes (end of XText)
77  GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
78 }
79 
81  const Reference < XPropertySet > & rPropSet,
82  bool bAutoStyles )
83 {
84  Any aAny;
85 
86  Reference < XText > xHeaderText;
87  aAny = rPropSet->getPropertyValue( gsHeaderText );
88  aAny >>= xHeaderText;
89 
90  Reference < XText > xHeaderTextFirst;
91  aAny = rPropSet->getPropertyValue( gsHeaderTextFirst );
92  aAny >>= xHeaderTextFirst;
93 
94  Reference < XText > xHeaderTextLeft;
95  aAny = rPropSet->getPropertyValue( gsHeaderTextLeft );
96  aAny >>= xHeaderTextLeft;
97 
98  Reference < XText > xFooterText;
99  aAny = rPropSet->getPropertyValue( gsFooterText );
100  aAny >>= xFooterText;
101 
102  Reference < XText > xFooterTextFirst;
103  aAny = rPropSet->getPropertyValue( gsFooterTextFirst );
104  aAny >>= xFooterTextFirst;
105 
106  Reference < XText > xFooterTextLeft;
107  aAny = rPropSet->getPropertyValue( gsFooterTextLeft );
108  aAny >>= xFooterTextLeft;
109 
110  if( bAutoStyles )
111  {
112  if( xHeaderText.is() )
113  exportHeaderFooterContent( xHeaderText, true );
114  if( xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText )
115  exportHeaderFooterContent( xHeaderTextFirst, true );
116  if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
117  exportHeaderFooterContent( xHeaderTextLeft, true );
118  if( xFooterText.is() )
119  exportHeaderFooterContent( xFooterText, true );
120  if( xFooterTextFirst.is() && xFooterTextFirst != xFooterText )
121  exportHeaderFooterContent( xFooterTextFirst, true );
122  if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
123  exportHeaderFooterContent( xFooterTextLeft, true );
124  }
125  else
126  {
127  auto const nVersion(GetExport().getSaneDefaultVersion());
128 
129  aAny = rPropSet->getPropertyValue( gsHeaderOn );
130  bool bHeader = false;
131  aAny >>= bHeader;
132 
133  bool bHeaderFirstShared = false;
134  if( bHeader )
135  {
136  aAny = rPropSet->getPropertyValue( gsFirstShareContent );
137  aAny >>= bHeaderFirstShared;
138  }
139 
140  bool bHeaderLeftShared = false;
141  if( bHeader )
142  {
143  aAny = rPropSet->getPropertyValue( gsHeaderShareContent );
144  aAny >>= bHeaderLeftShared;
145  }
146 
147  if( xHeaderText.is() )
148  {
149  if( !bHeader )
153  XML_HEADER, true, true );
154  exportHeaderFooterContent( xHeaderText, false );
155  }
156 
157  if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
158  {
159  if (bHeaderLeftShared)
163  XML_HEADER_LEFT, true, true );
164  exportHeaderFooterContent( xHeaderTextLeft, false );
165  }
166 
167  if (xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText
169  {
170  if (bHeaderFirstShared)
173  // ODF 1.3 OFFICE-3789
174  SvXMLElementExport aElem( GetExport(),
178  XML_HEADER_FIRST, true, true );
179  exportHeaderFooterContent( xHeaderTextFirst, false );
180  }
181 
182  aAny = rPropSet->getPropertyValue( gsFooterOn );
183  bool bFooter = false;
184  aAny >>= bFooter;
185 
186  bool bFooterFirstShared = false;
187  if( bFooter )
188  {
189  aAny = rPropSet->getPropertyValue( gsFirstShareContent );
190  aAny >>= bFooterFirstShared;
191  }
192 
193  bool bFooterLeftShared = false;
194  if( bFooter )
195  {
196  aAny = rPropSet->getPropertyValue( gsFooterShareContent );
197  aAny >>= bFooterLeftShared;
198  }
199 
200  if( xFooterText.is() )
201  {
202  if( !bFooter )
206  XML_FOOTER, true, true );
207  exportHeaderFooterContent( xFooterText, false );
208  }
209 
210  if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
211  {
212  if (bFooterLeftShared)
216  XML_FOOTER_LEFT, true, true );
217  exportHeaderFooterContent( xFooterTextLeft, false );
218  }
219 
220  if (xFooterTextFirst.is() && xFooterTextFirst != xFooterText
222  {
223  if (bFooterFirstShared)
226  // ODF 1.3 OFFICE-3789
227  SvXMLElementExport aElem( GetExport(),
231  XML_FOOTER_FIRST, true, true );
232  exportHeaderFooterContent( xFooterTextFirst, false );
233  }
234  }
235 }
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUStringLiteral gsHeaderOn(u"HeaderIsOn")
const OUStringLiteral gsHeaderShareContent(u"HeaderIsShared")
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
Definition: xmlexp.hxx:560
const OUStringLiteral gsHeaderTextFirst(u"HeaderTextFirst")
const OUStringLiteral gsFooterTextFirst(u"FooterTextFirst")
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
const OUStringLiteral gsFooterShareContent(u"FooterIsShared")
const OUStringLiteral gsFooterText(u"FooterText")
const OUStringLiteral gsHeaderTextLeft(u"HeaderTextLeft")
XMLTextMasterPageExport(SvXMLExport &rExp)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:909
virtual void exportHeaderFooterContent(const css::uno::Reference< css::text::XText > &rText, bool bAutoStyles, bool bExportParagraph=true)
SvXMLExport & GetExport()
sal_Int16 nVersion
const OUStringLiteral gsFirstShareContent(u"FirstIsShared")
virtual ~XMLTextMasterPageExport() override
const OUStringLiteral gsFooterOn(u"FooterIsOn")
#define SAL_WARN_IF(condition, area, stream)
virtual void exportMasterPageContent(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyles) override
Handling of tokens in XML:
const OUStringLiteral gsHeaderText(u"HeaderText")
const OUStringLiteral gsFooterTextLeft(u"FooterTextLeft")
constexpr sal_uInt16 XML_NAMESPACE_STYLE