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