jlscp
v0.8

org.linuxsampler.lscp
Class Parser

java.lang.Object
  extended by org.linuxsampler.lscp.Parser

public final class Parser
extends java.lang.Object

This class contains only helper functions that are used from the other classes in this library.


Method Summary
protected static java.lang.String getCategoryInfo(java.lang.String[] resultSet, java.lang.String category)
          Gets the info character string to the specified information category.
static java.lang.String[] getDirectoryList(java.lang.String path)
          Returns an array containing all directories in the specified escaped path.
static java.lang.String getFileName(java.lang.String path)
          Extracts the file name from the specified escaped path.
static java.lang.String getParentDirectory(java.lang.String path)
          Gets the parent directory of the specified escaped path.
static boolean hasEndingFileSeparator(java.lang.String path)
          Determines whether the specified escaped path ends with a file separator.
static boolean isEscaped(java.lang.String s, int index)
          Determines whether the character at the specified position is escaped with backslash.
static java.lang.String[] parseArray(java.lang.String list)
          Parses a comma separated list whose items are encapsulated into curly braces.
static java.lang.Boolean[] parseBoolList(java.lang.String list)
          Parses a comma separated list with boolean values.
protected static org.linuxsampler.lscp.ResultSet parseEmptyResultSet(java.lang.String ln)
          Parses an empty result set and returns an appropriate ResultSet object.
protected static void parseError(java.lang.String ln, org.linuxsampler.lscp.ResultSet rs)
          Parses error message.
static java.lang.String[] parseEscapedStringList(java.lang.String list)
          Parses a comma separated string list, which elements contains escaped sequences.
static java.lang.String[] parseEscapedStringList(java.lang.String list, char separator)
          Parses a string list, which elements contains escaped sequences.
protected static float parseFloat(java.lang.String s)
          Parses a float value.
static java.lang.Float[] parseFloatList(java.lang.String list)
          Parses a comma separated list with float values.
protected static int parseInt(java.lang.String s)
          Parses an integer value.
static java.lang.Integer[] parseIntList(java.lang.String list)
          Parses a comma separated list with integer values.
static java.lang.Integer[] parseIntList(java.lang.String list, char separator)
          Parses a list of integer values.
static java.lang.String[] parseList(java.lang.String list)
          Parses a comma separated list.
static java.lang.String[] parseList(java.lang.String list, char separator)
          Parses a list.
protected static java.lang.String[][] parseListOfStringLists(java.lang.String list)
           
protected static java.lang.Boolean parseMultiplicity(java.lang.String[] resultSet)
          Determines whether the parameter represented by the specified result set allows only one value or a list of values.
static java.lang.String[] parseStringList(java.lang.String list)
          Parses a comma separated list whose items are encapsulated into apostrophes.
static java.lang.String[] parseStringList(java.lang.String list, char separator)
          Parses a list whose items are encapsulated into apostrophes.
protected static ParameterType parseType(java.lang.String[] resultSet)
          Gets the type of the parameter represented by the specified result set.
protected static void parseWarning(java.lang.String ln, org.linuxsampler.lscp.ResultSet rs)
          Parses warning message.
static java.lang.String removeEndingFileSeparator(java.lang.String path)
          If the specified escaped path ends with a file separator, a new string is returned with the ending file separator removed.
static java.lang.String removeQuotation(java.lang.String s)
          Eliminates the quotation marks if the string is quoted.
static java.lang.String toEscapedFileName(java.lang.Object obj)
          Returns the provided file name with added escape sequences where necessary.
static java.lang.String toEscapedString(java.lang.Object obj)
          Returns the provided string with added escape sequences where necessary.
static java.lang.String toExtendedEscapeSequence(java.lang.String escapedString)
          Returns more aggressively escaped sequence of the provided escaped string.
static java.lang.String toNonEscapedFileName(java.lang.Object obj)
          Removes the escape sequences from the specified file name
static java.lang.String toNonEscapedString(java.lang.Object obj)
          Removes the escape sequences from the string obj.toString().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseInt

protected static int parseInt(java.lang.String s)
                       throws LscpException
Parses an integer value.

Parameters:
s - The integer value to be parsed.
Throws:
LscpException - If the string does not contain valid integer value.

parseFloat

protected static float parseFloat(java.lang.String s)
                           throws LscpException
Parses a float value.

Parameters:
s - The float value to be parsed.
Throws:
LscpException - If the string does not contain valid float value.

parseList

public static java.lang.String[] parseList(java.lang.String list)
Parses a comma separated list.

Parameters:
list - The comma separated list.
Returns:
A String array containing all items in the list.

parseList

public static java.lang.String[] parseList(java.lang.String list,
                                           char separator)
Parses a list.

Parameters:
list - The list to parse.
separator - Provides the character used as separator.
Returns:
A String array containing all items in the list.

parseBoolList

public static java.lang.Boolean[] parseBoolList(java.lang.String list)
Parses a comma separated list with boolean values.

Parameters:
list - The comma separated list with boolean values.
Returns:
A Boolean array containing all items in the list.

parseIntList

public static java.lang.Integer[] parseIntList(java.lang.String list)
                                        throws LscpException
Parses a comma separated list with integer values.

Parameters:
list - The comma separated list with integer values.
Returns:
A Integer array containing all items in the list.
Throws:
LscpException - if the list contains value(s) from different type.

parseIntList

public static java.lang.Integer[] parseIntList(java.lang.String list,
                                               char separator)
                                        throws LscpException
Parses a list of integer values.

Parameters:
list - The list of integer values.
separator - Provides the character used as separator.
Returns:
A Integer array containing all items in the list.
Throws:
LscpException - if the list contains value(s) from different type.

parseFloatList

public static java.lang.Float[] parseFloatList(java.lang.String list)
                                        throws LscpException
Parses a comma separated list with float values.

Parameters:
list - The comma separated list with float values.
Returns:
A Float array containing all items in the list.
Throws:
LscpException - if the list contains value(s) from different type.

parseEscapedStringList

public static java.lang.String[] parseEscapedStringList(java.lang.String list)
                                                 throws LscpException
Parses a comma separated string list, which elements contains escaped sequences.

Parameters:
list - The list to parse.
Returns:
A String array containing all items in the list.
Throws:
LscpException

parseEscapedStringList

public static java.lang.String[] parseEscapedStringList(java.lang.String list,
                                                        char separator)
                                                 throws LscpException
Parses a string list, which elements contains escaped sequences.

Parameters:
list - The list to parse.
separator - Provides the character used as separator.
Returns:
A String array containing all items in the list.
Throws:
LscpException

parseStringList

public static java.lang.String[] parseStringList(java.lang.String list)
                                          throws LscpException
Parses a comma separated list whose items are encapsulated into apostrophes.

Parameters:
list - The comma separated list.
Returns:
A String array containing all items in the list.
Throws:
LscpException - if the list is broken.

parseStringList

public static java.lang.String[] parseStringList(java.lang.String list,
                                                 char separator)
                                          throws LscpException
Parses a list whose items are encapsulated into apostrophes.

Parameters:
list - The list of strings.
separator - Provides the character used as separator.
Returns:
A String array containing all items in the list.
Throws:
LscpException - if the list is broken.

parseListOfStringLists

protected static java.lang.String[][] parseListOfStringLists(java.lang.String list)
                                                      throws LscpException
Throws:
LscpException

parseArray

public static java.lang.String[] parseArray(java.lang.String list)
                                     throws LscpException
Parses a comma separated list whose items are encapsulated into curly braces.

Parameters:
list - The comma separated list.
Returns:
A String array containing all items in the list.
Throws:
LscpException - if the list is broken.

parseType

protected static ParameterType parseType(java.lang.String[] resultSet)
Gets the type of the parameter represented by the specified result set.

Parameters:
resultSet - A String array containing the information categories of a multi-line result set.
Returns:
The type of the parameter represented by the specified result set or null if the specified result set does not contain TYPE category.

parseMultiplicity

protected static java.lang.Boolean parseMultiplicity(java.lang.String[] resultSet)
Determines whether the parameter represented by the specified result set allows only one value or a list of values.

Parameters:
resultSet - A String array containing the information categories of a multi-line result set.
Returns:
false if the parameter represented by the specified result set allows only one value and true if allows a list of values.

parseEmptyResultSet

protected static org.linuxsampler.lscp.ResultSet parseEmptyResultSet(java.lang.String ln)
                                                              throws LscpException,
                                                                     LSException
Parses an empty result set and returns an appropriate ResultSet object. Notice that the result set may be of type warning or error.

Parameters:
ln - A String representing the single line result set to be parsed.
Returns:
A ResultSet object.
Throws:
LscpException - If LSCP protocol error occurs.
LSException - If the LinuxSampler instance returns error message.

parseWarning

protected static void parseWarning(java.lang.String ln,
                                   org.linuxsampler.lscp.ResultSet rs)
                            throws LscpException
Parses warning message.

Parameters:
ln - The warning message to be parsed.
rs - A ResultSet instance where the warning must be stored.
Throws:
LscpException - If LSCP protocol corruption occurs.

parseError

protected static void parseError(java.lang.String ln,
                                 org.linuxsampler.lscp.ResultSet rs)
                          throws LscpException
Parses error message.

Parameters:
ln - The error message to be parsed.
rs - A ResultSet instance where the error must be stored.
Throws:
LscpException - If LSCP protocol corruption occurs.

getCategoryInfo

protected static java.lang.String getCategoryInfo(java.lang.String[] resultSet,
                                                  java.lang.String category)
Gets the info character string to the specified information category.

Parameters:
resultSet - A String array containing the information categories of a multi-line result set.
category - Specifies the category whose info character string to be returned.
Returns:
The info character string to the specified information category or null if the specified result set does not contain that category.

removeQuotation

public static java.lang.String removeQuotation(java.lang.String s)
Eliminates the quotation marks if the string is quoted.

Returns:
New string without quotation marks if the string is quoted; else the same string is returned.

toEscapedString

public static java.lang.String toEscapedString(java.lang.Object obj)
Returns the provided string with added escape sequences where necessary.


toEscapedFileName

public static java.lang.String toEscapedFileName(java.lang.Object obj)
Returns the provided file name with added escape sequences where necessary.


toExtendedEscapeSequence

public static java.lang.String toExtendedEscapeSequence(java.lang.String escapedString)
Returns more aggressively escaped sequence of the provided escaped string.

Parameters:
escapedString - Already escaped string, which should be escaped more aggressively.

toNonEscapedFileName

public static java.lang.String toNonEscapedFileName(java.lang.Object obj)
Removes the escape sequences from the specified file name

Returns:
The provided file name with removed escape sequences.

toNonEscapedString

public static java.lang.String toNonEscapedString(java.lang.Object obj)
Removes the escape sequences from the string obj.toString().

Returns:
The provided text with removed escape sequences.

isEscaped

public static boolean isEscaped(java.lang.String s,
                                int index)
Determines whether the character at the specified position is escaped with backslash.


hasEndingFileSeparator

public static boolean hasEndingFileSeparator(java.lang.String path)
Determines whether the specified escaped path ends with a file separator.


removeEndingFileSeparator

public static java.lang.String removeEndingFileSeparator(java.lang.String path)
If the specified escaped path ends with a file separator, a new string is returned with the ending file separator removed.


getParentDirectory

public static java.lang.String getParentDirectory(java.lang.String path)
Gets the parent directory of the specified escaped path.


getFileName

public static java.lang.String getFileName(java.lang.String path)
Extracts the file name from the specified escaped path. If the path does not ends with a file name, null is returned.


getDirectoryList

public static java.lang.String[] getDirectoryList(java.lang.String path)
Returns an array containing all directories in the specified escaped path.


jlscp
v0.8

Copyright © 2009 Grigor Iliev. All rights reserved.