FileDocCategorySizeDatePackage
MediaFieldParser.javaAPI DocphoneME MR2 API (J2ME)4770Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp.parser

MediaFieldParser

public class MediaFieldParser extends SDPParser
Parser for Media field.
version
JAIN-SDP-PUBLIC-RELEASE This code is in the public domain.

Fields Summary
Constructors Summary
public MediaFieldParser(String mediaField)
Creates new MediaFieldParser.

param
mediaField the media string to be parsed

        lexer = new Lexer("charLexer", mediaField);
    
protected MediaFieldParser()
Default constructor.

        super();
    
Methods Summary
public MediaFieldmediaField()
Perform the media type field parsing

return
the parsed media type field
exception
ParseException if a parsing error occurs

        if (ParserCore.debug) dbg_enter("mediaField");
        try {
            MediaField mediaField = new MediaField();

            lexer.match('m");
            lexer.SPorHT();
            lexer.match('=");
            lexer.SPorHT();



            lexer.match(Lexer.ID);
            Token media = lexer.getNextToken();
            mediaField.setMedia(media.getTokenValue());
            lexer.SPorHT();

            lexer.match(Lexer.ID);
            Token port = lexer.getNextToken();
            mediaField.setPort(Integer.parseInt(port.getTokenValue()));

            lexer.SPorHT();

            // Some strange media formatting from Sun Ray systems with media
            if (lexer.hasMoreChars() && lexer.lookAhead(1) == '\n")
                return  mediaField;
            if (lexer.lookAhead(0) == '/") {
                // The number of ports is present:
                lexer.consume(1);
                lexer.match(Lexer.ID);
                Token portsNumber = lexer.getNextToken();
                mediaField.setNports(Integer.parseInt
                                     (portsNumber.getTokenValue()));
                lexer.SPorHT();
            }

            lexer.match(Lexer.ID);
            Token token = lexer.getNextToken();
            this.lexer.SPorHT();
            String transport = token.getTokenValue();
            if (lexer.lookAhead(0) == '/") {
                lexer.consume(1);
                lexer.match(Lexer.ID);
                Token transportTemp = lexer.getNextToken();
                transport = transport + "/" + transportTemp.getTokenValue();
                lexer.SPorHT();
            }

            mediaField.setProto(transport);

            // The formats list:
            Vector formatList = new Vector();
            while (lexer.hasMoreChars()) {
                if (lexer.lookAhead(0) == '\n" || lexer.lookAhead(0) == '\r")
                    break;
                lexer.SPorHT();
                // while(lexer.lookAhead(0) == ' ') lexer.consume(1);
                lexer.match(Lexer.ID);
                Token tok = lexer.getNextToken();
                lexer.SPorHT();
                String format = tok.getTokenValue().trim();
                if (! format.equals(""))
                    formatList.addElement(format);
            }
            mediaField.setFormats(formatList);

            return mediaField;
        } catch (NumberFormatException e) {
            throw new ParseException(lexer.getBuffer(), lexer.getPtr());
        } finally {
            dbg_leave("mediaField");
        }
    
public SDPFieldparse()
Perform the media type field parsing

return
the parsed media type field
exception
ParseException if a parsing error occurs

        return mediaField();