bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / XMLReplacementImageContext.cxx
blob80e075b04dc85aaaf1561761b703fcc33b3a90fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/io/XOutputStream.hpp>
22 #include <osl/diagnose.h>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/XMLBase64ImportContext.hxx>
28 #include "XMLReplacementImageContext.hxx"
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::makeAny;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::com::sun::star::beans;
35 TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext );
37 XMLReplacementImageContext::XMLReplacementImageContext(
38 SvXMLImport& rImport,
39 sal_uInt16 nPrfx, const OUString& rLName,
40 const Reference< XAttributeList > & rAttrList,
41 const Reference< XPropertySet > & rPropSet ) :
42 SvXMLImportContext( rImport, nPrfx, rLName ),
43 m_xPropSet( rPropSet ),
44 m_sGraphicURL("GraphicURL")
46 rtl::Reference < XMLTextImportHelper > xTxtImport =
47 GetImport().GetTextImport();
48 const SvXMLTokenMap& rTokenMap =
49 xTxtImport->GetTextFrameAttrTokenMap();
51 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
52 for( sal_Int16 i=0; i < nAttrCount; i++ )
54 const OUString& rAttrName = rAttrList->getNameByIndex( i );
55 const OUString& rValue = rAttrList->getValueByIndex( i );
57 OUString aLocalName;
58 sal_uInt16 nPrefix =
59 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
60 &aLocalName );
61 switch( rTokenMap.Get( nPrefix, aLocalName ) )
63 case XML_TOK_TEXT_FRAME_HREF:
64 m_sHRef = rValue;
65 break;
70 XMLReplacementImageContext::~XMLReplacementImageContext()
74 void XMLReplacementImageContext::EndElement()
76 OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
77 "neither URL nor base64 image data given" );
78 rtl::Reference < XMLTextImportHelper > xTxtImport =
79 GetImport().GetTextImport();
80 OUString sHRef;
81 if( !m_sHRef.isEmpty() )
83 bool bForceLoad = xTxtImport->IsInsertMode() ||
84 xTxtImport->IsBlockMode() ||
85 xTxtImport->IsStylesOnlyMode() ||
86 xTxtImport->IsOrganizerMode();
87 sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
89 else if( m_xBase64Stream.is() )
91 sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
92 m_xBase64Stream = 0;
95 Reference < XPropertySetInfo > xPropSetInfo =
96 m_xPropSet->getPropertySetInfo();
97 if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
98 m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
101 SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
102 sal_uInt16 nPrefix,
103 const OUString& rLocalName,
104 const Reference< XAttributeList > & xAttrList )
106 SvXMLImportContext *pContext = 0;
108 if( XML_NAMESPACE_OFFICE == nPrefix &&
109 IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
110 !m_xBase64Stream.is() )
112 m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
113 if( m_xBase64Stream.is() )
114 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
115 rLocalName, xAttrList,
116 m_xBase64Stream );
119 if( !pContext )
120 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
122 return pContext;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */