Problem : Encoding-Decoding scheme in Domino Web Application

Dear All,

I am very confused about, How can I encode and decode a string which contains some special German or French characters. Basically these characters create some problem in my application.

What is my requirement

I am Storing a User’s information in a profile document, Information can be language specific and may contains special characters. The next time when the user logged into the application, if his/her information is stored in a profile document, it will be pre populated.

What I am doing,

Through XMLHttpRequest Object, I am calling an Agent. I am sending all user’s information in a string and send it via POST method.

This Agent extract the string and save the value in a profile document and return back to the calling function and process another things.

But when the user visits in the next time, it’s profile is populating but in some fields are displaying a junk chararater.

even I am trying to solve it by using @URLEncode and @URLDecode command but still problem exists.

Might be I am lacking some where, so please any body have idea about that then help me to sort out this situation.

Is there any link,where I can learn about this in details.

Thanks

Regards

Ashish

Subject: Problem : Encoding-Decoding scheme in Domino Web Application

there is a 2nd parameter in encode/decode function, set that to use UTF-8,

Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application

Thank you,

I used UTF-8, DOMINO and other charcter set but still problem exists.

Regards

Ashish

Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application

How are you encoding the string when you POST it? Have you tried encodeURIComponent()?

Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application

Yes Sir, I have tried with encodeURIComponent method of java script before posting the data, but it does not give any positive result.

What is the approach we should applied in such kind of situation while web application development.

I am asking this because I am new in Domino web application. this is my first web application. so it might be possible that somewhere I make some mistake.

Thank you

Regards

Ashish

Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application

You are going to have to post some code before anyone can be of further help.

Subject: RE: Problem : Encoding-Decoding scheme in Domino Web Application

I am really obliged that you want to see my code.

This is my code, in which I am facing problem.

saveRequestorProfile is a java script function, which calls an agent using AJAX. It has 4 parameters; last two parameter (i.e. strLabelName & strFieldValue) can have value as per the selection of language.

function saveRequestorProfile(strDBUrl, boolSetProfile, strLabelsName, strFieldValue)

{

try

{

	//generate url to call the agent and passed status in the query string 

	var url = strDBUrl+"/processRequestorInfo?OpenAgent&sid=" + Math.random();



	// make the request content to process

	var strRequestContent = "pg=PRCESSREQINFO&setProfile="+boolSetProfile 					+"&lblNames="+ strLabelsName + "&fldValues=" + strFieldValue;





	//var strRequestContent = encodeURIComponent(strRequestContent);



	//get the XMLHttp Object for specific browser

	objHTTP = GetXmlHttpObject()

	//Ajax coding

	objHTTP.open("Post", url, true);

	objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	objHTTP.send(strRequestContent);	

	objHTTP.onreadystatechange = function()

	{

		//Check if ready state if completed		

		if(objHTTP.readyState == 4)

		{

			//Check if status is OK

			if (objHTTP.status==200)

			{

				var strResponseText = objHTTP.responseText;		

				if(strResponseText ==0)

				{

					strResponseText = "Done;”								}

			}

		}	

	}

	return true;

}

catch(excep)

{

	alert('Common JS Library : Function :: saveRequestorProfile - Error : ' + excep.description);	

	return false;

}

}

Agent processRequestorInfo

Sub Initialize

%REM

Purpose : 1. if user selects the save as my default option then save information in profile document

		2. Validate the form as per process step document

		3. Then redirect to the next page i.e. service selection page

Author : Developer 3, Ideafarms

Date : Nov 12, 2007

Version : 1.0

%END REM

Print |Content-type:text|



On Error Goto errorHandler

'Set error flag to false assuming there is no error

objErr.errFlag=False



'variable declaration

Dim docCurrent			As NotesDocument

Dim docLogStatus		As NotesDocument



Dim strLoggedinUser		As String 

Dim strStatusLog			As String 

Dim strRequestContent		As String 

Dim strTemp			As String

Dim intPosition			As Integer

Dim boolStatus			As Boolean 



Dim strpgName			As String 

Dim strProfileStatus		As String 	

Dim varLblNames			As Variant 	

Dim varFldvalues			As Variant 



'Instanciate the current session and database

Call  IntialiseProc



'If there is an error then exit without further processing

If objErr.errFlag=True Then

	Goto cleanExit

End If



'Instanciate the notes object

'Get the current document handle using document context

Set docCurrent = currSession.DocumentContext	



If docCurrent Is Nothing Then

	'Force the error "current document does not exists"

	objErr.DisplayMsg=False 		

	Error 4002, "Current document not initialised by currentSession'"

End If



'create Log document

Set docLogStatus = New NotesDocument(dbCurrent)

docLogStatus.FORM = "frmStatusLog"

strStatusLog = "Agent Name :: processRequestorInfo : Started at: " & Now() & Chr(13)

'Write Agent activity

strStatusLog = strStatusLog + "Step 1: Retrieving request content . . ." & Chr(13)



'get the request contenet send by the calling

strRequestContent = docCurrent.REQUEST_CONTENT(0)



‘ I have tried to decode the strRequestContent here, using 	

‘strRequestContent = Evaluate(|@URLDecode(“Domino”;”|+strRequestContent +|”)|)





' extract the value from the request content

boolStatus = extractValue(strRequestContent,strpgName, strProfileStatus, varLblNames, varFldValues)

If boolStatus =False Then

	'Force the error "current document does not exists"

	objErr.DisplayMsg=False 		

	strStatusLog = strStatusLog + " - : Error while retrieving values from request content . . ." & Chr(13)

	Error 4002, "'Error while retrieving values from request content"		

End If

strStatusLog = strStatusLog + " - : Values retrieved from request content . . ." & Chr(13)



'Check if status is true then store the all information in profie document

strStatusLog = strStatusLog + "Step 2 : Checking status of profile setting option. . ." & Chr(13)



If strProfileStatus="true" Then

	' get all the logged in user name and store all the information in the profile document;

	strLoggedinUser = docCurrent.REMOTE_USER(0)

	strStatusLog = strStatusLog + " - : Status of profile setting option is true"	 & Chr(13)

	strStatusLog = strStatusLog + " - : Setting the requestor's information"	 & Chr(13)

	boolStatus = setRequestorProfile("RequestorInfo",strLoggedinUser, varFldValues)

	If boolStatus =False Then

	'Force the error "current document does not exists"

		objErr.DisplayMsg=False 		

		strStatusLog = strStatusLog + " - : Error while setting the values in profile document . . ." & 			Chr(13)

		Error 4002, "Error while setting the values in profile document"		

	End If

	strStatusLog = strStatusLog + " - : Requestor's information stored in profile document . . ." & 			Chr(13)

Else		

	strStatusLog = strStatusLog + " - : Status of profile setting option is false" & Chr(13)		

End If	

strStatusLog =strStatusLog & "Agent Name :: processRequestorInfo : Stopped at: " & Now() & Chr(13)

Print "0"

cleanExit:

If Not docLogStatus Is Nothing Then

	Call docLogStatus.ReplaceItemValue("Body", strStatusLog)

	Call docLogStatus.Save(True, False)

End If		

objErr.DisplayMsg=True

Exit Sub

errorHandler:

Call objErr.PostError (Err, Erl, "processRequestorInfo :: Agent ","",Nothing,objErr.CreateLogDoc)	

Resume cleanExit		

End Sub

Related function which is used in the above procedure.

Function extractValue(strRequestContent, strpgName, strProfileStatus, varLblNames, varFldValues) As Boolean

%REM

Purpose : To extract the values from the request content and store into variables

Author : Developer3, Ideafarms

Date : Nov 13,2007

version : 1.0

%END REM

Dim intPosition 		As Integer 

Dim strLblNames		As String 

Dim strFldValues		As String 





On Error Goto errorHandler

'Set error flag to false assuming there is no error

objErr.errFlag=False

'Assuming that there is no error and function returns true

extractValue = True



'Extracting the parameter passed by calling

intPosition = Instr(strRequestContent, "&")

strpgName=Mid(strRequestContent,1,intPosition-1)



strRequestContent = Mid(strRequestContent,intPosition+1)



intPosition = Instr(strRequestContent, "&")

strProfileStatus = Mid(strRequestContent,1, intPosition - 1)



strRequestContent = Mid(strRequestContent,intPosition+1)



intPosition = Instr(strRequestContent, "&")

strLblNames = Mid(strRequestContent,1, intPosition - 1)



strRequestContent = Mid(strRequestContent,intPosition+1)



strFldValues = strRequestContent 



'Extracting the pgname from the strpgName

intPosition = Instr(strpgName, "=")

strpgName = Mid(strpgName,intPosition+1)



'Extracting the profile status from the strProfileStatus

intPosition = Instr(strProfileStatus, "=")

strProfileStatus = Mid(strProfileStatus,intPosition+1)



'Extracting the lable's name from the strLblNames

intPosition = Instr(strLblNames, "=")

strLblNames = Mid(strLblNames,intPosition+1)

varLblNames = Split(strLblNames,"|")



'Extracting the field's value from the strfldValues

intPosition = Instr(strFldValues, "=")

strFldValues = Mid(strFldValues,intPosition+1)

varFldValues = Split(strFldValues,"|")

'Return the status

extractValue = True

cleanExit:

objErr.DisplayMsg=True

Exit Function	

errorHandler:

Call objErr.PostError (Err, Erl, "processRequestorInfo :: extractValue ","",Nothing,objErr.CreateLogDoc)	

extractValue = False

Resume cleanExit		

End Function

Function setRequestorProfile(strDocName,strUserName, varFldValue) As Boolean

%REM

Purpose : To set the fields value in profile document

Author : Developer3, Ideafarms

Date : Nov 13,2007

version : 1.0

%END REM

On Error Goto errorHandler



Dim docRequestorProfile		As NotesDocument



'Set error flag to false assuming there is no error

objErr.errFlag=False

'Assuming that there is no error and function returns true

setRequestorProfile = True	

'Instanciate the current session and database

Call  IntialiseProc



'If there is an error then exit without further processing

If objErr.errFlag=True Then

	Goto cleanExit

End If

'Instanciate the notes object

'get the profile document or create new if does not exists

Set docRequestorProfile = dbCurrent.GetProfileDocument(strDocName, strUserName)



'set the values

docRequestorProfile.fldDivision = varFldValue(0)

docRequestorProfile.fldCompany = varFldValue(1)

docRequestorProfile.fldCountry = varFldValue(2)

docRequestorProfile.fldLocation = varFldValue(3)

docRequestorProfile.fldProcessCategory = varFldValue(4)

docRequestorProfile.fldRequestorName = varFldValue(5)	

docRequestorProfile.fldRequestorPhone = varFldValue(6)

docRequestorProfile.fldRequestorEmail = varFldValue(7)

docRequestorProfile.fldCCName = varFldValue(8)

docRequestorProfile.fldCCPhone = varFldValue(9)

docRequestorProfile.fldCCEmail = varFldValue(10)

docRequestorProfile.fldPCType = varFldValue(11)

docRequestorProfile.fldPCAssetNo = varFldValue(12)

'save the document

Call docRequestorProfile.save(False,False)

setRequestorProfile = True

cleanExit:

objErr.DisplayMsg=True

Exit Function	

errorHandler:

Call objErr.PostError (Err, Erl, "processRequestorInfo :: setRequestorProfile ","",Nothing,objErr.CreateLogDoc)	

setRequestorProfile = False

Resume cleanExit			

End Function

Public Sub IntialiseProc

%REM

Purpose: to initialize variables for current session, database

Author: Developer 4

Date: Nov 13, 2007

Version: 1.0

%END REM

On Error Goto errorHandler

'Set error flag to false assuming there is no error

objErr.errFlag=False



If currSession Is Nothing Then

	Set currSession = New  NotesSession

End If



If dbCurrent Is Nothing Then

	Set dbCurrent = currsession.CurrentDatabase

End If

cleanExit:

Exit Sub

errorHandler:

Call objErr.PostError (Err, Erl, "Common :: Script Library ", "",Nothing,objErr.CreateLogDoc)

Resume cleanExit	

End Sub

Thanks

Ashish