fipaos.util
Class StringParser

java.lang.Object
  |
  +--fipaos.util.StringParser

public class StringParser
extends java.lang.Object

Provides methods to parse strings for ACL message fields. Useful for when you have an ACL message (or bit of one) as a string from which you want one or two fields - saves the overhead of a whole ACL parser.


Field Summary
static java.lang.String ACTION_TYPE
           
static java.lang.String PERFORMATIVE
           
 
Constructor Summary
StringParser()
           
 
Method Summary
static boolean contains(java.lang.String look_for, java.lang.String to_parse)
          Indicates whether the word to search for is actually present in the string to be parsed.
static java.lang.String getBracketedExpression(int start_from, java.lang.String to_parse)
          Returns an entire bracketed expression from the given string starting from the index given.
static java.lang.String getBracketedExpression(int start_from, java.lang.String to_parse, boolean keep_brackets)
          Returns an entire bracketed expression from the given string starting from the index given.
static java.lang.String getNextBracketedExpression(java.lang.String str)
          Gets the first bracketed expression from the String list
static int getNoOfBracketedExpressions(java.lang.String expressions)
          When given a list of bracketed expressions as a string and a tag within the expressions, this method will instanses of the expression are in the list
static java.util.List parseACL(java.lang.String messages)
          Method to provide conversion between a document containing ACL messages and a List of ACL objects - returns null if anything goes wrong
static java.lang.String parseFor(java.lang.String look_for, java.lang.String to_parse)
          Parses a string for the given ACL field (any field can be given except :receiver and :envelope)
