LCOV - code coverage report
Current view: top level - ucb/source/ucp/tdoc - tdoc_content.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 11 19 57.9 %
Date: 2014-11-03 Functions: 6 13 46.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
      21             : #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
      22             : 
      23             : #include <ucbhelper/contenthelper.hxx>
      24             : #include <com/sun/star/task/DocumentPasswordRequest.hpp>
      25             : #include <com/sun/star/ucb/XContentCreator.hpp>
      26             : #include <com/sun/star/ucb/CommandFailedException.hpp>
      27             : #include "tdoc_provider.hxx"
      28             : 
      29             : #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
      30             : 
      31             : namespace com { namespace sun { namespace star {
      32             :     namespace sdbc  { class XRow; }
      33             :     namespace io    { class XInputStream; class XOutputStream; }
      34             :     namespace beans { struct PropertyValue; }
      35             :     namespace ucb   { struct OpenCommandArgument2; struct TransferInfo;
      36             :                       struct ContentInfo; }
      37             : } } }
      38             : 
      39             : namespace tdoc_ucp
      40             : {
      41             : 
      42             : 
      43             : 
      44             : #define TDOC_ROOT_CONTENT_SERVICE_NAME \
      45             :                 "com.sun.star.ucb.TransientDocumentsRootContent"
      46             : #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \
      47             :                 "com.sun.star.ucb.TransientDocumentsDocumentContent"
      48             : #define TDOC_FOLDER_CONTENT_SERVICE_NAME \
      49             :                 "com.sun.star.ucb.TransientDocumentsFolderContent"
      50             : #define TDOC_STREAM_CONTENT_SERVICE_NAME \
      51             :                 "com.sun.star.ucb.TransientDocumentsStreamContent"
      52             : 
      53             : 
      54             : 
      55             : enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
      56             : 
      57        3120 : class ContentProperties
      58             : {
      59             : public:
      60         624 :     ContentProperties()
      61         624 :     : m_eType( STREAM )
      62         624 :     {}
      63             : 
      64         624 :     ContentProperties( const ContentType & rType, const OUString & rTitle )
      65             :     : m_eType( rType ),
      66         624 :       m_aContentType( rType == STREAM
      67             :         ? OUString( TDOC_STREAM_CONTENT_TYPE )
      68         624 :         : rType == FOLDER
      69             :             ? OUString( TDOC_FOLDER_CONTENT_TYPE )
      70         624 :             : rType == DOCUMENT
      71             :                 ? OUString( TDOC_DOCUMENT_CONTENT_TYPE )
      72             :                 : OUString( TDOC_ROOT_CONTENT_TYPE ) ),
      73        2496 :       m_aTitle( rTitle )
      74         624 :     {}
      75             : 
      76         328 :     ContentType getType() const { return m_eType; }
      77             : 
      78             :     // Properties
      79             : 
      80           0 :     const OUString & getContentType() const { return m_aContentType; }
      81             : 
      82           0 :     bool getIsFolder()   const { return m_eType > STREAM; }
      83           0 :     bool getIsDocument() const { return !getIsFolder(); }
      84             : 
      85           0 :     const OUString & getTitle() const { return m_aTitle; }
      86           0 :     void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; }
      87             : 
      88             :     com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
      89             :     getCreatableContentsInfo() const;
      90             : 
      91             :     bool isContentCreator() const;
      92             : 
      93             : private:
      94             :     ContentType   m_eType;
      95             :     OUString m_aContentType;
      96             :     OUString m_aTitle;
      97             : };
      98             : 
      99             : 
     100             : 
     101             : class Content : public ::ucbhelper::ContentImplHelper,
     102             :                 public com::sun::star::ucb::XContentCreator
     103             : {
     104             :     enum ContentState { TRANSIENT,  // created via createNewContent,
     105             :                                         // but did not process "insert" yet
     106             :                         PERSISTENT, // processed "insert"
     107             :                         DEAD        // processed "delete" / document was closed
     108             :                       };
     109             : 
     110             :     ContentProperties m_aProps;
     111             :     ContentState      m_eState;
     112             :     ContentProvider*  m_pProvider;
     113             : 
     114             : private:
     115             :     Content( const com::sun::star::uno::Reference<
     116             :                 com::sun::star::uno::XComponentContext >& rxContext,
     117             :              ContentProvider* pProvider,
     118             :              const com::sun::star::uno::Reference<
     119             :                 com::sun::star::ucb::XContentIdentifier >& Identifier,
     120             :             const ContentProperties & rProps );
     121             :     Content( const com::sun::star::uno::Reference<
     122             :                 com::sun::star::uno::XComponentContext >& rxContext,
     123             :              ContentProvider* pProvider,
     124             :              const com::sun::star::uno::Reference<
     125             :                 com::sun::star::ucb::XContentIdentifier >& Identifier,
     126             :              const com::sun::star::ucb::ContentInfo& Info );
     127             : 
     128             :     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
     129             :     getProperties( const com::sun::star::uno::Reference<
     130             :                     com::sun::star::ucb::XCommandEnvironment > & xEnv ) SAL_OVERRIDE;
     131             :     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
     132             :     getCommands( const com::sun::star::uno::Reference<
     133             :                     com::sun::star::ucb::XCommandEnvironment > & xEnv ) SAL_OVERRIDE;
     134             :     virtual OUString getParentURL() SAL_OVERRIDE;
     135             : 
     136             :     static bool hasData( ContentProvider* pProvider, const Uri & rUri );
     137           0 :     bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
     138             : 
     139             :     static bool loadData( ContentProvider* pProvider,
     140             :                           const Uri & rUri,
     141             :                           ContentProperties& rProps );
     142             :     bool storeData( const com::sun::star::uno::Reference<
     143             :                         com::sun::star::io::XInputStream >& xData,
     144             :                     const com::sun::star::uno::Reference<
     145             :                         com::sun::star::ucb::XCommandEnvironment >& xEnv )
     146             :         throw ( ::com::sun::star::ucb::CommandFailedException,
     147             :                 ::com::sun::star::task::DocumentPasswordRequest,
     148             :                 css::uno::RuntimeException );
     149             :     bool renameData( const com::sun::star::uno::Reference<
     150             :                         com::sun::star::ucb::XContentIdentifier >& xOldId,
     151             :                      const com::sun::star::uno::Reference<
     152             :                         com::sun::star::ucb::XContentIdentifier >& xNewId );
     153             :     bool removeData();
     154             : 
     155             :     bool copyData( const Uri & rSourceUri, const OUString & rNewName );
     156             : 
     157             :     ::com::sun::star::uno::Reference<
     158             :         ::com::sun::star::ucb::XContentIdentifier >
     159             :     makeNewIdentifier( const OUString& rTitle );
     160             : 
     161             :     typedef rtl::Reference< Content > ContentRef;
     162             :     typedef std::list< ContentRef > ContentRefList;
     163             :     void queryChildren( ContentRefList& rChildren );
     164             : 
     165             :     bool exchangeIdentity(
     166             :                 const ::com::sun::star::uno::Reference<
     167             :                         ::com::sun::star::ucb::XContentIdentifier >& xNewId );
     168             : 
     169             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     170             :     getPropertyValues( const ::com::sun::star::uno::Sequence<
     171             :                             ::com::sun::star::beans::Property >& rProperties );
     172             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
     173             :     setPropertyValues(
     174             :             const ::com::sun::star::uno::Sequence<
     175             :                     ::com::sun::star::beans::PropertyValue >& rValues,
     176             :             const ::com::sun::star::uno::Reference<
     177             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     178             :         throw( ::com::sun::star::uno::Exception );
     179             : 
     180             :     com::sun::star::uno::Any
     181             :     open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
     182             :           const ::com::sun::star::uno::Reference<
     183             :             ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
     184             :         throw( ::com::sun::star::uno::Exception );
     185             : 
     186             :     void insert( const ::com::sun::star::uno::Reference<
     187             :                     ::com::sun::star::io::XInputStream >& xData,
     188             :                  sal_Int32 nNameClashResolve,
     189             :                  const ::com::sun::star::uno::Reference<
     190             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     191             :         throw( ::com::sun::star::uno::Exception );
     192             : 
     193             :     void destroy( bool bDeletePhysical,
     194             :                   const ::com::sun::star::uno::Reference<
     195             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     196             :         throw( ::com::sun::star::uno::Exception );
     197             : 
     198             :     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
     199             :                    const ::com::sun::star::uno::Reference<
     200             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     201             :         throw( ::com::sun::star::uno::Exception );
     202             : 
     203             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     204             :     getPropertyValues( const ::com::sun::star::uno::Reference<
     205             :                         ::com::sun::star::uno::XComponentContext >& rxContext,
     206             :                        const ::com::sun::star::uno::Sequence<
     207             :                         ::com::sun::star::beans::Property >& rProperties,
     208             :                        const ContentProperties& rData,
     209             :                        ContentProvider* pProvider,
     210             :                        const OUString& rContentId );
     211             : 
     212             : 
     213             :     static bool commitStorage(
     214             :         const com::sun::star::uno::Reference<
     215             :             com::sun::star::embed::XStorage > & xStorage );
     216             : 
     217             :     static bool closeOutputStream(
     218             :         const com::sun::star::uno::Reference<
     219             :             com::sun::star::io::XOutputStream > & xOut );
     220             : 
     221             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
     222             :     getInputStream( const ::com::sun::star::uno::Reference<
     223             :                         ::com::sun::star::ucb::XCommandEnvironment > &
     224             :                             xEnv )
     225             :         throw ( css::ucb::CommandFailedException,
     226             :                 css::task::DocumentPasswordRequest,
     227             :                 css::uno::RuntimeException );
     228             : 
     229             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
     230             :     getTruncatedOutputStream(
     231             :         const ::com::sun::star::uno::Reference<
     232             :             ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     233             :         throw ( css::ucb::CommandFailedException,
     234             :                 css::task::DocumentPasswordRequest,
     235             :                 css::uno::RuntimeException );
     236             : 
     237             :     ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
     238             :     queryChildContent( const OUString & rRelativeChildUri );
     239             : 
     240             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
     241             :     getStream( const ::com::sun::star::uno::Reference<
     242             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     243             :         throw ( css::ucb::CommandFailedException,
     244             :                 css::task::DocumentPasswordRequest,
     245             :                 css::uno::RuntimeException );
     246             : 
     247             : public:
     248             :     // Create existing content. Fail, if not already exists.
     249             :     static Content* create(
     250             :             const com::sun::star::uno::Reference<
     251             :                 com::sun::star::uno::XComponentContext >& rxContext,
     252             :             ContentProvider* pProvider,
     253             :             const com::sun::star::uno::Reference<
     254             :                 com::sun::star::ucb::XContentIdentifier >& Identifier );
     255             : 
     256             :     // Create new content. Fail, if already exists.
     257             :     static Content* create(
     258             :             const com::sun::star::uno::Reference<
     259             :                 com::sun::star::uno::XComponentContext >& rxContext,
     260             :             ContentProvider* pProvider,
     261             :             const com::sun::star::uno::Reference<
     262             :                 com::sun::star::ucb::XContentIdentifier >& Identifier,
     263             :             const com::sun::star::ucb::ContentInfo& Info );
     264             : 
     265             :     virtual ~Content();
     266             : 
     267             :     // XInterface
     268             :     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType )
     269             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     270             :     virtual void SAL_CALL acquire()
     271             :         throw() SAL_OVERRIDE;
     272             :     virtual void SAL_CALL release()
     273             :         throw() SAL_OVERRIDE;
     274             : 
     275             :     // XTypeProvider
     276             :     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
     277             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     278             :     virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
     279             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     280             : 
     281             :     // XServiceInfo
     282             :     virtual OUString SAL_CALL
     283             :     getImplementationName()
     284             :         throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     285             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
     286             :     getSupportedServiceNames()
     287             :         throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     288             : 
     289             :     // XContent
     290             :     virtual OUString SAL_CALL
     291             :     getContentType()
     292             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     293             :     virtual com::sun::star::uno::Reference<
     294             :                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
     295             :     getIdentifier()
     296             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     297             : 
     298             :     // XCommandProcessor
     299             :     virtual com::sun::star::uno::Any SAL_CALL
     300             :     execute( const com::sun::star::ucb::Command& aCommand,
     301             :              sal_Int32 CommandId,
     302             :              const com::sun::star::uno::Reference<
     303             :                 com::sun::star::ucb::XCommandEnvironment >& Environment )
     304             :         throw( com::sun::star::uno::Exception,
     305             :                com::sun::star::ucb::CommandAbortedException,
     306             :                com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     307             :     virtual void SAL_CALL
     308             :     abort( sal_Int32 CommandId )
     309             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     310             : 
     311             : 
     312             :     // Additional interfaces
     313             : 
     314             : 
     315             :     // XContentCreator
     316             :     virtual com::sun::star::uno::Sequence<
     317             :                 com::sun::star::ucb::ContentInfo > SAL_CALL
     318             :     queryCreatableContentsInfo()
     319             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     320             :     virtual com::sun::star::uno::Reference<
     321             :                 com::sun::star::ucb::XContent > SAL_CALL
     322             :     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
     323             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     324             : 
     325             : 
     326             :     // Non-interface methods.
     327             : 
     328             : 
     329             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     330             :     getPropertyValues( const ::com::sun::star::uno::Reference<
     331             :                         ::com::sun::star::uno::XComponentContext >& rxContext,
     332             :                        const ::com::sun::star::uno::Sequence<
     333             :                         ::com::sun::star::beans::Property >& rProperties,
     334             :                        ContentProvider* pProvider,
     335             :                        const OUString& rContentId );
     336             : 
     337             :     void notifyDocumentClosed();
     338             :     void notifyChildRemoved( const OUString & rRelativeChildUri );
     339             :     void notifyChildInserted( const OUString & rRelativeChildUri );
     340             : 
     341           0 :     rtl::Reference< ContentProvider > getContentProvider() const
     342           0 :     { return rtl::Reference< ContentProvider >( m_pProvider ); }
     343             : };
     344             : 
     345             : } // namespace tdoc_ucp
     346             : 
     347             : #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
     348             : 
     349             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10