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: storages.hxx,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 #ifndef __FRAMEWORK_PATTERN_STORAGES_HXX_
32 #define __FRAMEWORK_PATTERN_STORAGES_HXX_
34 //_______________________________________________
40 //_______________________________________________
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 //_______________________________________________
53 //_______________________________________________
57 namespace css
= ::com::sun::star
;
64 //_______________________________________________
67 //-----------------------------------------------
68 css::uno::Reference
< css::embed::XStorage
> createTempStorageBasedOnFolder(const ::rtl::OUString
& sFolder
,
69 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
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
);
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
);
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
);
88 // open the temp. zip package - using the right open mode
89 sal_Int32 nOpenMode
= css::embed::ElementModes::ELEMENT_READWRITE
;
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
);
101 } // namespace storages
102 } // namespace pattern
103 } // namespace framework
105 #endif // __FRAMEWORK_PATTERN_STORAGES_HXX_