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