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: PageMasterImportContext.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"
35 #include "PageMasterImportContext.hxx"
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include "PageMasterPropHdl.hxx"
39 #include "PagePropertySetContext.hxx"
40 #ifndef _XMLOFF_PAGEPHEADERFOOTERCONTEXT_HXX
41 #include "PageHeaderFooterContext.hxx"
43 #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
44 #include "PageMasterPropMapper.hxx"
46 #include "PageMasterImportPropMapper.hxx"
47 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
48 #include <xmloff/PageMasterStyleMap.hxx>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 using namespace ::com::sun::star
;
53 using namespace ::xmloff::token
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::lang
;
57 void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey
,
58 const rtl::OUString
& rLocalName
,
59 const rtl::OUString
& rValue
)
61 // TODO: use a map here
62 if( XML_NAMESPACE_STYLE
== nPrefixKey
&& IsXMLToken( rLocalName
, XML_PAGE_USAGE
) )
68 XMLPropStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
72 TYPEINIT1( PageStyleContext
, XMLPropStyleContext
);
74 PageStyleContext::PageStyleContext( SvXMLImport
& rImport
,
75 sal_uInt16 nPrfx
, const rtl::OUString
& rLName
,
76 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
77 SvXMLStylesContext
& rStyles
,
78 sal_Bool bDefaultStyle
) :
79 XMLPropStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, XML_STYLE_FAMILY_PAGE_MASTER
, bDefaultStyle
),
84 PageStyleContext::~PageStyleContext()
88 SvXMLImportContext
*PageStyleContext::CreateChildContext(
90 const rtl::OUString
& rLocalName
,
91 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
93 SvXMLImportContext
*pContext
= NULL
;
95 if( XML_NAMESPACE_STYLE
== nPrefix
&&
96 ((IsXMLToken(rLocalName
, XML_HEADER_STYLE
)) ||
97 (IsXMLToken(rLocalName
, XML_FOOTER_STYLE
)) ) )
99 sal_Bool bHeader
= IsXMLToken(rLocalName
, XML_HEADER_STYLE
);
100 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
101 GetStyles()->GetImportPropertyMapper( GetFamily() );
104 const UniReference
< XMLPropertySetMapper
>& rMapper
= xImpPrMap
->getPropertySetMapper();
107 nFlag
= CTF_PM_HEADERFLAG
;
109 nFlag
= CTF_PM_FOOTERFLAG
;
110 sal_Int32
nStartIndex (-1);
111 sal_Int32
nEndIndex (-1);
112 sal_Bool
bFirst(sal_False
);
113 sal_Bool
bEnd(sal_False
);
114 sal_Int32 nIndex
= 0;
115 while ( nIndex
< rMapper
->GetEntryCount() && !bEnd
)
117 if ((rMapper
->GetEntryContextId( nIndex
) & CTF_PM_FLAGMASK
) == nFlag
)
122 nStartIndex
= nIndex
;
134 pContext
= new PageHeaderFooterContext(GetImport(), nPrefix
, rLocalName
,
135 xAttrList
, GetProperties(), xImpPrMap
, nStartIndex
, nEndIndex
, bHeader
);
138 if( XML_NAMESPACE_STYLE
== nPrefix
&&
139 IsXMLToken(rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
141 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
142 GetStyles()->GetImportPropertyMapper( GetFamily() );
145 const UniReference
< XMLPropertySetMapper
>& rMapper
= xImpPrMap
->getPropertySetMapper();
146 sal_Int32
nEndIndex (-1);
147 sal_Bool
bEnd(sal_False
);
148 sal_Int32 nIndex
= 0;
149 sal_Int16 nContextID
;
150 while ( nIndex
< rMapper
->GetEntryCount() && !bEnd
)
152 nContextID
= rMapper
->GetEntryContextId( nIndex
);
153 if (nContextID
&& ((nContextID
& CTF_PM_FLAGMASK
) != XML_PM_CTF_START
))
162 PageContextType aType
= Page
;
163 pContext
= new PagePropertySetContext( GetImport(), nPrefix
,
164 rLocalName
, xAttrList
,
165 XML_TYPE_PROP_PAGE_LAYOUT
,
167 xImpPrMap
, 0, nEndIndex
, aType
);
172 pContext
= XMLPropStyleContext::CreateChildContext( nPrefix
, rLocalName
,
177 void PageStyleContext::FillPropertySet(
178 const uno::Reference
<beans::XPropertySet
> & rPropSet
)
180 XMLPropStyleContext::FillPropertySet(rPropSet
);
181 if (sPageUsage
.getLength())
184 XMLPMPropHdl_PageStyleLayout aPageUsageHdl
;
185 if (aPageUsageHdl
.importXML(sPageUsage
, aPageUsage
, GetImport().GetMM100UnitConverter()))
186 rPropSet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage
);
190 // text grid enhancement for better CJK support
191 //set default page layout style
192 void PageStyleContext::SetDefaults( )
194 Reference
< XMultiServiceFactory
> xFactory ( GetImport().GetModel(), UNO_QUERY
);
197 Reference
< XInterface
> xInt
= xFactory
->createInstance (
198 rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
199 Reference
< beans::XPropertySet
> xProperties ( xInt
, UNO_QUERY
);
200 if ( xProperties
.is() )
201 FillPropertySet ( xProperties
);