1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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 .
 */

#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <xmloff/xmlexp.hxx>
#include <xmloff/XMLTextMasterPageExport.hxx>
#include <sal/log.hxx>


using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::beans;
using namespace ::xmloff::token;

static const OUStringLiteral gsHeaderText( "HeaderText" );
static const OUStringLiteral gsHeaderOn( "HeaderIsOn" );
static const OUStringLiteral gsHeaderShareContent( "HeaderIsShared" );
static const OUStringLiteral gsHeaderTextFirst( "HeaderTextFirst" );
static const OUStringLiteral gsHeaderTextLeft( "HeaderTextLeft" );
static const OUStringLiteral gsFirstShareContent( "FirstIsShared" );
static const OUStringLiteral gsFooterText( "FooterText" );
static const OUStringLiteral gsFooterOn( "FooterIsOn" );
static const OUStringLiteral gsFooterShareContent( "FooterIsShared" );
static const OUStringLiteral gsFooterTextFirst( "FooterTextFirst" );
static const OUStringLiteral gsFooterTextLeft( "FooterTextLeft" );

XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport& rExp ) :
    XMLPageExport( rExp )
{
}

XMLTextMasterPageExport::~XMLTextMasterPageExport()
{
}


void XMLTextMasterPageExport::exportHeaderFooterContent(
            const Reference< XText >& rText,
            bool bAutoStyles, bool bExportParagraph )
{
    SAL_WARN_IF( !rText.is(), "xmloff", "There is the text" );

    // tracked changes (autostyles + changes list)
    GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText);
    GetExport().GetTextParagraphExport()->exportTrackedChanges(rText,
                                                               bAutoStyles);
    if( bAutoStyles )
        GetExport().GetTextParagraphExport()
                ->collectTextAutoStyles( rText, true, bExportParagraph );
    else
    {
        GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
        GetExport().GetTextParagraphExport()->exportText( rText, true, bExportParagraph );
    }

    // tracked changes (end of XText)
    GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
}

void XMLTextMasterPageExport::exportMasterPageContent(
                const Reference < XPropertySet > & rPropSet,
                bool bAutoStyles )
{
    Any aAny;

    Reference < XText > xHeaderText;
    aAny = rPropSet->getPropertyValue( gsHeaderText );
    aAny >>= xHeaderText;<--- aAny is assigned

    Reference < XText > xHeaderTextFirst;
    aAny = rPropSet->getPropertyValue( gsHeaderTextFirst );<--- aAny is overwritten
    aAny >>= xHeaderTextFirst;<--- aAny is assigned

    Reference < XText > xHeaderTextLeft;
    aAny = rPropSet->getPropertyValue( gsHeaderTextLeft );<--- aAny is overwritten
    aAny >>= xHeaderTextLeft;<--- aAny is assigned

    Reference < XText > xFooterText;
    aAny = rPropSet->getPropertyValue( gsFooterText );<--- aAny is overwritten
    aAny >>= xFooterText;<--- aAny is assigned

    Reference < XText > xFooterTextFirst;
    aAny = rPropSet->getPropertyValue( gsFooterTextFirst );<--- aAny is overwritten
    aAny >>= xFooterTextFirst;<--- aAny is assigned

    Reference < XText > xFooterTextLeft;
    aAny = rPropSet->getPropertyValue( gsFooterTextLeft );<--- aAny is overwritten<--- Variable 'aAny' is assigned a value that is never used.
    aAny >>= xFooterTextLeft;<--- Variable 'aAny' is assigned a value that is never used.

    if( bAutoStyles )
    {
        if( xHeaderText.is() )
            exportHeaderFooterContent( xHeaderText, true );
        if( xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText )
            exportHeaderFooterContent( xHeaderTextFirst, true );
        if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
            exportHeaderFooterContent( xHeaderTextLeft, true );
        if( xFooterText.is() )
            exportHeaderFooterContent( xFooterText, true );
        if( xFooterTextFirst.is() && xFooterTextFirst != xFooterText )
            exportHeaderFooterContent( xFooterTextFirst, true );
        if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
            exportHeaderFooterContent( xFooterTextLeft, true );
    }
    else
    {
        auto const nVersion(GetExport().getSaneDefaultVersion());

        aAny = rPropSet->getPropertyValue( gsHeaderOn );
        bool bHeader = false;<--- Assignment 'bHeader=false', assigned value is 0
        aAny >>= bHeader;<--- aAny is assigned

        bool bHeaderFirstShared = false;
        if( bHeader )<--- Condition 'bHeader' is always false
        {
            aAny = rPropSet->getPropertyValue( gsFirstShareContent );
            aAny >>= bHeaderFirstShared;<--- aAny is assigned
        }

        bool bHeaderLeftShared = false;
        if( bHeader )
        {
            aAny = rPropSet->getPropertyValue( gsHeaderShareContent );
            aAny >>= bHeaderLeftShared;<--- aAny is assigned
        }

        if( xHeaderText.is() )
        {
            if( !bHeader )
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
                                        XML_HEADER, true, true );
            exportHeaderFooterContent( xHeaderText, false );
        }

        if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
        {
            if (bHeaderLeftShared)
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
                                        XML_HEADER_LEFT, true, true );
            exportHeaderFooterContent( xHeaderTextLeft, false );
        }

        if (xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText
            && SvtSaveOptions::ODFSVER_012 < nVersion)
        {
            if (bHeaderFirstShared)
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            // ODF 1.3 OFFICE-3789
            SvXMLElementExport aElem( GetExport(),
                                        SvtSaveOptions::ODFSVER_013 <= nVersion
                                            ? XML_NAMESPACE_STYLE
                                            : XML_NAMESPACE_LO_EXT,
                                        XML_HEADER_FIRST, true, true );
            exportHeaderFooterContent( xHeaderTextFirst, false );
        }

        aAny = rPropSet->getPropertyValue( gsFooterOn );<--- aAny is overwritten<--- aAny is overwritten<--- aAny is overwritten<--- Variable 'aAny' is assigned a value that is never used.
        bool bFooter = false;<--- Assignment 'bFooter=false', assigned value is 0
        aAny >>= bFooter;<--- Variable 'aAny' is assigned a value that is never used.

        bool bFooterFirstShared = false;
        if( bFooter )<--- Condition 'bFooter' is always false
        {
            aAny = rPropSet->getPropertyValue( gsFirstShareContent );<--- Variable 'aAny' is assigned a value that is never used.
            aAny >>= bFooterFirstShared;<--- Variable 'aAny' is assigned a value that is never used.
        }

        bool bFooterLeftShared = false;
        if( bFooter )
        {
            aAny = rPropSet->getPropertyValue( gsFooterShareContent );<--- Variable 'aAny' is assigned a value that is never used.
            aAny >>= bFooterLeftShared;<--- Variable 'aAny' is assigned a value that is never used.
        }

        if( xFooterText.is() )
        {
            if( !bFooter )
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
                                        XML_FOOTER, true, true );
            exportHeaderFooterContent( xFooterText, false );
        }

        if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
        {
            if (bFooterLeftShared)
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
                                        XML_FOOTER_LEFT, true, true );
            exportHeaderFooterContent( xFooterTextLeft, false );
        }

        if (xFooterTextFirst.is() && xFooterTextFirst != xFooterText
            && SvtSaveOptions::ODFSVER_012 < nVersion)
        {
            if (bFooterFirstShared)
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
                                          XML_DISPLAY, XML_FALSE );
            // ODF 1.3 OFFICE-3789
            SvXMLElementExport aElem( GetExport(),
                                        SvtSaveOptions::ODFSVER_013 <= nVersion
                                            ? XML_NAMESPACE_STYLE
                                            : XML_NAMESPACE_LO_EXT,
                                        XML_FOOTER_FIRST, true, true );
            exportHeaderFooterContent( xFooterTextFirst, false );
        }
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */