FileDocCategorySizeDatePackage
LocatorParser.javaAPI DocphoneME MR2 API (J2ME)7529Wed May 02 16:47:16 BST 2007com.sun.mmedia.protocol

LocatorParser

public final class LocatorParser extends Object
Parses a given locator or encoding string into its constituent properties. Breaks it up into 3 main parts : the protocol, the device and the parameter list of the form protocol://device?param1=value1¶m2=value2...

Fields Summary
public static final String
S_PROTOCOL_CAPTURE
public static final String
S_DEVICE_AUDIO
public static final String
S_DEVICE_VIDEO
public static final String
S_DEVICE_RADIO
public static final String
S_ENCODING
public static final String
S_ENCODING_JPEG
public static final String
S_ENCODING_PNG
public static final String
S_ENCODING_PCM
public static final String
S_TYPE
public static final String
S_TYPE_JFIF
public static final String
S_WIDTH
public static final String
S_HEIGHT
public static final String
S_QUALITY
public static final String
S_PROGRESSIVE
public static final String
S_INTERLACED
public static final String
S_FPS
public static final String
S_COLORS
public static final String
S_JPEG
public static final String
S_PNG
public static final String
S_JFIF
public static final String
S_TRUE
public static final String
S_FALSE
public static final String
S_AUDIO
public static final String
S_VIDEO
public static final String
S_RATE
public static final String
S_BITS
public static final String
S_CHANNELS
public static final String
S_ENDIAN
public static final String
S_ENDIAN_BIG
public static final String
S_ENDIAN_LITTLE
public static final String
S_SIGN
public static final String
S_SIGN_SIGNED
public static final String
S_SIGN_UNSIGNED
public static final String
S_RADIO_FREQ
public static final String
S_RADIO_MOD
public static final String
S_RADIO_MOD_FM
public static final String
S_RADIO_MOD_AM
public static final String
S_RADIO_ST
public static final String
S_RADIO_ST_MONO
public static final String
S_RADIO_ST_STEREO
public static final String
S_RADIO_ST_AUTO
public static final String
S_RADIO_PRGID
public static final String
S_RADIO_PRESET
private String
locator
The locator to be parsed
private int
index
The current pointer into the locator where parsing is to continue
private int
length
The length of the locator
private String
value
The latest value in a "key=value" pair
Constructors Summary
public LocatorParser(String s)
Constructs a parser object and initializes its state.

param
s The string to be parsed

	length = s.length();
	locator = s;
    
Methods Summary
public java.lang.StringgetDevice()
Parses and returns the device name part of the locator, if any.

return
The device name string, or null if there isn't one.

	if (index >= length)
	    return null;
	int oldIndex = index;
	// Get the index of the question mark
	int queryIndex = locator.indexOf("?", index);
	// If its not found, then the whole string is assumed to be the device
	if (queryIndex < 0) {
	    index = length;
	    return locator.substring(oldIndex);
	} else if (queryIndex == 0) {
	    return null;
	}
	// Otherwise move the index forward past the ?
	index = queryIndex + 1;
	// return the device name portion
	return locator.substring(oldIndex, queryIndex);
    
public java.lang.StringgetParameter()
Parses and returns the next parameter key in a parameter "key=value" pair.

return
The key part of the parameter "key=value" pair

	if (index >= length)
	    return null;
	int ampIndex = locator.indexOf("&", index);
	// Assume last parameter
	if (ampIndex < 0)
	    ampIndex = length;

	// token = "abc=xyz"
	String token = locator.substring(index, ampIndex);

	int eq = token.indexOf("=");
	// If there's no = or nothing before the = or nothing after the =
	if (eq < 1 || eq == token.length() - 1)
	    return null;
	String key = token.substring(0, eq);
	// What's after the = is the value. Store it for later query thru
	// the getValue() method
	value = token.substring(eq + 1);
	index = ampIndex + 1;
	return key;
    
public java.lang.StringgetProtocol()
Parses and returns the protocol part of the locator, if any.

return
The protocol string, or null if there isn't a protocol part

	int colonIndex = locator.indexOf("://");
	int oldIndex = index;
	if (colonIndex < 1)
	    return null;
	index = colonIndex + 3;
	return locator.substring(oldIndex, colonIndex);
    
public java.lang.StringgetValue()
Returns the value corresponding to the most recently parsed parameter

return
The value part of the "key=value" parameter pair.

	return value;
    
public booleanhasMore()
Checks if there are any more characters in the string that haven't been parsed yet.

return
true if there are more characters to be parsed, false otherwise

	return index < length;