cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a Properties Resource File in KM with Web Dynpro Java

Former Member
0 Kudos

Hello all,

I would like to store a resource file in KM and have my web dynpro application read that file at runtime. Is this possible? Any examples of how to achieve this?

I hoping to be able to modify this resource file in KM to easily change certain behaviors in my webdynpro application.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

These blogs show how to read an image from KM, is there a way to read a file with name/value pairs? Example:

Config = value1

Config = value2

etc.

Former Member
0 Kudos

Hi,

lets create a file named "sample.properties" contains values

Config1 = value1

Config2 = value2

placed in KM.

the code is below to read the values


IResourceFactory factory = com.sapportals.wcm.repository.ResourceFactory.getInstance(); 
IWDClientUser wdClientUser =WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser(); 
ResourceContext context = new ResourceContext(WPUMFactory.getUserFactory().getEP5User(sapUser)); 
IResource resource = factory.getResource(RID.getRID("/xxx/XXX/sample.properties"),context);
InputStream is=resource.getContent().getInputStream();
Properties prop=new Properties();
prop.load(is);
String val=prop.getProperty("Config1 ");
wdComponentAPI.getMessageManager().reportSuccess(val);

Regards,

Naga

Answers (5)

Answers (5)

Former Member
0 Kudos

I think your right about the UTF8 encoding... when i check out the document for editing locally, it automatically opens in Notepad. I can then save the document in a different encoding....but it looks like it always is saved in UTF8....I wonder if there's a way to encode the inputstream in java to remove those funny characters?

Former Member
0 Kudos

There is the native2ascii-tools in the JDK (of sun) to convert files into an acceptable encoding of properties-files. However, it is a batchtool. I'm not sure if it would remove those BOM-characters, maybe it just converts them into ascii-encoding ;-). Guess the easiest would be to use a reasonable editor.

Former Member
0 Kudos

I put it in debug mode and I see those special characters...it does not work without them...I have no idea where they are coming from...any thoughts?

Former Member
0 Kudos

They are UTF8-BOM characters. Maybe you edited the properties-file with an editor that adds those characters to a file that he thinks is a UTF8 file (which properties-files are usually not). I think the normal editor of Windows does so.

Former Member
0 Kudos

kind of strange, the only way to get a value out of the properties file is


String val = prop.getProperty("CONFIG1");

Do you know why I have to use these strange characters?



Former Member
0 Kudos

Thanks Naga Raju Meesala.

How come all these methods are deprecated...getEP5User

Also, since I am building a weddynpro DC, what is the proper way to include these jar files as Used DCs?

Now proceed in the same way with the variable PORTAL_HOME and add the following .jar files:

u2022 \lib\prtapi.jar The portal runtime APIs

u2022 \portalapps\com.sap.portal.usermanagement\lib\com.sap.security.api.ep5.jar The user management APIs of the Enterprise Portal 5.0 are deprecated, but still in use in SAP NetWeaver 04

u2022 \portalapps\com.sap.netweaver.bc.rf\lib\bc.rf.framework_api.jar KM Repository Framework APIs

u2022 \portalapps\com.sap.netweaver.bc.rf.service\lib\bc.rf.global.service.urlgenerator_api.jar Repository Framework Utility: URL Generator

u2022 \portalapps\com.sap.netweaver.bc.sf\lib\bc.sf.framework_api.jar Repository Framework: Repository Services

u2022 \portalapps\com.sap.netweaver.bc.util\lib\bc.util.public_api.jar Repository Framework Utilities

Former Member
0 Kudos

Hi,

No need to add the runtime jars. Simply use the jar files for designtime.

apart from that add sharing reference "sap.com/com.sap.km.application" to your DC.

yes getEP%User() is depricated, but as of now there is no other possibility.

What are those special characters?

Regards,

Naga

Former Member
0 Kudos

Hi,

/people/rohit.radhakrishnan/blog/2005/05/27/uploading-files-to-km-repository-using-webdynpro-apis

/people/bobu.georgeputheeckal/blog/2006/12/22/getting-an-image-from-km-documents-to-be-used-in-web-dynpro

Regards,

Naga