diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-11-22 11:26:49 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-11-26 23:14:33 +0100 |
commit | e6f81b1898a59280f41177206b777a7a0d32f3fc (patch) | |
tree | c8047f94d0e647630ce45f8159600fdad7ebad48 /sfx2 | |
parent | 31170413ae3786bf44564e813d7291354e939a77 (diff) |
API CHANGE: remove com.sun.star.document.XDocumentInfo
The following badly designed interfaces and services were deprecated
in OpenOffice.org 3.0 and are now remove from the API:
com.sun.star.document.DocumentInfo
com.sun.star.document.StandaloneDocumentInfo
com.sun.star.document.XDocumentInfo
com.sun.star.document.XDocumentInfoSupplier
com.sun.star.document.XStandaloneDocumentInfo
The supported replacements for these have been introduced in OOo 3.0:
com.sun.star.document.XDocumentProperties
com.sun.star.document.XDocumentPropertiesSupplier
com.sun.star.document.DocumentProperties
http://www.mail-archive.com/interface-announce@openoffice.org/msg00432.html
Remove the implementation of these interfaces and services in sfx2
(SfxBaseModel, objuno.cxx)
Also remove unit tests for these services in qadevOOo and sfx2.
Conflicts:
offapi/type_reference/types.rdb
Change-Id: Ib0b48a4e53a8079c82fac3bb49a829812f8e5256
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/JunitTest_sfx2_complex.mk | 8 | ||||
-rw-r--r-- | sfx2/Library_sfx.mk | 1 | ||||
-rw-r--r-- | sfx2/inc/sfx2/objuno.hxx | 186 | ||||
-rw-r--r-- | sfx2/inc/sfx2/sfxbasemodel.hxx | 33 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/DocumentInfo.java | 338 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java | 90 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java | 22 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java | 135 | ||||
-rw-r--r-- | sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java | 39 | ||||
-rw-r--r-- | sfx2/qa/unoapi/sfx.sce | 1 | ||||
-rw-r--r-- | sfx2/source/appl/appuno.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/objuno.cxx | 1351 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 92 | ||||
-rw-r--r-- | sfx2/util/sfx.component | 3 | ||||
-rw-r--r-- | sfx2/util/sfx.xml | 12 |
15 files changed, 13 insertions, 2300 deletions
diff --git a/sfx2/JunitTest_sfx2_complex.mk b/sfx2/JunitTest_sfx2_complex.mk index abe36164b2d8..cb77929c3632 100644 --- a/sfx2/JunitTest_sfx2_complex.mk +++ b/sfx2/JunitTest_sfx2_complex.mk @@ -34,17 +34,12 @@ $(eval $(call gb_JunitTest_use_jars,sfx2_complex,\ )) $(eval $(call gb_JunitTest_add_sourcefiles,sfx2_complex,\ - sfx2/qa/complex/sfx2/DocumentInfo \ sfx2/qa/complex/sfx2/DocumentMetadataAccess \ sfx2/qa/complex/sfx2/DocumentProperties \ sfx2/qa/complex/sfx2/GlobalEventBroadcaster \ - sfx2/qa/complex/sfx2/StandaloneDocumentInfo \ sfx2/qa/complex/sfx2/UndoManager \ sfx2/qa/complex/sfx2/JUnitBasedTest \ sfx2/qa/complex/sfx2/DocumentEvents \ - sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest \ - sfx2/qa/complex/sfx2/standalonedocinfo/Test01 \ - sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper \ sfx2/qa/complex/sfx2/tools/DialogThread \ sfx2/qa/complex/sfx2/tools/TestDocument \ sfx2/qa/complex/sfx2/tools/WriterHelper \ @@ -59,7 +54,6 @@ $(eval $(call gb_JunitTest_add_sourcefiles,sfx2_complex,\ )) $(eval $(call gb_JunitTest_add_classes,sfx2_complex,\ - complex.sfx2.DocumentInfo \ complex.sfx2.DocumentProperties \ complex.sfx2.DocumentMetadataAccess \ complex.sfx2.DocumentEvents \ @@ -69,7 +63,5 @@ $(eval $(call gb_JunitTest_add_classes,sfx2_complex,\ # complex.sfx2.UndoManager \ # #i115674# fails currently: misses some OnUnfocus event # complex.sfx2.GlobalEventBroadcaster \ -# breaks because binfilter export has been removed -# complex.sfx2.StandaloneDocumentInfo \ # vim: set noet sw=4 ts=4: diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 8a12ad9e9911..6cc8a1d5a64e 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -206,7 +206,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/doc/objmisc \ sfx2/source/doc/objserv \ sfx2/source/doc/objstor \ - sfx2/source/doc/objuno \ sfx2/source/doc/objxtor \ sfx2/source/doc/oleprops \ sfx2/source/doc/ownsubfilterservice \ diff --git a/sfx2/inc/sfx2/objuno.hxx b/sfx2/inc/sfx2/objuno.hxx deleted file mode 100644 index 3e18ad61527b..000000000000 --- a/sfx2/inc/sfx2/objuno.hxx +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef _SFX_OBJUNO_HXX -#define _SFX_OBJUNO_HXX - -#include <com/sun/star/document/XDocumentInfo.hpp> -#include <com/sun/star/document/XStandaloneDocumentInfo.hpp> -#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> -#include <com/sun/star/util/XModifyListener.hpp> -#include <com/sun/star/util/XModifyBroadcaster.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/beans/XFastPropertySet.hpp> -#include <com/sun/star/beans/XVetoableChangeListener.hpp> -#include <com/sun/star/beans/XPropertyChangeListener.hpp> -#include <com/sun/star/beans/XPropertyContainer.hpp> -#include <com/sun/star/beans/XPropertyAccess.hpp> -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/util/XCloneable.hpp> - -#include <com/sun/star/io/IOException.hpp> - -#include <svl/itemprop.hxx> -#include <cppuhelper/implbase10.hxx> - -#include "sfxuno.hxx" - - -// this is now just a wrapper around a XDocumentProperties instance - -class SAL_DLLPRIVATE SfxDocumentInfoObject: public ::cppu::WeakImplHelper10< - ::com::sun::star::document::XDocumentInfo, - ::com::sun::star::lang::XComponent, - ::com::sun::star::beans::XPropertySet, - ::com::sun::star::beans::XFastPropertySet, - ::com::sun::star::beans::XPropertyAccess, - ::com::sun::star::beans::XPropertyContainer, - ::com::sun::star::document::XDocumentPropertiesSupplier, - ::com::sun::star::util::XModifyBroadcaster, - ::com::sun::star::lang::XInitialization, - ::com::sun::star::util::XCloneable> -{ -protected: - struct SfxDocumentInfoObject_Impl* _pImp; - -public: - SfxDocumentInfoObject(); - ~SfxDocumentInfoObject(); - - // XComponent - virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener) throw( ::com::sun::star::uno::RuntimeException ); - - // XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValue(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString& aPropertyName) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & aListener) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & aListener) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - - // ::com::sun::star::beans::XFastPropertySet - virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException); - virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) throw( - ::com::sun::star::uno::RuntimeException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException); - - // ::com::sun::star::beans::XPropertyAccess - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues() throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - - // ::com::sun::star::beans::XPropertyContainer - virtual void SAL_CALL addProperty( const ::rtl::OUString& Name, ::sal_Int16 Attributes, const ::com::sun::star::uno::Any& DefaultValue ) throw (::com::sun::star::beans::PropertyExistException, ::com::sun::star::beans::IllegalTypeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeProperty( const ::rtl::OUString& Name ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::NotRemoveableException, ::com::sun::star::uno::RuntimeException); - - // ::com::sun::star::document::XDocumentInfo - virtual sal_Int16 SAL_CALL getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException ); - virtual ::rtl::OUString SAL_CALL getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ); - virtual ::rtl::OUString SAL_CALL getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setUserFieldValue(sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException ); - - // ::com::sun::star::document::XDocumentPropertiesSupplier - virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > - SAL_CALL getDocumentProperties() - throw (::com::sun::star::uno::RuntimeException); - - // ::com::sun::star::util::XModifiable - virtual sal_Bool SAL_CALL isModified() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setModified( sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); - - // ::com::sun::star::util::XModifyBroadcaster - virtual void SAL_CALL addModifyListener( const com::sun::star::uno::Reference< com::sun::star::util::XModifyListener >& xListener ) throw( ::com::sun::star::uno::RuntimeException ) ; - virtual void SAL_CALL removeModifyListener( const com::sun::star::uno::Reference< com::sun::star::util::XModifyListener > & xListener) throw( ::com::sun::star::uno::RuntimeException ) ; - - // ::com::sun::star::lang::XInitialization: - virtual void SAL_CALL initialize( - const com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) - throw (com::sun::star::uno::RuntimeException, - com::sun::star::uno::Exception); - - // ::com::sun::star::util::XCloneable: - virtual com::sun::star::uno::Reference<com::sun::star::util::XCloneable> SAL_CALL createClone() - throw (com::sun::star::uno::RuntimeException); - - const SfxDocumentInfoObject& operator=( const SfxDocumentInfoObject & rOther); -}; - -class SAL_DLLPRIVATE SfxStandaloneDocumentInfoObject: public SfxDocumentInfoObject, - public ::com::sun::star::lang::XServiceInfo, - public ::com::sun::star::document::XStandaloneDocumentInfo -{ - ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > _xFactory; - -public: - SfxStandaloneDocumentInfoObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); - virtual ~SfxStandaloneDocumentInfoObject(); - - void Clear(); - - // XInterface, XTypeProvider, XServiceInfo - SFX_DECL_XINTERFACE_XTYPEPROVIDER_XSERVICEINFO - - // ::com::sun::star::document::XDocumentInfo - virtual sal_Int16 SAL_CALL getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException ); - virtual ::rtl::OUString SAL_CALL getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ); - virtual ::rtl::OUString SAL_CALL getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setUserFieldValue(sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException ); - - // ::com::sun::star::document::XStandaloneDocumentInfo - virtual void SAL_CALL loadFromURL(const ::rtl::OUString& aURL) throw( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL storeIntoURL(const ::rtl::OUString& aURL) throw( ::com::sun::star::io::IOException ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/inc/sfx2/sfxbasemodel.hxx b/sfx2/inc/sfx2/sfxbasemodel.hxx index 49e4dcae72be..486426a5879e 100644 --- a/sfx2/inc/sfx2/sfxbasemodel.hxx +++ b/sfx2/inc/sfx2/sfxbasemodel.hxx @@ -33,8 +33,6 @@ #include <com/sun/star/container/XNameReplace.hpp> #include <com/sun/star/frame/XController2.hpp> #include <com/sun/star/document/XCmisDocument.hpp> -#include <com/sun/star/document/XDocumentInfo.hpp> -#include <com/sun/star/document/XDocumentInfoSupplier.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XDocumentRecovery.hpp> #include <com/sun/star/document/XUndoManagerSupplier.hpp> @@ -88,9 +86,9 @@ #include <com/sun/star/task/XInteractionHandler.hpp> //________________________________________________________________________________________________________ -#ifndef INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_33 -#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_33 -#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 33 +#ifndef INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_32 +#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_32 +#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 32 #include <comphelper/implbase_var.hxx> #endif @@ -123,8 +121,6 @@ #define XNAMEREPLACE ::com::sun::star::container::XNameReplace #define DOCEVENTOBJECT ::com::sun::star::document::EventObject #define XDOCEVENTLISTENER ::com::sun::star::document::XEventListener -#define XDOCUMENTINFO ::com::sun::star::document::XDocumentInfo -#define XDOCUMENTINFOSUPPLIER ::com::sun::star::document::XDocumentInfoSupplier #define XEVENTBROADCASTER ::com::sun::star::document::XEventBroadcaster #define XDOCUMENTEVENTBROADCASTER ::com::sun::star::document::XDocumentEventBroadcaster #define XEVENTSSUPPLIER ::com::sun::star::document::XEventsSupplier @@ -191,7 +187,6 @@ namespace sfx { namespace intern { @implements XChild XComponent - XDocumentInfoSupplier document::XDocumentPropertiesSupplier rdf::XDocumentMetadataAccess XEventListener @@ -210,8 +205,7 @@ namespace sfx { namespace intern { SfxListener */ -typedef ::comphelper::WeakImplHelper33 < XCHILD - , XDOCUMENTINFOSUPPLIER +typedef ::comphelper::WeakImplHelper32 < XCHILD , ::com::sun::star::document::XDocumentPropertiesSupplier , ::com::sun::star::document::XCmisDocument , ::com::sun::star::rdf::XDocumentMetadataAccess @@ -492,25 +486,6 @@ public: virtual void SAL_CALL removeEventListener(const REFERENCE< XEVENTLISTENER >& aListener ) throw (::com::sun::star::uno::RuntimeException); - //____________________________________________________________________________________________________ - // XDocumentInfoSupplier - //____________________________________________________________________________________________________ - - /**___________________________________________________________________________________________________ - @short - - @descr - - - @seealso - - - @param - - - @return - - - @onerror - - */ - - virtual REFERENCE< XDOCUMENTINFO > SAL_CALL getDocumentInfo() throw (::com::sun::star::uno::RuntimeException); - // XDocumentPropertiesSupplier virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > SAL_CALL getDocumentProperties() diff --git a/sfx2/qa/complex/sfx2/DocumentInfo.java b/sfx2/qa/complex/sfx2/DocumentInfo.java deleted file mode 100644 index 1532a3cc14c4..000000000000 --- a/sfx2/qa/complex/sfx2/DocumentInfo.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.sfx2; - -import com.sun.star.beans.PropertyAttribute; -import com.sun.star.beans.Property; -import com.sun.star.beans.PropertyValue; -import com.sun.star.beans.XPropertyContainer; -import com.sun.star.beans.XPropertySet; -import com.sun.star.beans.XPropertySetInfo; -import com.sun.star.document.XDocumentInfo; -import com.sun.star.document.XDocumentInfoSupplier; -import com.sun.star.frame.XComponentLoader; -import com.sun.star.frame.XStorable; -import com.sun.star.lang.XComponent; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.text.XTextDocument; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.util.Date; - - - -import util.DesktopTools; -import util.WriterTools; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openoffice.test.OfficeConnection; -import static org.junit.Assert.*; - -public class DocumentInfo -{ - XMultiServiceFactory m_xMSF = null; - XTextDocument xTextDoc = null; - XTextDocument xTextDocSecond = null; - - @Test public void checkDocInfo() throws Exception - { - m_xMSF = getMSF(); - - System.out.println("check whether there is a valid MultiServiceFactory"); - - assertNotNull("## Couldn't get MultiServiceFactory make sure your Office is started", m_xMSF); - - String tempdir = util.utils.getOfficeTemp/*Dir*/(m_xMSF); - String fs = System.getProperty("file.separator"); - - if (!tempdir.endsWith(fs)) - { - tempdir += fs; - } - tempdir = util.utils.getFullURL(tempdir); - final String sTempDocument = tempdir + "DocInfo.oot"; - - if (true) - { - System.out.println("... done"); - - - System.out.println("Opening a Writer document"); - xTextDoc = WriterTools.createTextDoc(m_xMSF); - System.out.println("... done"); - - XDocumentInfoSupplier xDocInfoSup = UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xTextDoc); - XDocumentInfo xDocInfo = xDocInfoSup.getDocumentInfo(); - XPropertyContainer xPropContainer = UnoRuntime.queryInterface(XPropertyContainer.class, xDocInfo); - - System.out.println("Trying to add a existing property"); - - boolean worked = addProperty(xPropContainer, "Author", (short) 0, ""); - assertTrue("Could set an existing property", !worked); - System.out.println("...done"); - - System.out.println("Trying to add a integer property"); - worked = addProperty(xPropContainer, "intValue", com.sun.star.beans.PropertyAttribute.READONLY, new Integer(17)); - assertTrue("Couldn't set an integer property", worked); - System.out.println("...done"); - - System.out.println("Trying to add a double property"); - worked = addProperty(xPropContainer, "doubleValue", com.sun.star.beans.PropertyAttribute.REMOVEABLE, new Double(17.7)); - assertTrue("Couldn't set an double property", worked); - System.out.println("...done"); - - System.out.println("Trying to add a boolean property"); - worked = addProperty(xPropContainer, "booleanValue", com.sun.star.beans.PropertyAttribute.REMOVEABLE, Boolean.TRUE); - assertTrue("Couldn't set an boolean property", worked); - System.out.println("...done"); - - System.out.println("Trying to add a date property"); - worked = addProperty(xPropContainer, "dateValue", com.sun.star.beans.PropertyAttribute.REMOVEABLE, new Date()); - assertTrue("Couldn't set an date property", worked); - System.out.println("...done"); - - System.out.println("trying to remove a read only Property"); - try - { - xPropContainer.removeProperty("intValue"); - fail("Could remove read only property"); - } - catch (Exception e) - { - System.out.println("\tException was thrown " + e); - System.out.println("\t...OK"); - } - System.out.println("...done"); - - XPropertySet xProps2 = UnoRuntime.queryInterface(XPropertySet.class, xPropContainer); - showPropertySet(xProps2); - - - System.out.println("Storing the document"); - XStorable store = UnoRuntime.queryInterface(XStorable.class, xTextDoc); - store.storeToURL(sTempDocument, new PropertyValue[] {}); - DesktopTools.closeDoc(xTextDoc); - - System.out.println("...done"); - } - - - if (true) - { - System.out.println("loading the document"); - - XComponentLoader xCL = UnoRuntime.queryInterface(XComponentLoader.class, m_xMSF.createInstance("com.sun.star.frame.Desktop")); - XComponent xComp = xCL.loadComponentFromURL(sTempDocument, "_blank", 0, new PropertyValue[] {}); - xTextDocSecond = UnoRuntime.queryInterface(XTextDocument.class, xComp); - - System.out.println("...done"); - - XDocumentInfoSupplier xDocInfoSup = UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xTextDocSecond); - XDocumentInfo xDocInfo = xDocInfoSup.getDocumentInfo(); - XPropertyContainer xPropContainer = UnoRuntime.queryInterface(XPropertyContainer.class, xDocInfo); - - XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, xDocInfo); - showPropertySet(xProps); - - assertTrue("Double doesn't work", checkType(xProps, "doubleValue", "java.lang.Double")); - assertTrue("Boolean doesn't work", checkType(xProps, "booleanValue", "java.lang.Boolean")); - - // TODO: dateValue does not exist. - // assertTrue("Date doesn't work", checkType(xProps, "dateValue", "com.sun.star.util.DateTime")); - - // TODO: is java.lang.Double - // assertTrue("Integer doesn't work", checkType(xProps, "intValue", "java.lang.Integer")); - - xPropContainer = UnoRuntime.queryInterface(XPropertyContainer.class, xDocInfo); - - System.out.println("trying to remove a not user defined Property"); - try - { - xPropContainer.removeProperty("Author"); - fail("Could remove non user defined property"); - } - catch (Exception e) - { - System.out.println("\tException was thrown " + e); - System.out.println("\t...OK"); - } - System.out.println("...done"); - - - System.out.println("Trying to remove a user defined property"); - try - { - xPropContainer.removeProperty("booleanValue"); - System.out.println("\t...OK"); - } - catch (Exception e) - { - System.out.println("\tException was thrown " + e); - System.out.println("\t...FAILED"); - fail("Could not remove user defined property"); - } - showPropertySet(xProps); - System.out.println("...done"); - } - } - - @After public void cleanup() - { - DesktopTools.closeDoc(xTextDocSecond); - DesktopTools.closeDoc(xTextDoc); - } - - private void showPropertySet(XPropertySet xProps) - { - try - { - // get an XPropertySet, here the one of a text cursor - // XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, mxDocCursor); - - // get the property info interface of this XPropertySet - XPropertySetInfo xPropsInfo = xProps.getPropertySetInfo(); - - // get all properties (NOT the values) from XPropertySetInfo - Property[] aProps = xPropsInfo.getProperties(); - int i; - for (i = 0; i < aProps.length; ++i) { - // number of property within this info object - System.out.print("Property #" + i); - - // name of property - System.out.print(": Name<" + aProps[i].Name); - - // handle of property (only for XFastPropertySet) - System.out.print("> Handle<" + aProps[i].Handle); - - // type of property - System.out.print("> " + aProps[i].Type.toString()); - - // attributes (flags) - System.out.print(" Attributes<"); - short nAttribs = aProps[i].Attributes; - if ((nAttribs & PropertyAttribute.MAYBEVOID) != 0) - System.out.print("MAYBEVOID|"); - if ((nAttribs & PropertyAttribute.BOUND) != 0) - System.out.print("BOUND|"); - if ((nAttribs & PropertyAttribute.CONSTRAINED) != 0) - System.out.print("CONSTRAINED|"); - if ((nAttribs & PropertyAttribute.READONLY) != 0) - System.out.print("READONLY|"); - if ((nAttribs & PropertyAttribute.TRANSIENT) != 0) - System.out.print("TRANSIENT|"); - if ((nAttribs & PropertyAttribute.MAYBEAMBIGUOUS ) != 0) - System.out.print("MAYBEAMBIGUOUS|"); - if ((nAttribs & PropertyAttribute.MAYBEDEFAULT) != 0) - System.out.print("MAYBEDEFAULT|"); - if ((nAttribs & PropertyAttribute.REMOVEABLE) != 0) - System.out.print("REMOVEABLE|"); - System.out.println("0>"); - } - } catch (Exception e) { - // If anything goes wrong, give the user a stack trace - e.printStackTrace(System.err); - } - } - - private boolean checkType(XPropertySet xProps, String aName, - String expected) - { - boolean ret = true; - System.out.println("Checking " + expected); - - String getting = - getPropertyByName(xProps, aName).getClass().getName(); - - if (!getting.equals(expected)) - { - System.out.println("\t Expected: " + expected); - System.out.println("\t Getting: " + getting); - ret = false; - } - - if (ret) - { - System.out.println("...OK"); - } - return ret; - } - - private Object getPropertyByName(XPropertySet xProps, String aName) - { - Object ret = null; - - try - { - ret = xProps.getPropertyValue(aName); - } - catch (Exception e) - { - System.out.println("\tCouldn't get Property " + aName); - System.out.println("\tMessage " + e); - } - - return ret; - } - - private boolean addProperty(XPropertyContainer xPropContainer, - String aName, short attr, Object defaults) - { - boolean ret = true; - - try - { - xPropContainer.addProperty(aName, attr, defaults); - } - catch (Exception e) - { - ret = false; - System.out.println("\tCouldn't get Property " + aName); - System.out.println("\tMessage " + e); - } - - return ret; - } - - private XMultiServiceFactory getMSF() - { - final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); - return xMSF1; - } - - // setup and close connections - @BeforeClass public static void setUpConnection() throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( "starting class: " + DocumentInfo.class.getName() ); - System.out.println( "------------------------------------------------------------" ); - connection.setUp(); - } - - @AfterClass public static void tearDownConnection() - throws InterruptedException, com.sun.star.uno.Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( "finishing class: " + DocumentInfo.class.getName() ); - System.out.println( "------------------------------------------------------------" ); - connection.tearDown(); - } - private static final OfficeConnection connection = new OfficeConnection(); -} diff --git a/sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java b/sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java deleted file mode 100644 index f7d9f679e8b0..000000000000 --- a/sfx2/qa/complex/sfx2/StandaloneDocumentInfo.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.sfx2; - -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.uno.UnoRuntime; -import complex.sfx2.standalonedocinfo.StandaloneDocumentInfoTest; -import complex.sfx2.standalonedocinfo.Test01; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openoffice.test.OfficeConnection; -import static org.junit.Assert.*; - -/* Document here -*/ - -public class StandaloneDocumentInfo { - private XMultiServiceFactory m_xMSF = null; - - @Before public void before() { - try { - m_xMSF = getMSF(); - } catch(Exception e) { - fail( "Failed to create service factory!" ); - } - if( m_xMSF ==null ) { - fail( "Failed to create service factory!" ); - } - } - - @After public void after() { - m_xMSF = null; - } - - @Test public void ExecuteTest01() { - StandaloneDocumentInfoTest aTest = new Test01 (m_xMSF); - assertTrue( "Test01 failed!", aTest.test() ); - } - - - - - private XMultiServiceFactory getMSF() - { - final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); - return xMSF1; - } - - // setup and close connections - @BeforeClass public static void setUpConnection() throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( "starting class: " + StandaloneDocumentInfo.class.getName() ); - System.out.println( "------------------------------------------------------------" ); - connection.setUp(); - } - - @AfterClass public static void tearDownConnection() - throws InterruptedException, com.sun.star.uno.Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( "finishing class: " + StandaloneDocumentInfo.class.getName() ); - System.out.println( "------------------------------------------------------------" ); - connection.tearDown(); - } - - private static final OfficeConnection connection = new OfficeConnection(); - -} - - diff --git a/sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java b/sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java deleted file mode 100644 index 83ba5bda80a5..000000000000 --- a/sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.sfx2.standalonedocinfo; - -public interface StandaloneDocumentInfoTest { - boolean test(); -} diff --git a/sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java b/sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java deleted file mode 100644 index 66daa4fec787..000000000000 --- a/sfx2/qa/complex/sfx2/standalonedocinfo/Test01.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.sfx2.standalonedocinfo; - -import complex.sfx2.standalonedocinfo.TestHelper; -import complex.sfx2.standalonedocinfo.StandaloneDocumentInfoTest; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.document.XStandaloneDocumentInfo; -import com.sun.star.io.XTempFile; -import com.sun.star.frame.XLoadable; -import com.sun.star.frame.XStorable; -import com.sun.star.beans.PropertyValue; -import com.sun.star.beans.XPropertySet; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.AnyConverter; - - -public class Test01 implements StandaloneDocumentInfoTest { - XMultiServiceFactory m_xMSF = null; - TestHelper m_aTestHelper = null; - - public Test01 ( XMultiServiceFactory xMSF ) { - m_xMSF = xMSF; - m_aTestHelper = new TestHelper( "Test01: " ); - } - - public boolean test() { - try { - final String sDocTitle [] = new String [] { - "ODF_Doc", "OOo6_Doc", "old_binary_Doc" }; - final String sFilterName [] = new String [] { - "writer8", "StarOffice XML (Writer)", "StarWriter 5.0" }; - - for (int i = 0; i < 3; ++i ) { - m_aTestHelper.Message ( "==============================" ); - m_aTestHelper.Message ( sFilterName[i] ); - m_aTestHelper.Message ( "==============================" ); - //create a new temporary file - Object oTempFile = m_xMSF.createInstance ( "com.sun.star.io.TempFile" ); - XTempFile xTempFile = UnoRuntime.queryInterface(XTempFile.class, oTempFile); - - //create a text document and initiallize it - Object oTextDocument = m_xMSF.createInstance ( "com.sun.star.text.TextDocument" ); - XLoadable xLoadable = UnoRuntime.queryInterface(XLoadable.class, oTextDocument); - xLoadable.initNew(); - m_aTestHelper.Message ( "New document initialized." ); - - //store the instance to the temporary file URL - XStorable xStorable = UnoRuntime.queryInterface(XStorable.class, oTextDocument); - String sURL = AnyConverter.toString ( xTempFile.getUri () ); - PropertyValue aProps[] = new PropertyValue[2]; - aProps[0] = new PropertyValue(); - aProps[0].Name = "DocumentTitle"; - aProps[0].Value = sDocTitle[i]; - aProps[1] = new PropertyValue(); - aProps[1].Name = "FilterName"; - aProps[1].Value = sFilterName[i]; - m_aTestHelper.Message ( "Set title: " + - sDocTitle[i] ); - xStorable.storeToURL ( sURL, aProps ); - m_aTestHelper.Message ( "Document stored." ); - - //create StandaloneDocumentInfo object and load it from the file - Object oStandaloneDocInfo = m_xMSF.createInstance ( - "com.sun.star.document.StandaloneDocumentInfo" ); - XStandaloneDocumentInfo xStandaloneDocInfo = - UnoRuntime.queryInterface(XStandaloneDocumentInfo.class, oStandaloneDocInfo); - xStandaloneDocInfo.loadFromURL ( sURL ); - m_aTestHelper.Message ( "StandaloneDocumentInfo loaded." ); - - //get the title from the object and check it - XPropertySet xPropSet = - UnoRuntime.queryInterface(XPropertySet.class, oStandaloneDocInfo); - String sTitle = xPropSet.getPropertyValue ( "Title" ).toString (); - m_aTestHelper.Message ( "Get title: " + sTitle ); - if ( sTitle.compareTo ( sDocTitle[i] ) != 0 ) { - m_aTestHelper.Error ( "Title not match. Expected \"" - + sDocTitle[i] + - "\"" ); - return false; - } else { - m_aTestHelper.Message ( "Title matched." ); - } - - //set a new title to the object - sTitle += "_new"; - xPropSet.setPropertyValue ( "Title", sTitle ); - m_aTestHelper.Message ( "Set new title: " + sTitle ); - - //store the object to the same file - xStandaloneDocInfo.storeIntoURL ( sURL ); - m_aTestHelper.Message ( "Document info stored." ); - - //create a new StandaloneDocumentInfo object and load it from the file - Object oStandaloneDocInfo_ = m_xMSF.createInstance ( - "com.sun.star.document.StandaloneDocumentInfo" ); - XStandaloneDocumentInfo xStandaloneDocInfo_ = - UnoRuntime.queryInterface(XStandaloneDocumentInfo.class, oStandaloneDocInfo_); - xStandaloneDocInfo_.loadFromURL ( sURL ); - m_aTestHelper.Message ( "New StandaloneDocumentInfo loaded." ); - - //get the title and check it - XPropertySet xPropSet_ = UnoRuntime.queryInterface(XPropertySet.class, oStandaloneDocInfo_); - String sTitle_ = xPropSet_.getPropertyValue ( "Title" ).toString (); - m_aTestHelper.Message ( "Get new title: " + sTitle_ ); - if ( sTitle_.compareTo ( sTitle ) != 0 ) { - m_aTestHelper.Error ( "New title not matched. Expected: \"" + sTitle - + "\"." ); - return false; - } else { - m_aTestHelper.Message ( "New title matched." ); - } - } - } catch ( Exception e ) { - m_aTestHelper.Error( "Exception: " + e ); - return false; - } - return true; - } -} diff --git a/sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java b/sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java deleted file mode 100644 index 18e5d5402cf7..000000000000 --- a/sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package complex.sfx2.standalonedocinfo; - - -public class TestHelper { - - String m_sTestPrefix; - - /** Creates a new instance of TestHelper - * @param sTestPrefix - */ - public TestHelper ( String sTestPrefix ) { - m_sTestPrefix = sTestPrefix; - } - - public void Error ( String sError ) { - System.out.println ( m_sTestPrefix + "Error: " + sError ); - } - - public void Message ( String sMessage ) { - System.out.println ( m_sTestPrefix + sMessage ); - } -} diff --git a/sfx2/qa/unoapi/sfx.sce b/sfx2/qa/unoapi/sfx.sce index ce72c463ee55..d75b95b31b56 100644 --- a/sfx2/qa/unoapi/sfx.sce +++ b/sfx2/qa/unoapi/sfx.sce @@ -2,4 +2,3 @@ #i113306 -o sfx.DocumentTemplates -o sfx.FrameLoader -o sfx.SfxMacroLoader -#i111283 -o sfx.StandaloneDocumentInfo diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index ffb4853e7ec1..0138f4168a00 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -105,7 +105,6 @@ using namespace ::com::sun::star::io; #include "frmload.hxx" #include <sfx2/frame.hxx> #include <sfx2/objsh.hxx> -#include <sfx2/objuno.hxx> #include <sfx2/unoctitm.hxx> #include <sfx2/dispatch.hxx> #include "doctemplates.hxx" @@ -2218,7 +2217,6 @@ SFX2_DLLPUBLIC void* SAL_CALL sfx_component_getFactory( IF_NAME_CREATECOMPONENTFACTORY( SfxGlobalEvents_Impl ) IF_NAME_CREATECOMPONENTFACTORY( SfxFrameLoader_Impl ) IF_NAME_CREATECOMPONENTFACTORY( SfxMacroLoader ) - IF_NAME_CREATECOMPONENTFACTORY( SfxStandaloneDocumentInfoObject ) IF_NAME_CREATECOMPONENTFACTORY( SfxAppDispatchProvider ) IF_NAME_CREATECOMPONENTFACTORY( SfxDocTplService ) IF_NAME_CREATECOMPONENTFACTORY( ShutdownIcon ) diff --git a/sfx2/source/doc/objuno.cxx b/sfx2/source/doc/objuno.cxx deleted file mode 100644 index 336affb2f2ba..000000000000 --- a/sfx2/source/doc/objuno.cxx +++ /dev/null @@ -1,1351 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/util/DateTime.hpp> -#include <com/sun/star/util/Date.hpp> -#include <com/sun/star/util/Time.hpp> -#include <com/sun/star/beans/PropertyAttribute.hpp> -#include <com/sun/star/beans/NamedValue.hpp> -#include <com/sun/star/beans/StringPair.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/xml/sax/XParser.hpp> -#include <com/sun/star/document/XImporter.hpp> -#include <com/sun/star/document/XExporter.hpp> -#include <com/sun/star/io/XActiveDataSource.hpp> -#include <com/sun/star/document/XFilter.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/lang/Locale.hpp> -#include <com/sun/star/util/XModifiable.hpp> -#include <com/sun/star/document/DocumentProperties.hpp> -#include <com/sun/star/document/XCompatWriterDocProperties.hpp> - -#include <unotools/configmgr.hxx> -#include <unotools/bootstrap.hxx> -#include <cppuhelper/interfacecontainer.hxx> -#include <osl/mutex.hxx> -#include <rtl/ustrbuf.hxx> -#include <vcl/svapp.hxx> - -#include <tools/errcode.hxx> -#include <svl/cntwids.hrc> -#include <comphelper/processfactory.hxx> -#include <comphelper/string.hxx> -#include <comphelper/sequenceasvector.hxx> -#include <comphelper/storagehelper.hxx> -#include <sot/storage.hxx> - -#include <sfx2/objuno.hxx> -#include <sfx2/sfx.hrc> - -#include <vector> -#include <algorithm> - -#include "sfx2/sfxresid.hxx" -#include "doc.hrc" - -using namespace ::com::sun::star; - -// TODO/REFACTOR: provide service for MS formats -// TODO/REFACTOR: IsEncrypted is never set nor read -// Generator is not saved ATM; which value?! -// Generator handling must be implemented -// Deprecate "Theme", rework IDL -// AutoLoadEnabled is deprecated?! -// Reasonable defaults for DateTime -// MIMEType readonly?! -// Announce changes about Theme, Language, Generator, removed entries etc. -// IsEncrypted is necessary for binary formats! -// Open: When to call PrepareDocInfoForSave? Currently only called for own formats and HTML/Writer -// Open: How to load and save EditingTime to MS formats -// PPT-Export should use SavePropertySet - -//============================================================================= - -// The number of user defined fields handled by the evil XDocumentInfo -// interface. There are exactly 4. No more, no less. -#define FOUR 4 - -#define PROPERTY_UNBOUND 0 -#define PROPERTY_MAYBEVOID ::com::sun::star::beans::PropertyAttribute::MAYBEVOID - -static const SfxItemPropertyMapEntry* lcl_GetDocInfoPropertyMap() -{ - static SfxItemPropertyMapEntry aDocInfoPropertyMap_Impl[] = - { - { "Author" , 6 , WID_FROM, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "AutoloadEnabled" , 15, MID_DOCINFO_AUTOLOADENABLED, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 }, - { "AutoloadSecs" , 12, MID_DOCINFO_AUTOLOADSECS, &::getCppuType((const sal_Int32*)0), PROPERTY_UNBOUND, 0 }, - { "AutoloadURL" , 11, MID_DOCINFO_AUTOLOADURL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Category" , 8 , MID_CATEGORY, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Company" , 7 , MID_COMPANY, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Manager" , 7 , MID_MANAGER, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "CreationDate" , 12, WID_DATE_CREATED, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 }, - { "DefaultTarget" , 13, MID_DOCINFO_DEFAULTTARGET, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Description" , 11, MID_DOCINFO_DESCRIPTION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "DocumentStatistic", 17 , MID_DOCINFO_STATISTIC, &::getCppuType((const uno::Sequence< beans::NamedValue >*)0), PROPERTY_UNBOUND, 0 }, - { "EditingCycles" , 13, MID_DOCINFO_REVISION, &::getCppuType((const sal_Int16*)0), PROPERTY_UNBOUND, 0 }, - { "EditingDuration" , 15, MID_DOCINFO_EDITTIME, &::getCppuType((const sal_Int32*)0), PROPERTY_UNBOUND, 0 }, - { "Generator" , 9, SID_APPLICATION, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Keywords" , 8 , WID_KEYWORDS, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Language" , 8, MID_DOCINFO_CHARLOCALE, &::getCppuType((const lang::Locale*)0), PROPERTY_UNBOUND, 0 }, - { "MIMEType" , 8 , WID_CONTENT_TYPE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND | ::com::sun::star::beans::PropertyAttribute::READONLY, 0 }, - { "ModifiedBy" , 10, MID_DOCINFO_MODIFICATIONAUTHOR, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "ModifyDate" , 10, WID_DATE_MODIFIED, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 }, - { "PrintDate" , 9 , MID_DOCINFO_PRINTDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 }, - { "PrintedBy" , 9 , MID_DOCINFO_PRINTEDBY, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Subject" , 7 , MID_DOCINFO_SUBJECT, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "Template" , 8 , MID_DOCINFO_TEMPLATE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "TemplateFileName", 16, SID_TEMPLATE_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - { "TemplateDate" , 12, MID_DOCINFO_TEMPLATEDATE, &::getCppuType((const ::com::sun::star::util::DateTime*)0),PROPERTY_MAYBEVOID, 0 }, - { "Title" , 5 , WID_TITLE, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, - {0,0,0,0,0,0} - }; - return aDocInfoPropertyMap_Impl; -} - -static sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30, - 31, 31, 30, 31, 30, 31 }; - -inline sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear ) -{ - if ( nMonth != 2 ) - return aDaysInMonth[nMonth-1]; - else - { - if ( (((nYear % 4) == 0) && ((nYear % 100) != 0)) || - ((nYear % 400) == 0) ) - return aDaysInMonth[nMonth-1] + 1; - else - return aDaysInMonth[nMonth-1]; - } -} - -bool IsValidDateTime( const util::DateTime& rDT ) -{ - if ( !rDT.Month || (rDT.Month > 12) ) - return false; - if ( !rDT.Day || (rDT.Day > DaysInMonth( rDT.Month, rDT.Year )) ) - return false; - else if ( rDT.Year <= 1582 ) - { - if ( rDT.Year < 1582 ) - return false; - else if ( rDT.Month < 10 ) - return false; - else if ( (rDT.Month == 10) && (rDT.Day < 15) ) - return false; - } - - return true; -} - -struct OUStringHashCode -{ - size_t operator()( const ::rtl::OUString& sString ) const - { - return sString.hashCode(); - } -}; - -struct SfxExtendedItemPropertyMap : public SfxItemPropertyMapEntry -{ - ::com::sun::star::uno::Any aValue; -}; - -void Copy( const uno::Reference < document::XStandaloneDocumentInfo >& rSource, const uno::Reference < document::XStandaloneDocumentInfo >& rTarget ) -{ - try - { - uno::Reference< beans::XPropertySet > xSet( rSource, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xTarget( rTarget, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo(); - uno::Reference< beans::XPropertyContainer > xContainer( rTarget, uno::UNO_QUERY ); - uno::Sequence< beans::Property > lProps = xSetInfo->getProperties(); - const beans::Property* pProps = lProps.getConstArray(); - sal_Int32 c = lProps.getLength(); - sal_Int32 i = 0; - for (i=0; i<c; ++i) - { - uno::Any aValue = xSet->getPropertyValue( pProps[i].Name ); - if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE ) - // QUESTION: DefaultValue?! - xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue ); - try - { - // it is possible that the propertysets from XML and binary files differ; we shouldn't break then - xTarget->setPropertyValue( pProps[i].Name, aValue ); - } - catch ( const uno::Exception& ) {} - } - - sal_Int16 nCount = rSource->getUserFieldCount(); - sal_Int16 nSupportedCount = rTarget->getUserFieldCount(); - for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ ) - { - ::rtl::OUString aPropName = rSource->getUserFieldName( nInd ); - rTarget->setUserFieldName( nInd, aPropName ); - ::rtl::OUString aPropVal = rSource->getUserFieldValue( nInd ); - rTarget->setUserFieldValue( nInd, aPropVal ); - } - } - catch ( const uno::Exception& ) {} -} - -class MixedPropertySetInfo : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo > -{ - private: - - SfxItemPropertyMap _aPropertyMap; - ::rtl::OUString* _pUserKeys; - uno::Reference<beans::XPropertySet> _xUDProps; - - public: - - MixedPropertySetInfo( const SfxItemPropertyMapEntry* pFixProps, - ::rtl::OUString* pUserKeys, - uno::Reference<beans::XPropertySet> xUDProps); - - virtual ~MixedPropertySetInfo(); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException); -}; - -//----------------------------------------------------------------------------- - -MixedPropertySetInfo::MixedPropertySetInfo(const SfxItemPropertyMapEntry* pFixProps, - ::rtl::OUString* pUserKeys, - uno::Reference<beans::XPropertySet> xUDProps) - : _aPropertyMap( pFixProps ) - , _pUserKeys(pUserKeys) - , _xUDProps(xUDProps) -{ -} - -//----------------------------------------------------------------------------- - -MixedPropertySetInfo::~MixedPropertySetInfo() -{ -} - -//----------------------------------------------------------------------------- - -::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL MixedPropertySetInfo::getProperties() - throw(::com::sun::star::uno::RuntimeException) -{ - ::comphelper::SequenceAsVector< ::com::sun::star::beans::Property > lProps; - - // copy "fix" props - //todo: os: this ugly thing should be replaced - const SfxItemPropertyMapEntry* pFixProp = lcl_GetDocInfoPropertyMap(); - - while(pFixProp && pFixProp->pName) - { - ::com::sun::star::beans::Property aProp; - - aProp.Name = ::rtl::OUString::createFromAscii(pFixProp->pName); - aProp.Handle = pFixProp->nWID; - aProp.Type = *(pFixProp->pType); - aProp.Attributes = (sal_Int16)(pFixProp->nFlags); - - lProps.push_back(aProp); - ++pFixProp; - } - - // copy "dynamic" props - - // NB: this is really ugly: - // The returned properties must _not_ include the 4 user-defined fields! - // These are _not_ properties of the XDocumentInfo interface. - // Some things rely on this, e.g. Copy would break otherwise. - // This will have interesting consequences if someone expects to insert - // a property with the same name as an user-defined key, but nobody - // sane does that. - uno::Sequence<beans::Property> udProps = - _xUDProps->getPropertySetInfo()->getProperties(); - for (sal_Int32 i = 0; i < udProps.getLength(); ++i) { - if (std::find(_pUserKeys, _pUserKeys+FOUR, udProps[i].Name) - == _pUserKeys+FOUR) { - // #i100027#: handles from udProps are not valid here - udProps[i].Handle = -1; - lProps.push_back(udProps[i]); - } - } - - return lProps.getAsConstList(); -} - -//----------------------------------------------------------------------------- - -::com::sun::star::beans::Property SAL_CALL MixedPropertySetInfo::getPropertyByName( - const ::rtl::OUString& sName ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::uno::RuntimeException ) -{ - ::com::sun::star::beans::Property aProp; - - // search it as "fix" prop - if( _aPropertyMap.hasPropertyByName( sName ) ) - return _aPropertyMap.getPropertyByName( sName ); - else - // search it as "dynamic" prop - return _xUDProps->getPropertySetInfo()->getPropertyByName(sName); -} - -//----------------------------------------------------------------------------- - -::sal_Bool SAL_CALL MixedPropertySetInfo::hasPropertyByName(const ::rtl::OUString& sName) - throw(::com::sun::star::uno::RuntimeException) -{ - return _aPropertyMap.hasPropertyByName( sName ) ? // "fix" prop? - sal_True : - _xUDProps->getPropertySetInfo()->hasPropertyByName(sName); // "dynamic" prop? -} - -//----------------------------------------------------------------------------- - -struct SfxDocumentInfoObject_Impl -{ - ::osl::Mutex _aMutex; - ::cppu::OInterfaceContainerHelper _aDisposeContainer; - - sal_Bool bDisposed; - - // this contains the names of the 4 user defined properties - // which are accessible via the evil XDocumentInfo interface - ::rtl::OUString m_UserDefined[FOUR]; - - // the actual contents - uno::Reference<document::XDocumentProperties> m_xDocProps; - SfxItemPropertyMap m_aPropertyMap; - - SfxDocumentInfoObject_Impl() - : _aDisposeContainer( _aMutex ) - , bDisposed(sal_False) - , m_xDocProps() - , m_aPropertyMap( lcl_GetDocInfoPropertyMap() ) - { - // the number of user fields is not changeable from the outside - // we can't set it too high because every name/value pair will be written to the file (even if empty) - // currently our dialog has only 4 user keys so 4 is still a reasonable number - } - - /// the initialization function - void Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined = 0); -}; - -void SfxDocumentInfoObject_Impl::Reset(uno::Reference<document::XDocumentProperties> xDocProps, ::rtl::OUString* pUserDefined) -{ - if (pUserDefined == 0) { - // NB: this is an ugly hack; the "Properties" ui dialog displays - // exactly 4 user-defined fields and expects these to be available - // (should be redesigned), but I do not want to do this in - // DocumentProperties; do it here instead - uno::Reference<beans::XPropertyAccess> xPropAccess( - xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertyContainer> xPropContainer( - xPropAccess, uno::UNO_QUERY_THROW); - uno::Sequence< beans::PropertyValue > - props = xPropAccess->getPropertyValues(); - sal_Int32 oldLength = props.getLength(); - if (oldLength < FOUR) { - std::vector< ::rtl::OUString > names; - for (sal_Int32 i = 0; i < oldLength; ++i) { - names.push_back(props[i].Name); - } - const ::rtl::OUString sInfo( - SfxResId(STR_DOCINFO_INFOFIELD).toString()); - for (sal_Int32 i = oldLength; i < FOUR; ++i) { - ::rtl::OUString sName(sInfo); - sal_Int32 idx = sName.indexOfAsciiL("%1", 2); - ::rtl::OUString name = (idx > 0) - ? sName.replaceAt(idx, 2, ::rtl::OUString::valueOf(i+1)) - : sName + ::rtl::OUString::valueOf(i+1); - while (std::find(names.begin(), names.end(), name) - != names.end()) { - name += ::rtl::OUString("'"); - } - // FIXME there is a race condition here - try { - xPropContainer->addProperty(name, - beans::PropertyAttribute::REMOVEABLE, - uno::makeAny(::rtl::OUString(""))); - } catch (const uno::RuntimeException&) { - throw; - } catch (const uno::Exception&) { - // ignore - } - } - } - props = xPropAccess->getPropertyValues(); - for (sal_Int32 i = 0; i < FOUR; ++i) { - m_UserDefined[i] = props[i].Name; - } - } else { - std::copy(pUserDefined, pUserDefined+FOUR, m_UserDefined); - } - m_xDocProps = xDocProps; -} - -//----------------------------------------------------------------------------- - -SfxDocumentInfoObject::SfxDocumentInfoObject() - : _pImp( new SfxDocumentInfoObject_Impl() ) -{ -} - -//----------------------------------------------------------------------------- - -SfxDocumentInfoObject::~SfxDocumentInfoObject() -{ - delete _pImp; -} - -//----------------------------------------------------------------------------- - -// ::com::sun::star::lang::XInitialization: -void SAL_CALL -SfxDocumentInfoObject::initialize(const uno::Sequence< uno::Any > & aArguments) - throw (uno::RuntimeException, uno::Exception) -{ - if (aArguments.getLength() >= 1) { - uno::Any any = aArguments[0]; - uno::Reference<document::XDocumentProperties> xDoc; - if (!(any >>= xDoc) || !xDoc.is()) throw lang::IllegalArgumentException( - ::rtl::OUString( - "SfxDocumentInfoObject::initialize: no XDocumentProperties given"), - *this, 0); - _pImp->Reset(xDoc); - } else { - throw lang::IllegalArgumentException( - ::rtl::OUString( - "SfxDocumentInfoObject::initialize: no argument given"), - *this, 0); - } -} - -// ::com::sun::star::util::XCloneable: -uno::Reference<util::XCloneable> SAL_CALL -SfxDocumentInfoObject::createClone() throw (uno::RuntimeException) -{ - SfxDocumentInfoObject *pNew = new SfxDocumentInfoObject; - uno::Reference< util::XCloneable > - xCloneable(_pImp->m_xDocProps, uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentProperties> xDocProps( - xCloneable->createClone(), uno::UNO_QUERY_THROW); - pNew->_pImp->Reset(xDocProps, _pImp->m_UserDefined); - return pNew; -} - -// ::com::sun::star::document::XDocumentProperties: -uno::Reference< document::XDocumentProperties > SAL_CALL -SfxDocumentInfoObject::getDocumentProperties() - throw(::com::sun::star::uno::RuntimeException) -{ - return _pImp->m_xDocProps; -} - -//----------------------------------------------------------------------------- - -const SfxDocumentInfoObject& SfxDocumentInfoObject::operator=( const SfxDocumentInfoObject & rOther) -{ - uno::Reference< util::XCloneable > - xCloneable(rOther._pImp->m_xDocProps, uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentProperties> xDocProps( - xCloneable->createClone(), uno::UNO_QUERY_THROW); - _pImp->Reset(xDocProps, rOther._pImp->m_UserDefined); - return *this; -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::dispose() throw( ::com::sun::star::uno::RuntimeException ) -{ - ::com::sun::star::lang::EventObject aEvent( (::cppu::OWeakObject *)this ); - _pImp->_aDisposeContainer.disposeAndClear( aEvent ); - ::osl::MutexGuard aGuard( _pImp->_aMutex ); - _pImp->m_xDocProps = 0; - // NB: do not call m_xDocProps->dispose(), there could be other refs - _pImp->bDisposed = sal_True; -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ) -{ - _pImp->_aDisposeContainer.addInterface( aListener ); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ) -{ - _pImp->_aDisposeContainer.removeInterface( aListener ); -} -//----------------------------------------------------------------------------- - -::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL SfxDocumentInfoObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( _pImp->_aMutex ); - - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - MixedPropertySetInfo* pInfo = new MixedPropertySetInfo( lcl_GetDocInfoPropertyMap(), _pImp->m_UserDefined, xPropSet); - uno::Reference< beans::XPropertySetInfo > xInfo( - static_cast< beans::XPropertySetInfo* >(pInfo), uno::UNO_QUERY_THROW); - return xInfo; -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aValue) throw ( - uno::RuntimeException, beans::UnknownPropertyException, - beans::PropertyVetoException, lang::IllegalArgumentException, - lang::WrappedTargetException) -{ - const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName ); - // fix prop! - if ( pEntry ) - setFastPropertyValue( pEntry->nWID, aValue ); - else - // dynamic prop! - { - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - return xPropSet->setPropertyValue(aPropertyName, aValue); - } -} - -//----------------------------------------------------------------------------- - -uno::Any SAL_CALL SfxDocumentInfoObject::getPropertyValue(const ::rtl::OUString& aPropertyName) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{ - const SfxItemPropertySimpleEntry* pEntry = _pImp->m_aPropertyMap.getByName( aPropertyName ); - // fix prop! - if ( pEntry ) - return getFastPropertyValue( pEntry->nWID ); - else - // dynamic prop! - { - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - return xPropSet->getPropertyValue(aPropertyName); - } -} - -sal_Bool SAL_CALL SfxDocumentInfoObject::isModified() throw(::com::sun::star::uno::RuntimeException) -{ - uno::Reference<util::XModifiable> xModif( - _pImp->m_xDocProps, uno::UNO_QUERY_THROW); - return xModif->isModified(); -} - -void SAL_CALL SfxDocumentInfoObject::setModified( sal_Bool bModified ) - throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) -{ - uno::Reference<util::XModifiable> xModif( - _pImp->m_xDocProps, uno::UNO_QUERY_THROW); - return xModif->setModified(bModified); -} - -void SAL_CALL SfxDocumentInfoObject::addModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException ) -{ - uno::Reference<util::XModifiable> xModif( - _pImp->m_xDocProps, uno::UNO_QUERY_THROW); - return xModif->addModifyListener(xListener); -} - -void SAL_CALL SfxDocumentInfoObject::removeModifyListener( const uno::Reference< util::XModifyListener >& xListener) throw( uno::RuntimeException ) -{ - uno::Reference<util::XModifiable> xModif( - _pImp->m_xDocProps, uno::UNO_QUERY_THROW); - return xModif->removeModifyListener(xListener); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::addPropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::removePropertyChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener > & ) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::addVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::removeVetoableChangeListener(const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener > & ) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{} - -uno::Sequence< beans::PropertyValue > SAL_CALL SfxDocumentInfoObject::getPropertyValues( void ) throw( uno::RuntimeException ) -{ - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = getPropertySetInfo(); - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps = xInfo->getProperties(); - - const ::com::sun::star::beans::Property* pProps = aProps.getConstArray(); - sal_uInt32 nCount = aProps.getLength(); - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >aSeq( nCount ); - ::com::sun::star::beans::PropertyValue* pValues = aSeq.getArray(); - - for ( sal_uInt32 n = 0; n < nCount; ++n ) - { - ::com::sun::star::beans::PropertyValue& rCurrValue = pValues[n]; - const ::com::sun::star::beans::Property& rCurrProp = pProps[n]; - - rCurrValue.Name = rCurrProp.Name; - rCurrValue.Handle = rCurrProp.Handle; - rCurrValue.Value = getPropertyValue( rCurrProp.Name ); - } - - return aSeq; -} - -void SAL_CALL SfxDocumentInfoObject::setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) - throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ) -{ - const ::com::sun::star::beans::PropertyValue* pProps = aProps.getConstArray(); - sal_uInt32 nCount = aProps.getLength(); - - for ( sal_uInt32 n = 0; n < nCount; ++n ) - { - const ::com::sun::star::beans::PropertyValue& rProp = pProps[n]; - setPropertyValue( rProp.Name, rProp.Value ); - } -} - -void SAL_CALL SfxDocumentInfoObject::addProperty(const ::rtl::OUString& sName , - sal_Int16 nAttributes , - const ::com::sun::star::uno::Any& aDefaultValue) - throw(::com::sun::star::beans::PropertyExistException , - ::com::sun::star::beans::IllegalTypeException , - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException ) -{ - // clash with "fix" properties ? - sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0; - if ( bFixProp ) - { - ::rtl::OUStringBuffer sMsg(256); - sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("The property \"")); - sMsg.append(sName); - sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("\" ")); - if ( bFixProp ) - sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM(" already exists as a fix property. Please have a look into the IDL documentation of the DocumentInfo service.")); - - throw ::com::sun::star::beans::PropertyExistException( - sMsg.makeStringAndClear(), - static_cast< ::cppu::OWeakObject* >(this)); - } - - uno::Reference<beans::XPropertyContainer> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - return xPropSet->addProperty(sName, nAttributes, aDefaultValue); -} - -void SAL_CALL SfxDocumentInfoObject::removeProperty(const ::rtl::OUString& sName) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::NotRemoveableException , - ::com::sun::star::uno::RuntimeException ) -{ - // clash with "fix" properties ? - sal_Bool bFixProp = _pImp->m_aPropertyMap.getByName( sName ) != 0; - if ( bFixProp ) - { - ::rtl::OUStringBuffer sMsg(256); - sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("The property \"")); - sMsg.append(sName); - sMsg.appendAscii(RTL_CONSTASCII_STRINGPARAM("\" cant be removed. Its a fix property of the DocumentInfo service.")); - - throw ::com::sun::star::beans::NotRemoveableException( - sMsg.makeStringAndClear(), - static_cast< ::cppu::OWeakObject* >(this)); - } - - uno::Reference<beans::XPropertyContainer> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - return xPropSet->removeProperty(sName); -} - -sal_Bool equalsDateTime( const util::DateTime& D1, const util::DateTime& D2 ) -{ - return D1.HundredthSeconds == D2.HundredthSeconds && - D1.Seconds == D2.Seconds && - D1.Minutes == D2.Minutes && - D1.Hours == D2.Hours && - D1.Day == D2.Day && - D1.Month == D2.Month && - D1.Year == D2.Year; -} - -void SAL_CALL SfxDocumentInfoObject::setFastPropertyValue(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue) throw( - uno::RuntimeException, beans::UnknownPropertyException, - beans::PropertyVetoException, lang::IllegalArgumentException, - lang::WrappedTargetException) -{ - // Attention: Only fix properties should be provided by this method. - // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-) - - ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex ); - - if ( aValue.getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) - { - ::rtl::OUString sTemp ; - aValue >>= sTemp ; - switch ( nHandle ) - { - case SID_APPLICATION : - _pImp->m_xDocProps->setGenerator(sTemp); - break; - case WID_FROM : - { - if ( _pImp->m_xDocProps->getAuthor() != sTemp ) - _pImp->m_xDocProps->setAuthor(sTemp); - break; - } - case MID_DOCINFO_PRINTEDBY: - if ( _pImp->m_xDocProps->getPrintedBy() != sTemp ) - _pImp->m_xDocProps->setPrintedBy(sTemp); - break; - case MID_DOCINFO_MODIFICATIONAUTHOR: - if ( _pImp->m_xDocProps->getModifiedBy() != sTemp ) - _pImp->m_xDocProps->setModifiedBy(sTemp); - break; - case WID_TITLE : - { - if ( _pImp->m_xDocProps->getTitle() != sTemp ) - _pImp->m_xDocProps->setTitle(sTemp); - break; - } - case MID_DOCINFO_SUBJECT : - if ( _pImp->m_xDocProps->getSubject() != sTemp ) - _pImp->m_xDocProps->setSubject(sTemp); - break; - case WID_KEYWORDS : - { - _pImp->m_xDocProps->setKeywords( - ::comphelper::string::convertCommaSeparated(sTemp)); - } - break; - case MID_DOCINFO_TEMPLATE: - if ( _pImp->m_xDocProps->getTemplateName() != sTemp ) - _pImp->m_xDocProps->setTemplateName(sTemp); - break; - case SID_TEMPLATE_NAME: - if ( _pImp->m_xDocProps->getTemplateURL() != sTemp ) - _pImp->m_xDocProps->setTemplateURL(sTemp); - break; - case MID_DOCINFO_DESCRIPTION: - if ( _pImp->m_xDocProps->getDescription() != sTemp ) - _pImp->m_xDocProps->setDescription(sTemp); - break; - case MID_DOCINFO_AUTOLOADURL: - if ( _pImp->m_xDocProps->getAutoloadURL() != sTemp ) - _pImp->m_xDocProps->setAutoloadURL(sTemp); - break; - case MID_DOCINFO_DEFAULTTARGET: - if ( _pImp->m_xDocProps->getDefaultTarget() != sTemp ) - _pImp->m_xDocProps->setDefaultTarget(sTemp); - break; - case MID_CATEGORY: - case MID_MANAGER: - case MID_COMPANY: - { - uno::Reference< document::XCompatWriterDocProperties > xWriterProps( _pImp->m_xDocProps, uno::UNO_QUERY ); - if ( xWriterProps.is() ) - { - if ( nHandle == MID_CATEGORY ) - xWriterProps->setCategory( sTemp ); - else if ( nHandle == MID_MANAGER ) - xWriterProps->setManager( sTemp ); - else - xWriterProps->setCompany( sTemp ); - break; - } - } - default: - break; - } - } - else if ( aValue.getValueType() == ::getCppuType((const ::com::sun::star::util::DateTime*)0) ) - { - com::sun::star::util::DateTime aTemp; - aValue >>= aTemp ; - switch ( nHandle ) - { - case WID_DATE_CREATED : - { - if ( !equalsDateTime(_pImp->m_xDocProps->getCreationDate(), aTemp ) ) - { - _pImp->m_xDocProps->setCreationDate(aTemp); - } - break; - } - case WID_DATE_MODIFIED : - { - if ( !equalsDateTime(_pImp->m_xDocProps->getModificationDate(), aTemp ) ) - { - _pImp->m_xDocProps->setModificationDate(aTemp); - } - break; - } - case MID_DOCINFO_PRINTDATE : - { - if ( !equalsDateTime(_pImp->m_xDocProps->getPrintDate(), aTemp ) ) - { - _pImp->m_xDocProps->setPrintDate(aTemp); - } - break; - } - case MID_DOCINFO_TEMPLATEDATE : - { - if ( !equalsDateTime(_pImp->m_xDocProps->getTemplateDate(), aTemp ) ) - { - _pImp->m_xDocProps->setTemplateDate(aTemp); - } - break; - } - default: - break; - } - } - - else if ( aValue.getValueType() == ::getBooleanCppuType() ) - { - sal_Bool bBoolVal = false; - aValue >>= bBoolVal ; - switch ( nHandle ) - { - case MID_DOCINFO_AUTOLOADENABLED: - // NB: this property does not exist any more - // it is emulated as enabled iff delay > 0 - if ( bBoolVal && (0 == _pImp->m_xDocProps->getAutoloadSecs()) ) { - _pImp->m_xDocProps->setAutoloadSecs(60); // default - } else if ( !bBoolVal && (0 != _pImp->m_xDocProps->getAutoloadSecs()) ) { - _pImp->m_xDocProps->setAutoloadSecs(0); - _pImp->m_xDocProps->setAutoloadURL(::rtl::OUString("")); - } - break; - default: - break; - } - } - else if ( aValue.getValueType() == ::getCppuType((const sal_Int32*)0) ) - { - sal_Int32 nIntVal = 0; - aValue >>= nIntVal ; - switch ( nHandle ) - { - case MID_DOCINFO_AUTOLOADSECS: - if ( nIntVal != _pImp->m_xDocProps->getAutoloadSecs()) - _pImp->m_xDocProps->setAutoloadSecs(nIntVal); - break; - case MID_DOCINFO_EDITTIME: - if ( nIntVal != _pImp->m_xDocProps->getEditingDuration()) - _pImp->m_xDocProps->setEditingDuration(nIntVal); - break; - default: - break; - } - } - else if ( aValue.getValueType() == ::getCppuType((const sal_Int16*)0) ) - { - short nIntVal = 0; - aValue >>= nIntVal ; - switch ( nHandle ) - { - case MID_DOCINFO_REVISION: - if ( nIntVal != _pImp->m_xDocProps->getEditingCycles()) - _pImp->m_xDocProps->setEditingCycles(nIntVal); - break; - default: - break; - } - } - else if ( aValue.getValueType() == ::getCppuType((const uno::Sequence< beans::NamedValue >*)0) ) - { - if ( nHandle == MID_DOCINFO_STATISTIC ) - { - uno::Sequence < beans::NamedValue > aData; - aValue >>= aData; - { - _pImp->m_xDocProps->setDocumentStatistics(aData); - } - } - } - else if ( aValue.getValueType() == ::getCppuType((const lang::Locale*)0) ) - { - if ( nHandle == MID_DOCINFO_CHARLOCALE ) - { - lang::Locale aLocale; - aValue >>= aLocale; - lang::Locale oldLocale = _pImp->m_xDocProps->getLanguage(); - if ( aLocale.Language != oldLocale.Language || - aLocale.Country != oldLocale.Country || - aLocale.Variant != oldLocale.Variant ) - { - _pImp->m_xDocProps->setLanguage(aLocale); - } - } - } -} - -//----------------------------------------------------------------------------- - -::com::sun::star::uno::Any SAL_CALL SfxDocumentInfoObject::getFastPropertyValue(sal_Int32 nHandle) throw( - uno::RuntimeException, beans::UnknownPropertyException, - lang::WrappedTargetException) -{ - // Attention: Only fix properties should be provided by this method. - // Dynamic properties has no handle in real ... because it cant be used inside multithreaded environments :-) - - ::osl::MutexGuard aGuard( _pImp->_aMutex ); - ::com::sun::star::uno::Any aValue; - switch ( nHandle ) - { - case SID_APPLICATION : - aValue <<= _pImp->m_xDocProps->getGenerator(); - break; - case WID_CONTENT_TYPE : -// FIXME this is not available anymore - aValue <<= ::rtl::OUString(); - break; - case MID_DOCINFO_REVISION : - aValue <<= _pImp->m_xDocProps->getEditingCycles(); - break; - case MID_DOCINFO_EDITTIME : - aValue <<= _pImp->m_xDocProps->getEditingDuration(); - break; - case WID_FROM : - aValue <<= _pImp->m_xDocProps->getAuthor(); - break; - case WID_DATE_CREATED : - if ( IsValidDateTime( _pImp->m_xDocProps->getCreationDate() ) ) - aValue <<= _pImp->m_xDocProps->getCreationDate(); - break; - case WID_TITLE : - aValue <<= _pImp->m_xDocProps->getTitle(); - break; - case MID_DOCINFO_SUBJECT: - aValue <<= _pImp->m_xDocProps->getSubject(); - break; - case MID_DOCINFO_MODIFICATIONAUTHOR: - aValue <<= _pImp->m_xDocProps->getModifiedBy(); - break; - case WID_DATE_MODIFIED : - if ( IsValidDateTime( _pImp->m_xDocProps->getModificationDate() ) ) - aValue <<= _pImp->m_xDocProps->getModificationDate(); - break; - case MID_DOCINFO_PRINTEDBY: - aValue <<= _pImp->m_xDocProps->getPrintedBy(); - break; - case MID_DOCINFO_PRINTDATE: - if ( IsValidDateTime( _pImp->m_xDocProps->getPrintDate() ) ) - aValue <<= _pImp->m_xDocProps->getPrintDate(); - break; - case WID_KEYWORDS : - aValue <<= ::comphelper::string::convertCommaSeparated( - _pImp->m_xDocProps->getKeywords()); - break; - case MID_DOCINFO_DESCRIPTION: - aValue <<= _pImp->m_xDocProps->getDescription(); - break; - case MID_DOCINFO_TEMPLATE: - aValue <<= _pImp->m_xDocProps->getTemplateName(); - break; - case SID_TEMPLATE_NAME: - aValue <<= _pImp->m_xDocProps->getTemplateURL(); - break; - case MID_DOCINFO_TEMPLATEDATE: - if ( IsValidDateTime( _pImp->m_xDocProps->getTemplateDate() ) ) - aValue <<= _pImp->m_xDocProps->getTemplateDate(); - break; - case MID_DOCINFO_AUTOLOADENABLED: - aValue <<= static_cast<sal_Bool> - ( (_pImp->m_xDocProps->getAutoloadSecs() != 0) - || !_pImp->m_xDocProps->getAutoloadURL().isEmpty()); - break; - case MID_DOCINFO_AUTOLOADURL: - aValue <<= _pImp->m_xDocProps->getAutoloadURL(); - break; - case MID_DOCINFO_AUTOLOADSECS: - aValue <<= _pImp->m_xDocProps->getAutoloadSecs(); - break; - case MID_DOCINFO_DEFAULTTARGET: - aValue <<= _pImp->m_xDocProps->getDefaultTarget(); - break; - case MID_DOCINFO_STATISTIC: - aValue <<= _pImp->m_xDocProps->getDocumentStatistics(); - break; - case MID_DOCINFO_CHARLOCALE: - aValue <<= _pImp->m_xDocProps->getLanguage(); - break; - case MID_CATEGORY: - case MID_MANAGER: - case MID_COMPANY: - { - uno::Reference< document::XCompatWriterDocProperties > xWriterProps( _pImp->m_xDocProps, uno::UNO_QUERY ); - if ( xWriterProps.is() ) - { - if ( nHandle == MID_CATEGORY ) - aValue <<= xWriterProps->getCategory(); - else if ( nHandle == MID_MANAGER ) - aValue <<= xWriterProps->getManager(); - else - aValue <<= xWriterProps->getCompany(); - break; - } - } - - default: - aValue <<= ::rtl::OUString(); - break; - } - - return aValue; -} - -//----------------------------------------------------------------------------- - -sal_Int16 SAL_CALL SfxDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException ) -{ - return FOUR; -} - -//----------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL SfxDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( _pImp->_aMutex ); - if (nIndex < FOUR) - return _pImp->m_UserDefined[nIndex]; - else - return ::rtl::OUString(); -} - -//----------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL SfxDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( _pImp->_aMutex ); - if (nIndex < FOUR) { - ::rtl::OUString name = _pImp->m_UserDefined[nIndex]; - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); - ::rtl::OUString val; - try { - xPropSet->getPropertyValue(name) >>= val; - return val; - } catch (const uno::RuntimeException &) { - throw; - } catch (const uno::Exception &) { - return ::rtl::OUString(); // ignore - } - } else - return ::rtl::OUString(); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException ) -{ - ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex ); - if (nIndex < FOUR) // yes, four! - { - // FIXME this is full of race conditions because the PropertyBag - // can be accessed from clients of the DocumentProperties! - ::rtl::OUString name = _pImp->m_UserDefined[nIndex]; - if (name != aName) { - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), - uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertyContainer> xPropContainer( - _pImp->m_xDocProps->getUserDefinedProperties(), - uno::UNO_QUERY_THROW); - uno::Any value; - try { - value = xPropSet->getPropertyValue(name); - xPropContainer->removeProperty(name); - xPropContainer->addProperty(aName, - beans::PropertyAttribute::REMOVEABLE, value); - _pImp->m_UserDefined[nIndex] = aName; - } catch (const beans::UnknownPropertyException&) { - try { - xPropContainer->addProperty(aName, - beans::PropertyAttribute::REMOVEABLE, - uno::makeAny(::rtl::OUString(""))); - _pImp->m_UserDefined[nIndex] = aName; - } catch (const beans::PropertyExistException&) { - _pImp->m_UserDefined[nIndex] = aName; - // ignore - } - } catch (const beans::PropertyExistException&) { - try { - xPropContainer->addProperty(name, - beans::PropertyAttribute::REMOVEABLE, value); - } catch (const beans::PropertyExistException&) { - // bugger... - } - } catch (const uno::RuntimeException &) { - throw; - } catch (const uno::Exception &) { - // ignore everything else; xPropSet _may_ be corrupted - } - } - } -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException ) -{ - ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex ); - if (nIndex < FOUR) // yes, four! - { - ::rtl::OUString name = _pImp->m_UserDefined[nIndex]; - uno::Reference<beans::XPropertySet> xPropSet( - _pImp->m_xDocProps->getUserDefinedProperties(), - uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertyContainer> xPropContainer( - _pImp->m_xDocProps->getUserDefinedProperties(), - uno::UNO_QUERY_THROW); - uno::Any aAny; - aAny <<= aValue; - try { - uno::Any value = xPropSet->getPropertyValue(name); - if (value != aAny) { - xPropSet->setPropertyValue(name, aAny); - } - } catch (const beans::UnknownPropertyException&) { - try { - // someone removed it, add it back again - xPropContainer->addProperty(name, - beans::PropertyAttribute::REMOVEABLE, aAny); - } catch (const uno::RuntimeException &) { - throw; - } catch (const uno::Exception &) { - // ignore everything else - } - } catch (const uno::RuntimeException &) { - throw; - } catch (const uno::Exception &) { - // ignore everything else - } - } -} - -//----------------------------------------------------------------------------- -SFX_IMPL_XINTERFACE_2( SfxStandaloneDocumentInfoObject, SfxDocumentInfoObject, ::com::sun::star::lang::XServiceInfo, ::com::sun::star::document::XStandaloneDocumentInfo ) -SFX_IMPL_XTYPEPROVIDER_10( SfxStandaloneDocumentInfoObject, ::com::sun::star::document::XDocumentInfo, ::com::sun::star::lang::XComponent, - ::com::sun::star::beans::XPropertySet, ::com::sun::star::beans::XFastPropertySet, ::com::sun::star::beans::XPropertyAccess, - ::com::sun::star::beans::XPropertyContainer, ::com::sun::star::util::XModifiable, ::com::sun::star::util::XModifyBroadcaster, - ::com::sun::star::document::XStandaloneDocumentInfo, ::com::sun::star::lang::XServiceInfo ) - -SFX_IMPL_XSERVICEINFO( SfxStandaloneDocumentInfoObject, "com.sun.star.document.StandaloneDocumentInfo", "com.sun.star.comp.sfx2.StandaloneDocumentInfo" ) -SFX_IMPL_SINGLEFACTORY( SfxStandaloneDocumentInfoObject ) - -SfxStandaloneDocumentInfoObject::SfxStandaloneDocumentInfoObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) - : SfxDocumentInfoObject() - , _xFactory( xFactory ) -{ - uno::Reference< lang::XInitialization > xDocProps( - document::DocumentProperties::create(comphelper::getComponentContext(_xFactory)), - uno::UNO_QUERY_THROW); - uno::Any a; - a <<= xDocProps; - uno::Sequence<uno::Any> args(1); - args[0] = a; - initialize(args); -} - -//----------------------------------------------------------------------------- - -SfxStandaloneDocumentInfoObject::~SfxStandaloneDocumentInfoObject() -{ -} - -//----------------------------------------------------------------------------- - -uno::Reference< embed::XStorage > GetStorage_Impl( const ::rtl::OUString& rName, sal_Bool bWrite, uno::Reference < lang::XMultiServiceFactory >& xFactory ) -{ - // catch unexpected exceptions under solaris - // Client code checks the returned reference but is not interested on error details. - try - { - SolarMutexGuard aSolarGuard; - return ::comphelper::OStorageHelper::GetStorageFromURL( - rName, - bWrite ? embed::ElementModes::READWRITE : embed::ElementModes::READ, - xFactory ); - } - catch(const uno::Exception&) - {} - - return uno::Reference< embed::XStorage >(); -} - -//----------------------------------------------------------------------------- - -sal_Int16 SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldCount() throw( ::com::sun::star::uno::RuntimeException ) -{ - return SfxDocumentInfoObject::getUserFieldCount(); -} - -//----------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldName(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ) -{ - return SfxDocumentInfoObject::getUserFieldName(nIndex); -} - -//----------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL SfxStandaloneDocumentInfoObject::getUserFieldValue(sal_Int16 nIndex) throw( ::com::sun::star::uno::RuntimeException ) -{ - return SfxDocumentInfoObject::getUserFieldValue(nIndex); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxStandaloneDocumentInfoObject::setUserFieldName(sal_Int16 nIndex, const ::rtl::OUString& aName ) throw( ::com::sun::star::uno::RuntimeException ) -{ - SfxDocumentInfoObject::setUserFieldName( nIndex, aName ); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxStandaloneDocumentInfoObject::setUserFieldValue( sal_Int16 nIndex, const ::rtl::OUString& aValue ) throw( ::com::sun::star::uno::RuntimeException ) -{ - SfxDocumentInfoObject::setUserFieldValue( nIndex, aValue ); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxStandaloneDocumentInfoObject::loadFromURL(const ::rtl::OUString& aURL) - throw( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ) -{ - sal_Bool bOK = sal_False; - - ::osl::ClearableMutexGuard aGuard( _pImp->_aMutex ); - uno::Reference< document::XDocumentProperties > xDocProps( - document::DocumentProperties::create(comphelper::getComponentContext(_xFactory)) ); - _pImp->Reset(xDocProps); - aGuard.clear(); - - uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_False, _xFactory ); - if ( xStorage.is() ) - { - try - { - uno::Sequence<beans::PropertyValue> medium(2); - medium[0].Name = ::rtl::OUString("DocumentBaseURL"); - medium[0].Value <<= aURL; - medium[1].Name = ::rtl::OUString("URL"); - medium[1].Value <<= aURL; - _pImp->m_xDocProps->loadFromStorage(xStorage, medium); - _pImp->Reset(_pImp->m_xDocProps); - bOK = sal_True; - } - catch( const uno::Exception& ) - { - } - } - else - { - uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance( - ::rtl::OUString("com.sun.star.document.BinaryStandaloneDocumentInfo" ) ), uno::UNO_QUERY ); - if ( xBinary.is() ) - { - xBinary->loadFromURL( aURL ); - bOK = sal_True; - uno::Reference < document::XStandaloneDocumentInfo > xTarget( static_cast < document::XStandaloneDocumentInfo*> (this), uno::UNO_QUERY ); - Copy( xBinary, xTarget ); - } - } - - if ( !bOK ) - throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTREAD ); -} - -//----------------------------------------------------------------------------- - -void SAL_CALL SfxStandaloneDocumentInfoObject::storeIntoURL(const ::rtl::OUString& aURL) throw( ::com::sun::star::io::IOException ) -{ - sal_Bool bOK = sal_False; - uno::Reference< embed::XStorage > xStorage = GetStorage_Impl( aURL, sal_True, _xFactory ); - if ( xStorage.is() ) - { - try - { - uno::Sequence<beans::PropertyValue> medium(2); - medium[0].Name = ::rtl::OUString("DocumentBaseURL"); - medium[0].Value <<= aURL; - medium[1].Name = ::rtl::OUString("URL"); - medium[1].Value <<= aURL; - - _pImp->m_xDocProps->storeToStorage(xStorage, medium); - bOK = sal_True; - } - catch( const io::IOException & ) - { - throw; - } - catch( const uno::RuntimeException& ) - { - throw; - } - catch( const uno::Exception& ) - { - } - } - else - { - uno::Reference < document::XStandaloneDocumentInfo > xBinary( _xFactory->createInstance( - ::rtl::OUString("com.sun.star.document.BinaryStandaloneDocumentInfo" ) ), uno::UNO_QUERY ); - if ( xBinary.is() ) - { - Copy( this, xBinary ); - xBinary->storeIntoURL( aURL ); - bOK = sal_True; - } - } - - if ( !bOK ) - throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_CANTWRITE ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 276b1b7bbb09..57e8f27d4609 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -46,6 +46,7 @@ #include <com/sun/star/document/DocumentProperties.hpp> #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp> #include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/util/XCloneable.hpp> #include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service #include <cppuhelper/interfacecontainer.hxx> @@ -91,7 +92,6 @@ #include <sfx2/docfile.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/request.hxx> -#include <sfx2/objuno.hxx> #include <sfx2/printer.hxx> #include <sfx2/basmgr.hxx> #include <sfx2/event.hxx> @@ -187,7 +187,6 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument ::cppu::OMultiTypeInterfaceContainerHelper m_aInterfaceContainer ; uno::Reference< uno::XInterface > m_xParent ; uno::Reference< frame::XController > m_xCurrent ; - uno::Reference< document::XDocumentInfo > m_xDocumentInfo ; uno::Reference< document::XDocumentProperties > m_xDocumentProperties; uno::Reference< script::XStarBasicAccess > m_xStarBasicAccess ; uno::Reference< container::XNameReplace > m_xEvents ; @@ -813,13 +812,6 @@ void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeExcept lang::EventObject aEvent( (frame::XModel *)this ); m_pData->m_aInterfaceContainer.disposeAndClear( aEvent ); - if ( m_pData->m_xDocumentInfo.is() ) - { - // as long as an SfxObjectShell is assigned to an SfxBaseModel it is still existing here - // so we can't dispose the shared DocumentInfoObject here - m_pData->m_xDocumentInfo = 0; - } - m_pData->m_xDocumentProperties.clear(); m_pData->m_xDocumentMetadata.clear(); @@ -859,53 +851,6 @@ void SAL_CALL SfxBaseModel::removeEventListener( const uno::Reference< XEVENTLIS m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference< XEVENTLISTENER >*)0), aListener ); } -//________________________________________________________________________________________________________ -// document::XDocumentInfoSupplier -//________________________________________________________________________________________________________ - -uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo() throw(::com::sun::star::uno::RuntimeException) -{ - SfxModelGuard aGuard( *this, SfxModelGuard::E_INITIALIZING ); - if ( !m_pData->m_xDocumentInfo.is() ) - { - // WARNING: this will only work if (when loading a document) the - // document meta-data has already been read and completely written - // into the XDocumentProperties at this point - // ==> DO NOT call getDocumentInfo before document info has been read! - uno::Reference< document::XDocumentInfo > xDocInfo = - new SfxDocumentInfoObject; - uno::Reference< document::XDocumentProperties > xDocProps = - getDocumentProperties(); - uno::Sequence< uno::Any > args(1); - args[0] <<= xDocProps; - uno::Reference< lang::XInitialization > xInit( - xDocInfo, uno::UNO_QUERY_THROW); - try { - xInit->initialize(args); - ((SfxBaseModel*)this)->m_pData->m_xDocumentInfo = xDocInfo; - } catch (uno::RuntimeException &) { - throw; - } catch (const uno::Exception & e) { - throw lang::WrappedTargetRuntimeException(::rtl::OUString( - "SfxBaseModel::getDocumentInfo: cannot initialize"), *this, - uno::makeAny(e)); - } - try { - rtl::OUString aName("MediaType"); - uno::Reference < beans::XPropertySet > xSet( - getDocumentStorage(), uno::UNO_QUERY_THROW ); - uno::Any aMediaType = xSet->getPropertyValue( aName ); - uno::Reference < beans::XPropertySet > xDocSet( - m_pData->m_xDocumentInfo, uno::UNO_QUERY_THROW ); - xDocSet->setPropertyValue( aName, aMediaType ); - } catch (uno::Exception &) { - //ignore - } - } - - return m_pData->m_xDocumentInfo; -} - void IMPL_SfxBaseModel_DataContainer::impl_setDocumentProperties( const uno::Reference< document::XDocumentProperties >& rxNewDocProps) @@ -3086,47 +3031,28 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL uno::Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo(); m_pData->m_pObjectShell->SetModifyPasswordInfo( aModifyPasswordInfo ); - // since saving a document modifies its DocumentInfo, the current - // DocumentInfo must be saved on "SaveTo", so it can be restored + // since saving a document modifies its DocumentProperties, the current + // DocumentProperties must be saved on "SaveTo", so it can be restored // after saving sal_Bool bCopyTo = bSaveTo || m_pData->m_pObjectShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED; uno::Reference<document::XDocumentProperties> xOldDocProps; - uno::Reference<document::XDocumentInfo> xOldDocInfo; if ( bCopyTo ) { xOldDocProps = getDocumentProperties(); - if (m_pData->m_xDocumentInfo.is()) - { - xOldDocInfo = getDocumentInfo(); - const Reference<util::XCloneable> xCloneable(xOldDocInfo, - UNO_QUERY_THROW); - const Reference<document::XDocumentInfo> xNewDocInfo( - xCloneable->createClone(), UNO_QUERY_THROW); - const Reference<document::XDocumentPropertiesSupplier> xDPS( - xNewDocInfo, UNO_QUERY_THROW); - const Reference<document::XDocumentProperties> xNewDocProps( - xDPS->getDocumentProperties()); - m_pData->m_xDocumentProperties = xNewDocProps; - m_pData->m_xDocumentInfo = xNewDocInfo; - } - else // try not to create DocumentInfo if it does not exist... - { - const Reference<util::XCloneable> xCloneable(xOldDocProps, - UNO_QUERY_THROW); - const Reference<document::XDocumentProperties> xNewDocProps( - xCloneable->createClone(), UNO_QUERY_THROW); - m_pData->m_xDocumentProperties = xNewDocProps; - } + const Reference<util::XCloneable> xCloneable(xOldDocProps, + UNO_QUERY_THROW); + const Reference<document::XDocumentProperties> xNewDocProps( + xCloneable->createClone(), UNO_QUERY_THROW); + m_pData->m_xDocumentProperties = xNewDocProps; } sal_Bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams ); if ( bCopyTo ) { - // restore DocumentInfo if a copy was created + // restore DocumentProperties if a copy was created m_pData->m_xDocumentProperties = xOldDocProps; - m_pData->m_xDocumentInfo = xOldDocInfo; } uno::Reference < task::XInteractionHandler > xHandler; diff --git a/sfx2/util/sfx.component b/sfx2/util/sfx.component index b05a67302e0a..567e10a6ed80 100644 --- a/sfx2/util/sfx.component +++ b/sfx2/util/sfx.component @@ -63,7 +63,4 @@ <implementation name="com.sun.star.comp.sfx2.SfxMacroLoader"> <service name="com.sun.star.frame.ProtocolHandler"/> </implementation> - <implementation name="com.sun.star.comp.sfx2.StandaloneDocumentInfo"> - <service name="com.sun.star.document.StandaloneDocumentInfo"/> - </implementation> </component> diff --git a/sfx2/util/sfx.xml b/sfx2/util/sfx.xml index 660744547876..b188878f05cd 100644 --- a/sfx2/util/sfx.xml +++ b/sfx2/util/sfx.xml @@ -70,18 +70,6 @@ <supported-service> com.sun.star.frame.ProtocolHandler </supported-service> </component-description> - <component-description> - <author> Mathias Bauer </author> - <name> com.sun.star.comp.sfx2.StandaloneDocumentInfo </name> - <description> - StandaloneDocumentInfo. - </description> - <loader-name> com.sun.star.loader.SharedLibrary </loader-name> - <language> c++ </language> - <status value="final"/> - <supported-service> com.sun.star.document.StandaloneDocumentInfo </supported-service> - </component-description> - <project-build-dependency> cppu </project-build-dependency> <project-build-dependency> cppuhelper </project-build-dependency> <project-build-dependency> sal </project-build-dependency> |