From 3269035ee8f15af7484d1247a349cd38a6fa7fde Mon Sep 17 00:00:00 2001
From: Martin Gallwey <mtg@openoffice.org>
Date: Thu, 15 Nov 2001 19:27:48 +0000
Subject: #94679#, #92268# support XServiceInfo and XTypeProvider

---
 package/source/zippackage/ZipPackageStream.cxx | 63 +++++++++++++++++--------
 package/source/zippackage/ZipPackageStream.hxx | 64 ++++++++++----------------
 2 files changed, 68 insertions(+), 59 deletions(-)

(limited to 'package/source')

diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 9a2b8ac920d5..5665421cf059 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: ZipPackageStream.cxx,v $
  *
- *  $Revision: 1.27 $
+ *  $Revision: 1.28 $
  *
- *  last change: $Author: mtg $ $Date: 2001-10-02 22:27:29 $
+ *  last change: $Author: mtg $ $Date: 2001-11-15 20:27:47 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -83,29 +83,18 @@ using namespace com::sun::star;
 using namespace cppu;
 using namespace rtl;
 
-::cppu::class_data5 ZipPackageStream::s_cd =
-{
-    5 +1, sal_False, sal_False,
-    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
-    {
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSink > const * )) &getCppuType, ((sal_Int32)(::com::sun::star::io::XActiveDataSink *) (ZipPackageStream * ) 16) - 16 },
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > const * )) &getCppuType, ((sal_Int32)(::com::sun::star::beans::XPropertySet *) (ZipPackageStream * ) 16) - 16 },
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed > const * ))   &getCppuType, ((sal_Int32)(::com::sun::star::container::XNamed *)   (ZipPackageStream * ) 16) - 16 },
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > const * ))   &getCppuType, ((sal_Int32)(::com::sun::star::container::XChild *)   (ZipPackageStream * ) 16) - 16 },
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > const * ))    &getCppuType, ((sal_Int32)(::com::sun::star::lang::XUnoTunnel *)    (ZipPackageStream * ) 16) - 16 },
-        { (::cppu::fptr_getCppuType)(::com::sun::star::uno::Type const & (SAL_CALL *)( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider > const * )) &getCppuType, ((sal_Int32)(::com::sun::star::lang::XTypeProvider *) (ZipPackageStream * ) 16) - 16 }
-    }
-};
+Sequence < sal_Int8 > ZipPackageStream::aImplementationId = Sequence < sal_Int8 > ();
 
 ZipPackageStream::ZipPackageStream (ZipPackage & rNewPackage )
 : rZipPackage(rNewPackage)
 , bToBeCompressed ( sal_True )
 , bToBeEncrypted ( sal_False )
+, bIsEncrypted ( sal_False )
 , bPackageMember ( sal_False )
 , bHaveOwnKey ( sal_False )
 , xEncryptionData ( )
-, ZipPackageEntry ( false )
 {
+    SetFolder ( sal_False );
     aEntry.nVersion     = -1;
     aEntry.nFlag        = 0;
     aEntry.nMethod      = -1;
@@ -114,6 +103,8 @@ ZipPackageStream::ZipPackageStream (ZipPackage & rNewPackage )
     aEntry.nCompressedSize  = -1;
     aEntry.nSize        = -1;
     aEntry.nOffset      = -1;
+    if ( !aImplementationId.getLength() )
+        aImplementationId = getImplementationId();
 }
 
 ZipPackageStream::~ZipPackageStream( void )
@@ -151,7 +142,7 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream( )
         {
             if ( !xEncryptionData.isEmpty() && !bHaveOwnKey )
                 xEncryptionData->aKey = rZipPackage.getEncryptionKey();
-            return rZipPackage.getZipFile().getRawStream(aEntry, xEncryptionData);
+            return rZipPackage.getZipFile().getRawStream(aEntry, xEncryptionData, bIsEncrypted );
         }
         catch (ZipException &)//rException)
         {
@@ -172,7 +163,7 @@ Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream(  )
         {
             if ( !xEncryptionData.isEmpty() && !bHaveOwnKey )
                 xEncryptionData->aKey = rZipPackage.getEncryptionKey();
-            return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData);
+            return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData, bIsEncrypted );
         }
         catch (ZipException &)//rException)
         {
@@ -190,7 +181,7 @@ sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& a
 {
     sal_Int64 nMe = 0;
     if ( aIdentifier.getLength() == 16 &&
-         0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
+         0 == rtl_compareMemory( static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
         nMe = reinterpret_cast < sal_Int64 > ( this );
     return nMe;
 }
@@ -225,7 +216,21 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName,
             xEncryptionData = new EncryptionData;
         bHaveOwnKey = bToBeEncrypted = sal_True;
         if ( !( aValue >>= xEncryptionData->aKey ) )
-            throw IllegalArgumentException();
+        {
+            OUString sTempString;
+            if ( ( aValue >>= sTempString ) )
+            {
+                sal_Int32 nNameLength = sTempString.getLength();
+                Sequence < sal_Int8 > aSequence ( nNameLength );
+                sal_Int8 *pArray = aSequence.getArray();
+                const sal_Unicode *pChar = sTempString.getStr();
+                for ( sal_Int16 i = 0; i < nNameLength; i++)
+                    pArray[i] = static_cast < const sal_Int8 > (pChar[i]);
+                xEncryptionData->aKey = aSequence;
+            }
+            else
+                throw IllegalArgumentException();
+        }
     }
 #if SUPD>617
     else if (aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
@@ -279,3 +284,21 @@ void ZipPackageStream::setSize (const sal_Int32 nNewSize)
         aEntry.nMethod = DEFLATED;
     aEntry.nSize = nNewSize;
 }
+OUString ZipPackageStream::getImplementationName()
+    throw (RuntimeException)
+{
+    return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) );
+}
+
+Sequence< OUString > ZipPackageStream::getSupportedServiceNames()
+    throw (RuntimeException)
+{
+    Sequence< OUString > aNames(1);
+    aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) );
+    return aNames;
+}
+sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName )
+    throw (RuntimeException)
+{
+    return rServiceName == getSupportedServiceNames()[0];
+}
diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/source/zippackage/ZipPackageStream.hxx
index 6a9a6bb1fb9f..a1a37a861916 100644
--- a/package/source/zippackage/ZipPackageStream.hxx
+++ b/package/source/zippackage/ZipPackageStream.hxx
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: ZipPackageStream.hxx,v $
  *
