Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/style/XStyle.hpp>
30 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : : #include <com/sun/star/style/PageStyleLayout.hpp>
32 : : #include <com/sun/star/beans/XMultiPropertyStates.hpp>
33 : : #include <xmloff/nmspmap.hxx>
34 : : #include "xmloff/xmlnmspe.hxx"
35 : : #include <xmloff/xmltoken.hxx>
36 : : #include <xmloff/XMLTextMasterPageContext.hxx>
37 : : #include "XMLTextHeaderFooterContext.hxx"
38 : : #include <xmloff/xmlimp.hxx>
39 : : #include "PageMasterImportContext.hxx"
40 : :
41 : :
42 : : using ::rtl::OUString;
43 : : using ::rtl::OUStringBuffer;
44 : :
45 : : using namespace ::com::sun::star;
46 : : using namespace ::com::sun::star::uno;
47 : : using namespace ::com::sun::star::xml::sax;
48 : : using namespace ::com::sun::star::style;
49 : : using namespace ::com::sun::star::text;
50 : : using namespace ::com::sun::star::beans;
51 : : using namespace ::com::sun::star::container;
52 : : using namespace ::com::sun::star::lang;
53 : : using namespace ::xmloff::token;
54 : :
55 : 27 : Reference < XStyle > XMLTextMasterPageContext::Create()
56 : : {
57 : 27 : Reference < XStyle > xNewStyle;
58 : :
59 : 27 : Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(),
60 [ + - ]: 27 : UNO_QUERY );
61 [ + - ]: 27 : if( xFactory.is() )
62 : : {
63 : : Reference < XInterface > xIfc =
64 [ + - ]: 27 : xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM(
65 [ + - ][ + - ]: 27 : "com.sun.star.style.PageStyle")) );
66 [ + - ]: 27 : if( xIfc.is() )
67 [ + - ][ + - ]: 27 : xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY );
68 : : }
69 : :
70 : 27 : return xNewStyle;
71 : : }
72 [ # # ][ # # ]: 0 : TYPEINIT1( XMLTextMasterPageContext, SvXMLStyleContext );
73 : :
74 : 311 : XMLTextMasterPageContext::XMLTextMasterPageContext( SvXMLImport& rImport,
75 : : sal_uInt16 nPrfx, const OUString& rLName,
76 : : const Reference< XAttributeList > & xAttrList,
77 : : sal_Bool bOverwrite )
78 : : : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_MASTER_PAGE )
79 : : , sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) )
80 : : , sPageStyleLayout( RTL_CONSTASCII_USTRINGPARAM( "PageStyleLayout" ) )
81 : : , sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) )
82 : : , bInsertHeader( sal_False )
83 : : , bInsertFooter( sal_False )
84 : : , bInsertHeaderLeft( sal_False )
85 : : , bInsertFooterLeft( sal_False )
86 : : , bInsertHeaderFirst( sal_False )
87 : : , bInsertFooterFirst( sal_False )
88 : : , bHeaderInserted( sal_False )
89 : : , bFooterInserted( sal_False )
90 : : , bHeaderLeftInserted( sal_False )
91 : : , bFooterLeftInserted( sal_False )
92 : : , bHeaderFirstInserted( sal_False )
93 [ + - ][ + - ]: 311 : , bFooterFirstInserted( sal_False )
[ + - ]
94 : : {
95 : 311 : OUString sName, sDisplayName;
96 [ + - ][ + - ]: 311 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
97 [ + + ]: 975 : for( sal_Int16 i=0; i < nAttrCount; i++ )
98 : : {
99 [ + - ][ + - ]: 664 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
100 : 664 : OUString aLocalName;
101 [ + - ]: 664 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
102 [ + - ]: 664 : if( XML_NAMESPACE_STYLE == nPrefix )
103 : : {
104 [ + - ][ + + ]: 664 : if( IsXMLToken( aLocalName, XML_NAME ) )
105 : : {
106 [ + - ][ + - ]: 311 : sName = xAttrList->getValueByIndex( i );
107 : : }
108 [ + - ][ + + ]: 353 : else if( IsXMLToken( aLocalName, XML_DISPLAY_NAME ) )
109 : : {
110 [ + - ][ + - ]: 27 : sDisplayName = xAttrList->getValueByIndex( i );
111 : : }
112 [ + - ][ + + ]: 326 : else if( IsXMLToken( aLocalName, XML_NEXT_STYLE_NAME ) )
113 : : {
114 [ + - ][ + - ]: 15 : sFollow = xAttrList->getValueByIndex( i );
115 : : }
116 [ + - ][ + - ]: 311 : else if( IsXMLToken( aLocalName, XML_PAGE_LAYOUT_NAME ) )
117 : : {
118 [ + - ][ + - ]: 311 : sPageMasterName = xAttrList->getValueByIndex( i );
119 : : }
120 : : }
121 : 664 : }
122 : :
123 [ + + ]: 311 : if( !sDisplayName.isEmpty() )
124 : : {
125 : : rImport.AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sName,
126 [ + - ]: 27 : sDisplayName );
127 : : }
128 : : else
129 : : {
130 : 284 : sDisplayName = sName;
131 : : }
132 : :
133 [ - + ]: 311 : if( sDisplayName.isEmpty() )
134 : : return;
135 : :
136 : : Reference < XNameContainer > xPageStyles =
137 [ + - ][ + - ]: 311 : GetImport().GetTextImport()->GetPageStyles();
[ + - ][ + - ]
138 [ - + ]: 311 : if( !xPageStyles.is() )
139 : : return;
140 : :
141 : 311 : Any aAny;
142 : 311 : sal_Bool bNew = sal_False;
143 [ + - ][ + + ]: 311 : if( xPageStyles->hasByName( sDisplayName ) )
[ + - ]
144 : : {
145 [ + - ][ + - ]: 284 : aAny = xPageStyles->getByName( sDisplayName );
146 [ + - ]: 284 : aAny >>= xStyle;
147 : : }
148 : : else
149 : : {
150 [ + - ][ + - ]: 27 : xStyle = Create();
151 [ - + ]: 27 : if( !xStyle.is() )
152 : : return;
153 : :
154 [ + - ]: 27 : aAny <<= xStyle;
155 [ + - ][ + - ]: 27 : xPageStyles->insertByName( sDisplayName, aAny );
156 : 27 : bNew = sal_True;
157 : : }
158 : :
159 [ + - ]: 311 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
160 : : Reference< XPropertySetInfo > xPropSetInfo =
161 [ + - ][ + - ]: 311 : xPropSet->getPropertySetInfo();
162 [ + + ][ + - ]: 311 : if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) )
[ + - ][ + + ]
[ + + ]
163 : : {
164 [ + - ][ + - ]: 98 : aAny = xPropSet->getPropertyValue( sIsPhysical );
165 : 98 : bNew = !*(sal_Bool *)aAny.getValue();
166 : : }
167 : 311 : SetNew( bNew );
168 : :
169 [ # # ][ - + ]: 311 : if( bOverwrite || bNew )
170 : : {
171 : : Reference < XMultiPropertyStates > xMultiStates( xPropSet,
172 [ + - ]: 311 : UNO_QUERY );
173 : : OSL_ENSURE( xMultiStates.is(),
174 : : "text page style does not support multi property set" );
175 [ + - ]: 311 : if( xMultiStates.is() )
176 [ + - ][ + - ]: 311 : xMultiStates->setAllPropertiesToDefault();
177 : :
178 : 311 : bInsertHeader = bInsertFooter = sal_True;
179 : 311 : bInsertHeaderLeft = bInsertFooterLeft = sal_True;
180 : 311 : bInsertHeaderFirst = bInsertFooterFirst = sal_True;
181 [ - + ][ - + ]: 311 : }
[ - + ][ + - ]
182 : : }
183 : :
184 : 311 : XMLTextMasterPageContext::~XMLTextMasterPageContext()
185 : : {
186 [ - + ]: 430 : }
187 : :
188 : 768 : SvXMLImportContext *XMLTextMasterPageContext::CreateChildContext(
189 : : sal_uInt16 nPrefix,
190 : : const OUString& rLocalName,
191 : : const Reference< XAttributeList > & xAttrList )
192 : : {
193 : 768 : SvXMLImportContext *pContext = 0;
194 : :
195 : : const SvXMLTokenMap& rTokenMap =
196 [ + - ][ + - ]: 768 : GetImport().GetTextImport()->GetTextMasterPageElemTokenMap();
197 : :
198 : 768 : sal_Bool bInsert = sal_False, bFooter = sal_False, bLeft = sal_False, bFirst = sal_False;
199 [ + + + + : 768 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
- - - ]
200 : : {
201 : : case XML_TOK_TEXT_MP_HEADER:
202 [ + - ][ + - ]: 201 : if( bInsertHeader && !bHeaderInserted )
203 : : {
204 : 201 : bInsert = sal_True;
205 : 201 : bHeaderInserted = sal_True;
206 : : }
207 : 201 : break;
208 : : case XML_TOK_TEXT_MP_FOOTER:
209 [ + - ][ + - ]: 203 : if( bInsertFooter && !bFooterInserted )
210 : : {
211 : 203 : bInsert = bFooter = sal_True;
212 : 203 : bFooterInserted = sal_True;
213 : : }
214 : 203 : break;
215 : : case XML_TOK_TEXT_MP_HEADER_LEFT:
216 [ + - ][ + - ]: 182 : if( bInsertHeaderLeft && bHeaderInserted && !bHeaderLeftInserted )
[ + - ]
217 : 182 : bInsert = bLeft = sal_True;
218 : 182 : break;
219 : : case XML_TOK_TEXT_MP_FOOTER_LEFT:
220 [ + - ][ + - ]: 182 : if( bInsertFooterLeft && bFooterInserted && !bFooterLeftInserted )
[ + - ]
221 : 182 : bInsert = bFooter = bLeft = sal_True;
222 : 182 : break;
223 : : case XML_TOK_TEXT_MP_HEADER_FIRST:
224 [ # # ][ # # ]: 0 : if( bInsertHeaderFirst && bHeaderInserted && !bHeaderFirstInserted )
[ # # ]
225 : 0 : bInsert = bFirst = sal_True;
226 : 0 : break;
227 : : case XML_TOK_TEXT_MP_FOOTER_FIRST:
228 [ # # ][ # # ]: 0 : if( bInsertFooterFirst && bFooterInserted && !bFooterFirstInserted )
[ # # ]
229 : 0 : bInsert = bFooter = bFirst = sal_True;
230 : 0 : break;
231 : : }
232 : :
233 [ + - ][ + - ]: 768 : if( bInsert && xStyle.is() )
[ + - ]
234 : : {
235 : : pContext = CreateHeaderFooterContext( nPrefix, rLocalName,
236 : : xAttrList,
237 : 768 : bFooter, bLeft, bFirst );
238 : : }
239 : : else
240 : : {
241 : : pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
242 : 0 : xAttrList );
243 : : }
244 : :
245 : 768 : return pContext;
246 : : }
247 : :
248 : 20 : SvXMLImportContext *XMLTextMasterPageContext::CreateHeaderFooterContext(
249 : : sal_uInt16 nPrefix,
250 : : const ::rtl::OUString& rLocalName,
251 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
252 : : const sal_Bool bFooter,
253 : : const sal_Bool bLeft,
254 : : const sal_Bool bFirst )
255 : : {
256 [ + - ]: 20 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
257 : 20 : return new XMLTextHeaderFooterContext( GetImport(),
258 : : nPrefix, rLocalName,
259 : : xAttrList,
260 : : xPropSet,
261 [ + - ][ + - ]: 20 : bFooter, bLeft, bFirst );
262 : : }
263 : :
264 : 311 : void XMLTextMasterPageContext::Finish( sal_Bool bOverwrite )
265 : : {
266 [ + - ][ + + ]: 311 : if( xStyle.is() && (IsNew() || bOverwrite) )
[ + - ][ + - ]
267 : : {
268 [ + - ]: 311 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
269 [ + - ]: 311 : if( !sPageMasterName.isEmpty() )
270 : : {
271 : : XMLPropStyleContext* pStyle =
272 [ + - ][ + - ]: 311 : GetImport().GetTextImport()->FindPageMaster( sPageMasterName );
[ + - ][ + - ]
273 [ + - ]: 311 : if (pStyle)
274 : : {
275 [ + - ]: 311 : pStyle->FillPropertySet(xPropSet);
276 : : }
277 : : }
278 : :
279 : : Reference < XNameContainer > xPageStyles =
280 [ + - ][ + - ]: 311 : GetImport().GetTextImport()->GetPageStyles();
[ + - ][ + - ]
281 [ - + ]: 311 : if( !xPageStyles.is() )
282 : 311 : return;
283 : :
284 : : Reference< XPropertySetInfo > xPropSetInfo =
285 [ + - ][ + - ]: 311 : xPropSet->getPropertySetInfo();
286 [ + - ][ + - ]: 311 : if( xPropSetInfo->hasPropertyByName( sFollowStyle ) )
[ + + ]
287 : : {
288 : : OUString sDisplayFollow(
289 : 119 : GetImport().GetStyleDisplayName(
290 [ + - ]: 119 : XML_STYLE_FAMILY_MASTER_PAGE, sFollow ) );
291 [ + + ][ - + ]: 134 : if( sDisplayFollow.isEmpty() ||
[ + + ]
292 [ + - ][ + - ]: 15 : !xPageStyles->hasByName( sDisplayFollow ) )
293 [ + - ][ + - ]: 104 : sDisplayFollow = xStyle->getName();
294 : :
295 [ + - ][ + - ]: 119 : Any aAny = xPropSet->getPropertyValue( sFollowStyle );
296 : 119 : OUString sCurrFollow;
297 : 119 : aAny >>= sCurrFollow;
298 [ + + ]: 119 : if( sCurrFollow != sDisplayFollow )
299 : : {
300 [ + - ]: 12 : aAny <<= sDisplayFollow;
301 [ + - ][ + - ]: 12 : xPropSet->setPropertyValue( sFollowStyle, aAny );
302 : 119 : }
303 [ - + ][ + - ]: 311 : }
304 : : }
305 : : }
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|