Update ooo320-m1
[ooovba.git] / svx / inc / xmlgrhlp.hxx
blob71d52a42c3c4ba2b865aa06920516ea9123941ba
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: xmlgrhlp.hxx,v $
10 * $Revision: 1.17 $
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 #ifndef _XMLGRHLP_HXX
32 #define _XMLGRHLP_HXX
34 #include <cppuhelper/compbase2.hxx>
35 #include <osl/mutex.hxx>
36 #include <goodies/grfmgr.hxx>
37 #include <vector>
38 #include <set>
39 #include <utility>
40 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
41 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
42 #include <com/sun/star/embed/XStorage.hpp>
43 #include "svx/svxdllapi.h"
45 // ----------------------
46 // - SvXMLGraphicHelper -
47 // ----------------------
49 enum SvXMLGraphicHelperMode
51 GRAPHICHELPER_MODE_READ = 0,
52 GRAPHICHELPER_MODE_WRITE = 1
55 // ----------------------
56 // - SvXMLGraphicHelper -
57 // ----------------------
58 struct SvxGraphicHelperStream_Impl
60 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > xStorage;
61 ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > xStream;
64 class SVX_DLLPUBLIC SvXMLGraphicHelper : public ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
65 ::com::sun::star::document::XBinaryStreamResolver >
67 private:
69 typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > URLPair;
70 typedef ::std::vector< URLPair > URLPairVector;
71 typedef ::std::vector< GraphicObject > GraphicObjectVector;
72 typedef ::std::set< ::rtl::OUString > URLSet;
73 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > > GraphicOutputStreamVector;
75 ::osl::Mutex maMutex;
76 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > mxRootStorage;
77 ::rtl::OUString maCurStorageName;
78 URLPairVector maGrfURLs;
79 GraphicObjectVector maGrfObjs;
80 GraphicOutputStreamVector maGrfStms;
81 URLSet maURLSet;
82 SvXMLGraphicHelperMode meCreateMode;
83 sal_Bool mbDirect;
85 SVX_DLLPRIVATE sal_Bool ImplGetStreamNames( const ::rtl::OUString& rURLStr,
86 ::rtl::OUString& rPictureStorageName,
87 ::rtl::OUString& rPictureStreamName );
88 SVX_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > ImplGetGraphicStorage( const ::rtl::OUString& rPictureStorageName );
89 SVX_DLLPRIVATE SvxGraphicHelperStream_Impl ImplGetGraphicStream( const ::rtl::OUString& rPictureStorageName,
90 const ::rtl::OUString& rPictureStreamName,
91 BOOL bTruncate );
92 SVX_DLLPRIVATE String ImplGetGraphicMimeType( const String& rFileName ) const;
93 SVX_DLLPRIVATE Graphic ImplReadGraphic( const ::rtl::OUString& rPictureStorageName,
94 const ::rtl::OUString& rPictureStreamName );
95 SVX_DLLPRIVATE sal_Bool ImplWriteGraphic( const ::rtl::OUString& rPictureStorageName,
96 const ::rtl::OUString& rPictureStreamName,
97 const ::rtl::OUString& rGraphicId );
98 SVX_DLLPRIVATE void ImplInsertGraphicURL( const ::rtl::OUString& rURLStr, sal_uInt32 nInsertPos, rtl::OUString& rRequestedFileName );
100 protected:
101 SvXMLGraphicHelper();
102 ~SvXMLGraphicHelper();
103 void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage,
104 SvXMLGraphicHelperMode eCreateMode,
105 BOOL bDirect );
107 virtual void SAL_CALL disposing();
109 public:
110 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
112 static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage,
113 SvXMLGraphicHelperMode eCreateMode,
114 BOOL bDirect = TRUE );
115 static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode );
117 static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper );
119 public:
121 // XGraphicObjectResolver
122 virtual ::rtl::OUString SAL_CALL resolveGraphicObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException);
124 // XBinaryStreamResolver
125 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const ::rtl::OUString& rURL ) throw (::com::sun::star::uno::RuntimeException);
126 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException);
127 virtual ::rtl::OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException);
131 // for instantiation via service manager
132 namespace svx
134 /** Create this with createInstanceWithArguments. service name
135 "com.sun.star.comp.Svx.GraphicImportHelper", one argument which is the
136 XStorage. Without arguments no helper class is created. With an empty
137 argument the helper class is created and initialized like in the CTOR to
138 SvXMLGraphicHelper that only gets the create mode.
140 You should call dispose after you no longer need this component.
142 uses eCreateMode == GRAPHICHELPER_MODE_READ, bDirect == TRUE in
143 SvXMLGraphicHelper
145 SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicImportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception );
146 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames() throw();
147 SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName() throw();
149 /** Create this with createInstanceWithArguments. service name
150 "com.sun.star.comp.Svx.GraphicExportHelper", one argument which is the
151 XStorage. Without arguments no helper class is created. With an empty
152 argument the helper class is created and initialized like in the CTOR to
153 SvXMLGraphicHelper that only gets the create mode
155 To write the Pictures stream, you have to call dispose at this component.
156 Make sure you call dipose before you commit the parent storage.
158 uses eCreateMode == GRAPHICHELPER_MODE_WRITE, bDirect == TRUE in
159 SvXMLGraphicHelper
161 SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicExportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception );
162 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames() throw();
163 SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName() throw();
166 #endif