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: XMLReplacementImageContext.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"
33 #include <tools/debug.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/io/XOutputStream.hpp>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include "xmlnmspe.hxx"
39 #include "xmlkywd.hxx"
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/XMLBase64ImportContext.hxx>
42 #include "XMLReplacementImageContext.hxx"
44 using ::rtl::OUString
;
45 using ::com::sun::star::uno::Reference
;
46 using ::com::sun::star::uno::makeAny
;
47 using namespace ::com::sun::star::xml::sax
;
48 using namespace ::com::sun::star::beans
;
50 TYPEINIT1( XMLReplacementImageContext
, SvXMLImportContext
);
52 XMLReplacementImageContext::XMLReplacementImageContext(
54 sal_uInt16 nPrfx
, const OUString
& rLName
,
55 const Reference
< XAttributeList
> & rAttrList
,
56 const Reference
< XPropertySet
> & rPropSet
) :
57 SvXMLImportContext( rImport
, nPrfx
, rLName
),
58 m_xPropSet( rPropSet
),
59 m_sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))
61 UniReference
< XMLTextImportHelper
> xTxtImport
=
62 GetImport().GetTextImport();
63 const SvXMLTokenMap
& rTokenMap
=
64 xTxtImport
->GetTextFrameAttrTokenMap();
66 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
67 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
69 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
70 const OUString
& rValue
= rAttrList
->getValueByIndex( i
);
74 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
76 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
78 case XML_TOK_TEXT_FRAME_HREF
:
85 XMLReplacementImageContext::~XMLReplacementImageContext()
89 void XMLReplacementImageContext::EndElement()
91 OSL_ENSURE( m_sHRef
.getLength() > 0 || m_xBase64Stream
.is(),
92 "neither URL nor base64 image data given" );
93 UniReference
< XMLTextImportHelper
> xTxtImport
=
94 GetImport().GetTextImport();
96 if( m_sHRef
.getLength() )
98 sal_Bool bForceLoad
= xTxtImport
->IsInsertMode() ||
99 xTxtImport
->IsBlockMode() ||
100 xTxtImport
->IsStylesOnlyMode() ||
101 xTxtImport
->IsOrganizerMode();
102 sHRef
= GetImport().ResolveGraphicObjectURL( m_sHRef
, !bForceLoad
);
104 else if( m_xBase64Stream
.is() )
106 sHRef
= GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream
);
110 Reference
< XPropertySetInfo
> xPropSetInfo
=
111 m_xPropSet
->getPropertySetInfo();
112 if( xPropSetInfo
->hasPropertyByName( m_sGraphicURL
) )
113 m_xPropSet
->setPropertyValue( m_sGraphicURL
, makeAny( sHRef
) );
116 SvXMLImportContext
*XMLReplacementImageContext::CreateChildContext(
118 const OUString
& rLocalName
,
119 const Reference
< XAttributeList
> & xAttrList
)
121 SvXMLImportContext
*pContext
= 0;
123 if( XML_NAMESPACE_OFFICE
== nPrefix
&&
124 IsXMLToken( rLocalName
, ::xmloff::token::XML_BINARY_DATA
) &&
125 !m_xBase64Stream
.is() )
127 m_xBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
128 if( m_xBase64Stream
.is() )
129 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
130 rLocalName
, xAttrList
,
135 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);