1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: content.cxx,v $
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 /**************************************************************************
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>
54 #include <ucbhelper/contentidentifier.hxx>
55 #include <ucbhelper/propertyvalueset.hxx>
56 #ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX
57 #include <ucbhelper/cancelcommandexecution.hxx>
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
>&
83 Databases
* pDatabases
)
84 : ContentImplHelper( rxSMgr
, pProvider
, Identifier
),
85 m_aURLParameter( Identifier
->getContentIdentifier(),pDatabases
),
86 m_pDatabases( pDatabases
) // not owner
90 //=========================================================================
96 //=========================================================================
98 // XInterface methods.
100 //=========================================================================
103 void SAL_CALL
Content::acquire()
106 ContentImplHelper::acquire();
109 //=========================================================================
111 void SAL_CALL
Content::release()
114 ContentImplHelper::release();
117 //=========================================================================
119 uno::Any SAL_CALL
Content::queryInterface( const uno::Type
& rType
)
120 throw ( uno::RuntimeException
)
123 return aRet
.hasValue() ? aRet
: ContentImplHelper::queryInterface( rType
);
126 //=========================================================================
128 // XTypeProvider methods.
130 //=========================================================================
132 XTYPEPROVIDER_COMMON_IMPL( Content
);
134 //=========================================================================
136 uno::Sequence
< uno::Type
> SAL_CALL
Content::getTypes()
137 throw( uno::RuntimeException
)
139 static cppu::OTypeCollection
* pCollection
= NULL
;
143 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() );
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 //=========================================================================
171 rtl::OUString SAL_CALL
Content::getImplementationName()
172 throw( uno::RuntimeException
)
174 return rtl::OUString::createFromAscii( "CHelpContent" );
177 //=========================================================================
179 uno::Sequence
< rtl::OUString
> SAL_CALL
Content::getSupportedServiceNames()
180 throw( uno::RuntimeException
)
182 uno::Sequence
< rtl::OUString
> aSNS( 1 );
184 = rtl::OUString::createFromAscii( MYUCP_CONTENT_SERVICE_NAME
);
188 //=========================================================================
192 //=========================================================================
195 rtl::OUString SAL_CALL
Content::getContentType()
196 throw( uno::RuntimeException
)
198 return rtl::OUString::createFromAscii( MYUCP_CONTENT_TYPE
);
201 //=========================================================================
203 // XCommandProcessor methods.
205 //=========================================================================
208 void SAL_CALL
Content::abort( sal_Int32
/*CommandId*/ )
209 throw( uno::RuntimeException
)
215 class ResultSetForRootFactory
216 : public ResultSetFactory
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
;
231 ResultSetForRootFactory(
232 const uno::Reference
< lang::XMultiServiceFactory
>& xSMgr
,
233 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
235 const uno::Sequence
< beans::Property
>& seq
,
236 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
,
237 URLParameter aURLParameter
,
238 Databases
* pDatabases
)
240 m_xProvider( xProvider
),
241 m_nOpenMode( nOpenMode
),
243 m_seqSort( seqSort
),
244 m_aURLParameter( aURLParameter
),
245 m_pDatabases( pDatabases
)
249 ResultSetBase
* createResultSet()
251 return new ResultSetForRoot( m_xSMgr
,
263 class ResultSetForQueryFactory
264 : public ResultSetFactory
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
;
279 ResultSetForQueryFactory(
280 const uno::Reference
< lang::XMultiServiceFactory
>& xSMgr
,
281 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
283 const uno::Sequence
< beans::Property
>& seq
,
284 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
,
285 URLParameter aURLParameter
,
286 Databases
* pDatabases
)
288 m_xProvider( xProvider
),
289 m_nOpenMode( nOpenMode
),
291 m_seqSort( seqSort
),
292 m_aURLParameter( aURLParameter
),
293 m_pDatabases( pDatabases
)
297 ResultSetBase
* createResultSet()
299 return new ResultSetForQuery( m_xSMgr
,
312 uno::Any SAL_CALL
Content::execute(
313 const ucb::Command
& aCommand
,
315 const uno::Reference
< ucb::XCommandEnvironment
>& Environment
)
316 throw( uno::Exception
,
317 ucb::CommandAbortedException
,
318 uno::RuntimeException
)
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();
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
,
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
,
403 if( m_aURLParameter
.isRoot() )
405 uno::Reference
< ucb::XDynamicResultSet
> xSet
406 = new DynamicResultSet(
411 new ResultSetForRootFactory(
415 aOpenCommand
.Properties
,
416 aOpenCommand
.SortingInfo
,
421 else if( m_aURLParameter
.isQuery() )
423 uno::Reference
< ucb::XDynamicResultSet
> xSet
424 = new DynamicResultSet(
429 new ResultSetForQueryFactory(
433 aOpenCommand
.Properties
,
434 aOpenCommand
.SortingInfo
,
442 //////////////////////////////////////////////////////////////////
443 // Unsupported command
444 //////////////////////////////////////////////////////////////////
445 aRet
<<= ucb::UnsupportedCommandException();
446 ucbhelper::cancelCommandExecution(aRet
,Environment
);
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 )
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 )
480 m_aURLParameter
.isFile() || m_aURLParameter
.isRoot() );
481 else if( rProp
.Name
.compareToAscii( "IsFolder" ) == 0 )
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() )
491 rtl::OUString::createFromAscii( "image/gif" ) );
492 else if( m_aURLParameter
.isActive() )
495 rtl::OUString::createFromAscii( "text/plain" ) );
496 else if( m_aURLParameter
.isFile() )
498 rProp
,rtl::OUString::createFromAscii( "text/html" ) );
499 else if( m_aURLParameter
.isRoot() )
502 rtl::OUString::createFromAscii( "text/css" ) );
504 xRow
->appendVoid( rProp
);
505 else if( m_aURLParameter
.isModule() )
506 if( rProp
.Name
.compareToAscii( "KeywordList" ) == 0 )
509 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
510 m_aURLParameter
.get_language() );
514 aAny
<<= inf
->getKeywordList();
515 xRow
->appendObject( rProp
,aAny
);
517 else if( rProp
.Name
.compareToAscii( "KeywordRef" ) == 0 )
520 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
521 m_aURLParameter
.get_language() );
525 aAny
<<= inf
->getIdList();
526 xRow
->appendObject( rProp
,aAny
);
528 else if( rProp
.Name
.compareToAscii( "KeywordAnchorForRef" ) == 0 )
531 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
532 m_aURLParameter
.get_language() );
536 aAny
<<= inf
->getAnchorList();
537 xRow
->appendObject( rProp
,aAny
);
539 else if( rProp
.Name
.compareToAscii( "KeywordTitleForRef" ) == 0 )
542 m_pDatabases
->getKeyword( m_aURLParameter
.get_module(),
543 m_aURLParameter
.get_language() );
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" );
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() );
568 aAny
<<= sal_Int32( inf
->get_order() );
569 xRow
->appendObject( rProp
,aAny
);
572 xRow
->appendVoid( rProp
);
573 else if( rProp
.Name
.compareToAscii( "AnchorName" ) == 0 &&
574 m_aURLParameter
.isFile() )
575 xRow
->appendString( rProp
,m_aURLParameter
.get_tag() );
577 xRow
->appendVoid( rProp
);
580 return uno::Reference
< sdbc::XRow
>( xRow
.get() );