Are you trying to do a key/value pair like the XML properties file read and fetch value from a xml or config file?
Here is the sample JS and modify with your needs:(Purpose: Read a property file and get the values. )
Service Inputs:
properties (string list)
propertyFileName (string)
Service output:
Values (string list)
imports:
java.io.*
java.util.*
java.text.*
/ pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String properties = IDataUtil.getStringArray( pipelineCursor, "properties" );
String ConfigFileName = IDataUtil.getString( pipelineCursor, "propertyFileName" );
pipelineCursor.destroy();
String result = new String();
String values = null;
if(properties != null)
{
values = new String[properties.length];
String str = new String("");
int count,i = 0 ;
int tokencount;
StringTokenizer propValue = null;
FileInputStream fis = null;
String c= properties;
try
{
fis = new FileInputStream (ConfigFileName);
int size = fis.available ();
byte bytes = new byte [size];
fis.read (bytes);
str = new String (bytes);
StringTokenizer propName = new StringTokenizer(str,"\n" );
tokencount = propName.countTokens();
String iorPath[] = new String[tokencount];
while ( propName.hasMoreTokens() )
{
propValue = new StringTokenizer(propName.nextToken(),"=");
while ( propValue.hasMoreTokens() )
{
String interfaceName = propValue.nextToken();
if(c.length > 0 && c.length > i)
{
if((interfaceName.trim()).equals(c[i].trim()))
{
values[i] = propValue.nextToken().trim();
i++;
}
}
//iorPath[count] = propValue.nextToken().trim();
}//eof while
}
}
catch (EOFException e)
{
result += "End of File Found";
}
catch (IOException e)
{
result += "File Not Found" + e.toString();
}
catch (ArrayIndexOutOfBoundsException e)
{
result += "Array Error" + e;
}
catch (Exception e)
{
result += "General Error" + e;
}
}
else
{
values = null;
result += "null values received";
}
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "values", values );
IDataUtil.put( pipelineCursor_1, "Status", result );
pipelineCursor_1.destroy();
Shared Tab code:
static Date currentDate = new Date();
static SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
static String dateStringer = sdf.format(currentDate);
static String programlogFile = null;
static FileWriter log = null;
// output
static IData output = IDataFactory.create();
static void log(String message)
{
Date currentDate = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String dateString = sdf.format(currentDate);
System.out.println("inside log else");
System.out.println("inside log after else");
if (programlogFile == null)
programlogFile = "c:\log.txt";
try
{
FileWriter log = new FileWriter(programlogFile, true);
log.write(dateStringer + " " + "\n" + message);
log.write("\r\n");
log.write("\r\n");
log.flush();
log.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}