cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a semi column delimited multi line Flat file on KM repository

Former Member
0 Kudos

Hi,

I have a requirement in our project to read a multi line, semi column delimited flat from kept on the Knowledge Management repository and display the contents in the Portal.

I had tried couple of options and was unable to read the file. I am not sure which are the correct APIs I should be using.

Can any one of the experts could guide me with the sample code, that will be great!

Your early response is highly appreciated.

Regards

Venkat

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

here you go.

			
//******* Read file from KM
 String repository_km;
 String FileURL;
 repository_km="/documents/data/data.txt";	
  try
 {
//Getting the user...... 
  IWDClientUser wdClientUser = WDClientUser.getCurrentUser(); 
  IUser sapUser = wdClientUser.getSAPUser(); 
  com.sapportals.portal.security.usermanagement.IUser ep5User = 
  WPUMFactory.getUserFactory().getEP5User(sapUser); 
//Getting the Resource......... 
  IResourceContext resourseContext = new ResourceContext(ep5User); 
  IResourceFactory resourseFactory = ResourceFactory.getInstance(); 
//path to the KM Folder ("/documents/data/data.txt") 
  RID rid= RID.getRID(repository_km);
  com.sapportals.wcm.repository.IResource resource = 
  resourseFactory.getResource(rid, resourseContext); 
 if (resource != null) 
{
	String text = "";
	BufferedReader in = new BufferedReader(new InputStreamReader(resource.getContent().getInputStream()));
	int count=0;
	while ((text = in.readLine()) != null) 
	{
	strText[count] =text;
	count++;
	}
}
} 
catch (RuntimeException e2) {
wdComponentAPI.getMessageManager().reportException("Error in reading file from KM : "+e2.getMessage(),true);
//			   TODO Auto-generated catch block
}

Former Member
0 Kudos

Hi John,

Thanks for your response.

I am using exactly the same code. But, my application is unable to read the file kept on KM repository.

Any other suggestions?

Regards

Venkat

Qualiture
Active Contributor
0 Kudos

Hi,

Do you get an exception, is the code unable to locate your document, or is no data read at all?

Also, bear in mind the current user should have read permissions to the KM file.

Although John's code seem somewhat incomplete (the string fileURL is never used and the file's content is apparently stored in a yet undeclared string array strText) in essence in should work and you should be able to iron out these glitches yourself

Cheers,

Robin

junwu
Active Contributor
0 Kudos

then please debug, that's the basic for a programmer.

Former Member
0 Kudos

Hi Robin,

Thanks for your response.

Yes, I have taken care of those missing parts. But, still it is not working. I am not getting any detailed error message either.

It was failing while getting the RID object.

RID rid = RID.getRID("/documents/testdata.txt");

Application is failing at the execution of this statement. But it is not giving any error message.

I tried keeping the file in the KM repository, shared drive on my own desktop, but still it is not working.

Any idea why it is failing.

Early response is highly appreciated.

Regards

Venkat

Former Member
0 Kudos

Hi John,

I was trying to debug the program.

It was failing at the following statement but not giving any detailed error message. It was in the try catch block and going to catch exception bloc when trying to execute the statement.

RID rid = RID.getRID("/documents/testdata.txt");

Any idea why it is failing at this stage?

Regards

Venkat

Qualiture
Active Contributor
0 Kudos

Hi,

Can you try and see if retrieving the RID of the document root fails as well?

I.e.

RID rid = RID.getRID("/documents");