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_extensions.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 32*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 33*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/deployment/UpdateInformationEntry.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/deployment/UpdateInformationProvider.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/ucb/XWebDAVCommandEnvironment.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor2.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 49*cdf0e10cSrcweir #include "com/sun/star/ucb/XInteractionSupplyAuthentication.hpp" 50*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/xml/dom/XDocumentBuilder.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/xml/xpath/XXPathAPI.hpp> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <rtl/ref.hxx> 58*cdf0e10cSrcweir #include <rtl/memory.h> 59*cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 60*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 61*cdf0e10cSrcweir #include <osl/process.h> 62*cdf0e10cSrcweir #include <osl/conditn.hxx> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir namespace beans = com::sun::star::beans ; 65*cdf0e10cSrcweir namespace container = com::sun::star::container ; 66*cdf0e10cSrcweir namespace deployment = com::sun::star::deployment ; 67*cdf0e10cSrcweir namespace io = com::sun::star::io ; 68*cdf0e10cSrcweir namespace lang = com::sun::star::lang ; 69*cdf0e10cSrcweir namespace task = com::sun::star::task ; 70*cdf0e10cSrcweir namespace ucb = com::sun::star::ucb ; 71*cdf0e10cSrcweir namespace uno = com::sun::star::uno ; 72*cdf0e10cSrcweir namespace xml = com::sun::star::xml ; 73*cdf0e10cSrcweir namespace sdbc = com::sun::star::sdbc ; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //------------------------------------------------------------------------------ 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir namespace 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir #ifdef DEBUG 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir class InputStreamWrapper : public ::cppu::WeakImplHelper1< io::XInputStream > 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir uno::Reference< io::XInputStream > m_xStream; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir public: 89*cdf0e10cSrcweir InputStreamWrapper(const uno::Reference< io::XInputStream >& rxStream) : 90*cdf0e10cSrcweir m_xStream(rxStream) {}; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes(uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) 93*cdf0e10cSrcweir throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir sal_Int32 n = m_xStream->readBytes(aData, nBytesToRead); 96*cdf0e10cSrcweir if ( n ) 97*cdf0e10cSrcweir OSL_TRACE( "Read [%d] bytes: %s\n", n, aData.get()->elements ); 98*cdf0e10cSrcweir return n; 99*cdf0e10cSrcweir }; 100*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes(uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) 101*cdf0e10cSrcweir throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir sal_Int32 n = m_xStream->readSomeBytes(aData, nMaxBytesToRead); 104*cdf0e10cSrcweir if ( n ) 105*cdf0e10cSrcweir OSL_TRACE( "Read [%d] bytes: %s\n", n, aData.get()->elements ); 106*cdf0e10cSrcweir return n; 107*cdf0e10cSrcweir }; 108*cdf0e10cSrcweir virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) 109*cdf0e10cSrcweir throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) 110*cdf0e10cSrcweir { m_xStream->skipBytes(nBytesToSkip); }; 111*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available() 112*cdf0e10cSrcweir throw (io::NotConnectedException, io::IOException, uno::RuntimeException) 113*cdf0e10cSrcweir { return m_xStream->available(); }; 114*cdf0e10cSrcweir virtual void SAL_CALL closeInput( ) 115*cdf0e10cSrcweir throw (io::NotConnectedException, io::IOException, uno::RuntimeException) 116*cdf0e10cSrcweir {}; 117*cdf0e10cSrcweir }; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir #define INPUT_STREAM(i) new InputStreamWrapper(i) 120*cdf0e10cSrcweir #else 121*cdf0e10cSrcweir #define INPUT_STREAM(i) i 122*cdf0e10cSrcweir #endif 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //------------------------------------------------------------------------------ 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir class ActiveDataSink : public ::cppu::WeakImplHelper1< io::XActiveDataSink > 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir uno::Reference< io::XInputStream > m_xStream; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir public: 131*cdf0e10cSrcweir ActiveDataSink() {}; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir inline operator uno::Reference< io::XActiveDataSink > () { return this; }; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir virtual uno::Reference< io::XInputStream > SAL_CALL getInputStream() 136*cdf0e10cSrcweir throw (uno::RuntimeException) { return m_xStream; }; 137*cdf0e10cSrcweir virtual void SAL_CALL setInputStream( uno::Reference< io::XInputStream > const & rStream ) 138*cdf0e10cSrcweir throw (uno::RuntimeException) { m_xStream = rStream; }; 139*cdf0e10cSrcweir }; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //------------------------------------------------------------------------------ 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir class UpdateInformationProvider : 144*cdf0e10cSrcweir public ::cppu::WeakImplHelper4< deployment::XUpdateInformationProvider, 145*cdf0e10cSrcweir ucb::XCommandEnvironment, 146*cdf0e10cSrcweir ucb::XWebDAVCommandEnvironment, 147*cdf0e10cSrcweir lang::XServiceInfo > 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir public: 150*cdf0e10cSrcweir static uno::Reference< uno::XInterface > createInstance(const uno::Reference<uno::XComponentContext>& xContext); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > getServiceNames(); 153*cdf0e10cSrcweir static rtl::OUString getImplName(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir uno::Reference< xml::dom::XElement > getDocumentRoot(const uno::Reference< xml::dom::XNode >& rxNode); 156*cdf0e10cSrcweir uno::Reference< xml::dom::XNode > getChildNode(const uno::Reference< xml::dom::XNode >& rxNode, const rtl::OUString& rName); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // XUpdateInformationService 160*cdf0e10cSrcweir virtual uno::Sequence< uno::Reference< xml::dom::XElement > > SAL_CALL 161*cdf0e10cSrcweir getUpdateInformation( 162*cdf0e10cSrcweir uno::Sequence< rtl::OUString > const & repositories, 163*cdf0e10cSrcweir rtl::OUString const & extensionId 164*cdf0e10cSrcweir ) throw (uno::Exception, uno::RuntimeException); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir virtual void SAL_CALL cancel() 167*cdf0e10cSrcweir throw (uno::RuntimeException); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir virtual void SAL_CALL setInteractionHandler( 170*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > const & handler ) 171*cdf0e10cSrcweir throw (uno::RuntimeException); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL 174*cdf0e10cSrcweir getUpdateInformationEnumeration( 175*cdf0e10cSrcweir uno::Sequence< rtl::OUString > const & repositories, 176*cdf0e10cSrcweir rtl::OUString const & extensionId 177*cdf0e10cSrcweir ) throw (uno::Exception, uno::RuntimeException); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // XCommandEnvironment 180*cdf0e10cSrcweir virtual uno::Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler() 181*cdf0e10cSrcweir throw ( uno::RuntimeException ); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir virtual uno::Reference< ucb::XProgressHandler > SAL_CALL getProgressHandler() 184*cdf0e10cSrcweir throw ( uno::RuntimeException ) { return uno::Reference< ucb::XProgressHandler >(); }; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // XWebDAVCommandEnvironment 187*cdf0e10cSrcweir virtual uno::Sequence< beans::NamedValue > SAL_CALL getUserRequestHeaders( 188*cdf0e10cSrcweir const rtl::OUString&, const rtl::OUString& ) 189*cdf0e10cSrcweir throw ( uno::RuntimeException ) { return m_aRequestHeaderList; }; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // XServiceInfo 192*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 193*cdf0e10cSrcweir throw (uno::RuntimeException); 194*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName) 195*cdf0e10cSrcweir throw (uno::RuntimeException); 196*cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() 197*cdf0e10cSrcweir throw (uno::RuntimeException); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir protected: 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir virtual ~UpdateInformationProvider(); 202*cdf0e10cSrcweir static uno::Any getConfigurationItem(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, rtl::OUString const & node, rtl::OUString const & item); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir private: 205*cdf0e10cSrcweir uno::Reference< io::XInputStream > load(const rtl::OUString& rURL); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir void storeCommandInfo( sal_Int32 nCommandId, 208*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor > const & rxCommandProcessor); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir UpdateInformationProvider(const uno::Reference<uno::XComponentContext>& xContext, 211*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifierFactory >& xContentIdFactory, 212*cdf0e10cSrcweir const uno::Reference< ucb::XContentProvider >& xContentProvider, 213*cdf0e10cSrcweir const uno::Reference< xml::dom::XDocumentBuilder >& xDocumentBuilder, 214*cdf0e10cSrcweir const uno::Reference< xml::xpath::XXPathAPI >& xXPathAPI); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext> m_xContext; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifierFactory > m_xContentIdFactory; 219*cdf0e10cSrcweir const uno::Reference< ucb::XContentProvider > m_xContentProvider; 220*cdf0e10cSrcweir const uno::Reference< xml::dom::XDocumentBuilder > m_xDocumentBuilder; 221*cdf0e10cSrcweir const uno::Reference< xml::xpath::XXPathAPI > m_xXPathAPI; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > m_aRequestHeaderList; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor > m_xCommandProcessor; 226*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > m_xInteractionHandler; 227*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > m_xPwContainerInteractionHandler; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir osl::Mutex m_aMutex; 230*cdf0e10cSrcweir osl::Condition m_bCancelled; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir sal_Int32 m_nCommandId; 233*cdf0e10cSrcweir }; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //------------------------------------------------------------------------------ 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir class UpdateInformationEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir public: 240*cdf0e10cSrcweir UpdateInformationEnumeration(const uno::Reference< xml::dom::XNodeList >& xNodeList, 241*cdf0e10cSrcweir const uno::Reference< UpdateInformationProvider > xUpdateInformationProvider) : 242*cdf0e10cSrcweir m_xUpdateInformationProvider(xUpdateInformationProvider), 243*cdf0e10cSrcweir m_xNodeList(xNodeList), 244*cdf0e10cSrcweir m_nNodes(xNodeList.is() ? xNodeList->getLength() : 0), 245*cdf0e10cSrcweir m_nCount(0) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir }; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir virtual ~UpdateInformationEnumeration() {}; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // XEnumeration 252*cdf0e10cSrcweir sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException) { return m_nCount < m_nNodes; }; 253*cdf0e10cSrcweir uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir OSL_ASSERT( m_xNodeList.is() ); 256*cdf0e10cSrcweir OSL_ASSERT( m_xUpdateInformationProvider.is() ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir if( !(m_nCount < m_nNodes ) ) 259*cdf0e10cSrcweir throw container::NoSuchElementException(rtl::OUString::valueOf(m_nCount), *this); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir try 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir deployment::UpdateInformationEntry aEntry; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir uno::Reference< xml::dom::XNode > xAtomEntryNode( m_xNodeList->item(m_nCount++) ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir uno::Reference< xml::dom::XNode > xSummaryNode( 268*cdf0e10cSrcweir m_xUpdateInformationProvider->getChildNode( xAtomEntryNode, UNISTRING( "summary/text()" ) ) 269*cdf0e10cSrcweir ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir if( xSummaryNode.is() ) 272*cdf0e10cSrcweir aEntry.Description = xSummaryNode->getNodeValue(); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir uno::Reference< xml::dom::XNode > xContentNode( 275*cdf0e10cSrcweir m_xUpdateInformationProvider->getChildNode( xAtomEntryNode, UNISTRING( "content" ) ) ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir if( xContentNode.is() ) 278*cdf0e10cSrcweir aEntry.UpdateDocument = m_xUpdateInformationProvider->getDocumentRoot(xContentNode); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir return uno::makeAny(aEntry); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // action has been aborted 284*cdf0e10cSrcweir catch( ucb::CommandAbortedException const & e) 285*cdf0e10cSrcweir { throw lang::WrappedTargetException( UNISTRING( "Command aborted" ), *this, uno::makeAny(e) ); } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // let runtime exception pass 288*cdf0e10cSrcweir catch( uno::RuntimeException const & ) { throw; } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir // document not accessible 291*cdf0e10cSrcweir catch( uno::Exception const & e) 292*cdf0e10cSrcweir { throw lang::WrappedTargetException( UNISTRING( "Document not accessible" ), *this, uno::makeAny(e) ); } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir private: 296*cdf0e10cSrcweir const uno::Reference< UpdateInformationProvider > m_xUpdateInformationProvider; 297*cdf0e10cSrcweir const uno::Reference< xml::dom::XNodeList > m_xNodeList; 298*cdf0e10cSrcweir const sal_Int32 m_nNodes; 299*cdf0e10cSrcweir sal_Int32 m_nCount; 300*cdf0e10cSrcweir }; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir //------------------------------------------------------------------------------ 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir class SingleUpdateInformationEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir public: 307*cdf0e10cSrcweir SingleUpdateInformationEnumeration(const uno::Reference< xml::dom::XElement >& xElement) 308*cdf0e10cSrcweir : m_nCount(0) { m_aEntry.UpdateDocument = xElement; }; 309*cdf0e10cSrcweir virtual ~SingleUpdateInformationEnumeration() {}; 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // XEnumeration 312*cdf0e10cSrcweir sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException) { return 0 == m_nCount; }; 313*cdf0e10cSrcweir uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir if( m_nCount > 0 ) 316*cdf0e10cSrcweir throw container::NoSuchElementException(rtl::OUString::valueOf(m_nCount), *this); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir ++m_nCount; 319*cdf0e10cSrcweir return uno::makeAny(m_aEntry); 320*cdf0e10cSrcweir }; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir private: 323*cdf0e10cSrcweir sal_uInt8 m_nCount; 324*cdf0e10cSrcweir deployment::UpdateInformationEntry m_aEntry; 325*cdf0e10cSrcweir }; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir //------------------------------------------------------------------------------ 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir UpdateInformationProvider::UpdateInformationProvider( 331*cdf0e10cSrcweir const uno::Reference<uno::XComponentContext>& xContext, 332*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifierFactory >& xContentIdFactory, 333*cdf0e10cSrcweir const uno::Reference< ucb::XContentProvider >& xContentProvider, 334*cdf0e10cSrcweir const uno::Reference< xml::dom::XDocumentBuilder >& xDocumentBuilder, 335*cdf0e10cSrcweir const uno::Reference< xml::xpath::XXPathAPI >& xXPathAPI 336*cdf0e10cSrcweir ) : m_xContext(xContext), m_xContentIdFactory(xContentIdFactory), 337*cdf0e10cSrcweir m_xContentProvider(xContentProvider), m_xDocumentBuilder(xDocumentBuilder), 338*cdf0e10cSrcweir m_xXPathAPI(xXPathAPI), m_aRequestHeaderList(1) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir uno::Reference< lang::XMultiComponentFactory > xServiceManager(xContext->getServiceManager()); 341*cdf0e10cSrcweir if( !xServiceManager.is() ) 342*cdf0e10cSrcweir throw uno::RuntimeException( 343*cdf0e10cSrcweir UNISTRING("unable to obtain service manager from component context"), 344*cdf0e10cSrcweir uno::Reference< uno::XInterface >()); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider( 347*cdf0e10cSrcweir xServiceManager->createInstanceWithContext( 348*cdf0e10cSrcweir UNISTRING("com.sun.star.configuration.ConfigurationProvider"), 349*cdf0e10cSrcweir xContext ), 350*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir rtl::OUStringBuffer buf; 353*cdf0e10cSrcweir rtl::OUString name; 354*cdf0e10cSrcweir getConfigurationItem( 355*cdf0e10cSrcweir xConfigurationProvider, 356*cdf0e10cSrcweir UNISTRING("org.openoffice.Setup/Product"), 357*cdf0e10cSrcweir UNISTRING("ooName")) >>= name; 358*cdf0e10cSrcweir buf.append(name); 359*cdf0e10cSrcweir buf.append(sal_Unicode(' ')); 360*cdf0e10cSrcweir rtl::OUString version; 361*cdf0e10cSrcweir getConfigurationItem( 362*cdf0e10cSrcweir xConfigurationProvider, 363*cdf0e10cSrcweir UNISTRING("org.openoffice.Setup/Product"), 364*cdf0e10cSrcweir UNISTRING("ooSetupVersion")) >>= version; 365*cdf0e10cSrcweir buf.append(version); 366*cdf0e10cSrcweir rtl::OUString edition( 367*cdf0e10cSrcweir UNISTRING( 368*cdf0e10cSrcweir "${${BRAND_BASE_DIR}/program/edition/edition.ini:" 369*cdf0e10cSrcweir "EDITIONNAME}")); 370*cdf0e10cSrcweir rtl::Bootstrap::expandMacros(edition); 371*cdf0e10cSrcweir if (edition.getLength() != 0) { 372*cdf0e10cSrcweir buf.append(sal_Unicode(' ')); 373*cdf0e10cSrcweir buf.append(edition); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir rtl::OUString extension; 376*cdf0e10cSrcweir getConfigurationItem( 377*cdf0e10cSrcweir xConfigurationProvider, 378*cdf0e10cSrcweir UNISTRING("org.openoffice.Setup/Product"), 379*cdf0e10cSrcweir UNISTRING("ooSetupExtension")) >>= extension; 380*cdf0e10cSrcweir if (extension.getLength() != 0) { 381*cdf0e10cSrcweir buf.append(sal_Unicode(' ')); 382*cdf0e10cSrcweir buf.append(extension); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir rtl::OUString product(buf.makeStringAndClear()); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir rtl::OUString aBaseBuildId( UNISTRING( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":buildid}" ) ); 387*cdf0e10cSrcweir rtl::Bootstrap::expandMacros( aBaseBuildId ); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir rtl::OUString aBrandBuildId( UNISTRING( "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version") ":buildid}" ) ); 390*cdf0e10cSrcweir rtl::Bootstrap::expandMacros( aBrandBuildId ); 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir rtl::OUString aUserAgent( UNISTRING( "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version") ":UpdateUserAgent}" ) ); 393*cdf0e10cSrcweir rtl::Bootstrap::expandMacros( aUserAgent ); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir if ( ! aBaseBuildId.equals( aBrandBuildId ) ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir sal_Int32 nIndex = aUserAgent.indexOf( aBrandBuildId, 0 ); 398*cdf0e10cSrcweir if ( nIndex != -1 ) 399*cdf0e10cSrcweir aUserAgent = aUserAgent.replaceAt( nIndex, aBrandBuildId.getLength(), aBaseBuildId ); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir for (sal_Int32 i = 0;;) { 403*cdf0e10cSrcweir i = aUserAgent.indexOfAsciiL( 404*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("<PRODUCT>"), i); 405*cdf0e10cSrcweir if (i == -1) { 406*cdf0e10cSrcweir break; 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir aUserAgent = aUserAgent.replaceAt( 409*cdf0e10cSrcweir i, RTL_CONSTASCII_LENGTH("<PRODUCT>"), product); 410*cdf0e10cSrcweir i += product.getLength(); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir m_aRequestHeaderList[0].Name = UNISTRING("Accept-Language"); 414*cdf0e10cSrcweir m_aRequestHeaderList[0].Value = getConfigurationItem( xConfigurationProvider, UNISTRING("org.openoffice.Setup/L10N"), UNISTRING("ooLocale") ); 415*cdf0e10cSrcweir if( aUserAgent.getLength() > 0 ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir m_aRequestHeaderList.realloc(2); 418*cdf0e10cSrcweir m_aRequestHeaderList[1].Name = UNISTRING("User-Agent"); 419*cdf0e10cSrcweir m_aRequestHeaderList[1].Value = uno::makeAny(aUserAgent); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //------------------------------------------------------------------------------ 424*cdf0e10cSrcweir uno::Reference< uno::XInterface > 425*cdf0e10cSrcweir UpdateInformationProvider::createInstance(const uno::Reference<uno::XComponentContext>& xContext) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir uno::Reference< lang::XMultiComponentFactory > xServiceManager(xContext->getServiceManager()); 428*cdf0e10cSrcweir if( !xServiceManager.is() ) 429*cdf0e10cSrcweir throw uno::RuntimeException( 430*cdf0e10cSrcweir UNISTRING( "unable to obtain service manager from component context" ), 431*cdf0e10cSrcweir uno::Reference< uno::XInterface > ()); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifierFactory > xContentIdFactory( 434*cdf0e10cSrcweir xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.ucb.UniversalContentBroker" ), xContext ), 435*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir uno::Reference< ucb::XContentProvider > xContentProvider(xContentIdFactory, uno::UNO_QUERY_THROW); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir uno::Reference< xml::dom::XDocumentBuilder > xDocumentBuilder( 440*cdf0e10cSrcweir xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.xml.dom.DocumentBuilder" ), xContext ), 441*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir uno::Reference< xml::xpath::XXPathAPI > xXPath( 444*cdf0e10cSrcweir xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.xml.xpath.XPathAPI" ), xContext ), 445*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir xXPath->registerNS( UNISTRING("atom"), UNISTRING("http://www.w3.org/2005/Atom") ); 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir return *new UpdateInformationProvider(xContext, xContentIdFactory, xContentProvider, xDocumentBuilder, xXPath); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir //------------------------------------------------------------------------------ 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir UpdateInformationProvider::~UpdateInformationProvider() 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir //------------------------------------------------------------------------------ 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir uno::Any 461*cdf0e10cSrcweir UpdateInformationProvider::getConfigurationItem(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, rtl::OUString const & node, rtl::OUString const & item) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir beans::PropertyValue aProperty; 464*cdf0e10cSrcweir aProperty.Name = UNISTRING("nodepath"); 465*cdf0e10cSrcweir aProperty.Value = uno::makeAny(node); 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgumentList( 1 ); 468*cdf0e10cSrcweir aArgumentList[0] = uno::makeAny( aProperty ); 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( 471*cdf0e10cSrcweir configurationProvider->createInstanceWithArguments( 472*cdf0e10cSrcweir UNISTRING("com.sun.star.configuration.ConfigurationAccess"), 473*cdf0e10cSrcweir aArgumentList ), 474*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir return xNameAccess->getByName(item); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir //------------------------------------------------------------------------------ 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir void 482*cdf0e10cSrcweir UpdateInformationProvider::storeCommandInfo( 483*cdf0e10cSrcweir sal_Int32 nCommandId, 484*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor > const & rxCommandProcessor) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir m_nCommandId = nCommandId; 489*cdf0e10cSrcweir m_xCommandProcessor = rxCommandProcessor; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir //------------------------------------------------------------------------------ 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir uno::Reference< io::XInputStream > 495*cdf0e10cSrcweir UpdateInformationProvider::load(const rtl::OUString& rURL) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId = m_xContentIdFactory->createContentIdentifier(rURL); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir if( !xId.is() ) 500*cdf0e10cSrcweir throw uno::RuntimeException( 501*cdf0e10cSrcweir UNISTRING( "unable to obtain universal content id" ), *this); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor > xCommandProcessor(m_xContentProvider->queryContent(xId), uno::UNO_QUERY_THROW); 504*cdf0e10cSrcweir rtl::Reference< ActiveDataSink > aSink(new ActiveDataSink()); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenArgument; 507*cdf0e10cSrcweir aOpenArgument.Mode = ucb::OpenMode::DOCUMENT; 508*cdf0e10cSrcweir aOpenArgument.Priority = 32768; 509*cdf0e10cSrcweir aOpenArgument.Sink = *aSink; 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir ucb::Command aCommand; 512*cdf0e10cSrcweir aCommand.Name = UNISTRING("open"); 513*cdf0e10cSrcweir aCommand.Argument = uno::makeAny(aOpenArgument); 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir sal_Int32 nCommandId = xCommandProcessor->createCommandIdentifier(); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir storeCommandInfo(nCommandId, xCommandProcessor); 518*cdf0e10cSrcweir try 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir uno::Any aResult = xCommandProcessor->execute(aCommand, nCommandId, 521*cdf0e10cSrcweir static_cast < XCommandEnvironment *> (this)); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir catch( const uno::Exception & /* e */ ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir storeCommandInfo(0, uno::Reference< ucb::XCommandProcessor > ()); 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor2 > xCommandProcessor2(xCommandProcessor, uno::UNO_QUERY); 528*cdf0e10cSrcweir if( xCommandProcessor2.is() ) 529*cdf0e10cSrcweir xCommandProcessor2->releaseCommandIdentifier(nCommandId); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir throw; 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir storeCommandInfo(0, uno::Reference< ucb::XCommandProcessor > ()); 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir uno::Reference< ucb::XCommandProcessor2 > xCommandProcessor2(xCommandProcessor, uno::UNO_QUERY); 536*cdf0e10cSrcweir if( xCommandProcessor2.is() ) 537*cdf0e10cSrcweir xCommandProcessor2->releaseCommandIdentifier(nCommandId); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir return INPUT_STREAM(aSink->getInputStream()); 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir //------------------------------------------------------------------------------ 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir // TODO: docu content node 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir uno::Reference< xml::dom::XElement > 547*cdf0e10cSrcweir UpdateInformationProvider::getDocumentRoot(const uno::Reference< xml::dom::XNode >& rxNode) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir OSL_ASSERT(m_xDocumentBuilder.is()); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir uno::Reference< xml::dom::XElement > xElement(rxNode, uno::UNO_QUERY_THROW); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir // load the document referenced in 'src' attribute .. 554*cdf0e10cSrcweir if( xElement->hasAttribute( UNISTRING("src") ) ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir uno::Reference< xml::dom::XDocument > xUpdateXML = 557*cdf0e10cSrcweir m_xDocumentBuilder->parse(load(xElement->getAttribute( UNISTRING("src") ))); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir OSL_ASSERT( xUpdateXML.is() ); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir if( xUpdateXML.is() ) 562*cdf0e10cSrcweir return xUpdateXML->getDocumentElement(); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir // .. or return the (single) child element 565*cdf0e10cSrcweir else 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir uno::Reference< xml::dom::XNodeList> xChildNodes = rxNode->getChildNodes(); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir // ignore possible #text nodes 570*cdf0e10cSrcweir sal_Int32 nmax = xChildNodes->getLength(); 571*cdf0e10cSrcweir for(sal_Int32 n=0; n < nmax; n++) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir uno::Reference< xml::dom::XElement > xChildElement(xChildNodes->item(n), uno::UNO_QUERY); 574*cdf0e10cSrcweir if( xChildElement.is() ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir /* Copy the content to a dedicated document since XXPathAPI->selectNodeList 577*cdf0e10cSrcweir * seems to evaluate expression always relative to the root node. 578*cdf0e10cSrcweir */ 579*cdf0e10cSrcweir uno::Reference< xml::dom::XDocument > xUpdateXML = m_xDocumentBuilder->newDocument(); 580*cdf0e10cSrcweir xUpdateXML->appendChild( xUpdateXML->importNode(xChildElement.get(), sal_True ) ); 581*cdf0e10cSrcweir return xUpdateXML->getDocumentElement(); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir return uno::Reference< xml::dom::XElement > (); 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir //------------------------------------------------------------------------------ 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir uno::Reference< xml::dom::XNode > 592*cdf0e10cSrcweir UpdateInformationProvider::getChildNode(const uno::Reference< xml::dom::XNode >& rxNode, 593*cdf0e10cSrcweir const rtl::OUString& rName) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir OSL_ASSERT(m_xXPathAPI.is()); 596*cdf0e10cSrcweir try { 597*cdf0e10cSrcweir return m_xXPathAPI->selectSingleNode(rxNode, UNISTRING( "./atom:" ) + rName); 598*cdf0e10cSrcweir } catch (xml::xpath::XPathException &) { 599*cdf0e10cSrcweir // ignore 600*cdf0e10cSrcweir return 0; 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir //------------------------------------------------------------------------------ 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL 607*cdf0e10cSrcweir UpdateInformationProvider::getUpdateInformationEnumeration( 608*cdf0e10cSrcweir uno::Sequence< rtl::OUString > const & repositories, 609*cdf0e10cSrcweir rtl::OUString const & extensionId 610*cdf0e10cSrcweir ) throw (uno::Exception, uno::RuntimeException) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir OSL_ASSERT(m_xDocumentBuilder.is()); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir // reset cancelled flag 615*cdf0e10cSrcweir m_bCancelled.reset(); 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir for(sal_Int32 n=0; n<repositories.getLength(); n++) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir try 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir uno::Reference< xml::dom::XDocument > xDocument = m_xDocumentBuilder->parse(load(repositories[n])); 622*cdf0e10cSrcweir uno::Reference< xml::dom::XElement > xElement; 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir if( xDocument.is() ) 625*cdf0e10cSrcweir xElement = xDocument->getDocumentElement(); 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir if( xElement.is() ) 628*cdf0e10cSrcweir { 629*cdf0e10cSrcweir if( xElement->getNodeName().equalsAsciiL("feed", 4) ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir rtl::OUString aXPathExpression; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir if( extensionId.getLength() > 0 ) 634*cdf0e10cSrcweir aXPathExpression = UNISTRING("//atom:entry/atom:category[@term=\'") + extensionId + UNISTRING("\']/.."); 635*cdf0e10cSrcweir else 636*cdf0e10cSrcweir aXPathExpression = UNISTRING("//atom:entry"); 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir uno::Reference< xml::dom::XNodeList > xNodeList; 639*cdf0e10cSrcweir try { 640*cdf0e10cSrcweir xNodeList = m_xXPathAPI->selectNodeList(xDocument.get(), 641*cdf0e10cSrcweir aXPathExpression); 642*cdf0e10cSrcweir } catch (xml::xpath::XPathException &) { 643*cdf0e10cSrcweir // ignore 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir return new UpdateInformationEnumeration(xNodeList, this); 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir else 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir return new SingleUpdateInformationEnumeration(xElement); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir if( m_bCancelled.check() ) 655*cdf0e10cSrcweir break; 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir // rethrow runtime exceptions 658*cdf0e10cSrcweir catch( uno::RuntimeException const & ) { throw; } 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir // rethrow only if last url in the list 661*cdf0e10cSrcweir catch( uno::Exception const & ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir if( n+1 >= repositories.getLength() ) 664*cdf0e10cSrcweir throw; 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir return uno::Reference< container::XEnumeration >(); 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir //------------------------------------------------------------------------------ 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir uno::Sequence< uno::Reference< xml::dom::XElement > > SAL_CALL 674*cdf0e10cSrcweir UpdateInformationProvider::getUpdateInformation( 675*cdf0e10cSrcweir uno::Sequence< rtl::OUString > const & repositories, 676*cdf0e10cSrcweir rtl::OUString const & extensionId 677*cdf0e10cSrcweir ) throw (uno::Exception, uno::RuntimeException) 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xEnumeration( 680*cdf0e10cSrcweir getUpdateInformationEnumeration(repositories, extensionId) 681*cdf0e10cSrcweir ); 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir uno::Sequence< uno::Reference< xml::dom::XElement > > aRet; 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir if( xEnumeration.is() ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir while( xEnumeration->hasMoreElements() ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir try 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir deployment::UpdateInformationEntry aEntry; 692*cdf0e10cSrcweir if( (xEnumeration->nextElement() >>= aEntry ) && aEntry.UpdateDocument.is() ) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir sal_Int32 n = aRet.getLength(); 695*cdf0e10cSrcweir aRet.realloc(n + 1); 696*cdf0e10cSrcweir aRet[n] = aEntry.UpdateDocument; 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir catch( const lang::WrappedTargetException& e ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir // command aborted, return what we have got so far 703*cdf0e10cSrcweir if( e.TargetException.isExtractableTo( ::cppu::UnoType< ::com::sun::star::ucb::CommandAbortedException >::get() ) ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir break; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir // ignore files that can't be loaded 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir return aRet; 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir //------------------------------------------------------------------------------ 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir void SAL_CALL 719*cdf0e10cSrcweir UpdateInformationProvider::cancel() throw (uno::RuntimeException) 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir m_bCancelled.set(); 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 724*cdf0e10cSrcweir if( m_xCommandProcessor.is() ) 725*cdf0e10cSrcweir m_xCommandProcessor->abort(m_nCommandId); 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir //------------------------------------------------------------------------------ 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir void SAL_CALL 731*cdf0e10cSrcweir UpdateInformationProvider::setInteractionHandler( 732*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > const & handler ) 733*cdf0e10cSrcweir throw (uno::RuntimeException) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 736*cdf0e10cSrcweir m_xInteractionHandler = handler; 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir //------------------------------------------------------------------------------ 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > SAL_CALL 742*cdf0e10cSrcweir UpdateInformationProvider::getInteractionHandler() 743*cdf0e10cSrcweir throw ( uno::RuntimeException ) 744*cdf0e10cSrcweir { 745*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir if ( m_xInteractionHandler.is() ) 748*cdf0e10cSrcweir return m_xInteractionHandler; 749*cdf0e10cSrcweir else 750*cdf0e10cSrcweir { 751*cdf0e10cSrcweir try 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir // Supply an interaction handler that uses the password container 754*cdf0e10cSrcweir // service to obtain credentials without displaying a password gui. 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir if ( !m_xPwContainerInteractionHandler.is() ) 757*cdf0e10cSrcweir m_xPwContainerInteractionHandler 758*cdf0e10cSrcweir = task::PasswordContainerInteractionHandler::create( 759*cdf0e10cSrcweir m_xContext ); 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 762*cdf0e10cSrcweir { 763*cdf0e10cSrcweir throw; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir catch ( uno::Exception const & ) 766*cdf0e10cSrcweir { 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir return m_xPwContainerInteractionHandler; 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir //------------------------------------------------------------------------------ 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 774*cdf0e10cSrcweir UpdateInformationProvider::getServiceNames() 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aServiceList(1); 777*cdf0e10cSrcweir aServiceList[0] = UNISTRING( "com.sun.star.deployment.UpdateInformationProvider"); 778*cdf0e10cSrcweir return aServiceList; 779*cdf0e10cSrcweir }; 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir //------------------------------------------------------------------------------ 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir rtl::OUString 784*cdf0e10cSrcweir UpdateInformationProvider::getImplName() 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir return UNISTRING( "vnd.sun.UpdateInformationProvider"); 787*cdf0e10cSrcweir } 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir //------------------------------------------------------------------------------ 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir rtl::OUString SAL_CALL 792*cdf0e10cSrcweir UpdateInformationProvider::getImplementationName() throw (uno::RuntimeException) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir return getImplName(); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir //------------------------------------------------------------------------------ 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL 800*cdf0e10cSrcweir UpdateInformationProvider::getSupportedServiceNames() throw (uno::RuntimeException) 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir return getServiceNames(); 803*cdf0e10cSrcweir } 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir //------------------------------------------------------------------------------ 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir sal_Bool SAL_CALL 808*cdf0e10cSrcweir UpdateInformationProvider::supportsService( rtl::OUString const & serviceName ) throw (uno::RuntimeException) 809*cdf0e10cSrcweir { 810*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aServiceNameList = getServiceNames(); 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir for( sal_Int32 n=0; n < aServiceNameList.getLength(); n++ ) 813*cdf0e10cSrcweir if( aServiceNameList[n].equals(serviceName) ) 814*cdf0e10cSrcweir return sal_True; 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir return sal_False; 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir } // anonymous namespace 820*cdf0e10cSrcweir 821*cdf0e10cSrcweir //------------------------------------------------------------------------------ 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir static uno::Reference<uno::XInterface> SAL_CALL 824*cdf0e10cSrcweir createInstance(uno::Reference<uno::XComponentContext> const & xContext) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir return UpdateInformationProvider::createInstance(xContext); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir //------------------------------------------------------------------------------ 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir static const cppu::ImplementationEntry kImplementations_entries[] = 832*cdf0e10cSrcweir { 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir createInstance, 835*cdf0e10cSrcweir UpdateInformationProvider::getImplName, 836*cdf0e10cSrcweir UpdateInformationProvider::getServiceNames, 837*cdf0e10cSrcweir cppu::createSingleComponentFactory, 838*cdf0e10cSrcweir NULL, 839*cdf0e10cSrcweir 0 840*cdf0e10cSrcweir }, 841*cdf0e10cSrcweir { NULL, NULL, NULL, NULL, NULL, 0 } 842*cdf0e10cSrcweir } ; 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir //------------------------------------------------------------------------------ 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir extern "C" void SAL_CALL 847*cdf0e10cSrcweir component_getImplementationEnvironment( const sal_Char **aEnvTypeName, uno_Environment **) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir *aEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ; 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir //------------------------------------------------------------------------------ 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir extern "C" void * 855*cdf0e10cSrcweir component_getFactory(const sal_Char *pszImplementationName, void *pServiceManager, void *pRegistryKey) 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir return cppu::component_getFactoryHelper( 858*cdf0e10cSrcweir pszImplementationName, 859*cdf0e10cSrcweir pServiceManager, 860*cdf0e10cSrcweir pRegistryKey, 861*cdf0e10cSrcweir kImplementations_entries) ; 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir 864