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 : #ifndef INCLUDED_SVX_XMLGRHLP_HXX
21 : #define INCLUDED_SVX_XMLGRHLP_HXX
22 :
23 : #include <cppuhelper/compbase2.hxx>
24 : #include <osl/mutex.hxx>
25 : #include <svtools/grfmgr.hxx>
26 : #include <vector>
27 : #include <set>
28 : #include <utility>
29 : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
30 : #include <com/sun/star/document/XBinaryStreamResolver.hpp>
31 : #include <com/sun/star/embed/XStorage.hpp>
32 : #include <svx/svxdllapi.h>
33 :
34 : enum SvXMLGraphicHelperMode
35 : {
36 : GRAPHICHELPER_MODE_READ = 0,
37 : GRAPHICHELPER_MODE_WRITE = 1
38 : };
39 :
40 284 : struct SvxGraphicHelperStream_Impl
41 : {
42 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > xStorage;
43 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > xStream;
44 : };
45 :
46 : class SVX_DLLPUBLIC SvXMLGraphicHelper : public ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
47 : ::com::sun::star::document::XBinaryStreamResolver >
48 : {
49 : private:
50 :
51 : typedef ::std::pair< OUString, OUString > URLPair;
52 : typedef ::std::vector< URLPair > URLPairVector;
53 : typedef ::std::vector< GraphicObject > GraphicObjectVector;
54 : typedef ::std::set< OUString > URLSet;
55 : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > > GraphicOutputStreamVector;
56 :
57 : ::osl::Mutex maMutex;
58 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > mxRootStorage;
59 : OUString maCurStorageName;
60 : URLPairVector maGrfURLs;
61 : GraphicObjectVector maGrfObjs;
62 : GraphicOutputStreamVector maGrfStms;
63 : URLSet maURLSet;
64 : SvXMLGraphicHelperMode meCreateMode;
65 : bool mbDirect;
66 :
67 : SVX_DLLPRIVATE bool ImplGetStreamNames( const OUString& rURLStr,
68 : OUString& rPictureStorageName,
69 : OUString& rPictureStreamName );
70 : SVX_DLLPRIVATE css::uno::Reference < css::embed::XStorage >
71 : ImplGetGraphicStorage( const OUString& rPictureStorageName );
72 : SVX_DLLPRIVATE SvxGraphicHelperStream_Impl
73 : ImplGetGraphicStream( const OUString& rPictureStorageName,
74 : const OUString& rPictureStreamName,
75 : bool bTruncate );
76 : SVX_DLLPRIVATE OUString ImplGetGraphicMimeType( const OUString& rFileName ) const;
77 : SVX_DLLPRIVATE Graphic ImplReadGraphic( const OUString& rPictureStorageName,
78 : const OUString& rPictureStreamName );
79 : SVX_DLLPRIVATE bool ImplWriteGraphic( const OUString& rPictureStorageName,
80 : const OUString& rPictureStreamName,
81 : const OUString& rGraphicId,
82 : bool bUseGfxLink );
83 : SVX_DLLPRIVATE void ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt32 nInsertPos, OUString& rRequestedFileName );
84 :
85 : protected:
86 : SvXMLGraphicHelper();
87 : virtual ~SvXMLGraphicHelper();
88 : void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage,
89 : SvXMLGraphicHelperMode eCreateMode,
90 : bool bDirect );
91 :
92 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
93 :
94 : public:
95 : SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
96 :
97 : static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage,
98 : SvXMLGraphicHelperMode eCreateMode,
99 : bool bDirect = true );
100 : static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode );
101 :
102 : static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper );
103 :
104 : public:
105 :
106 : // XGraphicObjectResolver
107 : virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 :
109 : // XBinaryStreamResolver
110 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const OUString& rURL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 : virtual OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : };
114 :
115 : #endif
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|