on 07-22-2008 7:59 AM
Hi Experts,
I have a requirement where I have created a .properties file in my webdynpro src->configuration and deployed it .All the parameters are available at visual admin and I am able to access it in my application.So far so good.Now I hava a JAVA project without dynpro and I want to access all these parameters but it seems that I only have webdynpro IWD...and WD APIs to do so.
Any idea how can I access this key value pair from JAVA application basically a servlet
Thanks
Vinay
Hi Vinay,
This post is on top of my previous post.
ResourceBundle is a class which has the code to read the data from properties file.
So to use the above line of code you need to create a java class of name ResourceBundle .
below is the code for creating it.
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
/**
* @author Narendra_Singh
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SWResourceBundle {
private transient ResourceBundle resourceBundle;
protected static final String KEY_DELIMETER = ".";
public SWResourceBundle(String baseName) {
resourceBundle = ResourceBundle.getBundle(baseName);
}
public String getString(String key) {
String message = key;
if (resourceBundle != null) {
try {
if ((key != null) && (key.trim().indexOf(" ")) > 0)
key = replaceWhiteSpace(key);
message = resourceBundle.getString(key);
} catch (MissingResourceException mre) {
//throw new ResourceNotFoundException("The key is missing", mre);
//Consume the error & return the key
}
}
return message;
}
public static String replaceWhiteSpace(String key) {
StringTokenizer tokenizer = new StringTokenizer(key, " ");
StringBuffer newKey = new StringBuffer();
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
newKey.append(token);
newKey.append(KEY_DELIMETER);
}
return newKey.substring(0, newKey.length() - 1);
}
}
i worked on it. it will be helpful to you.
please revert if you require more info.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vinay,
for getting parameters from a . properties file in java project you can use the below code.
SWResourceBundle resourceBundle =
new SWResourceBundle("here you need to specify yor properties file name only");
resourceBundle.getString("parameter1/ here you need to specify the key to get the value.");
hope this will help.
Ragards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use this code..
IWDConfiguration config = WDConfiguration.getConfigurationByName(wdComponentAPI.getDeployableObjectPart().getDeployableObject(),"your file name")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.