Source code for ooodev.adapter.document.storage_based_document_partial

from __future__ import annotations
from typing import Any, TYPE_CHECKING
import uno

from import XStorageBasedDocument

from ooodev.exceptions import ex as mEx
from ooodev.loader import lo as mLo

    from ooodev.utils.type_var import UnoInterface
    from import PropertyValue
    from import XStorageChangeListener
    from import XStorage

[docs]class StorageBasedDocumentPartial: """ Partial class for XStorageBasedDocument. """
[docs] def __init__( self, component: XStorageBasedDocument, interface: UnoInterface | None = XStorageBasedDocument ) -> None: """ Constructor Args: component (XStorageBasedDocument): UNO Component that implements ```` interface. interface (UnoInterface, optional): The interface to be validated. Defaults to ``XStorageBasedDocument``. """ def validate(comp: Any, obj_type: Any) -> None: if obj_type is None: return if not mLo.Lo.is_uno_interfaces(comp, obj_type): raise mEx.MissingInterfaceError(obj_type) validate(component, interface) self.__component = component
# region XStorageBasedDocument
[docs] def add_storage_change_listener(self, listener: XStorageChangeListener) -> None: """ Allows to register a listener that will be notified when another storage is set to the document. """ self.__component.addStorageChangeListener(listener)
[docs] def get_document_storage(self) -> XStorage: """ Allows to get the storage the document is based on. Raises: ``IOException`` ``Exception`` """ return self.__component.getDocumentStorage()
[docs] def load_from_storage(self, storage: XStorage, *media_descriptor: PropertyValue) -> None: """ Lets the document load itself using provided storage. Raises: ``IllegalArgumentException`` ``DoubleInitializationException`` ``IOException`` ``Exception`` """ self.__component.loadFromStorage(storage, media_descriptor)
[docs] def remove_storage_change_listener(self, listener: XStorageChangeListener) -> None: """ Allows to deregister the listener. """ self.__component.removeStorageChangeListener(listener)
[docs] def store_to_storage(self, storage: XStorage, *media_descriptor: PropertyValue) -> None: """ Lets the document store itself to the provided storage. Raises: ``IllegalArgumentException`` ``IOException`` ``Exception`` """ self.__component.storeToStorage(storage, media_descriptor)
[docs] def switch_to_storage(self, storage: XStorage) -> None: """ Allows to switch the document to the provided storage. Raises: ``IllegalArgumentException`` ``IOException`` ``Exception`` """ self.__component.switchToStorage(storage)
# endregion XStorageBasedDocument