All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swim.uri.UriParser Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package swim.uri;

import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.codec.Unicode;

public class UriParser {
  public Uri absolute(UriScheme scheme, UriAuthority authority, UriPath path,
                      UriQuery query, UriFragment fragment) {
    return Uri.from(scheme, authority, path, query, fragment);
  }

  public UriScheme scheme(String name) {
    return UriScheme.from(name);
  }

  public UriAuthority authority(UriUser user, UriHost host, UriPort port) {
    return UriAuthority.from(user, host, port);
  }

  public UriUser user(String username, String password) {
    return UriUser.from(username, password);
  }

  public UriHost hostName(String address) {
    return UriHost.name(address);
  }

  public UriHost hostIPv4(String address) {
    return UriHost.ipv4(address);
  }

  public UriHost hostIPv6(String address) {
    return UriHost.ipv6(address);
  }

  public UriPort port(int number) {
    return UriPort.from(number);
  }

  public UriPath pathEmpty() {
    return UriPath.empty();
  }

  public UriPathBuilder pathBuilder() {
    return new UriPathBuilder();
  }

  public UriQueryBuilder queryBuilder() {
    return new UriQueryBuilder();
  }

  public UriFragment fragment(String identifier) {
    return UriFragment.from(identifier);
  }

  public Parser absoluteParser() {
    return new UriAbsoluteParser(this);
  }

  public Parser parseAbsolute(Input input) {
    return UriAbsoluteParser.parse(input, this);
  }

  public Uri parseAbsoluteString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseAbsolute(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    if (!parser.isDone()) {
      System.out.println(parser);
    }
    return parser.bind();
  }

  public Parser schemeParser() {
    return new UriSchemeParser(this);
  }

  public Parser parseScheme(Input input) {
    return UriSchemeParser.parse(input, this);
  }

  public UriScheme parseSchemeString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseScheme(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser authorityParser() {
    return new UriAuthorityParser(this);
  }

  public Parser parseAuthority(Input input) {
    return UriAuthorityParser.parse(input, this);
  }

  public UriAuthority parseAuthorityString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseAuthority(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser userParser() {
    return new UriUserParser(this);
  }

  public Parser parseUser(Input input) {
    return UriUserParser.parse(input, this);
  }

  public UriUser parseUserString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseUser(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser hostParser() {
    return new UriHostParser(this);
  }

  public Parser parseHost(Input input) {
    return UriHostParser.parse(input, this);
  }

  public UriHost parseHostString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseHost(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser hostAddressParser() {
    return new UriHostAddressParser(this);
  }

  public Parser parseHostAddress(Input input) {
    return UriHostAddressParser.parse(input, this);
  }

  public Parser hostLiteralParser() {
    return new UriHostLiteralParser(this);
  }

  public Parser parseHostLiteral(Input input) {
    return UriHostLiteralParser.parse(input, this);
  }

  public Parser portParser() {
    return new UriPortParser(this);
  }

  public Parser parsePort(Input input) {
    return UriPortParser.parse(input, this);
  }

  public UriPort parsePortString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parsePort(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser pathParser(UriPathBuilder builder) {
    return new UriPathParser(this, builder);
  }

  public Parser pathParser() {
    return new UriPathParser(this);
  }

  public Parser parsePath(Input input, UriPathBuilder builder) {
    return UriPathParser.parse(input, this, builder);
  }

  public Parser parsePath(Input input) {
    return UriPathParser.parse(input, this);
  }

  public UriPath parsePathString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parsePath(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser queryParser(UriQueryBuilder builder) {
    return new UriQueryParser(this, builder);
  }

  public Parser queryParser() {
    return new UriQueryParser(this);
  }

  public Parser parseQuery(Input input, UriQueryBuilder builder) {
    return UriQueryParser.parse(input, this, builder);
  }

  public Parser parseQuery(Input input) {
    return UriQueryParser.parse(input, this);
  }

  public UriQuery parseQueryString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseQuery(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }

  public Parser fragmentParser() {
    return new UriFragmentParser(this);
  }

  public Parser parseFragment(Input input) {
    return UriFragmentParser.parse(input, this);
  }

  public UriFragment parseFragmentString(String string) {
    final Input input = Unicode.stringInput(string);
    Parser parser = parseFragment(input);
    if (input.isCont() && !parser.isError()) {
      parser = Parser.error(Diagnostic.unexpected(input));
    }
    return parser.bind();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy