public static function autoEncode( $ret, $type = null )
    {
        if ( $type === null )
            $type = self::getHttpAccept( );

        if ( $type === 'xml' )
            return self::xmlEncode( $ret );
        else if ( $type === 'json' )
            return json_encode( $ret );
        else
            return self::textEncode( $ret );
    }