1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <com/sun/star/text/XText.hpp>
27 #include <com/sun/star/text/XRelativeTextContentRemove.hpp>
28 #include <xmloff/nmspmap.hxx>
29 #include "xmloff/xmlnmspe.hxx"
30 #include "XMLTextHeaderFooterContext.hxx"
31 #ifndef _XMLOFF_TEXTTABLECONTEXT_HXX_
32 #include <xmloff/XMLTextTableContext.hxx>
33 #endif
34 #include <xmloff/xmlimp.hxx>
35
36
37 using ::rtl::OUString;
38 using ::rtl::OUStringBuffer;
39
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::xml::sax;
43 //using namespace ::com::sun::star::style;
44 using namespace ::com::sun::star::text;
45 using namespace ::com::sun::star::beans;
46 //using namespace ::com::sun::star::container;
47 //using namespace ::com::sun::star::lang;
48 //using namespace ::com::sun::star::text;
49
50
51 TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext );
52
XMLTextHeaderFooterContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,const Reference<XPropertySet> & rPageStylePropSet,sal_Bool bFooter,sal_Bool bLft)53 XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
54 const OUString& rLName,
55 const uno::Reference<
56 xml::sax::XAttributeList > &,
57 const Reference < XPropertySet > & rPageStylePropSet,
58 sal_Bool bFooter, sal_Bool bLft ) :
59 SvXMLImportContext( rImport, nPrfx, rLName ),
60 xPropSet( rPageStylePropSet ),
61 sOn( OUString::createFromAscii( bFooter ? "FooterIsOn" : "HeaderIsOn" ) ),
62 sShareContent( OUString::createFromAscii( bFooter ? "FooterIsShared"
63 : "HeaderIsShared" ) ),
64 sText( OUString::createFromAscii( bFooter ? "FooterText" : "HeaderText" ) ),
65 sTextLeft( OUString::createFromAscii( bFooter ? "FooterTextLeft"
66 : "HeaderTextLeft" ) ),
67 bInsertContent( sal_True ),
68 bLeft( bLft )
69 {
70 if( bLeft )
71 {
72 Any aAny;
73
74 aAny = xPropSet->getPropertyValue( sOn );
75 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
76
77 if( bOn )
78 {
79 aAny = xPropSet->getPropertyValue( sShareContent );
80 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
81 if( bShared )
82 {
83 // Don't share headers any longer
84 bShared = sal_False;
85 aAny.setValue( &bShared, ::getBooleanCppuType() );
86 xPropSet->setPropertyValue( sShareContent, aAny );
87 }
88 }
89 else
90 {
91 // If headers or footers are switched off, no content must be
92 // inserted.
93 bInsertContent = sal_False;
94 }
95 }
96 }
97
~XMLTextHeaderFooterContext()98 XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext()
99 {
100 }
101
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)102 SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext(
103 sal_uInt16 nPrefix,
104 const OUString& rLocalName,
105 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
106 {
107 SvXMLImportContext *pContext = 0;
108 if( bInsertContent )
109 {
110 if( !xOldTextCursor.is() )
111 {
112 sal_Bool bRemoveContent = sal_True;
113 Any aAny;
114 if( bLeft )
115 {
116 // Headers and footers are switched on already,
117 // and they aren't shared.
118 aAny = xPropSet->getPropertyValue( sTextLeft );
119 }
120 else
121 {
122 aAny = xPropSet->getPropertyValue( sOn );
123 sal_Bool bOn = *(sal_Bool *)aAny.getValue();
124
125 if( !bOn )
126 {
127 // Switch header on
128 bOn = sal_True;
129 aAny.setValue( &bOn, ::getBooleanCppuType() );
130 xPropSet->setPropertyValue( sOn, aAny );
131
132 // The content has not to be removed, because the header
133 // or footer is empty already.
134 bRemoveContent = sal_False;
135 }
136
137 // If a header or footer is not shared, share it now.
138 aAny = xPropSet->getPropertyValue( sShareContent );
139 sal_Bool bShared = *(sal_Bool *)aAny.getValue();
140 if( !bShared )
141 {
142 bShared = sal_True;
143 aAny.setValue( &bShared, ::getBooleanCppuType() );
144 xPropSet->setPropertyValue( sShareContent, aAny );
145 }
146
147 aAny = xPropSet->getPropertyValue( sText );
148 }
149
150 Reference < XText > xText;
151 aAny >>= xText;
152
153 if( bRemoveContent )
154 {
155 OUString aText;
156 xText->setString( aText );
157 }
158
159 UniReference < XMLTextImportHelper > xTxtImport =
160 GetImport().GetTextImport();
161
162 xOldTextCursor = xTxtImport->GetCursor();
163 xTxtImport->SetCursor( xText->createTextCursor() );
164 }
165
166 pContext =
167 GetImport().GetTextImport()->CreateTextChildContext(
168 GetImport(), nPrefix, rLocalName, xAttrList,
169 XML_TEXT_TYPE_HEADER_FOOTER );
170 }
171 if( !pContext )
172 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
173
174 return pContext;
175 }
176
EndElement()177 void XMLTextHeaderFooterContext::EndElement()
178 {
179 if( xOldTextCursor.is() )
180 {
181 GetImport().GetTextImport()->DeleteParagraph();
182 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
183 }
184 else if( !bLeft )
185 {
186 // If no content has been inserted inro the header or footer,
187 // switch it off.
188 sal_Bool bOn = sal_False;
189 Any aAny;
190 aAny.setValue( &bOn, ::getBooleanCppuType() );
191 xPropSet->setPropertyValue( sOn, aAny );
192 }
193 }
194
195