PageRenderTime 143ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/xmlhelp/source/cxxhelp/provider/content.cxx

https://bitbucket.org/jorgenio/libreoffice
C++ | 575 lines | 420 code | 68 blank | 87 comment | 85 complexity | b3a9c78dc39074950ceabe583cbd7034 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause-No-Nuclear-License-2014
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2000, 2010 Oracle and/or its affiliates.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. /**************************************************************************
  29. TODO
  30. **************************************************************************
  31. *************************************************************************/
  32. #include <com/sun/star/beans/PropertyAttribute.hpp>
  33. #include <com/sun/star/beans/XPropertyAccess.hpp>
  34. #include <com/sun/star/sdbc/XRow.hpp>
  35. #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
  36. #include <com/sun/star/ucb/OpenMode.hpp>
  37. #include <com/sun/star/ucb/XCommandInfo.hpp>
  38. #include <com/sun/star/io/XActiveDataSink.hpp>
  39. #include <com/sun/star/io/XOutputStream.hpp>
  40. #include <com/sun/star/lang/IllegalAccessException.hpp>
  41. #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
  42. #include <com/sun/star/io/XActiveDataStreamer.hpp>
  43. #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
  44. #include <osl/diagnose.h>
  45. #include <ucbhelper/contentidentifier.hxx>
  46. #include <ucbhelper/propertyvalueset.hxx>
  47. #include <ucbhelper/cancelcommandexecution.hxx>
  48. #include "content.hxx"
  49. #include "provider.hxx"
  50. #include "resultset.hxx"
  51. #include "databases.hxx"
  52. #include "resultsetfactory.hxx"
  53. #include "resultsetbase.hxx"
  54. #include "resultsetforroot.hxx"
  55. #include "resultsetforquery.hxx"
  56. using namespace com::sun::star;
  57. using namespace chelp;
  58. //=========================================================================
  59. //=========================================================================
  60. //
  61. // Content Implementation.
  62. //
  63. //=========================================================================
  64. //=========================================================================
  65. Content::Content( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
  66. ::ucbhelper::ContentProviderImplHelper* pProvider,
  67. const uno::Reference< ucb::XContentIdentifier >&
  68. Identifier,
  69. Databases* pDatabases )
  70. : ContentImplHelper( rxSMgr, pProvider, Identifier ),
  71. m_aURLParameter( Identifier->getContentIdentifier(),pDatabases ),
  72. m_pDatabases( pDatabases ) // not owner
  73. {
  74. }
  75. //=========================================================================
  76. // virtual
  77. Content::~Content()
  78. {
  79. }
  80. //=========================================================================
  81. //
  82. // XInterface methods.
  83. //
  84. //=========================================================================
  85. // virtual
  86. void SAL_CALL Content::acquire()
  87. throw( )
  88. {
  89. ContentImplHelper::acquire();
  90. }
  91. //=========================================================================
  92. // virtual
  93. void SAL_CALL Content::release()
  94. throw( )
  95. {
  96. ContentImplHelper::release();
  97. }
  98. //=========================================================================
  99. // virtual
  100. uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
  101. throw ( uno::RuntimeException )
  102. {
  103. uno::Any aRet;
  104. return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
  105. }
  106. //=========================================================================
  107. //
  108. // XTypeProvider methods.
  109. //
  110. //=========================================================================
  111. XTYPEPROVIDER_COMMON_IMPL( Content );
  112. //=========================================================================
  113. // virtual
  114. uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
  115. throw( uno::RuntimeException )
  116. {
  117. static cppu::OTypeCollection* pCollection = NULL;
  118. if ( !pCollection )
  119. {
  120. osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
  121. if ( !pCollection )
  122. {
  123. static cppu::OTypeCollection aCollection(
  124. CPPU_TYPE_REF( lang::XTypeProvider ),
  125. CPPU_TYPE_REF( lang::XServiceInfo ),
  126. CPPU_TYPE_REF( lang::XComponent ),
  127. CPPU_TYPE_REF( ucb::XContent ),
  128. CPPU_TYPE_REF( ucb::XCommandProcessor ),
  129. CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
  130. CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
  131. CPPU_TYPE_REF( beans::XPropertyContainer ),
  132. CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
  133. CPPU_TYPE_REF( container::XChild ) );
  134. pCollection = &aCollection;
  135. }
  136. }
  137. return (*pCollection).getTypes();
  138. }
  139. //=========================================================================
  140. //
  141. // XServiceInfo methods.
  142. //
  143. //=========================================================================
  144. // virtual
  145. rtl::OUString SAL_CALL Content::getImplementationName()
  146. throw( uno::RuntimeException )
  147. {
  148. return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CHelpContent" ));
  149. }
  150. //=========================================================================
  151. // virtual
  152. uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
  153. throw( uno::RuntimeException )
  154. {
  155. uno::Sequence< rtl::OUString > aSNS( 1 );
  156. aSNS.getArray()[ 0 ]
  157. = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( MYUCP_CONTENT_SERVICE_NAME ));
  158. return aSNS;
  159. }
  160. //=========================================================================
  161. //
  162. // XContent methods.
  163. //
  164. //=========================================================================
  165. // virtual
  166. rtl::OUString SAL_CALL Content::getContentType()
  167. throw( uno::RuntimeException )
  168. {
  169. return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( MYUCP_CONTENT_TYPE ));
  170. }
  171. //=========================================================================
  172. //
  173. // XCommandProcessor methods.
  174. //
  175. //=========================================================================
  176. //virtual
  177. void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
  178. throw( uno::RuntimeException )
  179. {
  180. }
  181. class ResultSetForRootFactory
  182. : public ResultSetFactory
  183. {
  184. private:
  185. uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
  186. uno::Reference< ucb::XContentProvider > m_xProvider;
  187. sal_Int32 m_nOpenMode;
  188. uno::Sequence< beans::Property > m_seq;
  189. uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
  190. URLParameter m_aURLParameter;
  191. Databases* m_pDatabases;
  192. public:
  193. ResultSetForRootFactory(
  194. const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
  195. const uno::Reference< ucb::XContentProvider >& xProvider,
  196. sal_Int32 nOpenMode,
  197. const uno::Sequence< beans::Property >& seq,
  198. const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
  199. URLParameter aURLParameter,
  200. Databases* pDatabases )
  201. : m_xSMgr( xSMgr ),
  202. m_xProvider( xProvider ),
  203. m_nOpenMode( nOpenMode ),
  204. m_seq( seq ),
  205. m_seqSort( seqSort ),
  206. m_aURLParameter( aURLParameter ),
  207. m_pDatabases( pDatabases )
  208. {
  209. }
  210. ResultSetBase* createResultSet()
  211. {
  212. return new ResultSetForRoot( m_xSMgr,
  213. m_xProvider,
  214. m_nOpenMode,
  215. m_seq,
  216. m_seqSort,
  217. m_aURLParameter,
  218. m_pDatabases );
  219. }
  220. };
  221. class ResultSetForQueryFactory
  222. : public ResultSetFactory
  223. {
  224. private:
  225. uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
  226. uno::Reference< ucb::XContentProvider > m_xProvider;
  227. sal_Int32 m_nOpenMode;
  228. uno::Sequence< beans::Property > m_seq;
  229. uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
  230. URLParameter m_aURLParameter;
  231. Databases* m_pDatabases;
  232. public:
  233. ResultSetForQueryFactory(
  234. const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
  235. const uno::Reference< ucb::XContentProvider >& xProvider,
  236. sal_Int32 nOpenMode,
  237. const uno::Sequence< beans::Property >& seq,
  238. const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
  239. URLParameter aURLParameter,
  240. Databases* pDatabases )
  241. : m_xSMgr( xSMgr ),
  242. m_xProvider( xProvider ),
  243. m_nOpenMode( nOpenMode ),
  244. m_seq( seq ),
  245. m_seqSort( seqSort ),
  246. m_aURLParameter( aURLParameter ),
  247. m_pDatabases( pDatabases )
  248. {
  249. }
  250. ResultSetBase* createResultSet()
  251. {
  252. return new ResultSetForQuery( m_xSMgr,
  253. m_xProvider,
  254. m_nOpenMode,
  255. m_seq,
  256. m_seqSort,
  257. m_aURLParameter,
  258. m_pDatabases );
  259. }
  260. };
  261. // virtual
  262. uno::Any SAL_CALL Content::execute(
  263. const ucb::Command& aCommand,
  264. sal_Int32 CommandId,
  265. const uno::Reference< ucb::XCommandEnvironment >& Environment )
  266. throw( uno::Exception,
  267. ucb::CommandAbortedException,
  268. uno::RuntimeException )
  269. {
  270. uno::Any aRet;
  271. if ( aCommand.Name == "getPropertyValues" )
  272. {
  273. uno::Sequence< beans::Property > Properties;
  274. if ( !( aCommand.Argument >>= Properties ) )
  275. {
  276. aRet <<= lang::IllegalArgumentException();
  277. ucbhelper::cancelCommandExecution(aRet,Environment);
  278. }
  279. aRet <<= getPropertyValues( Properties );
  280. }
  281. else if ( aCommand.Name == "setPropertyValues" )
  282. {
  283. uno::Sequence<beans::PropertyValue> propertyValues;
  284. if( ! ( aCommand.Argument >>= propertyValues ) ) {
  285. aRet <<= lang::IllegalArgumentException();
  286. ucbhelper::cancelCommandExecution(aRet,Environment);
  287. }
  288. uno::Sequence< uno::Any > ret(propertyValues.getLength());
  289. uno::Sequence< beans::Property > props(getProperties(Environment));
  290. // No properties can be set
  291. for(sal_Int32 i = 0; i < ret.getLength(); ++i) {
  292. ret[i] <<= beans::UnknownPropertyException();
  293. for(sal_Int32 j = 0; j < props.getLength(); ++j)
  294. if(props[j].Name == propertyValues[i].Name) {
  295. ret[i] <<= lang::IllegalAccessException();
  296. break;
  297. }
  298. }
  299. aRet <<= ret;
  300. }
  301. else if ( aCommand.Name == "getPropertySetInfo" )
  302. {
  303. // Note: Implemented by base class.
  304. aRet <<= getPropertySetInfo( Environment );
  305. }
  306. else if ( aCommand.Name == "getCommandInfo" )
  307. {
  308. // Note: Implemented by base class.
  309. aRet <<= getCommandInfo( Environment );
  310. }
  311. else if ( aCommand.Name == "open" )
  312. {
  313. ucb::OpenCommandArgument2 aOpenCommand;
  314. if ( !( aCommand.Argument >>= aOpenCommand ) )
  315. {
  316. aRet <<= lang::IllegalArgumentException();
  317. ucbhelper::cancelCommandExecution(aRet,Environment);
  318. }
  319. uno::Reference< io::XActiveDataSink > xActiveDataSink(
  320. aOpenCommand.Sink, uno::UNO_QUERY);
  321. if(xActiveDataSink.is())
  322. m_aURLParameter.open(m_xSMgr,
  323. aCommand,
  324. CommandId,
  325. Environment,
  326. xActiveDataSink);
  327. uno::Reference< io::XActiveDataStreamer > xActiveDataStreamer(
  328. aOpenCommand.Sink, uno::UNO_QUERY);
  329. if(xActiveDataStreamer.is()) {
  330. aRet <<= ucb::UnsupportedDataSinkException();
  331. ucbhelper::cancelCommandExecution(aRet,Environment);
  332. }
  333. uno::Reference< io::XOutputStream > xOutputStream(
  334. aOpenCommand.Sink, uno::UNO_QUERY);
  335. if(xOutputStream.is() )
  336. m_aURLParameter.open(m_xSMgr,
  337. aCommand,
  338. CommandId,
  339. Environment,
  340. xOutputStream);
  341. if( m_aURLParameter.isRoot() )
  342. {
  343. uno::Reference< ucb::XDynamicResultSet > xSet
  344. = new DynamicResultSet(
  345. m_xSMgr,
  346. this,
  347. aOpenCommand,
  348. Environment,
  349. new ResultSetForRootFactory(
  350. m_xSMgr,
  351. m_xProvider.get(),
  352. aOpenCommand.Mode,
  353. aOpenCommand.Properties,
  354. aOpenCommand.SortingInfo,
  355. m_aURLParameter,
  356. m_pDatabases));
  357. aRet <<= xSet;
  358. }
  359. else if( m_aURLParameter.isQuery() )
  360. {
  361. uno::Reference< ucb::XDynamicResultSet > xSet
  362. = new DynamicResultSet(
  363. m_xSMgr,
  364. this,
  365. aOpenCommand,
  366. Environment,
  367. new ResultSetForQueryFactory(
  368. m_xSMgr,
  369. m_xProvider.get(),
  370. aOpenCommand.Mode,
  371. aOpenCommand.Properties,
  372. aOpenCommand.SortingInfo,
  373. m_aURLParameter,
  374. m_pDatabases ) );
  375. aRet <<= xSet;
  376. }
  377. }
  378. else
  379. {
  380. //////////////////////////////////////////////////////////////////
  381. // Unsupported command
  382. //////////////////////////////////////////////////////////////////
  383. aRet <<= ucb::UnsupportedCommandException();
  384. ucbhelper::cancelCommandExecution(aRet,Environment);
  385. }
  386. return aRet;
  387. }
  388. //=========================================================================
  389. uno::Reference< sdbc::XRow > Content::getPropertyValues(
  390. const uno::Sequence< beans::Property >& rProperties )
  391. {
  392. osl::MutexGuard aGuard( m_aMutex );
  393. rtl::Reference< ::ucbhelper::PropertyValueSet > xRow =
  394. new ::ucbhelper::PropertyValueSet( m_xSMgr );
  395. for ( sal_Int32 n = 0; n < rProperties.getLength(); ++n )
  396. {
  397. const beans::Property& rProp = rProperties[n];
  398. if ( rProp.Name == "ContentType" )
  399. xRow->appendString(
  400. rProp,
  401. rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
  402. "application/vnd.sun.star.help" )) );
  403. else if ( rProp.Name == "Title" )
  404. xRow->appendString ( rProp,m_aURLParameter.get_title() );
  405. else if ( rProp.Name == "IsReadOnly" )
  406. xRow->appendBoolean( rProp,true );
  407. else if ( rProp.Name == "IsDocument" )
  408. xRow->appendBoolean(
  409. rProp,
  410. m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
  411. else if ( rProp.Name == "IsFolder" )
  412. xRow->appendBoolean(
  413. rProp,
  414. ! m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
  415. else if ( rProp.Name == "IsErrorDocument" )
  416. xRow->appendBoolean( rProp, m_aURLParameter.isErrorDocument() );
  417. else if ( rProp.Name == "MediaType" )
  418. if( m_aURLParameter.isPicture() )
  419. xRow->appendString(
  420. rProp,
  421. rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "image/gif" )) );
  422. else if( m_aURLParameter.isActive() )
  423. xRow->appendString(
  424. rProp,
  425. rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "text/plain" )) );
  426. else if( m_aURLParameter.isFile() )
  427. xRow->appendString(
  428. rProp,rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "text/html" )) );
  429. else if( m_aURLParameter.isRoot() )
  430. xRow->appendString(
  431. rProp,
  432. rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "text/css" )) );
  433. else
  434. xRow->appendVoid( rProp );
  435. else if( m_aURLParameter.isModule() )
  436. if ( rProp.Name == "KeywordList" )
  437. {
  438. KeywordInfo *inf =
  439. m_pDatabases->getKeyword( m_aURLParameter.get_module(),
  440. m_aURLParameter.get_language() );
  441. uno::Any aAny;
  442. if( inf )
  443. aAny <<= inf->getKeywordList();
  444. xRow->appendObject( rProp,aAny );
  445. }
  446. else if ( rProp.Name == "KeywordRef" )
  447. {
  448. KeywordInfo *inf =
  449. m_pDatabases->getKeyword( m_aURLParameter.get_module(),
  450. m_aURLParameter.get_language() );
  451. uno::Any aAny;
  452. if( inf )
  453. aAny <<= inf->getIdList();
  454. xRow->appendObject( rProp,aAny );
  455. }
  456. else if ( rProp.Name == "KeywordAnchorForRef" )
  457. {
  458. KeywordInfo *inf =
  459. m_pDatabases->getKeyword( m_aURLParameter.get_module(),
  460. m_aURLParameter.get_language() );
  461. uno::Any aAny;
  462. if( inf )
  463. aAny <<= inf->getAnchorList();
  464. xRow->appendObject( rProp,aAny );
  465. }
  466. else if ( rProp.Name == "KeywordTitleForRef" )
  467. {
  468. KeywordInfo *inf =
  469. m_pDatabases->getKeyword( m_aURLParameter.get_module(),
  470. m_aURLParameter.get_language() );
  471. uno::Any aAny;
  472. if( inf )
  473. aAny <<= inf->getTitleList();
  474. xRow->appendObject( rProp,aAny );
  475. }
  476. else if ( rProp.Name == "SearchScopes" )
  477. {
  478. uno::Sequence< rtl::OUString > seq( 2 );
  479. seq[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Heading" ));
  480. seq[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FullText" ));
  481. uno::Any aAny;
  482. aAny <<= seq;
  483. xRow->appendObject( rProp,aAny );
  484. }
  485. else if ( rProp.Name == "Order" )
  486. {
  487. StaticModuleInformation *inf =
  488. m_pDatabases->getStaticInformationForModule(
  489. m_aURLParameter.get_module(),
  490. m_aURLParameter.get_language() );
  491. uno::Any aAny;
  492. if( inf )
  493. aAny <<= sal_Int32( inf->get_order() );
  494. xRow->appendObject( rProp,aAny );
  495. }
  496. else
  497. xRow->appendVoid( rProp );
  498. else if( rProp.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AnchorName")) &&
  499. m_aURLParameter.isFile() )
  500. xRow->appendString( rProp,m_aURLParameter.get_tag() );
  501. else
  502. xRow->appendVoid( rProp );
  503. }
  504. return uno::Reference< sdbc::XRow >( xRow.get() );
  505. }
  506. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */