1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextHeaderFooterContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include "XMLTextHeaderFooterContext.hxx"
38 #ifndef _XMLOFF_TEXTTABLECONTEXT_HXX_
39 #include <xmloff/XMLTextTableContext.hxx>
41 #include <xmloff/xmlimp.hxx>
44 using ::rtl::OUString
;
45 using ::rtl::OUStringBuffer
;
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::xml::sax
;
50 //using namespace ::com::sun::star::style;
51 using namespace ::com::sun::star::text
;
52 using namespace ::com::sun::star::beans
;
53 //using namespace ::com::sun::star::container;
54 //using namespace ::com::sun::star::lang;
55 //using namespace ::com::sun::star::text;
58 TYPEINIT1( XMLTextHeaderFooterContext
, SvXMLImportContext
);
60 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
61 const OUString
& rLName
,
63 xml::sax::XAttributeList
> &,
64 const Reference
< XPropertySet
> & rPageStylePropSet
,
65 sal_Bool bFooter
, sal_Bool bLft
) :
66 SvXMLImportContext( rImport
, nPrfx
, rLName
),
67 xPropSet( rPageStylePropSet
),
68 sOn( OUString::createFromAscii( bFooter
? "FooterIsOn" : "HeaderIsOn" ) ),
69 sShareContent( OUString::createFromAscii( bFooter
? "FooterIsShared"
70 : "HeaderIsShared" ) ),
71 sText( OUString::createFromAscii( bFooter
? "FooterText" : "HeaderText" ) ),
72 sTextLeft( OUString::createFromAscii( bFooter
? "FooterTextLeft"
73 : "HeaderTextLeft" ) ),
74 bInsertContent( sal_True
),
81 aAny
= xPropSet
->getPropertyValue( sOn
);
82 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
86 aAny
= xPropSet
->getPropertyValue( sShareContent
);
87 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
90 // Don't share headers any longer
92 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
93 xPropSet
->setPropertyValue( sShareContent
, aAny
);
98 // If headers or footers are switched off, no content must be
100 bInsertContent
= sal_False
;
105 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
109 SvXMLImportContext
*XMLTextHeaderFooterContext::CreateChildContext(
111 const OUString
& rLocalName
,
112 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
114 SvXMLImportContext
*pContext
= 0;
117 if( !xOldTextCursor
.is() )
119 sal_Bool bRemoveContent
= sal_True
;
123 // Headers and footers are switched on already,
124 // and they aren't shared.
125 aAny
= xPropSet
->getPropertyValue( sTextLeft
);
129 aAny
= xPropSet
->getPropertyValue( sOn
);
130 sal_Bool bOn
= *(sal_Bool
*)aAny
.getValue();
136 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
137 xPropSet
->setPropertyValue( sOn
, aAny
);
139 // The content has not to be removed, because the header
140 // or footer is empty already.
141 bRemoveContent
= sal_False
;
144 // If a header or footer is not shared, share it now.
145 aAny
= xPropSet
->getPropertyValue( sShareContent
);
146 sal_Bool bShared
= *(sal_Bool
*)aAny
.getValue();
150 aAny
.setValue( &bShared
, ::getBooleanCppuType() );
151 xPropSet
->setPropertyValue( sShareContent
, aAny
);
154 aAny
= xPropSet
->getPropertyValue( sText
);
157 Reference
< XText
> xText
;
163 xText
->setString( aText
);
166 UniReference
< XMLTextImportHelper
> xTxtImport
=
167 GetImport().GetTextImport();
169 xOldTextCursor
= xTxtImport
->GetCursor();
170 xTxtImport
->SetCursor( xText
->createTextCursor() );
174 GetImport().GetTextImport()->CreateTextChildContext(
175 GetImport(), nPrefix
, rLocalName
, xAttrList
,
176 XML_TEXT_TYPE_HEADER_FOOTER
);
179 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
184 void XMLTextHeaderFooterContext::EndElement()
186 if( xOldTextCursor
.is() )
188 GetImport().GetTextImport()->DeleteParagraph();
189 GetImport().GetTextImport()->SetCursor( xOldTextCursor
);
193 // If no content has been inserted inro the header or footer,
195 sal_Bool bOn
= sal_False
;
197 aAny
.setValue( &bOn
, ::getBooleanCppuType() );
198 xPropSet
->setPropertyValue( sOn
, aAny
);