Example: Using bidirectional (bi-di) transformation on string-type data

When using information that is in a bidirectional language script, it might be necessary to transform the format of the data. This is a step-by-step example of the coding that transforms string-type data.

Before you begin

Icon indicating 6.0.0 content only For IBM® WebSphere® Process Server, version 6.0.0, make sure that all the classes that contain the bi-di engine implementation are installed on the server on which you are developing your modules. If you are using JDK 1.4.1 for Windows® , AIX® or Linux® operating systems, you will not have to install these classes.

Why and when to perform this task

The module requires that string information is transformed from one bidirectional format to another.
Note: If you are unfamiliar with the formats, see Values for the bidirectional (bi-di) format string.

Steps for this task

  1. Include all bi-di classes that contain the bi-di engine implementation.
    import com.ibm.bidiTools.bdlayout.*;
  2. Define the strings to contain the data object to transform, and the input and output format values.

    The input format is the bi-di format in which the string object is currently stored. The output format is the bi-di format in which you want to store the string object.

    String strIn = new String("Hello world");
    String formatIn = "ILYNN";
    String formatOut = "VLYNN";
  3. Call the BidiStringTransformation function.
    String strOut = BiDiStringTransformation(strIn, formatIn, formatOut);
    String BiDiStringTransformation(String strIn, String formatIn, String formatOut) {
    1. Test if input string is null.
      		if (strIn == null) return null;
    2. Perform transformation
      		BidiFlagSet flagsIn; 
      		BidiFlagSet flagsOut; 
      		formatIn = formatIn.toUpperCase(); 
      		formatOut = formatOut.toUpperCase(); 
      
      		if (formatIn != null) 
          		flagsIn = new BidiFlagSet(formatIn.toCharArray()); 
      		else 
          		flagsIn = new BidiFlagSet(); 
      
      		if (formatOut != null) 
          		flagsOut = new BidiFlagSet(formatOut.toCharArray()); 
      		else 
          		flagsOut = new BidiFlagSet();
      
      		if (flagsIn.equals(flagsOut)) return strIn; 
      		String strOut = BiDiStringTransformation(strIn, flagsIn, flagsOut); 
      		return strOut;
      }

Terms of use |

Last updated: Tue Feb 21 16:59:47 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)