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: xmlitemi.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_sw.hxx"
36 #include <hintids.hxx>
37 #include <rtl/ustring.hxx>
38 #include <rsc/rscsfx.hxx>
39 #include "xmlitmap.hxx"
40 #include "xmlimpit.hxx"
41 #include "xmlitem.hxx"
42 #include <xmloff/i18nmap.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #ifndef _XMLOFF_FAMILIES_HXX
45 #include <xmloff/families.hxx>
47 #include <svx/unomid.hxx>
48 #include <svx/boxitem.hxx>
49 #include <svx/fontitem.hxx>
50 #include <svx/tstpitem.hxx>
51 #include <svx/boxitem.hxx>
52 #include <svx/brshitem.hxx>
53 #include <svx/langitem.hxx>
55 #ifndef _XMLOFF_XMLTABI_HXX
56 //#include <xmloff/xmltabi.hxx>
58 #include "xmlbrshi.hxx"
66 using ::rtl::OUString
;
67 using namespace ::com::sun::star
;
68 using namespace ::com::sun::star::uno
;
70 extern SvXMLItemMapEntry aXMLTableItemMap
[];
71 extern SvXMLItemMapEntry aXMLTableColItemMap
[];
72 extern SvXMLItemMapEntry aXMLTableRowItemMap
[];
73 extern SvXMLItemMapEntry aXMLTableCellItemMap
[];
75 class SwXMLImportTableItemMapper_Impl
: public SvXMLImportItemMapper
80 SwXMLImportTableItemMapper_Impl( SvXMLItemMapEntriesRef rMapEntries
);
81 virtual ~SwXMLImportTableItemMapper_Impl();
83 virtual sal_Bool
handleSpecialItem( const SvXMLItemMapEntry
& rEntry
,
86 const OUString
& rValue
,
87 const SvXMLUnitConverter
& rUnitConverter
,
88 const SvXMLNamespaceMap
& rNamespaceMap
) const;
89 virtual void finished( SfxItemSet
& rSet
) const;
92 SwXMLImportTableItemMapper_Impl::SwXMLImportTableItemMapper_Impl(
93 SvXMLItemMapEntriesRef rMapEntries
) :
94 SvXMLImportItemMapper( rMapEntries
, RES_UNKNOWNATR_CONTAINER
)
98 SwXMLImportTableItemMapper_Impl::~SwXMLImportTableItemMapper_Impl()
102 sal_Bool
SwXMLImportTableItemMapper_Impl::handleSpecialItem(
103 const SvXMLItemMapEntry
& rEntry
,
105 SfxItemSet
& rItemSet
,
106 const OUString
& rValue
,
107 const SvXMLUnitConverter
& rUnitConv
,
108 const SvXMLNamespaceMap
& ) const
110 sal_Bool bRet
= sal_False
;
111 sal_uInt16 nMemberId
= static_cast< sal_Int16
>(rEntry
.nMemberId
& MID_SW_FLAG_MASK
);
112 switch( rItem
.Which() )
117 case MID_FRMSIZE_COL_WIDTH
:
118 // If the item is existing already, a relative value has been set
119 // already that must be preserved.
120 if( SFX_ITEM_SET
!= rItemSet
.GetItemState( RES_FRM_SIZE
,
122 bRet
= SvXMLImportItemMapper::PutXMLValue(
123 rItem
, rValue
, nMemberId
, rUnitConv
);
131 void SwXMLImportTableItemMapper_Impl::finished( SfxItemSet
& /*rSet*/ ) const
135 // ---------------------------------------------------------------------
137 class SwXMLItemSetContext_Impl
: public SvXMLItemSetContext
139 SvXMLImportContextRef xBackground
;
141 using SvXMLItemSetContext::CreateChildContext
;
144 SwXMLItemSetContext_Impl( SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
145 const OUString
& rLName
,
146 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
147 SfxItemSet
& rItemSet
,
148 const SvXMLImportItemMapper
& rIMapper
,
149 const SvXMLUnitConverter
& rUnitConv
);
150 virtual ~SwXMLItemSetContext_Impl();
152 virtual SvXMLImportContext
*CreateChildContext( USHORT nPrefix
,
153 const ::rtl::OUString
& rLocalName
,
154 const ::uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
155 SfxItemSet
& rItemSet
,
156 const SvXMLItemMapEntry
& rEntry
,
157 const SvXMLUnitConverter
& rUnitConv
);
160 SwXMLItemSetContext_Impl::SwXMLItemSetContext_Impl(
161 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
162 const OUString
& rLName
,
163 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
164 SfxItemSet
& _rItemSet
,
165 const SvXMLImportItemMapper
& _rIMapper
,
166 const SvXMLUnitConverter
& _rUnitConv
) :
167 SvXMLItemSetContext( rImport
, nPrfx
, rLName
, xAttrList
,
168 _rItemSet
, _rIMapper
, _rUnitConv
)
172 SwXMLItemSetContext_Impl::~SwXMLItemSetContext_Impl()
174 if( xBackground
.Is() )
176 const SvxBrushItem
& rItem
=
177 ((SwXMLBrushItemImportContext
*)&xBackground
)->GetItem();
178 rItemSet
.Put( rItem
);
182 SvXMLImportContext
*SwXMLItemSetContext_Impl::CreateChildContext(
184 const OUString
& rLocalName
,
185 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
186 SfxItemSet
& _rItemSet
,
187 const SvXMLItemMapEntry
& rEntry
,
188 const SvXMLUnitConverter
& _rUnitConv
)
190 SvXMLImportContext
*pContext
= 0;
192 switch( rEntry
.nWhichId
)
196 const SfxPoolItem
*pItem
;
197 if( SFX_ITEM_SET
== _rItemSet
.GetItemState( RES_BACKGROUND
,
198 sal_False
, &pItem
) )
200 pContext
= new SwXMLBrushItemImportContext(
201 GetImport(), nPrefix
, rLocalName
, xAttrList
,
202 _rUnitConv
, *(const SvxBrushItem
*)pItem
);
206 pContext
= new SwXMLBrushItemImportContext(
207 GetImport(), nPrefix
, rLocalName
, xAttrList
,
208 _rUnitConv
, RES_BACKGROUND
);
210 xBackground
= pContext
;
216 pContext
= SvXMLItemSetContext::CreateChildContext( nPrefix
, rLocalName
,
217 xAttrList
, _rItemSet
,
218 rEntry
, _rUnitConv
);
223 // ---------------------------------------------------------------------
225 void SwXMLImport::_InitItemImport()
228 pTwipUnitConv
= new SvXMLUnitConverter( MAP_TWIP
, MAP_TWIP
, getServiceFactory() );
230 xTableItemMap
= new SvXMLItemMapEntries( aXMLTableItemMap
);
231 xTableColItemMap
= new SvXMLItemMapEntries( aXMLTableColItemMap
);
232 xTableRowItemMap
= new SvXMLItemMapEntries( aXMLTableRowItemMap
);
233 xTableCellItemMap
= new SvXMLItemMapEntries( aXMLTableCellItemMap
);
235 pTableItemMapper
= new SwXMLImportTableItemMapper_Impl( xTableItemMap
);
238 void SwXMLImport::_FinitItemImport()
240 delete pTableItemMapper
;
241 delete pTwipUnitConv
;
244 SvXMLImportContext
*SwXMLImport::CreateTableItemImportContext(
246 const OUString
& rLocalName
,
247 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
249 SfxItemSet
& rItemSet
)
251 SvXMLItemMapEntriesRef xItemMap
;
255 case XML_STYLE_FAMILY_TABLE_TABLE
:
256 xItemMap
= xTableItemMap
;
258 case XML_STYLE_FAMILY_TABLE_COLUMN
:
259 xItemMap
= xTableColItemMap
;
261 case XML_STYLE_FAMILY_TABLE_ROW
:
262 xItemMap
= xTableRowItemMap
;
264 case XML_STYLE_FAMILY_TABLE_CELL
:
265 xItemMap
= xTableCellItemMap
;
269 pTableItemMapper
->setMapEntries( xItemMap
);
271 return new SwXMLItemSetContext_Impl( *this, nPrefix
, rLocalName
,
273 GetTableItemMapper(),
274 GetTwipUnitConverter() );