Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/beans/XPropertySet.hpp>
21 : #include <com/sun/star/io/XOutputStream.hpp>
22 : #include <xmloff/xmlimp.hxx>
23 : #include <xmloff/xmltoken.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include <xmloff/XMLBase64ImportContext.hxx>
27 : #include "XMLReplacementImageContext.hxx"
28 :
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::uno::makeAny;
31 : using namespace ::com::sun::star::xml::sax;
32 : using namespace ::com::sun::star::beans;
33 :
34 0 : TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext );
35 :
36 0 : XMLReplacementImageContext::XMLReplacementImageContext(
37 : SvXMLImport& rImport,
38 : sal_uInt16 nPrfx, const OUString& rLName,
39 : const Reference< XAttributeList > & rAttrList,
40 : const Reference< XPropertySet > & rPropSet ) :
41 : SvXMLImportContext( rImport, nPrfx, rLName ),
42 : m_xPropSet( rPropSet ),
43 0 : m_sGraphicURL("GraphicURL")
44 : {
45 : UniReference < XMLTextImportHelper > xTxtImport =
46 0 : GetImport().GetTextImport();
47 : const SvXMLTokenMap& rTokenMap =
48 0 : xTxtImport->GetTextFrameAttrTokenMap();
49 :
50 0 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
51 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
52 : {
53 0 : const OUString& rAttrName = rAttrList->getNameByIndex( i );
54 0 : const OUString& rValue = rAttrList->getValueByIndex( i );
55 :
56 0 : OUString aLocalName;
57 : sal_uInt16 nPrefix =
58 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
59 0 : &aLocalName );
60 0 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
61 : {
62 : case XML_TOK_TEXT_FRAME_HREF:
63 0 : m_sHRef = rValue;
64 0 : break;
65 : }
66 0 : }
67 0 : }
68 :
69 0 : XMLReplacementImageContext::~XMLReplacementImageContext()
70 : {
71 0 : }
72 :
73 0 : void XMLReplacementImageContext::EndElement()
74 : {
75 : OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
76 : "neither URL nor base64 image data given" );
77 : UniReference < XMLTextImportHelper > xTxtImport =
78 0 : GetImport().GetTextImport();
79 0 : OUString sHRef;
80 0 : if( !m_sHRef.isEmpty() )
81 : {
82 0 : sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
83 0 : xTxtImport->IsBlockMode() ||
84 0 : xTxtImport->IsStylesOnlyMode() ||
85 0 : xTxtImport->IsOrganizerMode();
86 0 : sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
87 : }
88 0 : else if( m_xBase64Stream.is() )
89 : {
90 0 : sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
91 0 : m_xBase64Stream = 0;
92 : }
93 :
94 : Reference < XPropertySetInfo > xPropSetInfo =
95 0 : m_xPropSet->getPropertySetInfo();
96 0 : if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
97 0 : m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
98 0 : }
99 :
100 0 : SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
101 : sal_uInt16 nPrefix,
102 : const OUString& rLocalName,
103 : const Reference< XAttributeList > & xAttrList )
104 : {
105 0 : SvXMLImportContext *pContext = 0;
106 :
107 0 : if( XML_NAMESPACE_OFFICE == nPrefix &&
108 0 : IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
109 0 : !m_xBase64Stream.is() )
110 : {
111 0 : m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
112 0 : if( m_xBase64Stream.is() )
113 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
114 : rLocalName, xAttrList,
115 0 : m_xBase64Stream );
116 : }
117 :
118 0 : if( !pContext )
119 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
120 :
121 0 : return pContext;
122 : }
123 :
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|