1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 #include <framework/configimporter.hxx>
28 #include <framework/toolboxconfiguration.hxx>
29 #include <com/sun/star/embed/ElementModes.hpp>
30 
31 #include <rtl/ustrbuf.hxx>
32 
33 using namespace ::com::sun::star;
34 
35 namespace framework
36 {
37 
ImportCustomToolbars(const uno::Reference<ui::XUIConfigurationManager> & rContainerFactory,uno::Sequence<uno::Reference<container::XIndexContainer>> & rSeqContainer,const uno::Reference<lang::XMultiServiceFactory> & rServiceManager,const uno::Reference<embed::XStorage> & rToolbarStorage)38 sal_Bool UIConfigurationImporterOOo1x::ImportCustomToolbars(
39     const uno::Reference< ui::XUIConfigurationManager >& rContainerFactory,
40     uno::Sequence< uno::Reference< container::XIndexContainer > >& rSeqContainer,
41     const uno::Reference< lang::XMultiServiceFactory >& rServiceManager,
42     const uno::Reference< embed::XStorage >& rToolbarStorage )
43 {
44     const char USERDEFTOOLBOX[] = "userdeftoolbox0.xml";
45     uno::Reference< lang::XMultiServiceFactory > rSrvMgr( rServiceManager );
46 
47     sal_Bool bResult ( sal_False );
48     if ( rToolbarStorage.is() && rContainerFactory.is() )
49     {
50         try
51         {
52             for ( sal_uInt16 i = 1; i <= 4; i++ )
53             {
54                 rtl::OUStringBuffer aCustomTbxName( 20 );
55                 aCustomTbxName.appendAscii( USERDEFTOOLBOX );
56                 aCustomTbxName.setCharAt( 14, aCustomTbxName.charAt( 14 ) + i );
57 
58                 rtl::OUString aTbxStreamName( aCustomTbxName.makeStringAndClear() );
59                 uno::Reference< io::XStream > xStream = rToolbarStorage->openStreamElement( aTbxStreamName, embed::ElementModes::READ );
60                 if ( xStream.is() )
61                 {
62                     uno::Reference< io::XInputStream > xInputStream = xStream->getInputStream();
63                     if ( xInputStream.is() )
64                     {
65                         uno::Reference< container::XIndexContainer > xContainer = rContainerFactory->createSettings();
66                         if ( ToolBoxConfiguration::LoadToolBox( rSrvMgr, xInputStream, xContainer ))
67                         {
68                             sal_uInt32 nIndex = rSeqContainer.getLength();
69                             rSeqContainer.realloc( nIndex+1 );
70                             rSeqContainer[nIndex] = xContainer;
71                             bResult = sal_True;
72                         }
73                     }
74                 }
75             }
76         }
77         catch ( uno::RuntimeException& )
78         {
79             throw;
80         }
81         catch ( uno::Exception& )
82         {
83         }
84     }
85 
86     return bResult;
87 }
88 
89 } // namespace framework
90