Update ooo320-m1
[ooovba.git] / xmlhelp / source / cxxhelp / provider / content.cxx
blob0dd138ac3db957d46429e5b1157717645ab67393
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: content.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlhelp.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/beans/XPropertyAccess.hpp>
41 #include <com/sun/star/sdbc/XRow.hpp>
42 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
43 #include <com/sun/star/ucb/OpenMode.hpp>
44 #include <com/sun/star/ucb/XCommandInfo.hpp>
45 #include <com/sun/star/io/XActiveDataSink.hpp>
46 #include <com/sun/star/io/XOutputStream.hpp>
47 #include <com/sun/star/lang/IllegalAccessException.hpp>
48 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
49 #include <com/sun/star/io/XActiveDataStreamer.hpp>
50 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
51 #ifndef _VOS_DIAGNOSE_HXX_
52 #include <vos/diagnose.hxx>
53 #endif
54 #include <ucbhelper/contentidentifier.hxx>
55 #include <ucbhelper/propertyvalueset.hxx>
56 #ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX
57 #include <ucbhelper/cancelcommandexecution.hxx>
58 #endif
59 #include "content.hxx"
60 #include "provider.hxx"
61 #include "resultset.hxx"
62 #include "databases.hxx"
63 #include "resultsetfactory.hxx"
64 #include "resultsetbase.hxx"
65 #include "resultsetforroot.hxx"
66 #include "resultsetforquery.hxx"
68 using namespace com::sun::star;
69 using namespace chelp;
71 //=========================================================================
72 //=========================================================================
74 // Content Implementation.
76 //=========================================================================
77 //=========================================================================
79 Content::Content( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
80 ::ucbhelper::ContentProviderImplHelper* pProvider,
81 const uno::Reference< ucb::XContentIdentifier >&
82 Identifier,
83 Databases* pDatabases )
84 : ContentImplHelper( rxSMgr, pProvider, Identifier ),
85 m_aURLParameter( Identifier->getContentIdentifier(),pDatabases ),
86 m_pDatabases( pDatabases ) // not owner
90 //=========================================================================
91 // virtual
92 Content::~Content()
96 //=========================================================================
98 // XInterface methods.
100 //=========================================================================
102 // virtual
103 void SAL_CALL Content::acquire()
104 throw( )
106 ContentImplHelper::acquire();
109 //=========================================================================
110 // virtual
111 void SAL_CALL Content::release()
112 throw( )
114 ContentImplHelper::release();
117 //=========================================================================
118 // virtual
119 uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
120 throw ( uno::RuntimeException )
122 uno::Any aRet;
123 return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
126 //=========================================================================
128 // XTypeProvider methods.
130 //=========================================================================
132 XTYPEPROVIDER_COMMON_IMPL( Content );
134 //=========================================================================
135 // virtual
136 uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
137 throw( uno::RuntimeException )
139 static cppu::OTypeCollection* pCollection = NULL;
141 if ( !pCollection )
143 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
144 if ( !pCollection )
146 static cppu::OTypeCollection aCollection(
147 CPPU_TYPE_REF( lang::XTypeProvider ),
148 CPPU_TYPE_REF( lang::XServiceInfo ),
149 CPPU_TYPE_REF( lang::XComponent ),
150 CPPU_TYPE_REF( ucb::XContent ),
151 CPPU_TYPE_REF( ucb::XCommandProcessor ),
152 CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
153 CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
154 CPPU_TYPE_REF( beans::XPropertyContainer ),
155 CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
156 CPPU_TYPE_REF( container::XChild ) );
157 pCollection = &aCollection;
161 return (*pCollection).getTypes();
164 //=========================================================================
166 // XServiceInfo methods.
168 //=========================================================================
170 // virtual
171 rtl::OUString SAL_CALL Content::getImplementationName()
172 throw( uno::RuntimeException )
174 return rtl::OUString::createFromAscii( "CHelpContent" );
177 //=========================================================================
178 // virtual
179 uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
180 throw( uno::RuntimeException )
182 uno::Sequence< rtl::OUString > aSNS( 1 );
183 aSNS.getArray()[ 0 ]
184 = rtl::OUString::createFromAscii( MYUCP_CONTENT_SERVICE_NAME );
185 return aSNS;
188 //=========================================================================
190 // XContent methods.
192 //=========================================================================
194 // virtual
195 rtl::OUString SAL_CALL Content::getContentType()
196 throw( uno::RuntimeException )
198 return rtl::OUString::createFromAscii( MYUCP_CONTENT_TYPE );
201 //=========================================================================
203 // XCommandProcessor methods.
205 //=========================================================================
207 //virtual
208 void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
209 throw( uno::RuntimeException )
215 class ResultSetForRootFactory
216 : public ResultSetFactory
218 private:
220 uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
221 uno::Reference< ucb::XContentProvider > m_xProvider;
222 sal_Int32 m_nOpenMode;
223 uno::Sequence< beans::Property > m_seq;
224 uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
225 URLParameter m_aURLParameter;
226 Databases* m_pDatabases;
229 public:
231 ResultSetForRootFactory(
232 const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
233 const uno::Reference< ucb::XContentProvider >& xProvider,
234 sal_Int32 nOpenMode,
235 const uno::Sequence< beans::Property >& seq,
236 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
237 URLParameter aURLParameter,
238 Databases* pDatabases )
239 : m_xSMgr( xSMgr ),
240 m_xProvider( xProvider ),
241 m_nOpenMode( nOpenMode ),
242 m_seq( seq ),
243 m_seqSort( seqSort ),
244 m_aURLParameter( aURLParameter ),
245 m_pDatabases( pDatabases )
249 ResultSetBase* createResultSet()
251 return new ResultSetForRoot( m_xSMgr,
252 m_xProvider,
253 m_nOpenMode,
254 m_seq,
255 m_seqSort,
256 m_aURLParameter,
257 m_pDatabases );
263 class ResultSetForQueryFactory
264 : public ResultSetFactory
266 private:
268 uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
269 uno::Reference< ucb::XContentProvider > m_xProvider;
270 sal_Int32 m_nOpenMode;
271 uno::Sequence< beans::Property > m_seq;
272 uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
273 URLParameter m_aURLParameter;
274 Databases* m_pDatabases;
277 public:
279 ResultSetForQueryFactory(
280 const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
281 const uno::Reference< ucb::XContentProvider >& xProvider,
282 sal_Int32 nOpenMode,
283 const uno::Sequence< beans::Property >& seq,
284 const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
285 URLParameter aURLParameter,
286 Databases* pDatabases )
287 : m_xSMgr( xSMgr ),
288 m_xProvider( xProvider ),
289 m_nOpenMode( nOpenMode ),
290 m_seq( seq ),
291 m_seqSort( seqSort ),
292 m_aURLParameter( aURLParameter ),
293 m_pDatabases( pDatabases )
297 ResultSetBase* createResultSet()
299 return new ResultSetForQuery( m_xSMgr,
300 m_xProvider,
301 m_nOpenMode,
302 m_seq,
303 m_seqSort,
304 m_aURLParameter,
305 m_pDatabases );
311 // virtual
312 uno::Any SAL_CALL Content::execute(
313 const ucb::Command& aCommand,
314 sal_Int32 CommandId,
315 const uno::Reference< ucb::XCommandEnvironment >& Environment )
316 throw( uno::Exception,
317 ucb::CommandAbortedException,
318 uno::RuntimeException )
320 uno::Any aRet;
322 if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 )
324 uno::Sequence< beans::Property > Properties;
325 if ( !( aCommand.Argument >>= Properties ) )
327 aRet <<= lang::IllegalArgumentException();
328 ucbhelper::cancelCommandExecution(aRet,Environment);
331 aRet <<= getPropertyValues( Properties );
333 else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 )
335 uno::Sequence<beans::PropertyValue> propertyValues;
337 if( ! ( aCommand.Argument >>= propertyValues ) ) {
338 aRet <<= lang::IllegalArgumentException();
339 ucbhelper::cancelCommandExecution(aRet,Environment);
342 uno::Sequence< uno::Any > ret(propertyValues.getLength());
343 uno::Sequence< beans::Property > props(getProperties(Environment));
344 // No properties can be set
345 for(sal_Int32 i = 0; i < ret.getLength(); ++i) {
346 ret[i] <<= beans::UnknownPropertyException();
347 for(sal_Int32 j = 0; j < props.getLength(); ++j)
348 if(props[j].Name == propertyValues[i].Name) {
349 ret[i] <<= lang::IllegalAccessException();
350 break;
354 aRet <<= ret;
356 else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 )
358 // Note: Implemented by base class.
359 aRet <<= getPropertySetInfo( Environment );
361 else if ( aCommand.Name.compareToAscii( "getCommandInfo" ) == 0 )
363 // Note: Implemented by base class.
364 aRet <<= getCommandInfo( Environment );
366 else if ( aCommand.Name.compareToAscii( "open" ) == 0 )
368 ucb::OpenCommandArgument2 aOpenCommand;
369 if ( !( aCommand.Argument >>= aOpenCommand ) )
371 aRet <<= lang::IllegalArgumentException();
372 ucbhelper::cancelCommandExecution(aRet,Environment);
375 uno::Reference< io::XActiveDataSink > xActiveDataSink(
376 aOpenCommand.Sink, uno::UNO_QUERY);
378 if(xActiveDataSink.is())
379 m_aURLParameter.open(m_xSMgr,
380 aCommand,
381 CommandId,
382 Environment,
383 xActiveDataSink);
385 uno::Reference< io::XActiveDataStreamer > xActiveDataStreamer(
386 aOpenCommand.Sink, uno::UNO_QUERY);
388 if(xActiveDataStreamer.is()) {
389 aRet <<= ucb::UnsupportedDataSinkException();
390 ucbhelper::cancelCommandExecution(aRet,Environment);
393 uno::Reference< io::XOutputStream > xOutputStream(
394 aOpenCommand.Sink, uno::UNO_QUERY);
396 if(xOutputStream.is() )
397 m_aURLParameter.open(m_xSMgr,
398 aCommand,
399 CommandId,
400 Environment,
401 xOutputStream);
403 if( m_aURLParameter.isRoot() )
405 uno::Reference< ucb::XDynamicResultSet > xSet
406 = new DynamicResultSet(
407 m_xSMgr,
408 this,
409 aOpenCommand,
410 Environment,
411 new ResultSetForRootFactory(
412 m_xSMgr,
413 m_xProvider.get(),
414 aOpenCommand.Mode,
415 aOpenCommand.Properties,
416 aOpenCommand.SortingInfo,
417 m_aURLParameter,
418 m_pDatabases));
419 aRet <<= xSet;
421 else if( m_aURLParameter.isQuery() )
423 uno::Reference< ucb::XDynamicResultSet > xSet
424 = new DynamicResultSet(
425 m_xSMgr,
426 this,
427 aOpenCommand,
428 Environment,
429 new ResultSetForQueryFactory(
430 m_xSMgr,
431 m_xProvider.get(),
432 aOpenCommand.Mode,
433 aOpenCommand.Properties,
434 aOpenCommand.SortingInfo,
435 m_aURLParameter,
436 m_pDatabases ) );
437 aRet <<= xSet;
440 else
442 //////////////////////////////////////////////////////////////////
443 // Unsupported command
444 //////////////////////////////////////////////////////////////////
445 aRet <<= ucb::UnsupportedCommandException();
446 ucbhelper::cancelCommandExecution(aRet,Environment);
449 return aRet;
455 //=========================================================================
456 uno::Reference< sdbc::XRow > Content::getPropertyValues(
457 const uno::Sequence< beans::Property >& rProperties )
459 osl::MutexGuard aGuard( m_aMutex );
461 rtl::Reference< ::ucbhelper::PropertyValueSet > xRow =
462 new ::ucbhelper::PropertyValueSet( m_xSMgr );
464 for ( sal_Int32 n = 0; n < rProperties.getLength(); ++n )
466 const beans::Property& rProp = rProperties[n];
468 if ( rProp.Name.compareToAscii( "ContentType" ) == 0 )
469 xRow->appendString(
470 rProp,
471 rtl::OUString::createFromAscii(
472 "application/vnd.sun.star.help" ) );
473 else if( rProp.Name.compareToAscii( "Title" ) == 0 )
474 xRow->appendString ( rProp,m_aURLParameter.get_title() );
475 else if( rProp.Name.compareToAscii( "IsReadOnly" ) == 0 )
476 xRow->appendBoolean( rProp,true );
477 else if( rProp.Name.compareToAscii( "IsDocument" ) == 0 )
478 xRow->appendBoolean(
479 rProp,
480 m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
481 else if( rProp.Name.compareToAscii( "IsFolder" ) == 0 )
482 xRow->appendBoolean(
483 rProp,
484 ! m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
485 else if( rProp.Name.compareToAscii( "IsErrorDocument" ) == 0 )
486 xRow->appendBoolean( rProp, m_aURLParameter.isErrorDocument() );
487 else if( rProp.Name.compareToAscii( "MediaType" ) == 0 )
488 if( m_aURLParameter.isPicture() )
489 xRow->appendString(
490 rProp,
491 rtl::OUString::createFromAscii( "image/gif" ) );
492 else if( m_aURLParameter.isActive() )
493 xRow->appendString(
494 rProp,
495 rtl::OUString::createFromAscii( "text/plain" ) );
496 else if( m_aURLParameter.isFile() )
497 xRow->appendString(
498 rProp,rtl::OUString::createFromAscii( "text/html" ) );
499 else if( m_aURLParameter.isRoot() )
500 xRow->appendString(
501 rProp,
502 rtl::OUString::createFromAscii( "text/css" ) );
503 else
504 xRow->appendVoid( rProp );
505 else if( m_aURLParameter.isModule() )
506 if( rProp.Name.compareToAscii( "KeywordList" ) == 0 )
508 KeywordInfo *inf =
509 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
510 m_aURLParameter.get_language() );
512 uno::Any aAny;
513 if( inf )
514 aAny <<= inf->getKeywordList();
515 xRow->appendObject( rProp,aAny );
517 else if( rProp.Name.compareToAscii( "KeywordRef" ) == 0 )
519 KeywordInfo *inf =
520 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
521 m_aURLParameter.get_language() );
523 uno::Any aAny;
524 if( inf )
525 aAny <<= inf->getIdList();
526 xRow->appendObject( rProp,aAny );
528 else if( rProp.Name.compareToAscii( "KeywordAnchorForRef" ) == 0 )
530 KeywordInfo *inf =
531 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
532 m_aURLParameter.get_language() );
534 uno::Any aAny;
535 if( inf )
536 aAny <<= inf->getAnchorList();
537 xRow->appendObject( rProp,aAny );
539 else if( rProp.Name.compareToAscii( "KeywordTitleForRef" ) == 0 )
541 KeywordInfo *inf =
542 m_pDatabases->getKeyword( m_aURLParameter.get_module(),
543 m_aURLParameter.get_language() );
545 uno::Any aAny;
546 if( inf )
547 aAny <<= inf->getTitleList();
548 xRow->appendObject( rProp,aAny );
550 else if( rProp.Name.compareToAscii( "SearchScopes" ) == 0 )
552 uno::Sequence< rtl::OUString > seq( 2 );
553 seq[0] = rtl::OUString::createFromAscii( "Heading" );
554 seq[1] = rtl::OUString::createFromAscii( "FullText" );
555 uno::Any aAny;
556 aAny <<= seq;
557 xRow->appendObject( rProp,aAny );
559 else if( rProp.Name.compareToAscii( "Order" ) == 0 )
561 StaticModuleInformation *inf =
562 m_pDatabases->getStaticInformationForModule(
563 m_aURLParameter.get_module(),
564 m_aURLParameter.get_language() );
566 uno::Any aAny;
567 if( inf )
568 aAny <<= sal_Int32( inf->get_order() );
569 xRow->appendObject( rProp,aAny );
571 else
572 xRow->appendVoid( rProp );
573 else if( rProp.Name.compareToAscii( "AnchorName" ) == 0 &&
574 m_aURLParameter.isFile() )
575 xRow->appendString( rProp,m_aURLParameter.get_tag() );
576 else
577 xRow->appendVoid( rProp );
580 return uno::Reference< sdbc::XRow >( xRow.get() );