fipaos.util
Class StringParser


public class StringParser

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
 final static StringACTION_TYPE
           
 final static StringPERFORMATIVE
           

Method Summary
 static booleancontains(String look_for, String to_parse)
          Indicates whether the word to search for is actually present in the string to be parsed.
 static StringgetBracketedExpression(int start_from, String to_parse)
          Returns an entire bracketed expression from the given string starting from the index given.
 static StringgetBracketedExpression(int start_from, String to_parse, boolean keep_brackets)
          Returns an entire bracketed expression from the given string starting from the index given.
 static StringgetNextBracketedExpression(String str)
          Gets the first bracketed expression from the String list
 static intgetNoOfBracketedExpressions(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 ListparseACL(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 StringparseFor(String look_for, 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.
 static intparseForIndex(String look_for, 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 VectorparseForList(String look_for, String to_parse)
          Parses the supplied string for a list of space seperated values marked by the look-for
parameter.
 static VectorparseForVector(String look_for, String to_parse)
          Parses a string for the ACL envelope or receiver field and returns the contents in a vector.
 static StringremoveExpressionFromList(String str)
          given a list of bracketed expressions as a string this function will return the list with the first expression removed
 static StringtrimBrackets(String content)
          Strips the outside pair of brackets from a string.
 static StringtrimSquareBrackets(String content)
          Strips the outside pair of brackets from a string.

Field Detail

ACTION_TYPE

public final static String ACTION_TYPE

PERFORMATIVE

public final static String PERFORMATIVE
Method Detail

contains

public static boolean contains(String look_for, 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

getBracketedExpression

public static String getBracketedExpression(int start_from, 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 String getBracketedExpression(int start_from, 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

getNextBracketedExpression

public static String getNextBracketedExpression(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

getNoOfBracketedExpressions

public static int getNoOfBracketedExpressions(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

parseACL

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

parseFor

public static String parseFor(String look_for, 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

parseForIndex

public static int parseForIndex(String look_for, 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

parseForList

public static Vector parseForList(String look_for, 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

parseForVector

public static Vector parseForVector(String look_for, 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 String removeExpressionFromList(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

trimBrackets

public static String trimBrackets(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 String trimSquareBrackets(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

Association Links

to Class java.lang.String

to Class java.lang.String