public InformationField informationField() throws ParseException { try { this.lexer.match('i'); this.lexer.SPorHT(); this.lexer.match('='); this.lexer.SPorHT(); InformationField informationField = new InformationField(); String rest = lexer.getRest(); informationField.setInformation(rest.trim()); return informationField; } catch (Exception e) { throw new ParseException(lexer.getBuffer(), lexer.getPtr()); } }
AttributeField attributeField = new AttributeField(); this.lexer.match('a'); this.lexer.SPorHT(); this.lexer.match('='); this.lexer.SPorHT(); int ptr = this.lexer.markInputPosition(); try { String name = lexer.getNextToken(':'); this.lexer.consume(1); String value = lexer.getRest(); nameValue = new NameValue(name.trim(), value.trim()); } catch (ParseException ex) { this.lexer.rewindInputPosition(ptr); String rest = this.lexer.getRest(); if (rest == null) throw new ParseException( this.lexer.getBuffer(), this.lexer.getPtr()); nameValue = new NameValue(rest.trim(), null); this.lexer.SPorHT();
/** Parse a comment string cursor is at a ". Leave cursor at closing " *@return the substring containing the quoted string excluding the * closing quote. */ public String quotedString() throws ParseException { int startIdx = ptr + 1; if (lookAhead(0) != '\"') return null; consume(1); while (true) { char next = getNextChar(); if (next == '\"') { // Got to the terminating quote. break; } else if (next == '\0') { throw new ParseException( String.valueOf(this.buffer) + " :unexpected EOL", this.ptr); } else if (next == '\\') { consume(1); } } return String.valueOf(buffer, startIdx, ptr - startIdx - 1); }
public boolean startsId() { try { char nextChar = lookAhead(0); return isTokenChar(nextChar); } catch (ParseException ex) { return false; } }
/** * parser the String message. * @param header - header structure to fill in. * @throws ParseException if the message does not respect the spec. */ public void parse(AuthenticationHeader header) throws ParseException { // the Scheme: this.lexer.SPorHT(); lexer.match(TokenTypes.ID); Token type = lexer.getNextToken(); this.lexer.SPorHT(); header.setScheme(type.getTokenValue()); // The parameters: try { while (lexer.lookAhead(0) != '\n') { this.parseParameter(header); this.lexer.SPorHT(); char la = lexer.lookAhead(0); if (la == '\n' || la == '\0') break; this.lexer.match(','); this.lexer.SPorHT(); } } catch (ParseException ex) { throw ex; } } }
lexer.match('m'); lexer.SPorHT(); lexer.match('='); lexer.SPorHT(); lexer.match(Lexer.ID); Token media = lexer.getNextToken(); mediaField.setMedia(media.getTokenValue()); this.lexer.SPorHT(); lexer.match(Lexer.ID); Token port = lexer.getNextToken(); mediaField.setPort(Integer.parseInt(port.getTokenValue())); this.lexer.SPorHT(); if (lexer.hasMoreChars() && lexer.lookAhead(1) == '\n') return mediaField; if (lexer.lookAhead(0) == '/') { lexer.consume(1); lexer.match(Lexer.ID); Token portsNumber = lexer.getNextToken(); mediaField.setNports( Integer.parseInt(portsNumber.getTokenValue())); this.lexer.SPorHT(); lexer.match(Lexer.ID);
this.lexer.match('r'); this.lexer.SPorHT(); this.lexer.match('='); this.lexer.SPorHT(); lexer.match(LexerCore.ID); Token repeatInterval = lexer.getNextToken(); this.lexer.SPorHT(); TypedTime typedTime = getTypedTime(repeatInterval.getTokenValue()); repeatField.setRepeatInterval(typedTime); lexer.match(LexerCore.ID); Token activeDuration = lexer.getNextToken(); this.lexer.SPorHT(); typedTime = getTypedTime(activeDuration.getTokenValue()); repeatField.setActiveDuration(typedTime); while (lexer.hasMoreChars()) { char la = lexer.lookAhead(0); if (la == '\n' || la == '\r') break; lexer.match(LexerCore.ID); Token offsets = lexer.getNextToken(); this.lexer.SPorHT(); typedTime = getTypedTime(offsets.getTokenValue()); repeatField.addOffset(typedTime); throw lexer.createParseException();
if (!startsId()) throw new ParseException(buffer + "\nID expected", ptr); String id = getNextId(); this.currentMatch = new Token(); this.currentMatch.tokenValue = id; this.currentMatch.tokenType = ID; } else if (tok == SAFE) { if (!startsSafeToken()) throw new ParseException(buffer + "\nID expected", ptr); String id = ttokenSafe(); this.currentMatch = new Token(); this.currentMatch.tokenValue = id; this.currentMatch.tokenType = SAFE; } else if (tok == ID_NO_WHITESPACE) { if (!startsIdNoWhiteSpace()) throw new ParseException(buffer + "\nID no white space expected", ptr); String id = getNextIdNoWhiteSpace(); this.currentMatch = new Token(); this.currentMatch.tokenValue = id; this.currentMatch.tokenType = ID_NO_WHITESPACE; } else { String nexttok = getNextId(); Integer cur = currentLexer.get(Utils.toUpperCase(nexttok)); char next = lookAhead(0); if (tok == DIGIT) { if (!isDigit(next)) throw new ParseException(buffer + "\nExpecting DIGIT", ptr); this.currentMatch = new Token();
try { lexer.match(LexerCore.ID); Token name = lexer.getNextToken(); lexer.SPorHT(); try { char la = lexer.lookAhead(0); lexer.consume(1); lexer.SPorHT(); String str = null; if (name.getTokenValue().compareToIgnoreCase(Via.RECEIVED) == 0) { str = lexer.byteStringNoSemicolon(); } else { if (lexer.lookAhead(0) == '\"') { str = lexer.quotedString(); quoted = true; } else { lexer.match(LexerCore.ID); Token value = lexer.getNextToken(); str = value.getTokenValue();
/** Name or value of a parameter. */ protected String paramNameOrValue() throws ParseException { int startIdx = lexer.getPtr(); while (lexer.hasMoreChars()) { char next = lexer.lookAhead(0); boolean isValidChar = false; switch (next) { case '[': case ']':// JvB: fixed this one case '/': case ':': case '&': case '+': case '$': isValidChar = true; } if (isValidChar || isUnreserved(next)) { lexer.consume(1); } else if (isEscaped()) { lexer.consume(3); } else break; } return lexer.getBuffer().substring(startIdx, lexer.getPtr()); }
public SIPHeader parse() throws ParseException { ContentType contentType = new ContentType(); if (debug) dbg_enter("ContentTypeParser.parse"); try { this.headerName(TokenTypes.CONTENT_TYPE); // The type: lexer.match(TokenTypes.ID); Token type = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentType(type.getTokenValue()); // The sub-type: lexer.match('/'); lexer.match(TokenTypes.ID); Token subType = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentSubType(subType.getTokenValue()); super.parse(contentType); this.lexer.match('\n'); } finally { if (debug) dbg_leave("ContentTypeParser.parse"); } return contentType; }
hp.setHost(host); if (allowWS) lexer.SPorHT(); // white space before ":port" should be accepted if (lexer.hasMoreChars()) { char la = lexer.lookAhead(0); switch (la) lexer.consume(1); if (allowWS) lexer.SPorHT(); // white space before port number should be accepted try { String port = lexer.number(); hp.setPort(Integer.parseInt(port)); } catch (NumberFormatException nfe) { throw new ParseException( lexer.getBuffer() + " :Error parsing port ", lexer.getPtr()); throw new ParseException( lexer.getBuffer() + " Illegal character in hostname:" + lexer.lookAhead(0), lexer.getPtr() );
public String ttokenNoWhiteSpace() { int startIdx = ptr; try { while (hasMoreChars()) { char nextChar = lookAhead(0); if ( nextChar == ' ' || nextChar == '\n' || nextChar == '\t' ) { break; } else { consume(1); } } return String.valueOf(buffer, startIdx, ptr - startIdx); } catch (ParseException ex) { return null; } }
public void consumeValidChars(char[] validChars) { int validCharsLength = validChars.length; try { while (hasMoreChars()) { char nextChar = lookAhead(0); boolean isValid = false; for (int i = 0; i < validCharsLength; i++) { switch(validChar) { case ALPHA_VALID_CHARS: isValid = isAlpha(nextChar); break; case DIGIT_VALID_CHARS: isValid = isDigit(nextChar); break; case ALPHADIGIT_VALID_CHARS: isValid = isAlphaDigit(nextChar); break; default: consume(1);
/** * parse the String message * @return SIPHeader (CallID object) * @throws ParseException if the message does not respect the spec. */ public SIPHeader parse() throws ParseException { if (debug) dbg_enter("parse"); try { headerName(TokenTypes.JOIN_TO); Join join = new Join(); this.lexer.SPorHT(); String callId = lexer.byteStringNoSemicolon(); this.lexer.SPorHT(); super.parse(join); join.setCallId(callId); return join; } finally { if (debug) dbg_leave("parse"); } }
public String ttoken() { int startIdx = ptr; try { while (hasMoreChars()) { char nextChar = lookAhead(0); if ( isTokenChar(nextChar) ) { consume(1); } else { break; } } return String.valueOf(buffer, startIdx, ptr - startIdx); } catch (ParseException ex) { return null; } }
int lineCount = 0; while ( (lexer.lookAhead(0) != '\n') && (lineCount < 20) ) { do { AlertInfo alertInfo = new AlertInfo(); URLParser urlParser; GenericURI uri; this.lexer.SPorHT(); if (this.lexer.lookAhead(0) == '<') { this.lexer.match('<'); urlParser = new URLParser((Lexer) this.lexer); uri = urlParser.uriReference( true ); alertInfo.setAlertInfo(uri); this.lexer.match('>'); } else { String alertInfoStr = this.lexer.byteStringNoSemicolon(); alertInfo.setAlertInfo(alertInfoStr); this.lexer.SPorHT(); if ( lexer.lookAhead(0) == ',' ) { this.lexer.match(','); } else break; } while (true);
private final TelephoneNumber global_phone_number( boolean inBrackets ) throws ParseException { if (debug) dbg_enter("global_phone_number"); try { TelephoneNumber tn = new TelephoneNumber(); tn.setGlobal(true); NameValueList nv = null; this.lexer.match(PLUS); String b = base_phone_number(); tn.setPhoneNumber(b); if (lexer.hasMoreChars()) { char tok = lexer.lookAhead(0); if (tok == ';' && inBrackets) { this.lexer.consume(1); nv = tel_parameters(); tn.setParameters(nv); } } return tn; } finally { if (debug) dbg_leave("global_phone_number"); } }