1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphichelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/helper/graphichelper.hxx"
32 #include <com/sun/star/graphic/GraphicObject.hpp>
33 #include <com/sun/star/graphic/XGraphicProvider.hpp>
34 #include <comphelper/componentcontext.hxx>
35 #include <comphelper/seqstream.hxx>
37 using ::rtl::OUString
;
38 using ::com::sun::star::uno::Exception
;
39 using ::com::sun::star::uno::Reference
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::uno::UNO_QUERY
;
42 using ::com::sun::star::uno::UNO_SET_THROW
;
43 using ::com::sun::star::beans::PropertyValue
;
44 using ::com::sun::star::io::XInputStream
;
45 using ::com::sun::star::lang::XMultiServiceFactory
;
46 using ::com::sun::star::graphic::GraphicObject
;
47 using ::com::sun::star::graphic::XGraphic
;
48 using ::com::sun::star::graphic::XGraphicObject
;
49 using ::com::sun::star::graphic::XGraphicProvider
;
53 // ============================================================================
55 GraphicHelper::GraphicHelper( const Reference
< XMultiServiceFactory
>& rxFactory
) :
56 mxGraphicProvider( rxFactory
->createInstance( CREATE_OUSTRING( "com.sun.star.graphic.GraphicProvider" ) ), UNO_QUERY
),
57 maGraphicObjScheme( CREATE_OUSTRING( "vnd.sun.star.GraphicObject:" ) )
59 ::comphelper::ComponentContext
aContext( rxFactory
);
60 mxCompContext
= aContext
.getUNOContext();
63 GraphicHelper::~GraphicHelper()
67 Reference
< XGraphic
> GraphicHelper::importGraphic( const Reference
< XInputStream
>& rxInStrm
)
69 Reference
< XGraphic
> xGraphic
;
70 if( rxInStrm
.is() && mxGraphicProvider
.is() ) try
72 Sequence
< PropertyValue
> aArgs( 1 );
73 aArgs
[ 0 ].Name
= CREATE_OUSTRING( "InputStream" );
74 aArgs
[ 0 ].Value
<<= rxInStrm
;
75 xGraphic
= mxGraphicProvider
->queryGraphic( aArgs
);
83 Reference
< XGraphic
> GraphicHelper::importGraphic( const StreamDataSequence
& rGraphicData
)
85 Reference
< XGraphic
> xGraphic
;
86 if( rGraphicData
.hasElements() )
88 Reference
< XInputStream
> xInStrm( new ::comphelper::SequenceInputStream( rGraphicData
) );
89 xGraphic
= importGraphic( xInStrm
);
94 OUString
GraphicHelper::createGraphicObject( const Reference
< XGraphic
>& rxGraphic
)
96 OUString aGraphicObjUrl
;
97 if( mxCompContext
.is() && rxGraphic
.is() ) try
99 Reference
< XGraphicObject
> xGraphicObj( GraphicObject::create( mxCompContext
), UNO_SET_THROW
);
100 xGraphicObj
->setGraphic( rxGraphic
);
101 maGraphicObjects
.push_back( xGraphicObj
);
102 aGraphicObjUrl
= maGraphicObjScheme
+ xGraphicObj
->getUniqueID();
107 return aGraphicObjUrl
;
110 OUString
GraphicHelper::importGraphicObject( const Reference
< XInputStream
>& rxInStrm
)
112 return createGraphicObject( importGraphic( rxInStrm
) );
115 OUString
GraphicHelper::importGraphicObject( const StreamDataSequence
& rGraphicData
)
117 return createGraphicObject( importGraphic( rGraphicData
) );
120 // ============================================================================