1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "oo3extensionmigration.hxx"
32*cdf0e10cSrcweir #include <rtl/instance.hxx>
33*cdf0e10cSrcweir #include <osl/file.hxx>
34*cdf0e10cSrcweir #include <osl/thread.h>
35*cdf0e10cSrcweir #include <tools/urlobj.hxx>
36*cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
37*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
38*cdf0e10cSrcweir #include <unotools/textsearch.hxx>
39*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionApprove.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/deployment/ExtensionManager.hpp>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace ::com::sun::star;
54*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace migration
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir static ::rtl::OUString sExtensionSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/uno_packages/" ) );
60*cdf0e10cSrcweir static ::rtl::OUString sSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cache" ) );
61*cdf0e10cSrcweir static ::rtl::OUString sConfigDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data" ) );
62*cdf0e10cSrcweir static ::rtl::OUString sOrgDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) );
63*cdf0e10cSrcweir static ::rtl::OUString sExcludeDir1 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) );
64*cdf0e10cSrcweir static ::rtl::OUString sExcludeDir2 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org/openoffice" ) );
65*cdf0e10cSrcweir static ::rtl::OUString sDescriptionXmlFile = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/description.xml" ) );
66*cdf0e10cSrcweir static ::rtl::OUString sExtensionRootSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/uno_packages" ) );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir static ::rtl::OUString sConfigurationDataType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-data"));
69*cdf0e10cSrcweir static ::rtl::OUString sConfigurationSchemaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-schema"));
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // =============================================================================
72*cdf0e10cSrcweir // component operations
73*cdf0e10cSrcweir // =============================================================================
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir ::rtl::OUString OO3ExtensionMigration_getImplementationName()
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     static ::rtl::OUString* pImplName = 0;
78*cdf0e10cSrcweir     if ( !pImplName )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
81*cdf0e10cSrcweir         if ( !pImplName )
82*cdf0e10cSrcweir 	    {
83*cdf0e10cSrcweir             static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.OOo3Extensions" ) );
84*cdf0e10cSrcweir 		    pImplName = &aImplName;
85*cdf0e10cSrcweir 	    }
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir     return *pImplName;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // -----------------------------------------------------------------------------
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir Sequence< ::rtl::OUString > OO3ExtensionMigration_getSupportedServiceNames()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     static Sequence< ::rtl::OUString >* pNames = 0;
95*cdf0e10cSrcweir     if ( !pNames )
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
98*cdf0e10cSrcweir 	    if ( !pNames )
99*cdf0e10cSrcweir 	    {
100*cdf0e10cSrcweir             static Sequence< ::rtl::OUString > aNames(1);
101*cdf0e10cSrcweir             aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Extensions" ) );
102*cdf0e10cSrcweir             pNames = &aNames;
103*cdf0e10cSrcweir 	    }
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir     return *pNames;
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir // =============================================================================
109*cdf0e10cSrcweir // ExtensionMigration
110*cdf0e10cSrcweir // =============================================================================
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir OO3ExtensionMigration::OO3ExtensionMigration(Reference< XComponentContext > const & ctx) :
113*cdf0e10cSrcweir m_ctx(ctx)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir // -----------------------------------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir OO3ExtensionMigration::~OO3ExtensionMigration()
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir ::osl::FileBase::RC OO3ExtensionMigration::checkAndCreateDirectory( INetURLObject& rDirURL )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
126*cdf0e10cSrcweir     if ( aResult == ::osl::FileBase::E_NOENT )
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         INetURLObject aBaseURL( rDirURL );
129*cdf0e10cSrcweir         aBaseURL.removeSegment();
130*cdf0e10cSrcweir         checkAndCreateDirectory( aBaseURL );
131*cdf0e10cSrcweir         return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir     else
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         return aResult;
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir void OO3ExtensionMigration::scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions )
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     osl::Directory    aScanRootDir( sSourceDir );
142*cdf0e10cSrcweir     osl::FileStatus   fs(FileStatusMask_Type | FileStatusMask_FileURL);
143*cdf0e10cSrcweir     osl::FileBase::RC nRetCode = aScanRootDir.open();
144*cdf0e10cSrcweir     if ( nRetCode == osl::Directory::E_None )
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         sal_uInt32    nHint( 0 );
147*cdf0e10cSrcweir         osl::DirectoryItem aItem;
148*cdf0e10cSrcweir         while ( aScanRootDir.getNextItem( aItem, nHint ) == osl::Directory::E_None )
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             if (( aItem.getFileStatus(fs) == osl::FileBase::E_None ) &&
151*cdf0e10cSrcweir                 ( fs.getFileType() == osl::FileStatus::Directory   ))
152*cdf0e10cSrcweir             {
153*cdf0e10cSrcweir                 //Check next folder as the "real" extension folder is below a temp folder!
154*cdf0e10cSrcweir                 ::rtl::OUString sExtensionFolderURL = fs.getFileURL();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir                 osl::DirectoryItem aExtDirItem;
157*cdf0e10cSrcweir                 osl::Directory     aExtensionRootDir( sExtensionFolderURL );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir                 nRetCode = aExtensionRootDir.open();
160*cdf0e10cSrcweir                 if (( nRetCode == osl::Directory::E_None ) &&
161*cdf0e10cSrcweir                     ( aExtensionRootDir.getNextItem( aExtDirItem, nHint ) == osl::Directory::E_None ))
162*cdf0e10cSrcweir                 {
163*cdf0e10cSrcweir                     bool bFileStatus = aExtDirItem.getFileStatus(fs) == osl::FileBase::E_None;
164*cdf0e10cSrcweir                     bool bIsDir      = fs.getFileType() == osl::FileStatus::Directory;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir                     if ( bFileStatus && bIsDir )
167*cdf0e10cSrcweir                     {
168*cdf0e10cSrcweir                         sExtensionFolderURL = fs.getFileURL();
169*cdf0e10cSrcweir                         ScanResult eResult = scanExtensionFolder( sExtensionFolderURL );
170*cdf0e10cSrcweir                         if ( eResult == SCANRESULT_MIGRATE_EXTENSION )
171*cdf0e10cSrcweir                             aMigrateExtensions.push_back( sExtensionFolderURL );
172*cdf0e10cSrcweir                     }
173*cdf0e10cSrcweir                 }
174*cdf0e10cSrcweir             }
175*cdf0e10cSrcweir         }
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir OO3ExtensionMigration::ScanResult OO3ExtensionMigration::scanExtensionFolder( const ::rtl::OUString& sExtFolder )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     ScanResult     aResult = SCANRESULT_NOTFOUND;
182*cdf0e10cSrcweir     osl::Directory aDir(sExtFolder);
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     // get sub dirs
185*cdf0e10cSrcweir     if (aDir.open() == osl::FileBase::E_None)
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         // work through directory contents...
188*cdf0e10cSrcweir         osl::DirectoryItem item;
189*cdf0e10cSrcweir         osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL);
190*cdf0e10cSrcweir         TStringVector aDirectories;
191*cdf0e10cSrcweir         while ((aDir.getNextItem(item) == osl::FileBase::E_None ) &&
192*cdf0e10cSrcweir                ( aResult == SCANRESULT_NOTFOUND ))
193*cdf0e10cSrcweir         {
194*cdf0e10cSrcweir             if (item.getFileStatus(fs) == osl::FileBase::E_None)
195*cdf0e10cSrcweir             {
196*cdf0e10cSrcweir                 ::rtl::OUString aDirEntryURL;
197*cdf0e10cSrcweir                 if (fs.getFileType() == osl::FileStatus::Directory)
198*cdf0e10cSrcweir                     aDirectories.push_back( fs.getFileURL() );
199*cdf0e10cSrcweir                 else
200*cdf0e10cSrcweir                 {
201*cdf0e10cSrcweir                     aDirEntryURL = fs.getFileURL();
202*cdf0e10cSrcweir                     if ( aDirEntryURL.indexOf( sDescriptionXmlFile ) > 0 )
203*cdf0e10cSrcweir                         aResult = scanDescriptionXml( aDirEntryURL ) ? SCANRESULT_MIGRATE_EXTENSION : SCANRESULT_DONTMIGRATE_EXTENSION;
204*cdf0e10cSrcweir                 }
205*cdf0e10cSrcweir             }
206*cdf0e10cSrcweir         }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir         TStringVector::const_iterator pIter = aDirectories.begin();
209*cdf0e10cSrcweir         while ( pIter != aDirectories.end() && aResult == SCANRESULT_NOTFOUND )
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             aResult = scanExtensionFolder( *pIter );
212*cdf0e10cSrcweir             ++pIter;
213*cdf0e10cSrcweir         }
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir     return aResult;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir bool OO3ExtensionMigration::scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlURL )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     if ( !m_xDocBuilder.is() )
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         m_xDocBuilder = uno::Reference< xml::dom::XDocumentBuilder >(
223*cdf0e10cSrcweir             m_ctx->getServiceManager()->createInstanceWithContext(
224*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder")),
225*cdf0e10cSrcweir                 m_ctx ), uno::UNO_QUERY );
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     if ( !m_xSimpleFileAccess.is() )
229*cdf0e10cSrcweir     {
230*cdf0e10cSrcweir         m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess >(
231*cdf0e10cSrcweir             m_ctx->getServiceManager()->createInstanceWithContext(
232*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")),
233*cdf0e10cSrcweir                 m_ctx ), uno::UNO_QUERY );
234*cdf0e10cSrcweir     }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     ::rtl::OUString aExtIdentifier;
237*cdf0e10cSrcweir     if ( m_xDocBuilder.is() && m_xSimpleFileAccess.is() )
238*cdf0e10cSrcweir     {
239*cdf0e10cSrcweir         try
240*cdf0e10cSrcweir         {
241*cdf0e10cSrcweir             uno::Reference< io::XInputStream > xIn =
242*cdf0e10cSrcweir                 m_xSimpleFileAccess->openFileRead( sDescriptionXmlURL );
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir             if ( xIn.is() )
245*cdf0e10cSrcweir             {
246*cdf0e10cSrcweir                 uno::Reference< xml::dom::XDocument > xDoc = m_xDocBuilder->parse( xIn );
247*cdf0e10cSrcweir                 if ( xDoc.is() )
248*cdf0e10cSrcweir                 {
249*cdf0e10cSrcweir                     uno::Reference< xml::dom::XElement > xRoot = xDoc->getDocumentElement();
250*cdf0e10cSrcweir                     if ( xRoot.is() &&
251*cdf0e10cSrcweir                          xRoot->getTagName().equals(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("description"))) )
252*cdf0e10cSrcweir                     {
253*cdf0e10cSrcweir                         uno::Reference< xml::xpath::XXPathAPI > xPath(
254*cdf0e10cSrcweir                             m_ctx->getServiceManager()->createInstanceWithContext(
255*cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.xpath.XPathAPI")),
256*cdf0e10cSrcweir                                 m_ctx),
257*cdf0e10cSrcweir                             uno::UNO_QUERY);
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir                         xPath->registerNS(
260*cdf0e10cSrcweir                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc")),
261*cdf0e10cSrcweir                             xRoot->getNamespaceURI());
262*cdf0e10cSrcweir                         xPath->registerNS(
263*cdf0e10cSrcweir                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xlink")),
264*cdf0e10cSrcweir                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.w3.org/1999/xlink")));
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir                         try
267*cdf0e10cSrcweir                         {
268*cdf0e10cSrcweir                             uno::Reference< xml::dom::XNode > xRootNode( xRoot, uno::UNO_QUERY );
269*cdf0e10cSrcweir                             uno::Reference< xml::dom::XNode > xNode(
270*cdf0e10cSrcweir                                 xPath->selectSingleNode(
271*cdf0e10cSrcweir                                     xRootNode,
272*cdf0e10cSrcweir                                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc:identifier/@value")) ));
273*cdf0e10cSrcweir                             if ( xNode.is() )
274*cdf0e10cSrcweir                                 aExtIdentifier = xNode->getNodeValue();
275*cdf0e10cSrcweir                         }
276*cdf0e10cSrcweir                         catch ( xml::xpath::XPathException& )
277*cdf0e10cSrcweir                         {
278*cdf0e10cSrcweir                         }
279*cdf0e10cSrcweir                         catch ( xml::dom::DOMException& )
280*cdf0e10cSrcweir                         {
281*cdf0e10cSrcweir                         }
282*cdf0e10cSrcweir                     }
283*cdf0e10cSrcweir                 }
284*cdf0e10cSrcweir             }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir             if ( aExtIdentifier.getLength() > 0 )
287*cdf0e10cSrcweir             {
288*cdf0e10cSrcweir                 // scan extension identifier and try to match with our black list entries
289*cdf0e10cSrcweir                 for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ )
290*cdf0e10cSrcweir                 {
291*cdf0e10cSrcweir                     utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP);
292*cdf0e10cSrcweir                     utl::TextSearch  ts(param, LANGUAGE_DONTKNOW);
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir                     xub_StrLen start = 0;
295*cdf0e10cSrcweir                     xub_StrLen end   = static_cast<sal_uInt16>(aExtIdentifier.getLength());
296*cdf0e10cSrcweir                     if (ts.SearchFrwrd(aExtIdentifier, &start, &end))
297*cdf0e10cSrcweir                         return false;
298*cdf0e10cSrcweir                 }
299*cdf0e10cSrcweir             }
300*cdf0e10cSrcweir         }
301*cdf0e10cSrcweir         catch ( ucb::CommandAbortedException& )
302*cdf0e10cSrcweir         {
303*cdf0e10cSrcweir         }
304*cdf0e10cSrcweir         catch ( uno::RuntimeException& )
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir         }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir         if ( aExtIdentifier.getLength() == 0 )
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             // Fallback:
311*cdf0e10cSrcweir             // Try to use the folder name to match our black list
312*cdf0e10cSrcweir             // as some extensions don't provide an identifier in the
313*cdf0e10cSrcweir             // description.xml!
314*cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ )
315*cdf0e10cSrcweir             {
316*cdf0e10cSrcweir                 utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP);
317*cdf0e10cSrcweir                 utl::TextSearch  ts(param, LANGUAGE_DONTKNOW);
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir                 xub_StrLen start = 0;
320*cdf0e10cSrcweir                 xub_StrLen end   = static_cast<sal_uInt16>(sDescriptionXmlURL.getLength());
321*cdf0e10cSrcweir                 if (ts.SearchFrwrd(sDescriptionXmlURL, &start, &end))
322*cdf0e10cSrcweir                     return false;
323*cdf0e10cSrcweir             }
324*cdf0e10cSrcweir         }
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     return true;
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir bool OO3ExtensionMigration::migrateExtension( const ::rtl::OUString& sSourceDir )
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     if ( !m_xExtensionManager.is() )
333*cdf0e10cSrcweir     {
334*cdf0e10cSrcweir         try
335*cdf0e10cSrcweir         {
336*cdf0e10cSrcweir             m_xExtensionManager = deployment::ExtensionManager::get( m_ctx );
337*cdf0e10cSrcweir         }
338*cdf0e10cSrcweir         catch ( ucb::CommandFailedException & ){}
339*cdf0e10cSrcweir         catch ( uno::RuntimeException & ) {}
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     if ( m_xExtensionManager.is() )
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         try
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv();
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir             uno::Reference< ucb::XCommandEnvironment > xCmdEnv(
349*cdf0e10cSrcweir                 static_cast< cppu::OWeakObject* >( pCmdEnv ), uno::UNO_QUERY );
350*cdf0e10cSrcweir             uno::Reference< task::XAbortChannel > xAbortChannel;
351*cdf0e10cSrcweir             uno::Reference< deployment::XPackage > xPackage =
352*cdf0e10cSrcweir                 m_xExtensionManager->addExtension(
353*cdf0e10cSrcweir                     sSourceDir, uno::Sequence<beans::NamedValue>(),
354*cdf0e10cSrcweir                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), xAbortChannel, xCmdEnv );
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir             if ( xPackage.is() )
357*cdf0e10cSrcweir                 return true;
358*cdf0e10cSrcweir         }
359*cdf0e10cSrcweir         catch ( ucb::CommandFailedException& )
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir         }
362*cdf0e10cSrcweir         catch ( ucb::CommandAbortedException& )
363*cdf0e10cSrcweir         {
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir         catch ( lang::IllegalArgumentException& )
366*cdf0e10cSrcweir         {
367*cdf0e10cSrcweir         }
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     return false;
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // -----------------------------------------------------------------------------
375*cdf0e10cSrcweir // XServiceInfo
376*cdf0e10cSrcweir // -----------------------------------------------------------------------------
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir ::rtl::OUString OO3ExtensionMigration::getImplementationName() throw (RuntimeException)
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir     return OO3ExtensionMigration_getImplementationName();
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir // -----------------------------------------------------------------------------
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir sal_Bool OO3ExtensionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir     Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
388*cdf0e10cSrcweir     const ::rtl::OUString* pNames = aNames.getConstArray();
389*cdf0e10cSrcweir     const ::rtl::OUString* pEnd = pNames + aNames.getLength();
390*cdf0e10cSrcweir     for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
391*cdf0e10cSrcweir 	    ;
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     return pNames != pEnd;
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir // -----------------------------------------------------------------------------
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir Sequence< ::rtl::OUString > OO3ExtensionMigration::getSupportedServiceNames() throw (RuntimeException)
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir     return OO3ExtensionMigration_getSupportedServiceNames();
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir // -----------------------------------------------------------------------------
404*cdf0e10cSrcweir // XInitialization
405*cdf0e10cSrcweir // -----------------------------------------------------------------------------
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir void OO3ExtensionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     const Any* pIter = aArguments.getConstArray();
412*cdf0e10cSrcweir     const Any* pEnd = pIter + aArguments.getLength();
413*cdf0e10cSrcweir     for ( ; pIter != pEnd ; ++pIter )
414*cdf0e10cSrcweir     {
415*cdf0e10cSrcweir         beans::NamedValue aValue;
416*cdf0e10cSrcweir         *pIter >>= aValue;
417*cdf0e10cSrcweir         if ( aValue.Name.equalsAscii( "UserData" ) )
418*cdf0e10cSrcweir         {
419*cdf0e10cSrcweir             if ( !(aValue.Value >>= m_sSourceDir) )
420*cdf0e10cSrcweir             {
421*cdf0e10cSrcweir                 OSL_ENSURE( false, "ExtensionMigration::initialize: argument UserData has wrong type!" );
422*cdf0e10cSrcweir             }
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir         else if ( aValue.Name.equalsAscii( "ExtensionBlackList" ) )
425*cdf0e10cSrcweir         {
426*cdf0e10cSrcweir             Sequence< ::rtl::OUString > aBlackList;
427*cdf0e10cSrcweir             if ( (aValue.Value >>= aBlackList ) && ( aBlackList.getLength() > 0 ))
428*cdf0e10cSrcweir             {
429*cdf0e10cSrcweir                 m_aBlackList.resize( aBlackList.getLength() );
430*cdf0e10cSrcweir                 ::comphelper::sequenceToArray< ::rtl::OUString >( &m_aBlackList[0], aBlackList );
431*cdf0e10cSrcweir             }
432*cdf0e10cSrcweir         }
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir // -----------------------------------------------------------------------------
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir TStringVectorPtr getContent( const ::rtl::OUString& rBaseURL )
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     TStringVectorPtr aResult( new TStringVector );
441*cdf0e10cSrcweir     ::osl::Directory aDir( rBaseURL);
442*cdf0e10cSrcweir     if ( aDir.open() == ::osl::FileBase::E_None )
443*cdf0e10cSrcweir     {
444*cdf0e10cSrcweir         // iterate over directory content
445*cdf0e10cSrcweir         TStringVector aSubDirs;
446*cdf0e10cSrcweir         ::osl::DirectoryItem aItem;
447*cdf0e10cSrcweir         while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None )
448*cdf0e10cSrcweir         {
449*cdf0e10cSrcweir             ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL );
450*cdf0e10cSrcweir             if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None )
451*cdf0e10cSrcweir                 aResult->push_back( aFileStatus.getFileURL() );
452*cdf0e10cSrcweir         }
453*cdf0e10cSrcweir     }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir     return aResult;
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir Any OO3ExtensionMigration::execute( const Sequence< beans::NamedValue >& )
459*cdf0e10cSrcweir     throw (lang::IllegalArgumentException, Exception, RuntimeException)
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 	::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( m_sTargetDir );
464*cdf0e10cSrcweir 	if ( aStatus == ::utl::Bootstrap::PATH_EXISTS )
465*cdf0e10cSrcweir 	{
466*cdf0e10cSrcweir 		// copy all extensions
467*cdf0e10cSrcweir 		::rtl::OUString sSourceDir( m_sSourceDir );
468*cdf0e10cSrcweir         sSourceDir += sExtensionSubDir;
469*cdf0e10cSrcweir 		sSourceDir += sSubDirName;
470*cdf0e10cSrcweir         sSourceDir += sExtensionRootSubDirName;
471*cdf0e10cSrcweir         TStringVector aExtensionToMigrate;
472*cdf0e10cSrcweir         scanUserExtensions( sSourceDir, aExtensionToMigrate );
473*cdf0e10cSrcweir         if ( aExtensionToMigrate.size() > 0 )
474*cdf0e10cSrcweir         {
475*cdf0e10cSrcweir             TStringVector::iterator pIter = aExtensionToMigrate.begin();
476*cdf0e10cSrcweir             while ( pIter != aExtensionToMigrate.end() )
477*cdf0e10cSrcweir             {
478*cdf0e10cSrcweir                 migrateExtension( *pIter );
479*cdf0e10cSrcweir                 ++pIter;
480*cdf0e10cSrcweir             }
481*cdf0e10cSrcweir         }
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir     return Any();
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir // -----------------------------------------------------------------------------
488*cdf0e10cSrcweir // TmpRepositoryCommandEnv
489*cdf0e10cSrcweir // -----------------------------------------------------------------------------
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir }
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv()
496*cdf0e10cSrcweir {
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir // XCommandEnvironment
499*cdf0e10cSrcweir //______________________________________________________________________________
500*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > TmpRepositoryCommandEnv::getInteractionHandler()
501*cdf0e10cSrcweir throw ( uno::RuntimeException )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     return this;
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir //______________________________________________________________________________
507*cdf0e10cSrcweir uno::Reference< ucb::XProgressHandler > TmpRepositoryCommandEnv::getProgressHandler()
508*cdf0e10cSrcweir throw ( uno::RuntimeException )
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir     return this;
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir // XInteractionHandler
514*cdf0e10cSrcweir void TmpRepositoryCommandEnv::handle(
515*cdf0e10cSrcweir     uno::Reference< task::XInteractionRequest> const & xRequest )
516*cdf0e10cSrcweir     throw ( uno::RuntimeException )
517*cdf0e10cSrcweir {
518*cdf0e10cSrcweir     uno::Any request( xRequest->getRequest() );
519*cdf0e10cSrcweir     OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir     bool approve = true;
522*cdf0e10cSrcweir     bool abort   = false;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     // select:
525*cdf0e10cSrcweir     uno::Sequence< Reference< task::XInteractionContinuation > > conts(
526*cdf0e10cSrcweir         xRequest->getContinuations() );
527*cdf0e10cSrcweir     Reference< task::XInteractionContinuation > const * pConts =
528*cdf0e10cSrcweir         conts.getConstArray();
529*cdf0e10cSrcweir     sal_Int32 len = conts.getLength();
530*cdf0e10cSrcweir     for ( sal_Int32 pos = 0; pos < len; ++pos )
531*cdf0e10cSrcweir     {
532*cdf0e10cSrcweir         if (approve) {
533*cdf0e10cSrcweir             uno::Reference< task::XInteractionApprove > xInteractionApprove(
534*cdf0e10cSrcweir                 pConts[ pos ], uno::UNO_QUERY );
535*cdf0e10cSrcweir             if (xInteractionApprove.is()) {
536*cdf0e10cSrcweir                 xInteractionApprove->select();
537*cdf0e10cSrcweir                 // don't query again for ongoing continuations:
538*cdf0e10cSrcweir                 approve = false;
539*cdf0e10cSrcweir             }
540*cdf0e10cSrcweir         }
541*cdf0e10cSrcweir         else if (abort) {
542*cdf0e10cSrcweir             uno::Reference< task::XInteractionAbort > xInteractionAbort(
543*cdf0e10cSrcweir                 pConts[ pos ], uno::UNO_QUERY );
544*cdf0e10cSrcweir             if (xInteractionAbort.is()) {
545*cdf0e10cSrcweir                 xInteractionAbort->select();
546*cdf0e10cSrcweir                 // don't query again for ongoing continuations:
547*cdf0e10cSrcweir                 abort = false;
548*cdf0e10cSrcweir             }
549*cdf0e10cSrcweir         }
550*cdf0e10cSrcweir 	}
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir // XProgressHandler
554*cdf0e10cSrcweir void TmpRepositoryCommandEnv::push( uno::Any const & /*Status*/ )
555*cdf0e10cSrcweir throw (uno::RuntimeException)
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir void TmpRepositoryCommandEnv::update( uno::Any const & /*Status */)
561*cdf0e10cSrcweir throw (uno::RuntimeException)
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir void TmpRepositoryCommandEnv::pop() throw (uno::RuntimeException)
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir // =============================================================================
570*cdf0e10cSrcweir // component operations
571*cdf0e10cSrcweir // =============================================================================
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir Reference< XInterface > SAL_CALL OO3ExtensionMigration_create(
574*cdf0e10cSrcweir     Reference< XComponentContext > const & ctx )
575*cdf0e10cSrcweir     SAL_THROW( () )
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir     return static_cast< lang::XTypeProvider * >( new OO3ExtensionMigration(
578*cdf0e10cSrcweir         ctx) );
579*cdf0e10cSrcweir }
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir // -----------------------------------------------------------------------------
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir }	// namespace migration
584