xref: /aoo4110/main/sw/source/ui/vba/vbaaddins.cxx (revision b1cdbd2c)
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 #include "vbaaddins.hxx"
24 #include "vbaaddin.hxx"
25 #include <cppuhelper/implbase3.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
28 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
29 
30 using namespace ::ooo::vba;
31 using namespace ::com::sun::star;
32 
lcl_getAddinCollection(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext)33 uno::Reference< container::XIndexAccess > lcl_getAddinCollection( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext )
34 {
35     XNamedObjectCollectionHelper< word::XAddin >::XNamedVec maAddins;
36 
37     // first get the autoload addins in the directory STARTUP
38     uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager(), uno::UNO_QUERY_THROW );
39     uno::Reference< ucb::XSimpleFileAccess > xSFA( xMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), xContext), uno::UNO_QUERY_THROW );
40     SvtPathOptions aPathOpt;
41     // FIXME: temporary the STARTUP path is located in $OO/basic3.1/program/addin
42     String aAddinPath = aPathOpt.GetAddinPath();
43     OSL_TRACE("lcl_getAddinCollection: %s", rtl::OUStringToOString( aAddinPath, RTL_TEXTENCODING_UTF8 ).getStr() );
44     if( xSFA->isFolder( aAddinPath ) )
45     {
46         uno::Sequence< rtl::OUString > sEntries = xSFA->getFolderContents( aAddinPath, sal_False );
47         sal_Int32 nEntry = sEntries.getLength();
48         for( sal_Int32 index = 0; index < nEntry; ++index )
49         {
50             rtl::OUString sUrl = sEntries[ index ];
51             if( !xSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) )
52             {
53                 maAddins.push_back( uno::Reference< word::XAddin >( new SwVbaAddin( xParent, xContext, sUrl, sal_True ) ) );
54             }
55         }
56     }
57 
58     // TODO: second get the customize addins in the org.openoffice.Office.Writer/GlobalTemplateList
59 
60     uno::Reference< container::XIndexAccess > xAddinsAccess( new XNamedObjectCollectionHelper< word::XAddin >( maAddins ) );
61     return xAddinsAccess;
62 }
63 
SwVbaAddins(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext)64 SwVbaAddins::SwVbaAddins( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext ) throw (uno::RuntimeException): SwVbaAddins_BASE( xParent, xContext, lcl_getAddinCollection( xParent,xContext ) )
65 {
66 }
67 // XEnumerationAccess
68 uno::Type
getElementType()69 SwVbaAddins::getElementType() throw (uno::RuntimeException)
70 {
71 	return word::XAddin::static_type(0);
72 }
73 uno::Reference< container::XEnumeration >
createEnumeration()74 SwVbaAddins::createEnumeration() throw (uno::RuntimeException)
75 {
76     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
77     return xEnumerationAccess->createEnumeration();
78 }
79 
80 uno::Any
createCollectionObject(const css::uno::Any & aSource)81 SwVbaAddins::createCollectionObject( const css::uno::Any& aSource )
82 {
83     return aSource;
84 }
85 
86 rtl::OUString&
getServiceImplName()87 SwVbaAddins::getServiceImplName()
88 {
89 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAddins") );
90 	return sImplName;
91 }
92 
93 css::uno::Sequence<rtl::OUString>
getServiceNames()94 SwVbaAddins::getServiceNames()
95 {
96 	static uno::Sequence< rtl::OUString > sNames;
97 	if ( sNames.getLength() == 0 )
98 	{
99 		sNames.realloc( 1 );
100 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Addins") );
101 	}
102 	return sNames;
103 }
104