LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/ucp/tdoc - tdoc_content.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 16 50.0 %
Date: 2012-12-27 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_TDOC_CONTENT_HXX
      21             : #define INCLUDED_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          25 : class ContentProperties
      58             : {
      59             : public:
      60           5 :     ContentProperties()
      61           5 :     : m_eType( STREAM )
      62           5 :     {}
      63             : 
      64           5 :     ContentProperties( const ContentType & rType, const rtl::OUString & rTitle )
      65             :     : m_eType( rType ),
      66             :       m_aContentType( rType == STREAM
      67             :         ? rtl::OUString( TDOC_STREAM_CONTENT_TYPE )
      68             :         : rType == FOLDER
      69             :             ? rtl::OUString( TDOC_FOLDER_CONTENT_TYPE )
      70             :             : rType == DOCUMENT
      71             :                 ? rtl::OUString( TDOC_DOCUMENT_CONTENT_TYPE )
      72             :                 : rtl::OUString( TDOC_ROOT_CONTENT_TYPE ) ),
      73           5 :       m_aTitle( rTitle )
      74           5 :     {}
      75             : 
      76           3 :     ContentType getType() const { return m_eType; }
      77             : 
      78             :     // Properties
      79             : 
      80           0 :     const rtl::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 rtl::OUString & getTitle() const { return m_aTitle; }
      86           0 :     void setTitle( const rtl::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             :     rtl::OUString m_aContentType;
      96             :     rtl::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 );
     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 );
     134             :     virtual ::rtl::OUString getParentURL();
     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             :     bool renameData( const com::sun::star::uno::Reference<
     149             :                         com::sun::star::ucb::XContentIdentifier >& xOldId,
     150             :                      const com::sun::star::uno::Reference<
     151             :                         com::sun::star::ucb::XContentIdentifier >& xNewId );
     152             :     bool removeData();
     153             : 
     154             :     bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName );
     155             : 
     156             :     ::com::sun::star::uno::Reference<
     157             :         ::com::sun::star::ucb::XContentIdentifier >
     158             :     makeNewIdentifier( const rtl::OUString& rTitle );
     159             : 
     160             :     typedef rtl::Reference< Content > ContentRef;
     161             :     typedef std::list< ContentRef > ContentRefList;
     162             :     void queryChildren( ContentRefList& rChildren );
     163             : 
     164             :     sal_Bool exchangeIdentity(
     165             :                 const ::com::sun::star::uno::Reference<
     166             :                         ::com::sun::star::ucb::XContentIdentifier >& xNewId );
     167             : 
     168             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     169             :     getPropertyValues( const ::com::sun::star::uno::Sequence<
     170             :                             ::com::sun::star::beans::Property >& rProperties );
     171             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
     172             :     setPropertyValues(
     173             :             const ::com::sun::star::uno::Sequence<
     174             :                     ::com::sun::star::beans::PropertyValue >& rValues,
     175             :             const ::com::sun::star::uno::Reference<
     176             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     177             :         throw( ::com::sun::star::uno::Exception );
     178             : 
     179             :     com::sun::star::uno::Any
     180             :     open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
     181             :           const ::com::sun::star::uno::Reference<
     182             :             ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
     183             :         throw( ::com::sun::star::uno::Exception );
     184             : 
     185             :     void insert( const ::com::sun::star::uno::Reference<
     186             :                     ::com::sun::star::io::XInputStream >& xData,
     187             :                  sal_Int32 nNameClashResolve,
     188             :                  const ::com::sun::star::uno::Reference<
     189             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     190             :         throw( ::com::sun::star::uno::Exception );
     191             : 
     192             :     void destroy( sal_Bool bDeletePhysical,
     193             :                   const ::com::sun::star::uno::Reference<
     194             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     195             :         throw( ::com::sun::star::uno::Exception );
     196             : 
     197             :     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
     198             :                    const ::com::sun::star::uno::Reference<
     199             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     200             :         throw( ::com::sun::star::uno::Exception );
     201             : 
     202             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     203             :     getPropertyValues( const ::com::sun::star::uno::Reference<
     204             :                         ::com::sun::star::uno::XComponentContext >& rxContext,
     205             :                        const ::com::sun::star::uno::Sequence<
     206             :                         ::com::sun::star::beans::Property >& rProperties,
     207             :                        const ContentProperties& rData,
     208             :                        ContentProvider* pProvider,
     209             :                        const ::rtl::OUString& rContentId );
     210             : 
     211             : 
     212             :     static bool commitStorage(
     213             :         const com::sun::star::uno::Reference<
     214             :             com::sun::star::embed::XStorage > & xStorage );
     215             : 
     216             :     static bool closeOutputStream(
     217             :         const com::sun::star::uno::Reference<
     218             :             com::sun::star::io::XOutputStream > & xOut );
     219             : 
     220             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
     221             :     getInputStream( const ::com::sun::star::uno::Reference<
     222             :                         ::com::sun::star::ucb::XCommandEnvironment > &
     223             :                             xEnv )
     224             :         throw ( ::com::sun::star::ucb::CommandFailedException,
     225             :                 ::com::sun::star::task::DocumentPasswordRequest );
     226             : 
     227             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
     228             :     getTruncatedOutputStream(
     229             :         const ::com::sun::star::uno::Reference<
     230             :             ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     231             :         throw ( ::com::sun::star::ucb::CommandFailedException,
     232             :                 ::com::sun::star::task::DocumentPasswordRequest );
     233             : 
     234             :     ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
     235             :     queryChildContent( const rtl::OUString & rRelativeChildUri );
     236             : 
     237             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
     238             :     getStream( const ::com::sun::star::uno::Reference<
     239             :                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
     240             :         throw ( ::com::sun::star::ucb::CommandFailedException,
     241             :                 ::com::sun::star::task::DocumentPasswordRequest );
     242             : 
     243             : public:
     244             :     // Create existing content. Fail, if not already exists.
     245             :     static Content* create(
     246             :             const com::sun::star::uno::Reference<
     247             :                 com::sun::star::uno::XComponentContext >& rxContext,
     248             :             ContentProvider* pProvider,
     249             :             const com::sun::star::uno::Reference<
     250             :                 com::sun::star::ucb::XContentIdentifier >& Identifier );
     251             : 
     252             :     // Create new content. Fail, if already exists.
     253             :     static Content* create(
     254             :             const com::sun::star::uno::Reference<
     255             :                 com::sun::star::uno::XComponentContext >& rxContext,
     256             :             ContentProvider* pProvider,
     257             :             const com::sun::star::uno::Reference<
     258             :                 com::sun::star::ucb::XContentIdentifier >& Identifier,
     259             :             const com::sun::star::ucb::ContentInfo& Info );
     260             : 
     261             :     virtual ~Content();
     262             : 
     263             :     // XInterface
     264             :     XINTERFACE_DECL()
     265             : 
     266             :     // XTypeProvider
     267             :     XTYPEPROVIDER_DECL()
     268             : 
     269             :     // XServiceInfo
     270             :     virtual ::rtl::OUString SAL_CALL
     271             :     getImplementationName()
     272             :         throw( ::com::sun::star::uno::RuntimeException );
     273             :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
     274             :     getSupportedServiceNames()
     275             :         throw( ::com::sun::star::uno::RuntimeException );
     276             : 
     277             :     // XContent
     278             :     virtual rtl::OUString SAL_CALL
     279             :     getContentType()
     280             :         throw( com::sun::star::uno::RuntimeException );
     281             :     virtual com::sun::star::uno::Reference<
     282             :                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
     283             :     getIdentifier()
     284             :         throw( com::sun::star::uno::RuntimeException );
     285             : 
     286             :     // XCommandProcessor
     287             :     virtual com::sun::star::uno::Any SAL_CALL
     288             :     execute( const com::sun::star::ucb::Command& aCommand,
     289             :              sal_Int32 CommandId,
     290             :              const com::sun::star::uno::Reference<
     291             :                 com::sun::star::ucb::XCommandEnvironment >& Environment )
     292             :         throw( com::sun::star::uno::Exception,
     293             :                com::sun::star::ucb::CommandAbortedException,
     294             :                com::sun::star::uno::RuntimeException );
     295             :     virtual void SAL_CALL
     296             :     abort( sal_Int32 CommandId )
     297             :         throw( com::sun::star::uno::RuntimeException );
     298             : 
     299             :     //////////////////////////////////////////////////////////////////////
     300             :     // Additional interfaces
     301             :     //////////////////////////////////////////////////////////////////////
     302             : 
     303             :     // XContentCreator
     304             :     virtual com::sun::star::uno::Sequence<
     305             :                 com::sun::star::ucb::ContentInfo > SAL_CALL
     306             :     queryCreatableContentsInfo()
     307             :         throw( com::sun::star::uno::RuntimeException );
     308             :     virtual com::sun::star::uno::Reference<
     309             :                 com::sun::star::ucb::XContent > SAL_CALL
     310             :     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
     311             :         throw( com::sun::star::uno::RuntimeException );
     312             : 
     313             :     //////////////////////////////////////////////////////////////////////
     314             :     // Non-interface methods.
     315             :     //////////////////////////////////////////////////////////////////////
     316             : 
     317             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
     318             :     getPropertyValues( const ::com::sun::star::uno::Reference<
     319             :                         ::com::sun::star::uno::XComponentContext >& rxContext,
     320             :                        const ::com::sun::star::uno::Sequence<
     321             :                         ::com::sun::star::beans::Property >& rProperties,
     322             :                        ContentProvider* pProvider,
     323             :                        const ::rtl::OUString& rContentId );
     324             : 
     325             :     void notifyDocumentClosed();
     326             :     void notifyChildRemoved( const rtl::OUString & rRelativeChildUri );
     327             :     void notifyChildInserted( const rtl::OUString & rRelativeChildUri );
     328             : 
     329           0 :     rtl::Reference< ContentProvider > getContentProvider() const
     330           0 :     { return rtl::Reference< ContentProvider >( m_pProvider ); }
     331             : };
     332             : 
     333             : } // namespace tdoc_ucp
     334             : 
     335             : #endif /* !INCLUDED_TDOC_CONTENT_HXX */
     336             : 
     337             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10