//----------------------------------------------------------------------------------------
// FetchAdsFileFromPath
//----------------------------------------------------------------------------------------
bool
ZMFileUtils::FetchAdsFileFromPath(
	const PMString&						parentPath,
	ZMPMStringSList &					oAdsList,
	const PMString&						inFilePrefix) const
{
	LogFunctionEnterExit;
	
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "From path : %s", parentPath.GrabCString());
	SDKFileHelper fileHelper(parentPath);
	IDFile fileId = fileHelper.GetIDFile();
	PlatformFileSystemIterator iter;
	if(!iter.IsDirectory(fileId))
		return false;

	iter.SetStartingPath(fileId);

	Utils<IZMAdFileFacade> adFileUtil;
	bool result = false;
	IDFile xmlIdFile;

	PMString filter(inFilePrefix);
	filter.Append("*.xml");
	filter.InsertW(FileUtils::GetDirectorySeperator(), 0);
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "File filter : %s", filter.GrabCString());

	bool16 hasNext = iter.FindFirstFile(xmlIdFile, filter);

	while(hasNext) {
		SDKFileHelper xmlFileHelper(xmlIdFile);
		
		PMString xmlFileName = xmlIdFile.GetFileName();
		if(ValidPath(xmlFileName))
		{
#ifdef MACINTOSH
			PMString extStr(".xml");
			extStr.SetTranslatable(kFalse);
			if (! VerifyPrefixAndSuffix(xmlFileName, inFilePrefix, extStr))
			{
				hasNext= iter.FindNextFile(xmlIdFile);
				continue;
			}
#endif
			
			PMString xmlFullPath (parentPath);
			xmlFullPath.Append(FileUtils::GetDirectorySeperator());
			xmlFullPath.Append(xmlFileName);

			if (adFileUtil->CanBeValidXMLFile(xmlFullPath))
			{
				oAdsList.push_back(new PMString(xmlIdFile.GetFileName()));
				result = true;
			}
		}

		hasNext= iter.FindNextFile(xmlIdFile);
	}

	return result;
}
//----------------------------------------------------------------------------------------
// MakeFullAdFilePath
//----------------------------------------------------------------------------------------
PMString
ZMAdFileFacade::MakeFullAdFilePath(
	const IZMAdInfo *					inAdInfo) const
{
	LogFunctionEnterExit;
	PMString toReturn;
	do
	{
		if( !inAdInfo )
			break;

		const PMString & adUrl = inAdInfo->GetUrl();
		toReturn = adUrl;

		if( adUrl.CharCount() == 0 )
			break;

		const PMString toFind( "%path%" );

		CharCounter foundIndex = adUrl.IndexOfString( toFind );

		if( foundIndex == -1 )
			break;

		InterfacePtr<const IWorkspace> iWorkspace(gSession->QueryWorkspace());
		InterfacePtr<const IZMPrefs> workspacePrefs( iWorkspace, UseDefaultIID() );
		ASSERT( workspacePrefs );

		const PMString & repositoryLocation = workspacePrefs->GetRepositoryPath();
		if( repositoryLocation.CharCount() == 0 )
			return kNullString;

		toReturn.Remove( foundIndex, toFind.CharCount() );
		if( foundIndex > 0 )
		{
			toReturn.Remove( 0, foundIndex );
			foundIndex = 0;
		}

		toReturn.Insert( repositoryLocation, foundIndex );

#ifdef MACINTOSH
		toReturn = Utils<IZMFileUtils>()->ReplaceSlashWithColon( toReturn );
		//const PMString volumeStr(":Volumes:");
		//toReturn.Insert(volumeStr, 0 );

		//toReturn = Utils<IZMFileUtils>()->MacPosixToUnixPath(toReturn);
#endif

	}while(false);

	IZPLog_Str( thisFileLA, enLT_DebugInfo, "Ad url for dnd = %s", toReturn.GrabCString() );

	return toReturn;
}
/** Sets the value of a service data parameter of type IDFile.
	@param dataID is a unique key to identify the data.
	@param inFile the contents of this are copied and saved.
*/	
void
CZPAMServiceDataDelegate::Set(
	int32 dataID, const IDFile & inFile)
{
	LogFunctionEnterExit;

	PMString filePath = FileUtils::SysFileToPMString(inFile);
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "In : dataID = 0x%08X, file = %s", dataID, filePath.GrabCString() );

	InterfacePtr<IAMServiceData> orgImpl( this, mDelegateIID );
	if( orgImpl )
		orgImpl->Set( dataID, inFile );
}
//----------------------------------------------------------------------------------------
// FetchEditionsFromPath
//----------------------------------------------------------------------------------------
bool
ZMFileUtils::FetchEditionsFromPath(
	const PMString&						parentPath,
	ZMstEditionSList &					oEditionList) const
{
	LogFunctionEnterExit;
	
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "From path : %s", parentPath.GrabCString());
	SDKFileHelper fileHelper(parentPath);
	IDFile fileId = fileHelper.GetIDFile();
	PlatformFileSystemIterator iter;
	if(!iter.IsDirectory(fileId))
		return false;

	InterfacePtr<const IWorkspace> iWorkspace(gSession->QueryWorkspace());
	InterfacePtr<const IZMPrefs> workspacePrefs( iWorkspace, UseDefaultIID() );
	ASSERT( workspacePrefs );
	
	const PMString & filePrefixName = workspacePrefs->GetAdFileNamePrefix();
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "File prefix name : %s", filePrefixName.GrabCString());
	
	bool result = false;
	ZMPMStringSList editionList;
	this->GetAllDirectoryNames(parentPath, editionList);
	ZMPMStringSListCIter editionIter = editionList.begin();
	ZMPMStringSListCIter editionIterEnd = editionList.end();
	for(; editionIter != editionIterEnd; ++editionIter)
	{
		stEdition *currEdition = new stEdition();
		StPtrDeleter<stEdition> autoDel( currEdition, true );

		const PMString edition(**editionIter);
		PMString editionFullPath (parentPath);
		editionFullPath.Append(FileUtils::GetDirectorySeperator());
		editionFullPath.Append(edition);

		if (this->FetchAdsFileFromPath(editionFullPath, currEdition->mXmlFiles, filePrefixName))
		{
			result = true;
			currEdition->mName = edition;
			oEditionList.push_back(currEdition);
			autoDel.Forget();
		}
	}

	return result;
}
//----------------------------------------------------------------------------------------
// FetchListFromPath
//----------------------------------------------------------------------------------------
void
ZMFileUtils::FetchListFromPath(
	const PMString&						parentPath,
	ZMstTitleSList &					oTitleList) const
{
	LogFunctionEnterExit;
	
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "From path : %s", parentPath.GrabCString());
	SDKFileHelper fileHelper(parentPath);
	IDFile fileId = fileHelper.GetIDFile();
	PlatformFileSystemIterator iter;
	if(!iter.IsDirectory(fileId))
		return;

	ZMPMStringSList titleList;
	this->GetAllDirectoryNames(parentPath, titleList);
	ZMPMStringSListCIter titleIter = titleList.begin();
	ZMPMStringSListCIter titleIterEnd = titleList.end();

	for(; titleIter != titleIterEnd; ++titleIter)
	{
		stTitle *currTitle = new stTitle();
		StPtrDeleter<stTitle> autoDel( currTitle, true);

		const PMString & title = (**titleIter);
		PMString titleFullPath(parentPath);
		titleFullPath.Append(FileUtils::GetDirectorySeperator());
		titleFullPath.Append(title);

		if ( this->FetchEditionsFromPath(titleFullPath, currTitle->mEditions) )
		{
			currTitle->mName = title;
			oTitleList.push_back(currTitle);
			autoDel.Forget();
		}
	}
}
//----------------------------------------------------------------------------------------
// AddUpdatedAssetId
//----------------------------------------------------------------------------------------
void
AZPAMAssetMonitor::AddUpdatedAssetId(
	const PMString &			inAssetID)
{
	LogFunctionEnterExit;
	if (!inAssetID.IsEmpty())
	{
		K2Vector<PMString>::iterator iter = std::find( mPendingAssetToUpdate.begin(), mPendingAssetToUpdate.end(), inAssetID );
		if( iter == mPendingAssetToUpdate.end() )
		{
			IZPLog_Str_( thisFileLA, enLT_DebugInfo, "Adding asset id : %s in pending update list", inAssetID.GrabCString());
			mPendingAssetToUpdate.push_back(inAssetID);
		}
	}
}
/** Sets the value of a service data parameter of type PMString.
	@param dataID is a unique key to identify the data.
	@param inPMString the contents of this are copied and saved.
*/	
void
CZPAMServiceDataDelegate::Set(
	int32 dataID, const PMString & inPMString)
{
	LogFunctionEnterExit;
	IZPLog_Str_( thisFileLA, enLT_DebugInfo, "In : dataID = 0x%08X, string = %s", dataID, inPMString.GrabCString() );
	InterfacePtr<IAMServiceData> orgImpl( this, mDelegateIID );
	if( orgImpl )
		orgImpl->Set( dataID, inPMString );
}
/** Retrieves a service data parameter of type PMString.
	@param dataID is a unique key to identify the data.
	@param outPMString will be populated with the PMString.
	@return kTrue if the data was found; kFalse otherwise.
*/		
bool16
CZPAMServiceDataDelegate::Get(
	int32 dataID, PMString & outPMString) const
{
	LogFunctionEnterExit;
	InterfacePtr<IAMServiceData> orgImpl( this, mDelegateIID );
	if( orgImpl )
	{
		bool16 toReturn = orgImpl->Get( dataID, outPMString );
		IZPLog_Str_( thisFileLA, enLT_DebugInfo, "Out : %hd, dataID = 0x%08X, string = %s", toReturn, dataID, outPMString.GrabCString() );
		return toReturn;
	}
	return ( bool16 )0;
}
/** Retrieves a service data parameter of type IDFile.
	@param dataID is a unique key to identify the data.
	@param outFile will be populated with the IDFile.
	@return kTrue if the data was found; kFalse otherwise.
*/	
bool16
CZPAMServiceDataDelegate::Get(
	int32 dataID, IDFile & outFile) const
{
	LogFunctionEnterExit;
	InterfacePtr<IAMServiceData> orgImpl( this, mDelegateIID );
	if( orgImpl )
	{
		bool16 toReturn = orgImpl->Get( dataID, outFile );
		PMString filePath;
		if( toReturn )
			filePath = FileUtils::SysFileToPMString(outFile);
		IZPLog_Str_( thisFileLA, enLT_DebugInfo, "Out : %hd, dataID = 0x%08X, file = %s", toReturn, dataID, filePath.GrabCString() );
		return toReturn;
	}
	return ( bool16 )0;
}
//----------------------------------------------------------------------------------------
// SetErrorDetails
//----------------------------------------------------------------------------------------
void
AZPSoapResponse::SetErrorDetails(
	const PMString &			inErrorDetails)
{
	mErrorDetails.SetStr( inErrorDetails.GrabCString(), inErrorDetails.CharCount() );
}