update dev300-m58
[ooovba.git] / sw / source / filter / xml / xmlbrsh.cxx
blobfc2b637d0da00036c90129a33c4488e42159df03
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlbrsh.cxx,v $
10 * $Revision: 1.16 $
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 <tools/debug.hxx>
38 #include <com/sun/star/io/XOutputStream.hpp>
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmlnmspe.hxx>
42 #include <xmloff/xmlimp.hxx>
43 #include <xmloff/xmltkmap.hxx>
44 #include <xmloff/XMLBase64ImportContext.hxx>
45 #include <goodies/grfmgr.hxx>
46 #include <svx/unomid.hxx>
47 #include <svx/brshitem.hxx>
48 #include <xmloff/xmluconv.hxx>
50 #include "xmlbrshi.hxx"
51 #include "xmlbrshe.hxx"
52 #include "xmlexp.hxx"
53 #include "xmlimpit.hxx"
54 #include "xmlexpit.hxx"
56 using ::rtl::OUString;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::xmloff::token;
61 enum SvXMLTokenMapAttrs
63 XML_TOK_BGIMG_HREF,
64 XML_TOK_BGIMG_TYPE,
65 XML_TOK_BGIMG_ACTUATE,
66 XML_TOK_BGIMG_SHOW,
67 XML_TOK_BGIMG_POSITION,
68 XML_TOK_BGIMG_REPEAT,
69 XML_TOK_BGIMG_FILTER,
70 XML_TOK_NGIMG_END=XML_TOK_UNKNOWN
73 static __FAR_DATA SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] =
75 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_BGIMG_HREF },
76 { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_BGIMG_TYPE },
77 { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_BGIMG_ACTUATE },
78 { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_BGIMG_SHOW },
79 { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_BGIMG_POSITION },
80 { XML_NAMESPACE_STYLE, XML_REPEAT, XML_TOK_BGIMG_REPEAT },
81 { XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TOK_BGIMG_FILTER },
82 XML_TOKEN_MAP_END
85 TYPEINIT1( SwXMLBrushItemImportContext, SvXMLImportContext );
87 void SwXMLBrushItemImportContext::ProcessAttrs(
88 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
89 const SvXMLUnitConverter& rUnitConv )
91 SvXMLTokenMap aTokenMap( aBGImgAttributesAttrTokenMap );
93 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
94 for( sal_Int16 i=0; i < nAttrCount; i++ )
96 const OUString& rAttrName = xAttrList->getNameByIndex( i );
97 OUString aLocalName;
98 sal_uInt16 nPrefix =
99 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
100 &aLocalName );
101 const OUString& rValue = xAttrList->getValueByIndex( i );
103 switch( aTokenMap.Get( nPrefix, aLocalName ) )
105 case XML_TOK_BGIMG_HREF:
106 SvXMLImportItemMapper::PutXMLValue(
107 *pItem, GetImport().ResolveGraphicObjectURL( rValue,sal_False),
108 MID_GRAPHIC_LINK, rUnitConv );
109 break;
110 case XML_TOK_BGIMG_TYPE:
111 case XML_TOK_BGIMG_ACTUATE:
112 case XML_TOK_BGIMG_SHOW:
113 break;
114 case XML_TOK_BGIMG_POSITION:
115 SvXMLImportItemMapper::PutXMLValue(
116 *pItem, rValue, MID_GRAPHIC_POSITION, rUnitConv );
117 break;
118 case XML_TOK_BGIMG_REPEAT:
119 SvXMLImportItemMapper::PutXMLValue(
120 *pItem, rValue, MID_GRAPHIC_REPEAT, rUnitConv );
121 break;
122 case XML_TOK_BGIMG_FILTER:
123 SvXMLImportItemMapper::PutXMLValue(
124 *pItem, rValue, MID_GRAPHIC_FILTER, rUnitConv );
125 break;
131 SvXMLImportContext *SwXMLBrushItemImportContext::CreateChildContext(
132 sal_uInt16 nPrefix, const OUString& rLocalName,
133 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
135 SvXMLImportContext *pContext = 0;
136 if( xmloff::token::IsXMLToken( rLocalName,
137 xmloff::token::XML_BINARY_DATA ) )
139 if( !xBase64Stream.is() && !pItem->GetGraphicLink() )
141 const GraphicObject *pGrObj = pItem->GetGraphicObject();
142 if( !pGrObj || GRAPHIC_NONE == pGrObj->GetType() )
144 xBase64Stream =
145 GetImport().GetStreamForGraphicObjectURLFromBase64();
146 if( xBase64Stream.is() )
147 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
148 rLocalName, xAttrList,
149 xBase64Stream );
153 if( !pContext )
155 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
158 return pContext;
161 void SwXMLBrushItemImportContext::EndElement()
163 if( xBase64Stream.is() )
165 OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ) );
166 xBase64Stream = 0;
167 SvXMLImportItemMapper::PutXMLValue( *pItem, sURL, MID_GRAPHIC_LINK, GetImport().GetMM100UnitConverter() );
170 if( !(pItem->GetGraphicLink() || pItem->GetGraphic() ) )
171 pItem->SetGraphicPos( GPOS_NONE );
172 else if( GPOS_NONE == pItem->GetGraphicPos() )
173 pItem->SetGraphicPos( GPOS_TILED );
176 SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
177 SvXMLImport& rImport, sal_uInt16 nPrfx,
178 const OUString& rLName,
179 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
180 const SvXMLUnitConverter& rUnitConv,
181 const SvxBrushItem& rItem ) :
182 SvXMLImportContext( rImport, nPrfx, rLName ),
183 pItem( new SvxBrushItem( rItem ) )
185 // delete any grephic that is existing
186 pItem->SetGraphicPos( GPOS_NONE );
188 ProcessAttrs( xAttrList, rUnitConv );
191 SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
192 SvXMLImport& rImport, sal_uInt16 nPrfx,
193 const OUString& rLName,
194 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
195 const SvXMLUnitConverter& rUnitConv,
196 sal_uInt16 nWhich ) :
197 SvXMLImportContext( rImport, nPrfx, rLName ),
198 pItem( new SvxBrushItem( nWhich ) )
200 ProcessAttrs( xAttrList, rUnitConv );
203 SwXMLBrushItemImportContext::~SwXMLBrushItemImportContext()
205 delete pItem;
208 SwXMLBrushItemExport::SwXMLBrushItemExport( SwXMLExport& rExp ) :
209 rExport( rExp )
213 SwXMLBrushItemExport::~SwXMLBrushItemExport()
218 void SwXMLBrushItemExport::exportXML( const SvxBrushItem& rItem )
220 GetExport().CheckAttrList();
222 OUString sValue, sURL;
223 const SvXMLUnitConverter& rUnitConv = GetExport().GetTwipUnitConverter();
224 if( SvXMLExportItemMapper::QueryXMLValue(
225 rItem, sURL, MID_GRAPHIC_LINK, rUnitConv ) )
227 sValue = GetExport().AddEmbeddedGraphicObject( sURL );
228 if( sValue.getLength() )
230 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sValue );
231 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
232 // AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, ACP2WS(sXML_embed) );
233 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
236 if( SvXMLExportItemMapper::QueryXMLValue(
237 rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv ) )
238 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION, sValue );
240 if( SvXMLExportItemMapper::QueryXMLValue(
241 rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv ) )
242 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT, sValue );
244 if( SvXMLExportItemMapper::QueryXMLValue(
245 rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv ) )
246 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME, sValue );
250 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE,
251 sal_True, sal_True );
252 if( sURL.getLength() )
254 // optional office:binary-data
255 GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );