コード例 #1
0
  /**
   * parse the String message
   *
   * @return SIPHeader (AcceptEncoding object)
   * @throws ParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {
    AcceptEncodingList acceptEncodingList = new AcceptEncodingList();
    if (debug) dbg_enter("AcceptEncodingParser.parse");

    try {
      headerName(TokenTypes.ACCEPT_ENCODING);
      // empty body is fine for this header.
      if (lexer.lookAhead(0) == '\n') {
        AcceptEncoding acceptEncoding = new AcceptEncoding();
        acceptEncodingList.add(acceptEncoding);
      } else {
        while (lexer.lookAhead(0) != '\n') {
          AcceptEncoding acceptEncoding = new AcceptEncoding();
          if (lexer.lookAhead(0) != ';') {
            // Content-Coding:
            lexer.match(TokenTypes.ID);
            Token value = lexer.getNextToken();
            acceptEncoding.setEncoding(value.getTokenValue());
          }

          while (lexer.lookAhead(0) == ';') {
            this.lexer.match(';');
            this.lexer.SPorHT();
            this.lexer.match('q');
            this.lexer.SPorHT();
            this.lexer.match('=');
            this.lexer.SPorHT();
            lexer.match(TokenTypes.ID);
            Token value = lexer.getNextToken();
            try {
              float qv = Float.parseFloat(value.getTokenValue());
              acceptEncoding.setQValue(qv);
            } catch (NumberFormatException ex) {
              throw createParseException(ex.getMessage());
            } catch (InvalidArgumentException ex) {
              throw createParseException(ex.getMessage());
            }
            this.lexer.SPorHT();
          }

          acceptEncodingList.add(acceptEncoding);
          if (lexer.lookAhead(0) == ',') {
            this.lexer.match(',');
            this.lexer.SPorHT();
          }
        }
      }
      return acceptEncodingList;
    } finally {
      if (debug) dbg_leave("AcceptEncodingParser.parse");
    }
  }
コード例 #2
0
  /**
   * parse the String message
   *
   * @return SIPHeader (RetryAfter object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {

    if (debug) dbg_enter("RetryAfterParser.parse");

    RetryAfter retryAfter = new RetryAfter();
    try {
      headerName(TokenTypes.RETRY_AFTER);

      // mandatory delatseconds:
      String value = lexer.number();
      try {
        int ds = Integer.parseInt(value);
        retryAfter.setRetryAfter(ds);
      } catch (NumberFormatException ex) {
        throw createParseException(ex.getMessage());
      } catch (InvalidArgumentException ex) {
        throw createParseException(ex.getMessage());
      }

      this.lexer.SPorHT();
      if (lexer.lookAhead(0) == '(') {
        String comment = this.lexer.comment();
        retryAfter.setComment(comment);
      }
      this.lexer.SPorHT();

      while (lexer.lookAhead(0) == ';') {
        this.lexer.match(';');
        this.lexer.SPorHT();
        lexer.match(TokenTypes.ID);
        Token token = lexer.getNextToken();
        value = token.getTokenValue();
        if (value.equalsIgnoreCase("duration")) {
          this.lexer.match('=');
          this.lexer.SPorHT();
          value = lexer.number();
          try {
            int duration = Integer.parseInt(value);
            retryAfter.setDuration(duration);
          } catch (NumberFormatException ex) {
            throw createParseException(ex.getMessage());
          } catch (InvalidArgumentException ex) {
            throw createParseException(ex.getMessage());
          }
        } else {
          this.lexer.SPorHT();
          this.lexer.match('=');
          this.lexer.SPorHT();
          lexer.match(TokenTypes.ID);
          Token secondToken = lexer.getNextToken();
          String secondValue = secondToken.getTokenValue();
          retryAfter.setParameter(value, secondValue);
        }
        this.lexer.SPorHT();
      }
    } finally {
      if (debug) dbg_leave("RetryAfterParser.parse");
    }

    return retryAfter;
  }