update dev300-m58
[ooovba.git] / framework / source / inc / pattern / storages.hxx
blob4bd75a3c22dd3f82bee69c790b80c6ab80ebc860
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: storages.hxx,v $
10 * $Revision: 1.4 $
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 __FRAMEWORK_PATTERN_STORAGES_HXX_
32 #define __FRAMEWORK_PATTERN_STORAGES_HXX_
34 //_______________________________________________
35 // own includes
37 #include <services.h>
38 #include <general.h>
40 //_______________________________________________
41 // interface includes
42 #include <com/sun/star/io/XOutputStream.hpp>
43 #include <com/sun/star/io/XSeekable.hpp>
44 #include <com/sun/star/embed/ElementModes.hpp>
45 #include <com/sun/star/embed/XStorage.hpp>
46 #include <com/sun/star/embed/XPackageStructureCreator.hpp>
47 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 //_______________________________________________
51 // other includes
53 //_______________________________________________
54 // namespaces
56 #ifndef css
57 namespace css = ::com::sun::star;
58 #endif
60 namespace framework{
61 namespace pattern{
62 namespace storages{
64 //_______________________________________________
65 // definitions
67 //-----------------------------------------------
68 css::uno::Reference< css::embed::XStorage > createTempStorageBasedOnFolder(const ::rtl::OUString& sFolder ,
69 const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
70 sal_Bool bReadOnly)
72 // error during opening the temp file isnt realy a runtime error -> handle it gracefully
73 css::uno::Reference< css::io::XOutputStream > xTempFile(xSMGR->createInstance(SERVICENAME_TEMPFILE), css::uno::UNO_QUERY);
74 if (!xTempFile.is())
75 return css::uno::Reference< css::embed::XStorage >();
77 // creation of needed resources is mandatory -> error = runtime error
78 css::uno::Reference< css::embed::XPackageStructureCreator > xPackageCreator(xSMGR->createInstance(SERVICENAME_PACKAGESTRUCTURECREATOR), css::uno::UNO_QUERY_THROW);
79 css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory(xSMGR->createInstance(SERVICENAME_STORAGEFACTORY) , css::uno::UNO_QUERY_THROW);
81 // create zip package
82 xPackageCreator->convertToPackage(sFolder, xTempFile);
84 // seek it back - so it can be used in a defined way.
85 css::uno::Reference< css::io::XSeekable > xSeekable(xTempFile, css::uno::UNO_QUERY_THROW);
86 xSeekable->seek(0);
88 // open the temp. zip package - using the right open mode
89 sal_Int32 nOpenMode = css::embed::ElementModes::ELEMENT_READWRITE;
90 if (bReadOnly)
91 nOpenMode = css::embed::ElementModes::ELEMENT_READ;
93 css::uno::Sequence< css::uno::Any > lArgs(2);
94 lArgs[0] <<= xTempFile;
95 lArgs[1] <<= nOpenMode;
97 css::uno::Reference< css::embed::XStorage > xStorage(xStorageFactory->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
98 return xStorage;
101 } // namespace storages
102 } // namespace pattern
103 } // namespace framework
105 #endif // __FRAMEWORK_PATTERN_STORAGES_HXX_