Package com.google.opengse.parser

Examples of com.google.opengse.parser.Chset


    }
  }


  static Parser<RequestContext> getParser() {
    Chset wsp = new Chset(" \t\r\n");

    // recognize standard methods
    Parser<RequestContext> method = null;
    for (String methodName : STANDARD_METHODS) {
      Parser<RequestContext> p = new Strcaselit(methodName).action(
          new ParserFactory.MethodAction(methodName));
      if (method == null) {
        method = p;
      } else {
        method = Parser.alternative(method, p);
      }
    }

    // support nonstandard methods too
    method = Parser.alternative(
        method,
        Chset.ALPHA.plus().action(new ParserFactory.MethodAction()));

    Parser<RequestContext> uri
        = Chset.not(wsp).plus().action(new ParserFactory.UriAction());

    Parser<RequestContext> version =
      Parser.sequence(new Strcaselit("http/"),
                      Chset.DIGIT.plus().action(new MajorVersionAction()));
    version = Parser.sequence(version, new Chset('.'));
    version = Parser.sequence(version,
      Chset.DIGIT.plus().action(new MinorVersionAction()));

    Parser<RequestContext> reqline = Parser.sequence(method, wsp.plus());
    reqline = Parser.sequence(reqline, uri);
    reqline = Parser.sequence(reqline, wsp.plus());
    reqline = Parser.sequence(reqline, version);

    return reqline;
  }
View Full Code Here


   * @param text a Chset representing a character in a quoted pair.
   * @param qtext a Chset representing a character that need not be quoted.
   */
  static Parser<MimeContentHeader> createParameterParser(
      Chset text, Chset qtext) {
    Chset special = new Chset(TSPECIAL_CHARS);
    Chset token = Chset.difference(Chset.difference(Chset.ANYCHAR,
                                                    Chset.WHITESPACE),
                                   special);

    // TODO(spencer): handling of quoted pairs is not correct in this parser.
    // They are simply left as \CHAR. Changing this now, however, would cause
    // existing servers to get different (possibly incompatible) inputs.
    // See ChunkHeader.java for a correct implementation.
    Parser<MimeContentHeader> quotedPair =
        Parser.sequence(new Chset('\\'), text);
    Parser<MimeContentHeader> quotedString =
        Parser.alternative(qtext, quotedPair);
    quotedString = quotedString.star().action(new ParamValueAction());
    quotedString = Parser.sequence(new Chset('"'), quotedString);
    quotedString = Parser.sequence(quotedString, new Chset('"'));

    Parser<MimeContentHeader> name =
        token.plus().action(new ParamNameAction());
    Parser<MimeContentHeader> value =
      token.plus().action(new ParamValueAction());
    value = Parser.alternative(value, quotedString);

    Parser<Object> wsp = Chset.WHITESPACE.star();
    Parser<MimeContentHeader> parameters =
      Parser.sequence(wsp, new Chset(';'));
    parameters = Parser.sequence(parameters, wsp);
    parameters = Parser.sequence(parameters, name);
    parameters = Parser.sequence(parameters, wsp);
    parameters = Parser.sequence(parameters, new Chset('='));
    parameters = Parser.sequence(parameters, wsp);
    parameters = Parser.sequence(parameters, value);
    return parameters.star();
  }
View Full Code Here

TOP

Related Classes of com.google.opengse.parser.Chset

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.