Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/beans/XPropertySet.hpp>
30 : : #include <com/sun/star/io/XOutputStream.hpp>
31 : : #include <xmloff/xmlimp.hxx>
32 : : #include <xmloff/xmltoken.hxx>
33 : : #include "xmloff/xmlnmspe.hxx"
34 : : #include <xmloff/nmspmap.hxx>
35 : : #include <xmloff/XMLBase64ImportContext.hxx>
36 : : #include "XMLReplacementImageContext.hxx"
37 : :
38 : : using ::rtl::OUString;
39 : : using ::com::sun::star::uno::Reference;
40 : : using ::com::sun::star::uno::makeAny;
41 : : using namespace ::com::sun::star::xml::sax;
42 : : using namespace ::com::sun::star::beans;
43 : :
44 [ # # ][ # # ]: 0 : TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext );
45 : :
46 : 2 : XMLReplacementImageContext::XMLReplacementImageContext(
47 : : SvXMLImport& rImport,
48 : : sal_uInt16 nPrfx, const OUString& rLName,
49 : : const Reference< XAttributeList > & rAttrList,
50 : : const Reference< XPropertySet > & rPropSet ) :
51 : : SvXMLImportContext( rImport, nPrfx, rLName ),
52 : : m_xPropSet( rPropSet ),
53 [ + - ]: 2 : m_sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))
54 : : {
55 : : UniReference < XMLTextImportHelper > xTxtImport =
56 [ + - ]: 2 : GetImport().GetTextImport();
57 : : const SvXMLTokenMap& rTokenMap =
58 [ + - ][ + - ]: 2 : xTxtImport->GetTextFrameAttrTokenMap();
59 : :
60 [ + - ][ + - ]: 2 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
[ + - ]
61 [ + + ]: 10 : for( sal_Int16 i=0; i < nAttrCount; i++ )
62 : : {
63 [ + - ][ + - ]: 8 : const OUString& rAttrName = rAttrList->getNameByIndex( i );
64 [ + - ][ + - ]: 8 : const OUString& rValue = rAttrList->getValueByIndex( i );
65 : :
66 : 8 : OUString aLocalName;
67 : : sal_uInt16 nPrefix =
68 : 8 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
69 [ + - ]: 8 : &aLocalName );
70 [ + - ][ + + ]: 8 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
71 : : {
72 : : case XML_TOK_TEXT_FRAME_HREF:
73 : 2 : m_sHRef = rValue;
74 : 2 : break;
75 : : }
76 [ + - ]: 10 : }
77 : 2 : }
78 : :
79 : 2 : XMLReplacementImageContext::~XMLReplacementImageContext()
80 : : {
81 [ - + ]: 4 : }
82 : :
83 : 2 : void XMLReplacementImageContext::EndElement()
84 : : {
85 : : OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
86 : : "neither URL nor base64 image data given" );
87 : : UniReference < XMLTextImportHelper > xTxtImport =
88 [ + - ]: 2 : GetImport().GetTextImport();
89 : 2 : OUString sHRef;
90 [ + - ]: 2 : if( !m_sHRef.isEmpty() )
91 : : {
92 [ + - ][ + - ]: 2 : sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
93 [ + - ][ + - ]: 2 : xTxtImport->IsBlockMode() ||
94 [ + - ][ + - ]: 2 : xTxtImport->IsStylesOnlyMode() ||
95 [ + - ][ + - ]: 6 : xTxtImport->IsOrganizerMode();
[ + - ][ + - ]
[ + - ][ - + ]
96 [ + - ]: 2 : sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
97 : : }
98 [ # # ]: 0 : else if( m_xBase64Stream.is() )
99 : : {
100 [ # # ]: 0 : sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
101 [ # # ]: 0 : m_xBase64Stream = 0;
102 : : }
103 : :
104 : : Reference < XPropertySetInfo > xPropSetInfo =
105 [ + - ][ + - ]: 2 : m_xPropSet->getPropertySetInfo();
106 [ + - ][ + - ]: 2 : if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
[ + - ]
107 [ + - ][ + - ]: 2 : m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
[ + - ][ + - ]
108 : 2 : }
109 : :
110 : 0 : SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
111 : : sal_uInt16 nPrefix,
112 : : const OUString& rLocalName,
113 : : const Reference< XAttributeList > & xAttrList )
114 : : {
115 : 0 : SvXMLImportContext *pContext = 0;
116 : :
117 [ # # # # : 0 : if( XML_NAMESPACE_OFFICE == nPrefix &&
# # ][ # # ]
118 : 0 : IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
119 : 0 : !m_xBase64Stream.is() )
120 : : {
121 [ # # ]: 0 : m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
122 [ # # ]: 0 : if( m_xBase64Stream.is() )
123 : 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
124 : : rLocalName, xAttrList,
125 [ # # ]: 0 : m_xBase64Stream );
126 : : }
127 : :
128 [ # # ]: 0 : if( !pContext )
129 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
130 : :
131 : 0 : return pContext;
132 : : }
133 : :
134 : :
135 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|