Examples
This example extracts the input field value and address, prints it to standard output and returns a hard-coded value.
/*
* $Id:$
* Infor
*/
import com.infor.CLOVERLEAF.upoc.*;
import java.util.*;
public class XlateSinglePre extends XLTString {
/**
* process a single value call
*/
public Object xlateString (CloverEnv cloverEnv, Xpm xpm, String inVal)
throws CLOVERLEAFException {
/*
* add something to the string
*/
Vector v = new Vector();
v.add(xpm.getInAddresses());
System.out.println("In TestXlateSingPre proc");
System.out.println("Input Address: " + v.toString() + \
"Input Value: " + inVal);
String outVal = new String( "Test Xlate PreProc with \
single value parameter");
System.out.println("Output Address: " + v.toString() + \
"Output Value: " + outVal);
System.out.println("End of TestXlateSingPre proc");
return outVal;
}
}
This example operates on multiple values. The input and return values are vectors of strings.
/*
* $Id:$
*Infor
*/
import com.healthvision.CLOVERLEAF.upoc.*;
import java.util.*;
/*
* this is a test for multi-valued call with strings
* and fetch from xpm
*/
public class TestXlateVectorPre extends XLTStrings {
/**
* return an array of out values
*/
public Vector xlateStrings (CloverEnv cloverEnv, Xpm xpm, Vector inVals)
throws CLOVERLEAFException {
Vector outputStrings = new Vector();
System.out.println("In TestXlateVectorPre Proc");
Enumeration e = xpm.getInAddresses().elements();
System.out.println("Input Addresses:");
System.out.println("---------------");
for (; e.hasMoreElements();) {
Object o = e.nextElement();
System.out.println("path="+o + " ");
System.out.print("xpmfetch=");
for (Enumeration e2 = xpm.getStrings(o.toString()).elements();
e2.hasMoreElements();) {
Object o2 = e2.nextElement();
System.out.print("["+o2+"] ");
/*
* add to output list
*/
outputStrings.add(o2);
}
System.out.println();
}
System.out.println("In TestXlateVectorPre Proc");
return outputStrings;
}
}
This example ignores the input field value, and replaces it with a hard-coded string.
package sample;
import com.healthvision.CLOVERLEAF.upoc.*;
public class SampleXLT extends XLTString
{
public String xlateString(CloverEnv env, \
Xpm xpm, \
String inVal)
throws CLOVERLEAFException
{
return "This is from Java sample.SampleXLT";
}
}
This example takes a property from its constructor argument. It then uses it to split a single input field into multiple output fields. Each field is no bigger than a maximum chunk size.
package sample;
import java.util.*;
import com.healthvision.CLOVERLEAF.upoc.*;
/**
* <code>Split_Text_XLT</code> is used because in
* messages many items consist of multiple lines of fixed
*size whereas in the back office they are single strings
*/
public class Split_Text_XLT extends XLTStrings
{
int chunkSize = 35;
public Split_Text_XLT(PropertyTree userArgs)
throws CLOVERLEAFException
{
super(userArgs);
String chunkString = userArgs.getString("CHUNKSIZE");
if(chunkString == null)
{
System.out.println("No CHUNKSIZE ?? using default: "
+ chunkSize);
}
else
{
try {
chunkSize = Integer.parseInt(chunkString);
}
catch(NumberFormatException e)
{
throw new CLOVERLEAFException\
("CHUNKSIZE must be an integer");
}
}
}
public Vector xlateStrings(CloverEnv cloverEnv,
Xpm xpm,
Vector inVals)
throws CLOVERLEAFException
{
if (inVals.size() == 0)
// nothing to do
return inVals;
Vector outVals = new Vector();
String inText = (String)inVals.firstElement();
int length = inText.length();
int startpos = 0;
int endpos = chunkSize;
while (endpos < length)
{
// add any full chunks to the outVals
outVals.add(inText.substring(startpos,endpos));
startpos += chunkSize;
endpos += chunkSize;
}
if (startpos < length)
outVals.add(inText.substring(startpos,length));
if (outVals.size() == 0)
outVals.add("");
return outVals;
}
}