Monday, December 3, 2012

Usage of string functions in PeopleCode using Java Objects



Here is the code for performing string manipulations in peoplesoft using JavaObjects, i have used the string utilities from "org.apache.commons.lang.StringUtils" which are part of "java.lang.object"



Local JavaObject &original = CreateJavaObject("java.lang.String", "Hello World!");

Local JavaObject &jClass = GetJavaClass("org.apache.commons.lang.StringUtils");

Local string &reversed = &jClass.reverse(&original);

Local string &caps = &jClass.upperCase(&original);

Local string &lower = &jClass.lowerCase(&original);

Local string &index_of = &jClass.indexOf(&original, "o");

Local string &removed = &jClass.remove(&original, "o");

Local string &substr = &jClass.substring(&original, 3);

MessageBox(0, "", 0, 0, "This is original " | ": " | &original.toString());

MessageBox(0, "", 0, 0, "The length of the string is " | ": " | &original.length());

MessageBox(0, "", 0, 0, "This is reversed " | ": " | &reversed);

MessageBox(0, "", 0, 0, "This is capitalised " | ": " | &caps);

MessageBox(0, "", 0, 0, "This is lower " | ": " | &lower);

Rem MessageBox(0, "", 0, 0, "This is splitted " | ": " | &splitted);

MessageBox(0, "", 0, 0, "The index of " | "o is" | ": " | &index_of);

Running the above program in the Application Engine would produce the following output:


PeopleTools 8.50 - Application Engine
Copyright (c) 1988-2012 PeopleSoft, Inc.
All Rights Reserved


This is original : Hello World! (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: This is original : Hello World! (0,0) (0,0)

The length of the string is : 12 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The length of the string is : 12 (0,0) (0,0)

This is reversed : !dlroW olleH (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: This is reversed : !dlroW olleH (0,0) (0,0)

This is capitalised : HELLO WORLD! (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: This is capitalised : HELLO WORLD! (0,0) (0,0)

This is lower : hello world! (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: This is lower : hello world! (0,0) (0,0)

The index of o is: 4 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The index of o is: 4 (0,0) (0,0)

String after o is removed : Hell Wrld! (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: String after o is removed : Hell Wrld! (0,0) (0,0)

Substr : lo World! (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: Substr : lo World! (0,0) (0,0)
Application Engine program TST_APPENGIN ended normally



Reference: http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html ; http://docs.oracle.com/cd/E28394_01/pt852pbh1/eng/psbooks/index.htm

No comments: