1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 28cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 29cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 31cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 32cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 33cdf0e10cSrcweir #include <xmloff/XMLBase64ImportContext.hxx> 34cdf0e10cSrcweir #include "XMLReplacementImageContext.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir using ::rtl::OUString; 37cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 38cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 39cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 40cdf0e10cSrcweir using namespace ::com::sun::star::beans; 41cdf0e10cSrcweir 42cdf0e10cSrcweir TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext ); 43cdf0e10cSrcweir 44cdf0e10cSrcweir XMLReplacementImageContext::XMLReplacementImageContext( 45cdf0e10cSrcweir SvXMLImport& rImport, 46cdf0e10cSrcweir sal_uInt16 nPrfx, const OUString& rLName, 47cdf0e10cSrcweir const Reference< XAttributeList > & rAttrList, 48cdf0e10cSrcweir const Reference< XPropertySet > & rPropSet ) : 49cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ), 50cdf0e10cSrcweir m_xPropSet( rPropSet ), 51cdf0e10cSrcweir m_sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir UniReference < XMLTextImportHelper > xTxtImport = 54cdf0e10cSrcweir GetImport().GetTextImport(); 55cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = 56cdf0e10cSrcweir xTxtImport->GetTextFrameAttrTokenMap(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0; 59cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir const OUString& rAttrName = rAttrList->getNameByIndex( i ); 62cdf0e10cSrcweir const OUString& rValue = rAttrList->getValueByIndex( i ); 63cdf0e10cSrcweir 64cdf0e10cSrcweir OUString aLocalName; 65cdf0e10cSrcweir sal_uInt16 nPrefix = 66cdf0e10cSrcweir GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 67cdf0e10cSrcweir &aLocalName ); 68cdf0e10cSrcweir switch( rTokenMap.Get( nPrefix, aLocalName ) ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir case XML_TOK_TEXT_FRAME_HREF: 71cdf0e10cSrcweir m_sHRef = rValue; 72cdf0e10cSrcweir break; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir XMLReplacementImageContext::~XMLReplacementImageContext() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir void XMLReplacementImageContext::EndElement() 82cdf0e10cSrcweir { 83cdf0e10cSrcweir OSL_ENSURE( m_sHRef.getLength() > 0 || m_xBase64Stream.is(), 84cdf0e10cSrcweir "neither URL nor base64 image data given" ); 85cdf0e10cSrcweir UniReference < XMLTextImportHelper > xTxtImport = 86cdf0e10cSrcweir GetImport().GetTextImport(); 87cdf0e10cSrcweir OUString sHRef; 88cdf0e10cSrcweir if( m_sHRef.getLength() ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir sal_Bool bForceLoad = xTxtImport->IsInsertMode() || 91cdf0e10cSrcweir xTxtImport->IsBlockMode() || 92cdf0e10cSrcweir xTxtImport->IsStylesOnlyMode() || 93cdf0e10cSrcweir xTxtImport->IsOrganizerMode(); 94cdf0e10cSrcweir sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir else if( m_xBase64Stream.is() ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream ); 99cdf0e10cSrcweir m_xBase64Stream = 0; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir Reference < XPropertySetInfo > xPropSetInfo = 103cdf0e10cSrcweir m_xPropSet->getPropertySetInfo(); 104cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) ) 105cdf0e10cSrcweir m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir SvXMLImportContext *XMLReplacementImageContext::CreateChildContext( 109cdf0e10cSrcweir sal_uInt16 nPrefix, 110cdf0e10cSrcweir const OUString& rLocalName, 111cdf0e10cSrcweir const Reference< XAttributeList > & xAttrList ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir SvXMLImportContext *pContext = 0; 114cdf0e10cSrcweir 115cdf0e10cSrcweir if( XML_NAMESPACE_OFFICE == nPrefix && 116cdf0e10cSrcweir IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) && 117cdf0e10cSrcweir !m_xBase64Stream.is() ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); 120cdf0e10cSrcweir if( m_xBase64Stream.is() ) 121cdf0e10cSrcweir pContext = new XMLBase64ImportContext( GetImport(), nPrefix, 122cdf0e10cSrcweir rLocalName, xAttrList, 123cdf0e10cSrcweir m_xBase64Stream ); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir if( !pContext ) 127cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir return pContext; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir 133