nss: upgrade to release 3.73
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / content.cxx
blob4ad2c3fa78c84a29475f21c56a34a51cc09badef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /**************************************************************************
21 TODO
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 >&
55 Identifier,
56 Databases* pDatabases )
57 : ContentImplHelper( rxContext, pProvider, Identifier ),
58 m_aURLParameter( Identifier->getContentIdentifier(),pDatabases ),
59 m_pDatabases( pDatabases ) // not owner
63 // virtual
64 Content::~Content()
68 // virtual
69 uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
71 uno::Any aRet;
72 return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
75 // XTypeProvider methods.
77 XTYPEPROVIDER_COMMON_IMPL( Content );
79 // virtual
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.
99 // virtual
100 OUString SAL_CALL Content::getImplementationName()
102 return "CHelpContent";
105 // virtual
106 uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames()
108 uno::Sequence<OUString> aSNS { "com.sun.star.ucb.CHelpContent" };
110 return aSNS;
113 // XContent methods.
115 // virtual
116 OUString SAL_CALL Content::getContentType()
118 return MYUCP_CONTENT_TYPE;
121 // XCommandProcessor methods.
123 //virtual
124 void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
128 namespace {
130 class ResultSetForRootFactory
131 : public ResultSetFactory
133 private:
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;
141 public:
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 ),
151 m_seq( seq ),
152 m_aURLParameter( rURLParameter ),
153 m_pDatabases( pDatabases )
157 ResultSetBase* createResultSet() override
159 return new ResultSetForRoot( m_xContext,
160 m_xProvider,
161 m_seq,
162 m_aURLParameter,
163 m_pDatabases );
167 class ResultSetForQueryFactory
168 : public ResultSetFactory
170 private:
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;
178 public:
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 ),
188 m_seq( seq ),
189 m_aURLParameter( rURLParameter ),
190 m_pDatabases( pDatabases )
194 ResultSetBase* createResultSet() override
196 return new ResultSetForQuery( m_xContext,
197 m_xProvider,
198 m_seq,
199 m_aURLParameter,
200 m_pDatabases );
206 // virtual
207 uno::Any SAL_CALL Content::execute(
208 const ucb::Command& aCommand,
209 sal_Int32,
210 const uno::Reference< ucb::XCommandEnvironment >& Environment )
212 uno::Any aRet;
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());
245 aRet <<= ret;
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(
290 m_xContext,
291 aOpenCommand,
292 std::make_unique<ResultSetForRootFactory>(
293 m_xContext,
294 m_xProvider.get(),
295 aOpenCommand.Properties,
296 m_aURLParameter,
297 m_pDatabases));
298 aRet <<= xSet;
300 else if( m_aURLParameter.isQuery() )
302 uno::Reference< ucb::XDynamicResultSet > xSet
303 = new DynamicResultSet(
304 m_xContext,
305 aOpenCommand,
306 std::make_unique<ResultSetForQueryFactory>(
307 m_xContext,
308 m_xProvider.get(),
309 aOpenCommand.Properties,
310 m_aURLParameter,
311 m_pDatabases ) );
312 aRet <<= xSet;
315 else
317 // Unsupported command
318 aRet <<= ucb::UnsupportedCommandException();
319 ucbhelper::cancelCommandExecution(aRet,Environment);
322 return aRet;
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" )
336 xRow->appendString(
337 rProp,
338 OUString(
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" )
345 xRow->appendBoolean(
346 rProp,
347 m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
348 else if ( rProp.Name == "IsFolder" )
349 xRow->appendBoolean(
350 rProp,
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() )
356 xRow->appendString(
357 rProp,
358 OUString( "text/plain" ) );
359 else if( m_aURLParameter.isFile() )
360 xRow->appendString(
361 rProp,OUString( "text/html" ) );
362 else if( m_aURLParameter.isRoot() )
363 xRow->appendString(
364 rProp,
365 OUString( "text/css" ) );
366 else
367 xRow->appendVoid( rProp );
368 else if( m_aURLParameter.isModule() )
369 if ( rProp.Name == "KeywordList" )
371 KeywordInfo *inf =
372 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
373 m_aURLParameter.get_language() );
375 uno::Any aAny;
376 if( inf )
377 aAny <<= inf->getKeywordList();
378 xRow->appendObject( rProp,aAny );
380 else if ( rProp.Name == "KeywordRef" )
382 KeywordInfo *inf =
383 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
384 m_aURLParameter.get_language() );
386 uno::Any aAny;
387 if( inf )
388 aAny <<= inf->getIdList();
389 xRow->appendObject( rProp,aAny );
391 else if ( rProp.Name == "KeywordAnchorForRef" )
393 KeywordInfo *inf =
394 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
395 m_aURLParameter.get_language() );
397 uno::Any aAny;
398 if( inf )
399 aAny <<= inf->getAnchorList();
400 xRow->appendObject( rProp,aAny );
402 else if ( rProp.Name == "KeywordTitleForRef" )
404 KeywordInfo *inf =
405 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
406 m_aURLParameter.get_language() );
408 uno::Any aAny;
409 if( inf )
410 aAny <<= inf->getTitleList();
411 xRow->appendObject( rProp,aAny );
413 else if ( rProp.Name == "SearchScopes" )
415 uno::Sequence< OUString > seq( 2 );
416 seq[0] = "Heading";
417 seq[1] = "FullText";
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() );
427 uno::Any aAny;
428 if( inf )
429 aAny <<= sal_Int32( inf->get_order() );
430 xRow->appendObject( rProp,aAny );
432 else
433 xRow->appendVoid( rProp );
434 else if( "AnchorName" == rProp.Name &&
435 m_aURLParameter.isFile() )
436 xRow->appendString( rProp,m_aURLParameter.get_tag() );
437 else
438 xRow->appendVoid( rProp );
441 return uno::Reference< sdbc::XRow >( xRow.get() );
444 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */