<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: xstorage.hxx,v $
 * $Revision: 1.16 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef __XSTORAGE_HXX_
#define __XSTORAGE_HXX_

#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/XOptimizedStorage.hpp>
#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp>
#include <com/sun/star/embed/XStorageRawAccess.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
#include <com/sun/star/embed/XClassifiedObject.hpp>
#include <com/sun/star/embed/XEncryptionProtectedSource.hpp>
#include <com/sun/star/embed/XRelationshipAccess.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/StringPair.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/packages/NoEncryptionException.hpp>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/interfacecontainer.h>

#include "mutexholder.hxx"


#define PACKAGE_STORAGE 0
#define ZIP_STORAGE     1
#define OFOPXML_STORAGE 2

#define RELINFO_NO_INIT             1
#define RELINFO_READ                2
#define RELINFO_CHANGED             3
#define RELINFO_CHANGED_STREAM      4
#define RELINFO_CHANGED_STREAM_READ 5
#define RELINFO_BROKEN              6
#define RELINFO_CHANGED_BROKEN      7

#define STOR_MESS_PRECOMMIT 1
#define STOR_MESS_COMMITED  2
#define STOR_MESS_PREREVERT 3
#define STOR_MESS_REVERTED  4

namespace cppu
{
    class OTypeCollection;
}

//================================================
// a common implementation for an entry

struct StorInternalData_Impl;
struct OStorage_Impl;
struct OWriteStream_Impl;

struct SotElement_Impl
{
    ::rtl::OUString             m_aName;
    ::rtl::OUString             m_aOriginalName;
    sal_Bool                    m_bIsRemoved;
    sal_Bool                    m_bIsInserted;
    sal_Bool                    m_bIsStorage;

    OStorage_Impl*              m_pStorage;
    OWriteStream_Impl*          m_pStream;

public:
                                SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew );
                                ~SotElement_Impl();
};

#include <list>
typedef ::std::list< SotElement_Impl* > SotElementList_Impl;

//=========================================================================
// Main storage implementation

class OStorage;

struct StorageHolder_Impl
{
    OStorage* m_pPointer;
    ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakRef;

    StorageHolder_Impl( OStorage* pStorage )
    : m_pPointer( pStorage )
    , m_xWeakRef( ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >(
                                                (::com::sun::star::embed::XStorage*)pStorage ) )
    {
    }

    StorageHolder_Impl( const StorageHolder_Impl& aSH )
    : m_pPointer( aSH.m_pPointer )
    , m_xWeakRef( aSH.m_xWeakRef )
    {
    }
};

typedef ::std::list< StorageHolder_Impl > OStorageList_Impl;

class SwitchablePersistenceStream;
struct OStorage_Impl
{
    SotMutexHolderRef           m_rMutexRef;

    OStorage*                   m_pAntiImpl;         // only valid if external references exists
    OStorageList_Impl           m_aReadOnlyWrapList; // only valid if readonly external reference exists

    sal_Int32                   m_nStorageMode; // open mode ( read/write/trunc/nocreate )
    sal_Bool                    m_bIsModified;  // only modified elements will be sent to the original content
    sal_Bool                    m_bBroadcastModified;  // will be set if notification is required
    sal_Bool                    m_bCommited;    // sending the streams is coordinated by the root storage of the package

    sal_Bool                    m_bIsRoot;      // marks this storage as root storages that manages all commits and reverts
    sal_Bool                    m_bListCreated;


    SotElementList_Impl                         m_aChildrenList;
    SotElementList_Impl                         m_aDeletedList;

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xPackageFolder;

    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage;
    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >  m_xFactory;

    // valid only for root storage
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties
    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties;
    sal_Bool m_bHasCommonPassword;
    ::rtl::OUString m_aCommonPassword;

    // must be empty in case of root storage
    OStorage_Impl* m_pParent;

    sal_Bool        m_bControlMediaType;
    ::rtl::OUString m_aMediaType;
    sal_Bool        m_bMTFallbackUsed;

    SwitchablePersistenceStream* m_pSwitchStream;

    sal_Int16 m_nStorageType; // the mode in wich the storage is used

    // the _rels substorage that is handled in a special way in OFOPXML_STORAGE
    SotElement_Impl* m_pRelStorElement;
    ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xRelStorage;
    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aRelInfo;
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream;
    sal_Int16 m_nRelInfoStatus;

    //////////////////////////////////////////
    // Constructors

    OStorage_Impl(  ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream,
                    sal_Int32 nMode,
                    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties,
                    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory,
                    sal_Int16 nStorageType );

    OStorage_Impl(  ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream,
                    sal_Int32 nMode,
                    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties,
                    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory,
                    sal_Int16 nStorageType );

    // constructor for a substorage
    OStorage_Impl(  OStorage_Impl* pParent,
                    sal_Int32 nMode,<commit_msg>INTEGRATION: CWS jl93 (1.15.56); FILE MERGED 2008/05/05 13:27:55 jl 1.15.56.2: RESYNC: (1.15-1.16); FILE MERGED 2008/04/08 15:43:28 mav 1.15.56.1: #i86651# add Version property<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: xstorage.hxx,v $
 * $Revision: 1.17 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef __XSTORAGE_HXX_
#define __XSTORAGE_HXX_

#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/XOptimizedStorage.hpp>
#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp>
#include <com/sun/star/embed/XStorageRawAccess.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
#include <com/sun/star/embed/XClassifiedObject.hpp>
#include <com/sun/star/embed/XEncryptionProtectedSource.hpp>
#include <com/sun/star/embed/XRelationshipAccess.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/StringPair.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/packages/NoEncryptionException.hpp>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/interfacecontainer.h>

#include "mutexholder.hxx"


#define PACKAGE_STORAGE 0
#define ZIP_STORAGE     1
#define OFOPXML_STORAGE 2

#define RELINFO_NO_INIT             1
#define RELINFO_READ                2
#define RELINFO_CHANGED             3
#define RELINFO_CHANGED_STREAM      4
#define RELINFO_CHANGED_STREAM_READ 5
#define RELINFO_BROKEN              6
#define RELINFO_CHANGED_BROKEN      7

#define STOR_MESS_PRECOMMIT 1
#define STOR_MESS_COMMITED  2
#define STOR_MESS_PREREVERT 3
#define STOR_MESS_REVERTED  4

namespace cppu
{
    class OTypeCollection;
}

//================================================
// a common implementation for an entry

struct StorInternalData_Impl;
struct OStorage_Impl;
struct OWriteStream_Impl;

struct SotElement_Impl
{
    ::rtl::OUString             m_aName;
    ::rtl::OUString             m_aOriginalName;
    sal_Bool                    m_bIsRemoved;
    sal_Bool                    m_bIsInserted;
    sal_Bool                    m_bIsStorage;

    OStorage_Impl*              m_pStorage;
    OWriteStream_Impl*          m_pStream;

public:
                                SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew );
                                ~SotElement_Impl();
};

#include <list>
typedef ::std::list< SotElement_Impl* > SotElementList_Impl;

//=========================================================================
// Main storage implementation

class OStorage;

struct StorageHolder_Impl
{
    OStorage* m_pPointer;
    ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakRef;

    StorageHolder_Impl( OStorage* pStorage )
    : m_pPointer( pStorage )
    , m_xWeakRef( ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >(
                                                (::com::sun::star::embed::XStorage*)pStorage ) )
    {
    }

    StorageHolder_Impl( const StorageHolder_Impl& aSH )
    : m_pPointer( aSH.m_pPointer )
    , m_xWeakRef( aSH.m_xWeakRef )
    {
    }
};

typedef ::std::list< StorageHolder_Impl > OStorageList_Impl;

class SwitchablePersistenceStream;
struct OStorage_Impl
{
    SotMutexHolderRef           m_rMutexRef;

    OStorage*                   m_pAntiImpl;         // only valid if external references exists
    OStorageList_Impl           m_aReadOnlyWrapList; // only valid if readonly external reference exists

    sal_Int32                   m_nStorageMode; // open mode ( read/write/trunc/nocreate )
    sal_Bool                    m_bIsModified;  // only modified elements will be sent to the original content
    sal_Bool                    m_bBroadcastModified;  // will be set if notification is required
    sal_Bool                    m_bCommited;    // sending the streams is coordinated by the root storage of the package

    sal_Bool                    m_bIsRoot;      // marks this storage as root storages that manages all commits and reverts
    sal_Bool                    m_bListCreated;


    SotElementList_Impl                         m_aChildrenList;
    SotElementList_Impl                         m_aDeletedList;

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xPackageFolder;

    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage;
    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >  m_xFactory;

    // valid only for root storage
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties
    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties;
    sal_Bool m_bHasCommonPassword;
    ::rtl::OUString m_aCommonPassword;

    // must be empty in case of root storage
    OStorage_Impl* m_pParent;

    sal_Bool        m_bControlMediaType;
    ::rtl::OUString m_aMediaType;
    sal_Bool        m_bMTFallbackUsed;

    sal_Bool        m_bControlVersion;
    ::rtl::OUString m_aVersion;

    SwitchablePersistenceStream* m_pSwitchStream;

    sal_Int16 m_nStorageType; // the mode in wich the storage is used

    // the _rels substorage that is handled in a special way in OFOPXML_STORAGE
    SotElement_Impl* m_pRelStorElement;
    ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xRelStorage;
    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aRelInfo;
    ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream;
    sal_Int16 m_nRelInfoStatus;

    //////////////////////////////////////////
    // Constructors

    OStorage_Impl(  ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream,
                    sal_Int32 nMode,
                    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties,
                    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory,
                    sal_Int16 nStorageType );

    OStorage_Impl(  ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream,
                    sal_Int32 nMode,
                    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties,
                    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory,
                    sal_Int16 nStorageType );

    // constructor for a substorage
    OStorage_Impl(  OStorage_Impl* pParent,
                    sal_Int32 nMode,
{'fraction_non_alphanumeric': 0.14816393642287315, 'fraction_numerical': 0.008525668351501127, 'mean_word_length': 3.327272727272727, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908124', 'n_tokens_mistral': 5196, 'n_tokens_neox': 4919, 'n_words': 1098}