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 <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"
29 :
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;
34 :
35 0 : TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext );
36 :
37 54 : 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 54 : m_sGraphicURL("GraphicURL")
45 : {
46 : rtl::Reference < XMLTextImportHelper > xTxtImport =
47 54 : GetImport().GetTextImport();
48 : const SvXMLTokenMap& rTokenMap =
49 54 : xTxtImport->GetTextFrameAttrTokenMap();
50 :
51 54 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
52 266 : for( sal_Int16 i=0; i < nAttrCount; i++ )
53 : {
54 212 : const OUString& rAttrName = rAttrList->getNameByIndex( i );
55 424 : const OUString& rValue = rAttrList->getValueByIndex( i );
56 :
57 424 : OUString aLocalName;
58 : sal_uInt16 nPrefix =
59 212 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
60 212 : &aLocalName );
61 212 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
62 : {
63 : case XML_TOK_TEXT_FRAME_HREF:
64 53 : m_sHRef = rValue;
65 53 : break;
66 : }
67 266 : }
68 54 : }
69 :
70 108 : XMLReplacementImageContext::~XMLReplacementImageContext()
71 : {
72 108 : }
73 :
74 54 : void XMLReplacementImageContext::EndElement()
75 : {
76 : OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
77 : "neither URL nor base64 image data given" );
78 : rtl::Reference < XMLTextImportHelper > xTxtImport =
79 54 : GetImport().GetTextImport();
80 108 : OUString sHRef;
81 54 : if( !m_sHRef.isEmpty() )
82 : {
83 106 : bool bForceLoad = xTxtImport->IsInsertMode() ||
84 106 : xTxtImport->IsBlockMode() ||
85 159 : xTxtImport->IsStylesOnlyMode() ||
86 106 : xTxtImport->IsOrganizerMode();
87 53 : sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
88 : }
89 1 : else if( m_xBase64Stream.is() )
90 : {
91 1 : sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
92 1 : m_xBase64Stream = 0;
93 : }
94 :
95 : Reference < XPropertySetInfo > xPropSetInfo =
96 108 : m_xPropSet->getPropertySetInfo();
97 54 : if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
98 64 : m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
99 54 : }
100 :
101 1 : SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
102 : sal_uInt16 nPrefix,
103 : const OUString& rLocalName,
104 : const Reference< XAttributeList > & xAttrList )
105 : {
106 1 : SvXMLImportContext *pContext = 0;
107 :
108 2 : if( XML_NAMESPACE_OFFICE == nPrefix &&
109 2 : IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
110 1 : !m_xBase64Stream.is() )
111 : {
112 1 : m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
113 1 : if( m_xBase64Stream.is() )
114 1 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
115 : rLocalName, xAttrList,
116 1 : m_xBase64Stream );
117 : }
118 :
119 1 : if( !pContext )
120 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
121 :
122 1 : return pContext;
123 : }
124 :
125 :
126 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|