update dev300-m58
[ooovba.git] / writerfilter / source / dmapper / OLEHandler.cxx
blob465410e00e01131f56da5844e01f2e4ae54be7f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OLEHandler.cxx,v $
10 * $Revision: 1.3 $
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 ************************************************************************/
30 #include <OLEHandler.hxx>
31 #include <PropertyMap.hxx>
32 #include <doctok/resourceids.hxx>
33 #include <ooxml/resourceids.hxx>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
37 #include <com/sun/star/document/XStorageBasedDocument.hpp>
38 #include <com/sun/star/drawing/XShape.hpp>
39 #include <com/sun/star/embed/XEmbeddedObject.hpp>
40 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
41 #include <com/sun/star/graphic/XGraphic.hpp>
42 #include <com/sun/star/io/XStream.hpp>
43 #include <com/sun/star/lang/XComponent.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <com/sun/star/text/XTextDocument.hpp>
46 #include <com/sun/star/uno/XComponentContext.hpp>
48 namespace writerfilter {
49 namespace dmapper {
51 using namespace ::com::sun::star;
52 /*-- 23.04.2008 10:46:14---------------------------------------------------
54 -----------------------------------------------------------------------*/
55 OLEHandler::OLEHandler() :
56 m_nDxaOrig(0),
57 m_nDyaOrig(0)
60 /*-- 23.04.2008 10:46:14---------------------------------------------------
62 -----------------------------------------------------------------------*/
63 OLEHandler::~OLEHandler()
66 /*-- 23.04.2008 10:46:14---------------------------------------------------
68 -----------------------------------------------------------------------*/
69 void OLEHandler::attribute(Id rName, Value & rVal)
71 rtl::OUString sStringValue = rVal.getString();
72 (void)rName;
73 /* WRITERFILTERSTATUS: table: OLEHandler_attributedata */
74 switch( rName )
76 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
77 case NS_ooxml::LN_CT_OLEObject_Type:
78 m_sObjectType = sStringValue;
79 break;
80 case NS_ooxml::LN_CT_OLEObject_ProgID:
81 m_sProgId = sStringValue;
82 break;
83 case NS_ooxml::LN_CT_OLEObject_ShapeID:
84 m_sShapeId = sStringValue;
85 break;
86 case NS_ooxml::LN_CT_OLEObject_DrawAspect:
87 m_sDrawAspect = sStringValue;
88 break;
89 case NS_ooxml::LN_CT_OLEObject_ObjectID:
90 m_sObjectId = sStringValue;
91 break;
92 case NS_ooxml::LN_CT_OLEObject_r_id:
93 m_sr_id = sStringValue;
94 break;
95 case NS_ooxml::LN_inputstream:
96 rVal.getAny() >>= m_xInputStream;
97 break;
98 case NS_ooxml::LN_CT_Object_dxaOrig:
99 m_nDxaOrig = rVal.getInt();
100 break;
101 case NS_ooxml::LN_CT_Object_dyaOrig:
102 m_nDyaOrig = rVal.getInt();
103 break;
104 case NS_ooxml::LN_shape:
105 /* WRITERFILTERSTATUS: done: 0, planned: 0.5, spent: 0 */
107 uno::Reference< drawing::XShape > xTempShape;
108 rVal.getAny() >>= xTempShape;
109 if( xTempShape.is() )
111 m_aShapeSize = xTempShape->getSize();
112 m_aShapePosition = xTempShape->getPosition();
115 uno::Reference< beans::XPropertySet > xShapeProps( xTempShape, uno::UNO_QUERY_THROW );
116 xShapeProps->getPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_BITMAP ) ) >>= m_xReplacement;
118 catch( const uno::Exception& )
123 break;
124 default:
125 OSL_ENSURE( false, "unknown attribute");
128 /*-- 23.04.2008 10:46:14---------------------------------------------------
130 -----------------------------------------------------------------------*/
131 void OLEHandler::sprm(Sprm & rSprm)
133 sal_uInt32 nSprmId = rSprm.getId();
134 switch( nSprmId )
136 case NS_ooxml::LN_OLEObject_OLEObject:
138 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
139 if( pProperties.get())
141 pProperties->resolve(*this);
144 break;
145 default:
146 OSL_ENSURE( false, "unknown attribute");
149 /*-- 23.04.2008 11:15:19---------------------------------------------------
151 -----------------------------------------------------------------------*/
152 ::rtl::OUString OLEHandler::copyOLEOStream( uno::Reference< text::XTextDocument > xTextDocument )
154 ::rtl::OUString sRet;
155 if( !m_xInputStream.is() )
156 return sRet;
157 try{
158 uno::Reference < lang::XMultiServiceFactory > xFactory(xTextDocument, uno::UNO_QUERY_THROW);
159 uno::Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver(
160 xFactory->createInstance(
161 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver" ))), uno::UNO_QUERY_THROW );
162 //hack to work with the ImportEmbeddedObjectResolver
163 static sal_Int32 nObjectCount = 100;
164 uno::Reference< container::XNameAccess > xNA( xEmbeddedResolver, uno::UNO_QUERY_THROW );
165 ::rtl::OUString aURL(RTL_CONSTASCII_USTRINGPARAM("Obj" ));
166 aURL += ::rtl::OUString::valueOf( nObjectCount++ );
167 uno::Reference < io::XOutputStream > xOLEStream;
168 if( (xNA->getByName( aURL ) >>= xOLEStream) && xOLEStream.is() )
170 const sal_Int32 nReadRequest = 0x1000;
171 uno::Sequence< sal_Int8 > aData;
173 while( true )
175 sal_Int32 nRead = m_xInputStream->readBytes( aData, nReadRequest );
176 xOLEStream->writeBytes( aData );
177 if( nRead < nReadRequest )
179 xOLEStream->closeOutput();
180 break;
184 static const ::rtl::OUString sProtocol = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.EmbeddedObject:" ));
185 ::rtl::OUString aPersistName( xEmbeddedResolver->resolveEmbeddedObjectURL( aURL ) );
186 sRet = aPersistName.copy( sProtocol.getLength() );
189 uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW );
190 xComp->dispose();
192 catch( const uno::Exception& rEx)
194 (void)rEx;
195 OSL_ENSURE(false, "exception in OLEHandler::createOLEObject");
197 return sRet;
200 } //namespace dmapper
201 } //namespace writerfilter