add system_property("property_name")
[scilab.git] / scilab / modules / jvm / src / c / system_getproperty.c
1 /*-----------------------------------------------------------------------------------*/\r
2 /* INRIA 2007 */\r
3 /* Allan CORNET */\r
4 /*-----------------------------------------------------------------------------------*/ \r
5 #include <jni.h>\r
6 #include <string.h>\r
7 #include "system_getproperty.h"\r
8 #include "getScilabJNIEnv.h"\r
9 #include "MALLOC.h"\r
10 /*-----------------------------------------------------------------------------------*/ \r
11 char * system_getproperty(char *property,char *defaultproperty)\r
12 {\r
13         char *retValue=NULL;\r
14         JNIEnv * currentENV = getScilabJNIEnv();\r
15 \r
16         if (currentENV)\r
17         {\r
18                 jclass cls=NULL;\r
19                 cls = (*currentENV)->FindClass(currentENV, "java/lang/System");\r
20                 if (cls)\r
21                 {\r
22                         jmethodID mid=NULL;\r
23                         mid = (*currentENV)->GetStaticMethodID(currentENV, cls, "getProperty","(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");\r
24                         if (mid)\r
25                         {\r
26                                 const char *strValue = NULL;\r
27                                 jstring jstrProperty;\r
28                                 jstring jstrDefaultValue;\r
29                                 jstring jstrValue;\r
30                                 jstrProperty = (*currentENV)->NewStringUTF(currentENV,property);\r
31                                 jstrDefaultValue = (*currentENV)->NewStringUTF(currentENV,defaultproperty);\r
32 \r
33                                 jstrValue=(*currentENV)->CallStaticObjectMethod(currentENV,cls, mid,jstrProperty,jstrDefaultValue);\r
34 \r
35                                 strValue = (*currentENV)->GetStringUTFChars(currentENV,jstrValue, 0);\r
36                                 if (strValue)\r
37                                 {\r
38                                         retValue = (char*)MALLOC(sizeof(char)*(strlen(strValue)+1));\r
39                                         strcpy(retValue,strValue);\r
40                                 }\r
41                                 (*currentENV)->ReleaseStringUTFChars(currentENV, jstrValue , strValue);\r
42                         }\r
43                 }\r
44         }\r
45         return retValue;\r
46 }\r
47 /*-----------------------------------------------------------------------------------*/ \r