Asterisk-Java

org.asteriskjava.util
Class AstUtil

java.lang.Object
  extended by org.asteriskjava.util.AstUtil

public class AstUtil
extends java.lang.Object

Some static utility methods to imitate Asterisk specific logic.

See Asterisk's util.c.

Client code is not supposed to use this class.

Version:
$Id: AstUtil.java 1300 2009-04-30 00:28:00Z srt $
Author:
srt

Method Summary
static boolean isNull(java.lang.Object s)
          Checks if the value of s was null in Asterisk.
static boolean isTrue(java.lang.Object o)
          Checks if a String represents true or false according to Asterisk's logic.
static java.lang.String[] parseCallerId(java.lang.String s)
          Parses a string for caller id information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isTrue

public static boolean isTrue(java.lang.Object o)
Checks if a String represents true or false according to Asterisk's logic.

The original implementation is util.c is as follows:

     int ast_true(const char *s)
     {
         if (!s || ast_strlen_zero(s))
             return 0;
 

if (!strcasecmp(s, "yes") || !strcasecmp(s, "true") || !strcasecmp(s, "y") || !strcasecmp(s, "t") || !strcasecmp(s, "1") || !strcasecmp(s, "on")) return -1;

return 0; }

To support the dnd property of ZapShowChannelsEvent this method also consideres the string "Enabled" as true.

Parameters:
o - the Object (usually a String) to check for true.
Returns:
true if s represents true, false otherwise.

parseCallerId

public static java.lang.String[] parseCallerId(java.lang.String s)
Parses a string for caller id information.

The caller id string should be in the form "Some Name" <1234>.

This resembles ast_callerid_parse in callerid.c but strips any whitespace.

Parameters:
s - the string to parse
Returns:
a String[] with name (index 0) and number (index 1)

isNull

public static boolean isNull(java.lang.Object s)
Checks if the value of s was null in Asterisk.

This method is useful as Asterisk likes to replace null values with different string values like "unknown", "<unknown>" or "<null>".

To find such replacements search for S_OR in Asterisk's source code. You will find things like

 S_OR(chan->cid.cid_num, "<unknown>")
 fdprintf(fd, "agi_callerid: %s\n", S_OR(chan->cid.cid_num, "unknown"));
 
and more...

Parameters:
s - the string to test, may be null. If s is not a string the only test that is performed is a check for null.
Returns:
true if the s was null in Asterisk; false otherwise.

Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.