Note: Giving ":performative" as the field name will return the message type.
Giving ":action-type" as the field to look for will return the next keyword after an "(action ..." statement in the string.
static int parseForIndex(java.lang.String look_for, java.lang.String to_parse)
          Parses the given string for the string specified, and returns the index of the character immediately following the end of that string ( e.g.
static java.util.Vector parseForList(java.lang.String look_for, java.lang.String to_parse)
          Parses the supplied string for a list of space seperated values marked by the look-for parameter.
static java.util.Vector parseForVector(java.lang.String look_for, java.lang.String to_parse)
          Parses a string for the ACL envelope or receiver field and returns the contents in a vector.
static java.lang.String removeExpressionFromList(java.lang.String str)
          given a list of bracketed expressions as a string this function will return the list with the first expression removed
static java.lang.String trimBrackets(java.lang.String content)
          Strips the outside pair of brackets from a string.
static java.lang.String trimSquareBrackets(java.lang.String content)
          Strips the outside pair of brackets from a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_TYPE

public static final java.lang.String ACTION_TYPE

PERFORMATIVE

public static final java.lang.String PERFORMATIVE
Constructor Detail

StringParser

public StringParser()
Method Detail

parseFor

public static java.lang.String parseFor(java.lang.String look_for,
                                        java.lang.String to_parse)
Parses a string for the given ACL field (any field can be given except :receiver and :envelope)
Note: Giving ":performative" as the field name will return the message type.
Giving ":action-type" as the field to look for will return the next keyword after an "(action ..." statement in the string. This is useful for ACL content strings. If no "(action ..." is found, null is returned.
If any other string is given then the corresponding word or bracketed expression is given depending on the first character found (e.g. searching for :language in ":language SL0" returns "SL0", but searching for :language in "@language (SL0 SL1) will return "(SL0 SL1)" ). This method will not deal with multiple brackets, e.g. searching for :language in ":language (SL0 (SL1 SL2) SL3)" will return "(SL0 (SL1 SL2)". To get the whole bracketed expression call parseForIndex() with :language as the string to look for and then call getBracketedExpression() with the returned index as the argument.
If an error occurs or the field cannot be found null is returned.
Parameters:
look_for - ACL field to look for
to_parse - String to look in

parseForVector

public static java.util.Vector parseForVector(java.lang.String look_for,
                                              java.lang.String to_parse)
Parses a string for the ACL envelope or receiver field and returns the contents in a vector. Assumes that the fields have bracketed sub-expressions listing the items to retrieve.
Parameters:
look_for - the ACL field to find
to_parse - the string to parse

removeExpressionFromList

public static java.lang.String removeExpressionFromList(java.lang.String str)
given a list of bracketed expressions as a string this function will return the list with the first expression removed
Parameters:
str - list of bracketed expressions as a list
Returns:
the list of bracketed expressions wilt the first one removed

getNoOfBracketedExpressions

public static int getNoOfBracketedExpressions(java.lang.String expressions)
When given a list of bracketed expressions as a string and a tag within the expressions, this method will instanses of the expression are in the list
Parameters:
expressions - list of bracketed expressions as a list
tag - Tag for which to search
Returns:
number of expressions in the list string

getNextBracketedExpression

public static java.lang.String getNextBracketedExpression(java.lang.String str)
Gets the first bracketed expression from the String list
Parameters:
str - String List of bracketed expressions
Returns:
the first expression in the list

parseACL

public static java.util.List parseACL(java.lang.String messages)
Method to provide conversion between a document containing ACL messages and a List of ACL objects - returns null if anything goes wrong

parseForIndex

public static int parseForIndex(java.lang.String look_for,
                                java.lang.String to_parse)
Parses the given string for the string specified, and returns the index of the character immediately following the end of that string ( e.g. looking for :language in the string ":language SL0" will return the integer 9 - marking the space after the word :language )
Parameters:
look_for - The string to parse for
to_parse - The string to look in
See Also:
getBracketedExpression

getBracketedExpression

public static java.lang.String getBracketedExpression(int start_from,
                                                      java.lang.String to_parse)
Returns an entire bracketed expression from the given string starting from the index given. Should be used with parseForIndex which will locate the index to the start of the expression.
Parameters:
start_from - The index to start from
to_parse - The string to look in
Returns:
The bracketed expression that is marked by index

getBracketedExpression

public static java.lang.String getBracketedExpression(int start_from,
                                                      java.lang.String to_parse,
                                                      boolean keep_brackets)
Returns an entire bracketed expression from the given string starting from the index given. Should be used with parseForIndex which will locate the index to the start of the expression.
Parameters:
start_from - The index to start from
to_parse - The string to look in
keep_brackets - True if the output should still have the enclosing brackets, false otherwise
Returns:
The bracketed expression that is marked by index

contains

public static boolean contains(java.lang.String look_for,
                               java.lang.String to_parse)
Indicates whether the word to search for is actually present in the string to be parsed.
Parameters:
look_for - The word to check for
to_parse - The string to check for keyword in
Returns:
True if the word to search for is present, false otherwise

parseForList

public static java.util.Vector parseForList(java.lang.String look_for,
                                            java.lang.String to_parse)
Parses the supplied string for a list of space seperated values marked by the look-for parameter. For example, given a list of addresses in the following format:
(:address agent1@iiop://47.47.47.47:9000/acc agent2@wap://123456789/acc)
you can call this method with the look_for parameter set to ":address" and it will return the two addresses in a vector. The value list must be space seperated and can end with " )" or ")".
Parameters:
look_for - The field marker to extract values for
to_parse - The content to look in
Returns:
A vector of values for the specified marker

trimBrackets

public static java.lang.String trimBrackets(java.lang.String content)
Strips the outside pair of brackets from a string. If only one odd bracket is present at the start or the end of the string then this will be removed as well. The string returned will also have any whitespace at the start and end removed.
Parameters:
content - The string to remove the brackets from
Returns:
The string with the brackets removed

trimSquareBrackets

public static java.lang.String trimSquareBrackets(java.lang.String content)
Strips the outside pair of brackets from a string. If only one odd bracket is present at the start or the end of the string then this will be removed as well. The string returned will also have any whitespace at the start and end removed.
Parameters:
content - The string to remove the brackets from
Returns:
The string with the brackets removed