1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /**************************************************************************
22 **************************************************************************
24 *************************************************************************/
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/beans/XPropertyAccess.hpp>
27 #include <com/sun/star/sdbc/XRow.hpp>
28 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
29 #include <com/sun/star/ucb/OpenMode.hpp>
30 #include <com/sun/star/ucb/XCommandInfo.hpp>
31 #include <com/sun/star/io/XActiveDataSink.hpp>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <com/sun/star/lang/IllegalAccessException.hpp>
34 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
35 #include <com/sun/star/io/XActiveDataStreamer.hpp>
36 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
37 #include <osl/diagnose.h>
38 #include <comphelper/processfactory.hxx>
39 #include <ucbhelper/contentidentifier.hxx>
40 #include <ucbhelper/propertyvalueset.hxx>
41 #include <ucbhelper/cancelcommandexecution.hxx>
42 #include "content.hxx"
43 #include "provider.hxx"
44 #include "resultset.hxx"
45 #include "databases.hxx"
46 #include "resultsetfactory.hxx"
47 #include "resultsetbase.hxx"
48 #include "resultsetforroot.hxx"
49 #include "resultsetforquery.hxx"
51 using namespace com::sun::star
;
52 using namespace chelp
;
54 // Content Implementation.
56 Content::Content( const uno::Reference
< uno::XComponentContext
>& rxContext
,
57 ::ucbhelper::ContentProviderImplHelper
* pProvider
,
58 const uno::Reference
< ucb::XContentIdentifier
>&
60 Databases
* pDatabases
)
61 : ContentImplHelper( rxContext
, pProvider
, Identifier
),
62 m_aURLParameter( Identifier
->getContentIdentifier(),pDatabases
),
63 m_pDatabases( pDatabases
) // not owner
72 // XInterface methods.
75 void SAL_CALL
Content::acquire()
78 ContentImplHelper::acquire();
82 void SAL_CALL
Content::release()
85 ContentImplHelper::release();
89 uno::Any SAL_CALL
Content::queryInterface( const uno::Type
& rType
)
90 throw ( uno::RuntimeException
, std::exception
)
93 return aRet
.hasValue() ? aRet
: ContentImplHelper::queryInterface( rType
);
96 // XTypeProvider methods.
98 XTYPEPROVIDER_COMMON_IMPL( Content
);
101 uno::Sequence
< uno::Type
> SAL_CALL
Content::getTypes()
102 throw( uno::RuntimeException
, std::exception
)
104 static cppu::OTypeCollection
* pCollection
= NULL
;
108 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() );
111 static cppu::OTypeCollection
aCollection(
112 CPPU_TYPE_REF( lang::XTypeProvider
),
113 CPPU_TYPE_REF( lang::XServiceInfo
),
114 CPPU_TYPE_REF( lang::XComponent
),
115 CPPU_TYPE_REF( ucb::XContent
),
116 CPPU_TYPE_REF( ucb::XCommandProcessor
),
117 CPPU_TYPE_REF( beans::XPropertiesChangeNotifier
),
118 CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier
),
119 CPPU_TYPE_REF( beans::XPropertyContainer
),
120 CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier
),
121 CPPU_TYPE_REF( container::XChild
) );
122 pCollection
= &aCollection
;
126 return (*pCollection
).getTypes();
129 // XServiceInfo methods.
132 OUString SAL_CALL
Content::getImplementationName()
133 throw( uno::RuntimeException
, std::exception
)
135 return OUString( "CHelpContent" );
139 uno::Sequence
< OUString
> SAL_CALL
Content::getSupportedServiceNames()
140 throw( uno::RuntimeException
, std::exception
)
142 uno::Sequence
< OUString
> aSNS( 1 );
143 aSNS
.getArray()[ 0 ] = MYUCP_CONTENT_SERVICE_NAME
;
150 OUString SAL_CALL
Content::getContentType()
151 throw( uno::RuntimeException
, std::exception
)
153 return OUString( MYUCP_CONTENT_TYPE
);
156 // XCommandProcessor methods.
159 void SAL_CALL
Content::abort( sal_Int32
/*CommandId*/ )
160 throw( uno::RuntimeException
, std::exception
)
164 class ResultSetForRootFactory
165 : public ResultSetFactory
169 uno::Reference
< uno::XComponentContext
> m_xContext
;
170 uno::Reference
< ucb::XContentProvider
> m_xProvider
;
171 sal_Int32 m_nOpenMode
;
172 uno::Sequence
< beans::Property
> m_seq
;
173 uno::Sequence
< ucb::NumberedSortingInfo
> m_seqSort
;
174 URLParameter m_aURLParameter
;
175 Databases
* m_pDatabases
;
179 ResultSetForRootFactory(
180 const uno::Reference
< uno::XComponentContext
>& xContext
,
181 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
183 const uno::Sequence
< beans::Property
>& seq
,
184 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
,
185 const URLParameter
& rURLParameter
,
186 Databases
* pDatabases
)
187 : m_xContext( xContext
),
188 m_xProvider( xProvider
),
189 m_nOpenMode( nOpenMode
),
191 m_seqSort( seqSort
),
192 m_aURLParameter( rURLParameter
),
193 m_pDatabases( pDatabases
)
197 ResultSetBase
* createResultSet() SAL_OVERRIDE
199 return new ResultSetForRoot( m_xContext
,
209 class ResultSetForQueryFactory
210 : public ResultSetFactory
214 uno::Reference
< uno::XComponentContext
> m_xContext
;
215 uno::Reference
< ucb::XContentProvider
> m_xProvider
;
216 sal_Int32 m_nOpenMode
;
217 uno::Sequence
< beans::Property
> m_seq
;
218 uno::Sequence
< ucb::NumberedSortingInfo
> m_seqSort
;
219 URLParameter m_aURLParameter
;
220 Databases
* m_pDatabases
;
224 ResultSetForQueryFactory(
225 const uno::Reference
< uno::XComponentContext
>& rxContext
,
226 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
228 const uno::Sequence
< beans::Property
>& seq
,
229 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
,
230 const URLParameter
& rURLParameter
,
231 Databases
* pDatabases
)
232 : m_xContext( rxContext
),
233 m_xProvider( xProvider
),
234 m_nOpenMode( nOpenMode
),
236 m_seqSort( seqSort
),
237 m_aURLParameter( rURLParameter
),
238 m_pDatabases( pDatabases
)
242 ResultSetBase
* createResultSet() SAL_OVERRIDE
244 return new ResultSetForQuery( m_xContext
,
255 uno::Any SAL_CALL
Content::execute(
256 const ucb::Command
& aCommand
,
258 const uno::Reference
< ucb::XCommandEnvironment
>& Environment
)
259 throw( uno::Exception
,
260 ucb::CommandAbortedException
,
261 uno::RuntimeException
, std::exception
)
265 if ( aCommand
.Name
== "getPropertyValues" )
267 uno::Sequence
< beans::Property
> Properties
;
268 if ( !( aCommand
.Argument
>>= Properties
) )
270 aRet
<<= lang::IllegalArgumentException();
271 ucbhelper::cancelCommandExecution(aRet
,Environment
);
274 aRet
<<= getPropertyValues( Properties
);
276 else if ( aCommand
.Name
== "setPropertyValues" )
278 uno::Sequence
<beans::PropertyValue
> propertyValues
;
280 if( ! ( aCommand
.Argument
>>= propertyValues
) ) {
281 aRet
<<= lang::IllegalArgumentException();
282 ucbhelper::cancelCommandExecution(aRet
,Environment
);
285 uno::Sequence
< uno::Any
> ret(propertyValues
.getLength());
286 uno::Sequence
< beans::Property
> props(getProperties(Environment
));
287 // No properties can be set
288 for(sal_Int32 i
= 0; i
< ret
.getLength(); ++i
) {
289 ret
[i
] <<= beans::UnknownPropertyException();
290 for(sal_Int32 j
= 0; j
< props
.getLength(); ++j
)
291 if(props
[j
].Name
== propertyValues
[i
].Name
) {
292 ret
[i
] <<= lang::IllegalAccessException();
299 else if ( aCommand
.Name
== "getPropertySetInfo" )
301 // Note: Implemented by base class.
302 aRet
<<= getPropertySetInfo( Environment
);
304 else if ( aCommand
.Name
== "getCommandInfo" )
306 // Note: Implemented by base class.
307 aRet
<<= getCommandInfo( Environment
);
309 else if ( aCommand
.Name
== "open" )
311 ucb::OpenCommandArgument2 aOpenCommand
;
312 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
314 aRet
<<= lang::IllegalArgumentException();
315 ucbhelper::cancelCommandExecution(aRet
,Environment
);
318 uno::Reference
< io::XActiveDataSink
> xActiveDataSink(
319 aOpenCommand
.Sink
, uno::UNO_QUERY
);
321 if(xActiveDataSink
.is())
322 m_aURLParameter
.open(aCommand
,
327 uno::Reference
< io::XActiveDataStreamer
> xActiveDataStreamer(
328 aOpenCommand
.Sink
, uno::UNO_QUERY
);
330 if(xActiveDataStreamer
.is()) {
331 aRet
<<= ucb::UnsupportedDataSinkException();
332 ucbhelper::cancelCommandExecution(aRet
,Environment
);
335 uno::Reference
< io::XOutputStream
> xOutputStream(
336 aOpenCommand
.Sink
, uno::UNO_QUERY
);
338 if(xOutputStream
.is() )
339 m_aURLParameter
.open(aCommand
,
344 if( m_aURLParameter
.isRoot() )
346 uno::Reference
< ucb::XDynamicResultSet
> xSet
347 = new DynamicResultSet(
352 new ResultSetForRootFactory(
356 aOpenCommand
.Properties
,
357 aOpenCommand
.SortingInfo
,
362 else if( m_aURLParameter
.isQuery() )
364 uno::Reference
< ucb::XDynamicResultSet
> xSet
365 = new DynamicResultSet(
370 new ResultSetForQueryFactory(
374 aOpenCommand
.Properties
,
375 aOpenCommand
.SortingInfo
,
383 // Unsupported command
384 aRet
<<= ucb::UnsupportedCommandException();
385 ucbhelper::cancelCommandExecution(aRet
,Environment
);
391 uno::Reference
< sdbc::XRow
> Content::getPropertyValues(
392 const uno::Sequence
< beans::Property
>& rProperties
)
394 osl::MutexGuard
aGuard( m_aMutex
);
396 rtl::Reference
< ::ucbhelper::PropertyValueSet
> xRow
=
397 new ::ucbhelper::PropertyValueSet( m_xContext
);
399 for ( sal_Int32 n
= 0; n
< rProperties
.getLength(); ++n
)
401 const beans::Property
& rProp
= rProperties
[n
];
403 if ( rProp
.Name
== "ContentType" )
407 "application/vnd.sun.star.help" ) );
408 else if ( rProp
.Name
== "Title" )
409 xRow
->appendString ( rProp
,m_aURLParameter
.get_title() );
410 else if ( rProp
.Name
== "IsReadOnly" )
411 xRow
->appendBoolean( rProp
,true );
412 else if ( rProp
.Name
== "IsDocument" )
415 m_aURLParameter
.isFile() || m_aURLParameter
.isRoot() );
416 else if ( rProp
.Name
== "IsFolder" )
419 ! m_aURLParameter
.isFile() || m_aURLParameter
.isRoot() );
420 else if ( rProp
.Name
== "IsErrorDocument" )
421 xRow
->appendBoolean( rProp
, m_aURLParameter
.isErrorDocument() );
422 else if ( rProp
.Name
== "MediaType" )
423 if( m_aURLParameter
.isPicture() )
426 OUString( "image/gif" ) );
427 else if( m_aURLParameter
.isActive() )
430 OUString( "text/plain" ) );
431 else if( m_aURLParameter
.isFile() )
433 rProp
,OUString( "text/html" ) );
434 else if( m_aURLParameter
.isRoot() )
437 OUString( "text/css" ) );
439 xRow
->appendVoid( rProp
);
440 else if( m_aURLParameter
.isModule() )
441 if ( rProp
.Name
== "KeywordList" )
444 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
445 m_aURLParameter
.get_language() );
449 aAny
<<= inf
->getKeywordList();
450 xRow
->appendObject( rProp
,aAny
);
452 else if ( rProp
.Name
== "KeywordRef" )
455 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
456 m_aURLParameter
.get_language() );
460 aAny
<<= inf
->getIdList();
461 xRow
->appendObject( rProp
,aAny
);
463 else if ( rProp
.Name
== "KeywordAnchorForRef" )
466 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
467 m_aURLParameter
.get_language() );
471 aAny
<<= inf
->getAnchorList();
472 xRow
->appendObject( rProp
,aAny
);
474 else if ( rProp
.Name
== "KeywordTitleForRef" )
477 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
478 m_aURLParameter
.get_language() );
482 aAny
<<= inf
->getTitleList();
483 xRow
->appendObject( rProp
,aAny
);
485 else if ( rProp
.Name
== "SearchScopes" )
487 uno::Sequence
< OUString
> seq( 2 );
492 xRow
->appendObject( rProp
,aAny
);
494 else if ( rProp
.Name
== "Order" )
496 StaticModuleInformation
*inf
=
497 m_pDatabases
->getStaticInformationForModule(
498 m_aURLParameter
.get_module(),
499 m_aURLParameter
.get_language() );
503 aAny
<<= sal_Int32( inf
->get_order() );
504 xRow
->appendObject( rProp
,aAny
);
507 xRow
->appendVoid( rProp
);
508 else if( "AnchorName" == rProp
.Name
&&
509 m_aURLParameter
.isFile() )
510 xRow
->appendString( rProp
,m_aURLParameter
.get_tag() );
512 xRow
->appendVoid( rProp
);
515 return uno::Reference
< sdbc::XRow
>( xRow
.get() );
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */