Friday, December 7, 2012

Calling java system utilities for the environment specification



The following program would give details on the user environment and also the java class path:


Local string &file_sep = GetJavaClass("org.apache.commons.lang.SystemUtils").FILE_SEPARATOR;
MessageBox(0, "", 0, 0, "The file seperator is: " | &file_sep);

Local string &file_encode = GetJavaClass("org.apache.commons.lang.SystemUtils").FILE_ENCODING;
MessageBox(0, "", 0, 0, "The file encoder: " | &file_encode);

Local string &java_ext_dirs = GetJavaClass("org.apache.commons.lang.SystemUtils").JAVA_EXT_DIRS;
MessageBox(0, "", 0, 0, "The java external directory is: " | &java_ext_dirs);

Local string &java_home = GetJavaClass("org.apache.commons.lang.SystemUtils").JAVA_HOME;
MessageBox(0, "", 0, 0, "The java home is: " | &java_home);

Local string &os_name = GetJavaClass("org.apache.commons.lang.SystemUtils").OS_NAME;
MessageBox(0, "", 0, 0, "The operating system is: " | &os_name);

Local string &java_vendor = GetJavaClass("org.apache.commons.lang.SystemUtils").JAVA_VENDOR;
MessageBox(0, "", 0, 0, "The java vendor is: " | &java_vendor);

Local string &usr_home = GetJavaClass("org.apache.commons.lang.SystemUtils").USER_HOME;
MessageBox(0, "", 0, 0, "The user home is: " | &usr_home);

Local string &user_lng = GetJavaClass("org.apache.commons.lang.SystemUtils").USER_LANGUAGE;
MessageBox(0, "", 0, 0, "The user language is: " | &user_lng);


The following would be the output file:

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


The file seperator is: \ (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The file seperator is: \ (0,0) (0,0)

The file encoder: Cp1252 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The file encoder: Cp1252 (0,0) (0,0)

The java external directory is: C:\PT8.50\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The java external directory is: C:\PT8.50\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext (0,0) (0,0)

The java home is: C:\PT8.50\jre (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The java home is: C:\PT8.50\jre (0,0) (0,0)

The operating system is: Windows 2003 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The operating system is: Windows 2003 (0,0) (0,0)

The java vendor is: Sun Microsystems Inc. (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The java vendor is: Sun Microsystems Inc. (0,0) (0,0)

The user home is: C:\Documents and Settings\Administrator (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The user home is: C:\Documents and Settings\Administrator (0,0) (0,0)

The user language is: en (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The user language is: en (0,0) (0,0)
Application Engine program TST_APPENGIN ended normally


String escaping utilities in Peoplecode



The following is the peoplecode program to show string escaping utilities:


[code]
Local JavaObject &escUtils = GetJavaClass("org.apache.commons.lang.StringEscapeUtils");

Local string &String = """Hello World!""";

Local string &jescString = &escUtils.escapeJava(&String);
MessageBox(0, "", 0, 0, "The string in java escape sequence is" | ": " | &jescString);

Local string &htmlescString = &escUtils.escapeHtml(&String);
MessageBox(0, "", 0, 0, "The string in html escape sequence is" | ": " | &htmlescString);

Local string &jscriptescString = &escUtils.escapeJavaScript(&String);
MessageBox(0, "", 0, 0, "The string in javascript escape sequence is" | ": " | &jscriptescString);


Local string &sqlescString = &escUtils.escapeSql(&String);
MessageBox(0, "", 0, 0, "The string in sql escape sequence is" | ": " | &sqlescString);


Local string &xmlescString = &escUtils.escapeXml(&String);
MessageBox(0, "", 0, 0, "The string in xml escape sequence is" | ": " | &xmlescString);
[/code]

The following is the output:



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


The string in java escape sequence is: \"Hello World!\" (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The string in java escape sequence is: \"Hello World!\" (0,0) (0,0)

The string in html escape sequence is: "Hello World!" (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The string in html escape sequence is: "Hello World!" (0,0) (0,0)

The string in javascript escape sequence is: \"Hello World!\" (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The string in javascript escape sequence is: \"Hello World!\" (0,0) (0,0)

The string in sql escape sequence is: "Hello World!" (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The string in sql escape sequence is: "Hello World!" (0,0) (0,0)

The string in xml escape sequence is: "Hello World!" (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The string in xml escape sequence is: "Hello World!" (0,0) (0,0)
Application Engine program TST_APPENGIN ended normally


Based on the language like java,javascript or xml, the string gets seperated. This would be useful for pattern matching.

Tuesday, December 4, 2012

Calling java.util and java.lang.System packages in PeopleSoft




This is a basic program which would call the packages java.util.* and java.lang.System packages in peoplesoft PeopleCode using GetJavaClass function:



Local string &userhome = GetJavaClass("java.lang.System").getProperty("user.home");

Local string &lng = GetJavaClass("java.lang.System").getProperty("user.language");

Local string &username = GetJavaClass("java.lang.System").getProperty("user.name");


Local string &osname = GetJavaClass("java.lang.System").getProperty("os.name");


Local string &osversion = GetJavaClass("java.lang.System").getProperty("os.version");

Local string &timezone = GetJavaClass("java.util.TimeZone").getDefault().getDisplayName();

Local string &country = GetJavaClass("java.lang.System").getProperty("user.country");


MessageBox(0, "", 0, 0, "The os name and version is " | ": " | &osname | "-" | &osversion);

MessageBox(0, "", 0, 0, "The user home-path is " | ": " | &userhome);

MessageBox(0, "", 0, 0, "The default language is " | ": " | &lng);

MessageBox(0, "", 0, 0, "The default user is " | ": " | &username);

MessageBox(0, "", 0, 0, "The default timezone is " | ": " | &timezone);

MessageBox(0, "", 0, 0, "The default country is " | ": " | &country);



The following would produce the output:



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


The os name and version is : Windows 2003-5.2 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The os name and version is : Windows 2003-5.2 (0,0) (0,0)

The user home-path is : C:\Documents and Settings\Administrator (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The user home-path is : C:\Documents and Settings\Administrator (0,0) (0,0)

The default language is : en (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The default language is : en (0,0) (0,0)

The default user is : Administrator (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The default user is : Administrator (0,0) (0,0)

The default timezone is : GMT+05:30 (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The default timezone is : GMT+05:30 (0,0) (0,0)

The default country is : US (0,0)
 Message Set Number: 0
 Message Number: 0
 Message Reason: The default country is : US (0,0) (0,0)
Application Engine program TST_APPENGIN ended normally


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

Sunday, December 2, 2012

Some Python Code



-As usual, Python program to print Hello World:


print("Hello World!")


- Python program to print Fibonnaci using Recursion:

Recursion - The programming technique where function calls itself till it encounters a break condition and then exits. So there must be condition to check the exit condition, or else, the program would loop till infinity which would cause memory overflow error, as the computer has got limited memory.




#To compute Fibonacci number
#using Recursion

def Fib(n):
 
    if n == 0 or n == 1: return 1  
    else: return Fib(n-1) + Fib(n-2)
 
print(Fib(4))


-Python program to reverse a string:


def Str_reverse(Str1):
 
    #return Str1
 
 
    return Str1[::-1]

print(Str_reverse("Hello World!"))