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/PropertyValue.hpp>
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
28 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
29 #include <com/sun/star/ucb/XCommandInfo.hpp>
30 #include <com/sun/star/io/XActiveDataSink.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/lang/IllegalAccessException.hpp>
33 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
34 #include <com/sun/star/io/XActiveDataStreamer.hpp>
35 #include <ucbhelper/propertyvalueset.hxx>
36 #include <ucbhelper/cancelcommandexecution.hxx>
37 #include <ucbhelper/macros.hxx>
38 #include "content.hxx"
39 #include "provider.hxx"
40 #include "resultset.hxx"
41 #include "databases.hxx"
42 #include "resultsetfactory.hxx"
43 #include "resultsetbase.hxx"
44 #include "resultsetforroot.hxx"
45 #include "resultsetforquery.hxx"
47 using namespace com::sun::star
;
48 using namespace chelp
;
50 // Content Implementation.
52 Content::Content( const uno::Reference
< uno::XComponentContext
>& rxContext
,
53 ::ucbhelper::ContentProviderImplHelper
* pProvider
,
54 const uno::Reference
< ucb::XContentIdentifier
>&
56 Databases
* pDatabases
)
57 : ContentImplHelper( rxContext
, pProvider
, Identifier
),
58 m_aURLParameter( Identifier
->getContentIdentifier(),pDatabases
),
59 m_pDatabases( pDatabases
) // not owner
69 uno::Any SAL_CALL
Content::queryInterface( const uno::Type
& rType
)
72 return aRet
.hasValue() ? aRet
: ContentImplHelper::queryInterface( rType
);
75 // XTypeProvider methods.
77 XTYPEPROVIDER_COMMON_IMPL( Content
);
80 uno::Sequence
< uno::Type
> SAL_CALL
Content::getTypes()
82 static cppu::OTypeCollection
ourTypeCollection(
83 CPPU_TYPE_REF( lang::XTypeProvider
),
84 CPPU_TYPE_REF( lang::XServiceInfo
),
85 CPPU_TYPE_REF( lang::XComponent
),
86 CPPU_TYPE_REF( ucb::XContent
),
87 CPPU_TYPE_REF( ucb::XCommandProcessor
),
88 CPPU_TYPE_REF( beans::XPropertiesChangeNotifier
),
89 CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier
),
90 CPPU_TYPE_REF( beans::XPropertyContainer
),
91 CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier
),
92 CPPU_TYPE_REF( container::XChild
) );
94 return ourTypeCollection
.getTypes();
97 // XServiceInfo methods.
100 OUString SAL_CALL
Content::getImplementationName()
102 return "CHelpContent";
106 uno::Sequence
< OUString
> SAL_CALL
Content::getSupportedServiceNames()
108 uno::Sequence
<OUString
> aSNS
{ "com.sun.star.ucb.CHelpContent" };
116 OUString SAL_CALL
Content::getContentType()
118 return MYUCP_CONTENT_TYPE
;
121 // XCommandProcessor methods.
124 void SAL_CALL
Content::abort( sal_Int32
/*CommandId*/ )
130 class ResultSetForRootFactory
131 : public ResultSetFactory
135 uno::Reference
< uno::XComponentContext
> m_xContext
;
136 uno::Reference
< ucb::XContentProvider
> m_xProvider
;
137 uno::Sequence
< beans::Property
> m_seq
;
138 URLParameter m_aURLParameter
;
139 Databases
* m_pDatabases
;
143 ResultSetForRootFactory(
144 const uno::Reference
< uno::XComponentContext
>& xContext
,
145 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
146 const uno::Sequence
< beans::Property
>& seq
,
147 const URLParameter
& rURLParameter
,
148 Databases
* pDatabases
)
149 : m_xContext( xContext
),
150 m_xProvider( xProvider
),
152 m_aURLParameter( rURLParameter
),
153 m_pDatabases( pDatabases
)
157 ResultSetBase
* createResultSet() override
159 return new ResultSetForRoot( m_xContext
,
167 class ResultSetForQueryFactory
168 : public ResultSetFactory
172 uno::Reference
< uno::XComponentContext
> m_xContext
;
173 uno::Reference
< ucb::XContentProvider
> m_xProvider
;
174 uno::Sequence
< beans::Property
> m_seq
;
175 URLParameter m_aURLParameter
;
176 Databases
* m_pDatabases
;
180 ResultSetForQueryFactory(
181 const uno::Reference
< uno::XComponentContext
>& rxContext
,
182 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
183 const uno::Sequence
< beans::Property
>& seq
,
184 const URLParameter
& rURLParameter
,
185 Databases
* pDatabases
)
186 : m_xContext( rxContext
),
187 m_xProvider( xProvider
),
189 m_aURLParameter( rURLParameter
),
190 m_pDatabases( pDatabases
)
194 ResultSetBase
* createResultSet() override
196 return new ResultSetForQuery( m_xContext
,
207 uno::Any SAL_CALL
Content::execute(
208 const ucb::Command
& aCommand
,
210 const uno::Reference
< ucb::XCommandEnvironment
>& Environment
)
214 if ( aCommand
.Name
== "getPropertyValues" )
216 uno::Sequence
< beans::Property
> Properties
;
217 if ( !( aCommand
.Argument
>>= Properties
) )
219 aRet
<<= lang::IllegalArgumentException();
220 ucbhelper::cancelCommandExecution(aRet
,Environment
);
223 aRet
<<= getPropertyValues( Properties
);
225 else if ( aCommand
.Name
== "setPropertyValues" )
227 uno::Sequence
<beans::PropertyValue
> propertyValues
;
229 if( ! ( aCommand
.Argument
>>= propertyValues
) ) {
230 aRet
<<= lang::IllegalArgumentException();
231 ucbhelper::cancelCommandExecution(aRet
,Environment
);
234 uno::Sequence
< uno::Any
> ret(propertyValues
.getLength());
235 uno::Sequence
< beans::Property
> props(getProperties(Environment
));
236 // No properties can be set
237 std::transform(propertyValues
.begin(), propertyValues
.end(), ret
.begin(),
238 [&props
](const beans::PropertyValue
& rPropVal
) {
239 if (std::any_of(props
.begin(), props
.end(),
240 [&rPropVal
](const beans::Property
& rProp
) { return rProp
.Name
== rPropVal
.Name
; }))
241 return css::uno::toAny(lang::IllegalAccessException());
242 return css::uno::toAny(beans::UnknownPropertyException());
247 else if ( aCommand
.Name
== "getPropertySetInfo" )
249 // Note: Implemented by base class.
250 aRet
<<= getPropertySetInfo( Environment
);
252 else if ( aCommand
.Name
== "getCommandInfo" )
254 // Note: Implemented by base class.
255 aRet
<<= getCommandInfo( Environment
);
257 else if ( aCommand
.Name
== "open" )
259 ucb::OpenCommandArgument2 aOpenCommand
;
260 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
262 aRet
<<= lang::IllegalArgumentException();
263 ucbhelper::cancelCommandExecution(aRet
,Environment
);
266 uno::Reference
< io::XActiveDataSink
> xActiveDataSink(
267 aOpenCommand
.Sink
, uno::UNO_QUERY
);
269 if(xActiveDataSink
.is())
270 m_aURLParameter
.open(xActiveDataSink
);
272 uno::Reference
< io::XActiveDataStreamer
> xActiveDataStreamer(
273 aOpenCommand
.Sink
, uno::UNO_QUERY
);
275 if(xActiveDataStreamer
.is()) {
276 aRet
<<= ucb::UnsupportedDataSinkException();
277 ucbhelper::cancelCommandExecution(aRet
,Environment
);
280 uno::Reference
< io::XOutputStream
> xOutputStream(
281 aOpenCommand
.Sink
, uno::UNO_QUERY
);
283 if(xOutputStream
.is() )
284 m_aURLParameter
.open(xOutputStream
);
286 if( m_aURLParameter
.isRoot() )
288 uno::Reference
< ucb::XDynamicResultSet
> xSet
289 = new DynamicResultSet(
292 std::make_unique
<ResultSetForRootFactory
>(
295 aOpenCommand
.Properties
,
300 else if( m_aURLParameter
.isQuery() )
302 uno::Reference
< ucb::XDynamicResultSet
> xSet
303 = new DynamicResultSet(
306 std::make_unique
<ResultSetForQueryFactory
>(
309 aOpenCommand
.Properties
,
317 // Unsupported command
318 aRet
<<= ucb::UnsupportedCommandException();
319 ucbhelper::cancelCommandExecution(aRet
,Environment
);
325 uno::Reference
< sdbc::XRow
> Content::getPropertyValues(
326 const uno::Sequence
< beans::Property
>& rProperties
)
328 osl::MutexGuard
aGuard( m_aMutex
);
330 rtl::Reference
< ::ucbhelper::PropertyValueSet
> xRow
=
331 new ::ucbhelper::PropertyValueSet( m_xContext
);
333 for ( const beans::Property
& rProp
: rProperties
)
335 if ( rProp
.Name
== "ContentType" )
339 "application/vnd.sun.star.help" ) );
340 else if ( rProp
.Name
== "Title" )
341 xRow
->appendString ( rProp
,m_aURLParameter
.get_title() );
342 else if ( rProp
.Name
== "IsReadOnly" )
343 xRow
->appendBoolean( rProp
,true );
344 else if ( rProp
.Name
== "IsDocument" )
347 m_aURLParameter
.isFile() || m_aURLParameter
.isRoot() );
348 else if ( rProp
.Name
== "IsFolder" )
351 ! m_aURLParameter
.isFile() || m_aURLParameter
.isRoot() );
352 else if ( rProp
.Name
== "IsErrorDocument" )
353 xRow
->appendBoolean( rProp
, m_aURLParameter
.isErrorDocument() );
354 else if ( rProp
.Name
== "MediaType" )
355 if( m_aURLParameter
.isActive() )
358 OUString( "text/plain" ) );
359 else if( m_aURLParameter
.isFile() )
361 rProp
,OUString( "text/html" ) );
362 else if( m_aURLParameter
.isRoot() )
365 OUString( "text/css" ) );
367 xRow
->appendVoid( rProp
);
368 else if( m_aURLParameter
.isModule() )
369 if ( rProp
.Name
== "KeywordList" )
372 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
373 m_aURLParameter
.get_language() );
377 aAny
<<= inf
->getKeywordList();
378 xRow
->appendObject( rProp
,aAny
);
380 else if ( rProp
.Name
== "KeywordRef" )
383 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
384 m_aURLParameter
.get_language() );
388 aAny
<<= inf
->getIdList();
389 xRow
->appendObject( rProp
,aAny
);
391 else if ( rProp
.Name
== "KeywordAnchorForRef" )
394 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
395 m_aURLParameter
.get_language() );
399 aAny
<<= inf
->getAnchorList();
400 xRow
->appendObject( rProp
,aAny
);
402 else if ( rProp
.Name
== "KeywordTitleForRef" )
405 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
406 m_aURLParameter
.get_language() );
410 aAny
<<= inf
->getTitleList();
411 xRow
->appendObject( rProp
,aAny
);
413 else if ( rProp
.Name
== "SearchScopes" )
415 uno::Sequence
< OUString
> seq( 2 );
418 xRow
->appendObject( rProp
, uno::Any(seq
) );
420 else if ( rProp
.Name
== "Order" )
422 StaticModuleInformation
*inf
=
423 m_pDatabases
->getStaticInformationForModule(
424 m_aURLParameter
.get_module(),
425 m_aURLParameter
.get_language() );
429 aAny
<<= sal_Int32( inf
->get_order() );
430 xRow
->appendObject( rProp
,aAny
);
433 xRow
->appendVoid( rProp
);
434 else if( "AnchorName" == rProp
.Name
&&
435 m_aURLParameter
.isFile() )
436 xRow
->appendString( rProp
,m_aURLParameter
.get_tag() );
438 xRow
->appendVoid( rProp
);
441 return uno::Reference
< sdbc::XRow
>( xRow
.get() );
444 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */