os/security/contentmgmt/contentaccessfwfordrm/source/caf/supplieroutputfile.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 #include <apgcli.h>
    19 #include <apmstd.h>
    20 #include <caf/supplieroutputfile.h>
    21 
    22 #include <caf/caftypes.h>
    23 #include "resolver.h"
    24 
    25 #ifndef REMOVE_CAF1
    26 #include <caf/attribute.h>
    27 #include <caf/content.h>
    28 #include <caf/bitset.h>
    29 #endif
    30 
    31 
    32 using namespace ContentAccess;
    33 
    34 #ifndef REMOVE_CAF1
    35 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType)
    36 	{
    37 	return CSupplierOutputFile::NewL(aFileName, aOutputType, KNullDesC8());
    38 	}
    39 #endif
    40 
    41 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType, const TDesC8& aMimeType)
    42 	{
    43 	CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
    44 	CleanupStack::PushL(self);
    45 	self->ConstructL(aFileName, aMimeType, aOutputType);
    46 	CleanupStack::Pop(self);
    47 	return self;
    48 	}
    49 
    50 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(RReadStream& aStream)
    51 	{
    52 	CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
    53 	CleanupStack::PushL(self);
    54 	self->InternalizeL(aStream);
    55 	CleanupStack::Pop(self);
    56 	return self;		
    57 	}
    58 
    59 CSupplierOutputFile::CSupplierOutputFile()
    60 	{
    61 	}
    62 	
    63 
    64 void CSupplierOutputFile::ConstructL(const TDesC& aFileName, const TDesC8& aMimeType, const TOutputType aOutputType)
    65 	{
    66 	iOutputType = aOutputType;
    67 	
    68 	CAgentResolver *resolver = CAgentResolver::NewL(EFalse);
    69 	CleanupStack::PushL(resolver);
    70 	iFileName = resolver->ConvertAgentFileNameL(aFileName);
    71 	CleanupStack::PopAndDestroy(resolver);
    72 	iMimeType.Copy(aMimeType);
    73 	
    74 	// convert mime type to lower case
    75 	iMimeType.LowerCase();
    76 	}
    77 
    78 
    79 CSupplierOutputFile::~CSupplierOutputFile()
    80 	{
    81 	delete iFileName;
    82 #ifndef REMOVE_CAF1
    83 	delete iAttr;
    84 #endif
    85 	}
    86 
    87 
    88 EXPORT_C TPtrC CSupplierOutputFile::FileName() const
    89 	{
    90 	return *iFileName;
    91 	}
    92 
    93 EXPORT_C TOutputType CSupplierOutputFile::OutputType() const
    94 	{
    95 	return iOutputType;
    96 	}
    97 
    98 EXPORT_C TPtrC8 CSupplierOutputFile::MimeTypeL()
    99 	{
   100 	TUid uid;
   101 	TDataType dataType;
   102 	RApaLsSession apparcSession;
   103 
   104 	if(iMimeType.Length() == 0)
   105 		{
   106 		// Use the Application Architecture Server to find the Mime type of the output File
   107 		User::LeaveIfError(apparcSession.Connect());
   108 		CleanupClosePushL(apparcSession);
   109 		    
   110    		// Use a temp FS session to preserve platsec 
   111 		RFs tempFsSession; 
   112 		User::LeaveIfError(tempFsSession.Connect());     
   113 	  	CleanupClosePushL(tempFsSession);
   114 	  	User::LeaveIfError(tempFsSession.ShareProtected());  
   115 	  	
   116 	  	// Open file here and send the handle because AppArc doesn't have Allfiles capability
   117 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   118 	  	// If file size is greater than 2GB than RFile::Open will fail with KErrTooBig.
   119 	  	// So RFile64.
   120 	  	RFile64 tempFile; 
   121 #else
   122 	  	RFile tempFile;
   123 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   124 	  	User::LeaveIfError(tempFile.Open(tempFsSession, *iFileName, EFileRead|EFileShareAny)); 
   125 	  	CleanupClosePushL(tempFile); 
   126    
   127 		User::LeaveIfError(apparcSession.AppForDocument(tempFile, uid, dataType)); 
   128 
   129 		iMimeType.Copy(dataType.Des8().Left(KMaxDataTypeLength)); 
   130 
   131 		CleanupStack::PopAndDestroy(&tempFile); // close 
   132 		CleanupStack::PopAndDestroy(&tempFsSession);    // close 
   133 		CleanupStack::PopAndDestroy(&apparcSession);	// close
   134 		}
   135 
   136 	return iMimeType;
   137 	}
   138 
   139 EXPORT_C void CSupplierOutputFile::ExternalizeL(RWriteStream& aStream) const
   140 	{
   141 	aStream.WriteInt32L(static_cast <TInt> (iOutputType));
   142 	aStream.WriteInt32L(iFileName->Des().Length());
   143 	aStream.WriteL(*iFileName);
   144 	aStream.WriteInt32L(iMimeType.Length());
   145 	aStream.WriteL(iMimeType);
   146 	}
   147 
   148 void CSupplierOutputFile::InternalizeL(RReadStream& aStream)
   149 	{
   150 	TInt length = 0;
   151 	iOutputType = static_cast <TOutputType> (aStream.ReadInt32L());
   152 	length = aStream.ReadInt32L();
   153 	iFileName = HBufC::NewL(length);
   154 	if(length)
   155 		{
   156 		TPtr filename = iFileName->Des();
   157 		aStream.ReadL(filename, length);
   158 		}
   159 	length = aStream.ReadInt32L();
   160 	aStream.ReadL(iMimeType, length);
   161 	}
   162 
   163 
   164 
   165 #ifndef REMOVE_CAF1
   166 EXPORT_C CAttribute &  CSupplierOutputFile::AttributesL (TBool aPreloaded) 
   167 	{
   168 	// retrieve the attributes, only need to do this once since this instance
   169 	// will only ever refer to one output file 
   170 	if(!iAttr)
   171 		{
   172 		// create a content consumer interface for the output file produced
   173 		CContent* content = CContent::NewLC(FileName());	
   174 		iAttr = content->NewAttributeL(ETrue);
   175 		CleanupStack::PopAndDestroy(content);
   176 		}
   177 	else if(aPreloaded)  // update all attribute bits
   178 		{
   179 		CBitset &bitset = iAttr->QuerySet();
   180 		bitset.SetAll();
   181 		iAttr->GetL();
   182 		}
   183 	return *iAttr;
   184 	}
   185 #endif // #ifndef REMOVE_CAF1