Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jaxen.function
Class TranslateFunction

    java.lang.Object
      org.jaxen.function.TranslateFunction

All Implemented Interfaces:
  Function

public class TranslateFunction
extends Object
implements Function

4.2 `string translate(string,string,string)`

> The translate function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string. For example, `translate("bar","abc","ABC")` returns the string `BAr`. If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), then occurrences of that character in the first argument string are removed. For example, `translate("--aaa--","abc-","ABC")` returns `"AAA"`. If a character occurs more than once in the second argument string, then the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, then excess characters are ignored.

> > NOTE: The translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.

Author:
  Jan Dvorak ( jan.dvorak @ mathan.cz )
See Also:
  Section 4.2 of the XPath Specification

Constructor Summary
`TranslateFunction()` Create a new `TranslateFunction` object.

Method Summary
`Object` | `call(Context context, List args)` Returns a copy of the first argument in which characters found in the second argument are replaced by corresponding characters from the third argument.
`static String` | `evaluate(Object strArg, Object fromArg, Object toArg, Navigator nav)` Returns a copy of `strArg` in which characters found in `fromArg` are replaced by corresponding characters from `toArg`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### TranslateFunction

    public TranslateFunction()

  Create a new `TranslateFunction` object.

Method Detail

### call

    public Object call(Context context,
                       List args)
                throws FunctionCallException

  Returns a copy of the first argument in which characters found in the second argument are replaced by corresponding characters from the third argument.

  Specified by:
    `call` in interface `Function`
  Parameters:
    `context` - the context at the point in the expression when the function is called
    `args` - a list that contains exactly three items
  Returns:
    a `String` built from `args.get(0)` in which occurrences of characters in `args.get(1)` are replaced by the corresponding characters in `args.get(2)`
  Throws:
    `FunctionCallException` - if `args` does not have exactly three items

### evaluate

    public static String evaluate(Object strArg,
                                  Object fromArg,
                                  Object toArg,
                                  Navigator nav)
                           throws FunctionCallException

  Returns a copy of `strArg` in which characters found in `fromArg` are replaced by corresponding characters from `toArg`. If necessary each argument is first converted to it string-value as if by the XPath `string()` function.

  Parameters:
    `strArg` - the base string
    `fromArg` - the characters to be replaced
    `toArg` - the characters they will be replaced by
    `nav` - the `Navigator` used to calculate the string-values of the arguments.
  Returns:
    a copy of `strArg` in which characters found in `fromArg` are replaced by corresponding characters from `toArg`
  Throws:
    `FunctionCallException` - if one of the arguments is a malformed Unicode string; that is, if surrogate characters don't line up properly

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 Codehaus. All Rights Reserved.