[an error occurred while processing this directive]
> developer > web app development
Make use of xCommerce's ability to use the features of Java
by exteNd Composer Product Team, eBusiness Integration Products, Novell
Date Created: 2001-05-31 08:47:00.000
  Introduction
introduction

For many custom functions, you may want to reference or work directly with Java classes to perform an operation on data in your XML documents. To assist you in this regard, the Custom Script Editor provides a Java class browser that scans your current XCCLASSPATH and displays the classes, methods, and properties it finds. 

This makes specifying and using the Java constructors, methods, and properties easier by allowing you to drag and drop these items into the body of your function definition or into the test area to test your functions.  Sometime having access to these java classes, methods, and properties makes coding in a project easier.

For instance, instead of writing a routine to parse and tokenize a string the user can take advantage of the java StringTokenizer class. This java class allows the user to break a string up into a series of tokens separated by user-defined delimiters. 

A sample of a user-defined function that uses this class is shown below:

/*********************************************************************************/
// functionname: strTok (aString, asDelimiter, aiOccurence )
// Description: this function will break a string apart at the specified delimiter
// aString: is required, the string to work on
// asDelimiter: is required, the string delimiter
// aiEnd: is required, the integer value of the occurance of the token that 
// should be extraced
// Example: strTok("abc def ghi", " ", 3) returns "ghi"
// Returns: returns a substring
/*********************************************************************************/
function strTok(aString, asDelimiter, aiOccurence)
{
    var f = new String();

    aiOccurence -= 1;

    var st = java.util.StringTokenizer(aString, asDelimiter, false);

    if (aiOccurence < st.countTokens()) 

        {
        for (var i = 0; i <= aiOccurence; ++i)
            f = st.nextToken();
        }

    return(f.toString());
}

This user-defined function uses the java StringTokenizer class to return a specific token from a string.

 For example:

 strTok("SilverStream Software\n\rB2B Division\n\rOne Reservoir Corporate Centre\n\rShelton, CT 06484\n\r", "\n\r", 2)

This would return the 2nd token in the string where each token is delimited by a carriage-return and line-feed.  In this example the 2nd token is the phrase "B2B Division".

 

Note: For more detailed information about accessing Java Classes from xCommerce please reference the xCommerce Designer User's Guide in Appendix A - "Adding Java Extensions to xCommerce with XCCLASSPATH". 

Appendix A