- *  $Revision: 1.10 $
+ *  $Revision: 1.11 $
  *
- *  last change: $Author: mtg $ $Date: 2001-10-02 22:29:08 $
+ *  last change: $Author: mtg $ $Date: 2001-11-15 20:27:48 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -73,28 +73,30 @@
 #ifndef _ENCRYPTION_DATA_HXX_
 #include <EncryptionData.hxx>
 #endif
-#ifndef _CPPUHELPER_IMPLBASE5_HXX
-#include <cppuhelper/implbase5.hxx>
+#ifndef _CPPUHELPER_IMPLBASE1_HXX
+#include <cppuhelper/implbase1.hxx>
 #endif
 
 
 class ZipPackage;
 struct ZipEntry;
-class ZipPackageStream : public ZipPackageEntry,
-                         public cppu::OWeakObject,
-                         public ::com::sun::star::io::XActiveDataSink,
-                         public ::com::sun::star::lang::XTypeProvider
+class ZipPackageStream : public cppu::ImplInheritanceHelper1
+<
+    ZipPackageEntry,
+    ::com::sun::star::io::XActiveDataSink
+>
 {
-    static cppu::class_data5 s_cd;
+    static com::sun::star::uno::Sequence < sal_Int8 > aImplementationId;
 protected:
     com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
     ZipPackage          &rZipPackage;
-    sal_Bool            bToBeCompressed, bToBeEncrypted, bPackageMember, bHaveOwnKey;
+    sal_Bool            bToBeCompressed, bToBeEncrypted, bPackageMember, bHaveOwnKey, bIsEncrypted;
     vos::ORef < EncryptionData > xEncryptionData;
 public:
     sal_Bool HasOwnKey ()        { return bHaveOwnKey;}
     sal_Bool IsToBeCompressed () { return bToBeCompressed;}
     sal_Bool IsToBeEncrypted ()  { return bToBeEncrypted;}
+    sal_Bool IsEncrypted ()      { return bIsEncrypted;}
     sal_Bool IsPackageMember ()  { return bPackageMember;}
     vos::ORef < EncryptionData > & getEncryptionData ()
     { return xEncryptionData;}
@@ -112,11 +114,14 @@ public:
     { return aEntry.nSize;}
 
     void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;}
+    void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;}
     void SetToBeEncrypted (sal_Bool bNewValue)
     {
         bToBeEncrypted  = bNewValue;
         if ( bToBeEncrypted && xEncryptionData.isEmpty())
             xEncryptionData = new EncryptionData;
+        else if ( !bToBeEncrypted && !xEncryptionData.isEmpty() )
+            xEncryptionData.unbind();
     }
     void SetPackageMember (sal_Bool bNewValue)  { bPackageMember  = bNewValue;}
     void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey )
@@ -138,31 +143,9 @@ public:
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream( )
         throw(::com::sun::star::uno::RuntimeException);
 
-    // XTypeProvider
-    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
-        throw (::com::sun::star::uno::RuntimeException)
+    static ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId()
     {
-        return cppu::WeakImplHelper_getTypes( ( cppu::class_data *)&s_cd );
-    }
-    virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  )
-        throw (::com::sun::star::uno::RuntimeException)
-    {
-        return cppu::ImplHelper_getImplementationId ( ( cppu::class_data * ) &s_cd );
-    }
-
-    // XInterface
-    virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
-        throw(::com::sun::star::uno::RuntimeException)
-    {
-        return cppu::WeakImplHelper_query ( rType, (cppu::class_data *) &s_cd, this, (cppu::OWeakObject *)this );
-    }
-    virtual void SAL_CALL acquire() throw ()
-    {
-        OWeakObject::acquire();
-    }
-    virtual void SAL_CALL release() throw ()
-    {
-        OWeakObject::release();
+        return aImplementationId;
     }
 
     // XActiveDataSink
@@ -172,10 +155,6 @@ public:
         throw(::com::sun::star::uno::RuntimeException);
 
     // XUnoTunnel
-    static ::com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void )
-    {
-        return cppu::ImplHelper_getImplementationId ( ( cppu::class_data * ) &s_cd );
-    }
     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
         throw(::com::sun::star::uno::RuntimeException);
 
@@ -184,6 +163,13 @@ public:
         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);
     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName )
         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
-};
 
+    // XServiceInfo
+    virtual ::rtl::OUString SAL_CALL getImplementationName(  )
+        throw (::com::sun::star::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+        throw (::com::sun::star::uno::RuntimeException);
+    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
+        throw (::com::sun::star::uno::RuntimeException);
+};
 #endif
-- 
cgit