javacommons/jvms/nativeportlayer/src.s60/javafile.cpp
changeset 80 d6dafc5d983f
parent 21 2a9601315dfc
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include "javafile.h"
    20 #include "javafile.h"
    21 
    21 
    22 using namespace javaruntime;
    22 using namespace javaruntime;
    23 
    23 
    24 //*****************************************************************************
    24 //*****************************************************************************
    25 MJavaFile* CJavaFile::NewL()
       
    26 {
       
    27     JELOG2(EJVM);
       
    28     CJavaFile* self = new(ELeave) CJavaFile();
       
    29     CleanupStack::PushL(self);
       
    30     self->ConstructL();
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33 }
       
    34 
       
    35 //*****************************************************************************
       
    36 CJavaFile::CJavaFile(): iJavaFileMode(EJavaFileClosed)
    25 CJavaFile::CJavaFile(): iJavaFileMode(EJavaFileClosed)
    37 {
       
    38     JELOG2(EJVM);
       
    39 }
       
    40 
       
    41 //*****************************************************************************
       
    42 void CJavaFile::ConstructL()
       
    43 {
    26 {
    44     JELOG2(EJVM);
    27     JELOG2(EJVM);
    45 }
    28 }
    46 
    29 
    47 //*****************************************************************************
    30 //*****************************************************************************
    79         LOG1(EJVM, EInfo,"Opening file %S using CAF", mFileName.c_str());
    62         LOG1(EJVM, EInfo,"Opening file %S using CAF", mFileName.c_str());
    80         iJavaFileMode = EJavaFileOpenForCaf; //This is set before opening
    63         iJavaFileMode = EJavaFileOpenForCaf; //This is set before opening
    81         //in order to allow proper
    64         //in order to allow proper
    82         //cleanup if something fails.
    65         //cleanup if something fails.
    83         TRAP(status, OpenCafL(aFileName));
    66         TRAP(status, OpenCafL(aFileName));
    84         if (status != KErrNone)
       
    85         {
       
    86             // Clean up and set the class ready for opening another file.
       
    87             Close();
       
    88         }
       
    89     }
    67     }
    90     else
    68     else
    91     {
    69     {
    92         // Using RFile
    70         // Using RFile
    93         LOG1(EJVM, EInfo,"Opening file %S using RFile", mFileName.c_str());
    71         LOG1(EJVM, EInfo,"Opening file %S using RFile", mFileName.c_str());
    94         status = iNormalFile.Open(aFs, aFileName, aFileMode);
    72         status = iNormalFile.Open(aFs, aFileName, aFileMode);
    95         if (status == KErrNone)
    73         if (status == KErrNone)
    96         {
    74         {
    97             iJavaFileMode = EJavaFileOpenForNormalFile;
    75             iJavaFileMode = EJavaFileOpenForNormalFile;
    98         }
    76         }
    99         // No need for cleaning.
    77     }
       
    78     if (status != KErrNone)
       
    79     {
       
    80         // Clean up and set the class ready for opening another file.
       
    81         Close();
   100     }
    82     }
   101     return status;
    83     return status;
   102 }
    84 }
   103 
    85 
   104 //*****************************************************************************
    86 //*****************************************************************************
   174 }
   156 }
   175 
   157 
   176 //*****************************************************************************
   158 //*****************************************************************************
   177 TInt CJavaFile::Read(TDes8& aDes) const
   159 TInt CJavaFile::Read(TDes8& aDes) const
   178 {
   160 {
   179     //JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   161     JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   180     if (iJavaFileMode == EJavaFileOpenForCaf)
   162     if (iJavaFileMode == EJavaFileOpenForCaf)
   181     {
   163     {
   182         //Using CAF
   164         //Using CAF
   183         return iCafData->Read(aDes);
   165         return iCafData->Read(aDes);
   184     }
   166     }
   190 }
   172 }
   191 
   173 
   192 //*****************************************************************************
   174 //*****************************************************************************
   193 TInt CJavaFile::Read(TDes8& aDes, TInt aLength) const
   175 TInt CJavaFile::Read(TDes8& aDes, TInt aLength) const
   194 {
   176 {
   195     //JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   177     JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   196     if (iJavaFileMode == EJavaFileOpenForCaf)
   178     if (iJavaFileMode == EJavaFileOpenForCaf)
   197     {
   179     {
   198         //Using CAF
   180         //Using CAF
   199         return iCafData->Read(aDes, aLength);
   181         return iCafData->Read(aDes, aLength);
   200     }
   182     }
   208 //*****************************************************************************
   190 //*****************************************************************************
   209 TInt CJavaFile::Replace(RFs& aFs,const TDesC& aName,TUint aFileMode)
   191 TInt CJavaFile::Replace(RFs& aFs,const TDesC& aName,TUint aFileMode)
   210 {
   192 {
   211     JELOG2(EJVM);
   193     JELOG2(EJVM);
   212     //Using RFile
   194     //Using RFile
       
   195     if (iJavaFileMode != EJavaFileClosed)
       
   196     {
       
   197         // Not allowed if some file is already opened and not properly closed.
       
   198         return KErrInUse;
       
   199     }
   213     TInt status = iNormalFile.Replace(aFs, aName, aFileMode);
   200     TInt status = iNormalFile.Replace(aFs, aName, aFileMode);
   214     if (status == KErrNone)
   201     if (status == KErrNone)
   215     {
   202     {
   216         iJavaFileMode = EJavaFileOpenForNormalFile;
   203         iJavaFileMode = EJavaFileOpenForNormalFile;
   217     }
   204     }
   322 }
   309 }
   323 
   310 
   324 //*****************************************************************************
   311 //*****************************************************************************
   325 TInt CJavaFile::Seek(TSeek aMode,TInt& aPos) const
   312 TInt CJavaFile::Seek(TSeek aMode,TInt& aPos) const
   326 {
   313 {
   327 //        JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   314     JELOG4(EJVM, EEntry & EInfoHeavyLoad);
   328     if (iJavaFileMode == EJavaFileOpenForCaf)
   315     if (iJavaFileMode == EJavaFileOpenForCaf)
   329     {
   316     {
   330         //Using CAF
   317         //Using CAF
   331         return iCafData->Seek(aMode, aPos);
   318         return iCafData->Seek(aMode, aPos);
   332     }
   319     }
   358 {
   345 {
   359     TParse filename;
   346     TParse filename;
   360     filename.Set(aFileName, NULL, NULL);
   347     filename.Set(aFileName, NULL, NULL);
   361     TPtrC filenameExt = filename.Ext();
   348     TPtrC filenameExt = filename.Ext();
   362 
   349 
   363     if (filenameExt.CompareF(_L(".dm")) == 0 ||
   350     _LIT(KDmExtension, ".dm");
   364             filenameExt.CompareF(_L(".dcf")) == 0)
   351     _LIT(KDcfExtension, ".dcf");
       
   352     if (filenameExt.CompareF(KDmExtension) == 0 ||
       
   353             filenameExt.CompareF(KDcfExtension) == 0)
   365     {
   354     {
   366         // Filename extension indicates this is a DRM protected file.
   355         // Filename extension indicates this is a DRM protected file.
   367         return ETrue;
   356         return ETrue;
   368     }
   357     }
   369 
   358 
   370     if (filenameExt.CompareF(_L(".jar")) != 0)
   359     _LIT(KJarExtension, ".jar");
       
   360     if (filenameExt.CompareF(KJarExtension) != 0)
   371     {
   361     {
   372         // Filename extension indicates this is not a jar file,
   362         // Filename extension indicates this is not a jar file,
   373         // assume it is not DRM protected.
   363         // assume it is not DRM protected.
   374         return EFalse;
   364         return EFalse;
   375     }
   365     }
   376 
   366 
   377     RProcess thisProcess;
   367     RProcess thisProcess;
   378     TName thisProcessName = thisProcess.Name();
   368     TName thisProcessName = thisProcess.Name();
   379     if (KErrNotFound == thisProcessName.FindF(_L("Installer")))
   369     _LIT(KInstallerName, "Installer");
       
   370     if (KErrNotFound == thisProcessName.FindF(KInstallerName))
   380     {
   371     {
   381         // We are not running in JavaInstaller process,
   372         // We are not running in JavaInstaller process,
   382         // do not check if file is DRM protected from CAF
   373         // do not check if file is DRM protected from CAF
   383         // but assume that file is not DRM protected.
   374         // but assume that file is not DRM protected.
   384         return EFalse;
   375         return EFalse;
   385     }
   376     }
   386 
   377 
   387     // Check from CAF if file is DRM protected.
   378     // Check from CAF if file is DRM protected.
   388     TBool drmFile = EFalse;
   379     TBool drmFile = EFalse;
   389     if (NULL == iCafContent)
   380     TRAP_IGNORE(iCafContent = ContentAccess::CContent::NewL(aFileName));
   390     {
   381     if (NULL != iCafContent)
   391         TRAP_IGNORE(iCafContent = ContentAccess::CContent::NewL(aFileName));
   382     {
   392         if (NULL != iCafContent)
   383         TInt value = 0;
       
   384         TInt err = iCafContent->GetAttribute(
       
   385                        ContentAccess::EIsProtected, value);
       
   386         if (KErrNone == err && value)
   393         {
   387         {
   394             TInt value = 0;
   388             // This is a DRM file.
   395             TInt err = iCafContent->GetAttribute(
   389             drmFile = ETrue;
   396                            ContentAccess::EIsProtected, value);
       
   397             if (KErrNone == err && value)
       
   398             {
       
   399                 // This is a DRM file.
       
   400                 drmFile = ETrue;
       
   401             }
       
   402             else
       
   403             {
       
   404                 // Not a DRM file, delete iCafContent instance.
       
   405                 delete iCafContent;
       
   406                 iCafContent = NULL;
       
   407             }
       
   408         }
   390         }
       
   391         else
       
   392         {
       
   393             // Not a DRM file, delete iCafContent instance.
       
   394             delete iCafContent;
       
   395             iCafContent = NULL;
       
   396         }
   409     }
   397     }
   410     return drmFile;
   398     return drmFile;
   411 }
   399 }
   412 
       
   413 
       
   414 EXPORT_C void Dummy1() {}
       
   415 EXPORT_C void Dummy2() {}
       
   416 EXPORT_C void Dummy3() {}
       
   417 EXPORT_C void Dummy4() {}
       
   418 EXPORT_C void Dummy5() {}
       
   419 EXPORT_C void Dummy6() {}
       
   420 EXPORT_C void Dummy7() {}
       
   421 EXPORT_C void Dummy8() {}
       
   422 EXPORT_C void Dummy9() {}