Package java.net

Examples of java.net.URISyntaxException


     * Parses the string representation of the URI into its component parts.
     */
    private void parseURI(String uri) throws URISyntaxException {
        /* If the uri is null, throw an Exception */
        if (uri == null) {
            throw new URISyntaxException(uri, "URI is NULL");
        }

        /* First check whether the uri contains a <protocol>:// */
        int protocolIndex = uri.indexOf("://");
        if (protocolIndex == -1 || protocolIndex == 0) {
            throw new URISyntaxException(uri, "URI does not contain a protocol");
        }
        protocol = uri.substring(0, protocolIndex);

        /* Advance the index to after the "://" */
        protocolIndex += 3;

        /*
         * Next parse out the root. If we find a "@" first, then there
         * is also a hostname. If we find a "/" next, then there is no host name
         */
        int atIndex = uri.indexOf("@", protocolIndex);
        int slashIndex = uri.indexOf("/", protocolIndex);
        if (atIndex != -1 && atIndex < slashIndex) {
            root = uri.substring(protocolIndex, atIndex);
        }
        else if (slashIndex != -1) {
            root = uri.substring(protocolIndex, slashIndex);
        }
        else {
            throw new URISyntaxException(uri, "Cannot find module name in URI");
        }

        /*
         * Next parse out the host name and port if there is one.
         */
        if (atIndex != -1 && atIndex < slashIndex) {
            int colonIndex = uri.indexOf(":", atIndex + 1);
            if (colonIndex != -1 && colonIndex < slashIndex) {
                hostName = uri.substring(atIndex + 1, colonIndex);
                try {
                    hostPort = new Integer(uri.substring(colonIndex + 1, slashIndex));
                } catch (NumberFormatException excp) {
                    hostPort = -1;
                    throw new URISyntaxException(uri, "Invalid Host port given in URI");
                }
            }
            else {
                hostName = uri.substring(atIndex + 1, slashIndex);
                hostPort = -1;
View Full Code Here


  public static void checkVersion(String version) throws URISyntaxException {
    boolean ok = version.equals(LATEST_VERSION_INDICATOR) ||
      VERSION_PATTERN.matcher(version).find();
   
    if ( ! ok ) {       
      throw new URISyntaxException(version, "Invalid version string: " +version);
    }

  }
View Full Code Here

        final String fullRequestedUri = getFullRequestedUri(juri);

    final String path = juri.getPath();

    if ( path == null ) {
      throw new URISyntaxException(str, "not path");
    }

    if ( !path.startsWith("/") ) {
      throw new URISyntaxException(str, "not absolute path");
    }
    int idx = path.indexOf('/', 1);
    if ( idx < 0 ) {
      throw new URISyntaxException(str, "No root");
    }
    String root = path.substring(0, idx); // include leading slash 
   
    String reqUri = path;
    String contextPath = root;
   
    String requestedUri = reqUri;
    // parsing described with an example:
   
    // afterRoot = /mmi/someVocab.owl/someTerm
    String afterRoot = requestedUri.substring(contextPath.length());
    if ( afterRoot.startsWith("/") ) {
      afterRoot = afterRoot.substring(1);
    }
   
    int rootIdx = fullRequestedUri.indexOf(afterRoot);
    untilRoot = fullRequestedUri.substring(0, rootIdx);
    assert untilRoot.endsWith("/");
   
    String[] parts = afterRoot.split("/");

    // Either:  1 part = { mmi }  if allowUntilAuthority
    //     or:  2 parts = { mmi, someVocab.owl }
    //     or:  3 parts = { mmi, someVocab.owl, someTerm }
    //               or = { mmi, someVersion, someVocab.owl}
    //     or:  4 parts = { mmi, someVersion, someVocab.owl, someTerm }
    if ( parts.length < 2 || parts.length > 4 ) {
      // if only one part, then accepted only if allowUntilAuthority
      if ( parts.length == 1 && allowUntilAuthority ) {
        // OK
      }
      else {
        throw new URISyntaxException(fullRequestedUri, "2, 3, or 4 parts expected: "
            +Arrays.asList(parts));
      }
    }

    String _version = null; // will remain null if not given.
    String _topic = "";
    String _term = "";     // will remain "" if not given
   
    if ( parts.length == 1 ) {
      // OK
      assert allowUntilAuthority;
    }
    else if ( parts.length == 2 ) {
      _topic = parts[1];
    }
    else if ( parts.length == 4 ) {
      _version = parts[1];
      _topic = parts[2];
      _term = parts[3];
    }
    else {
      assert parts.length == 3 ;
     
      // Determine which of the two cases (a) or (b) we are dealing with:
      //   (a) { mmi, someVocab.owl, someTerm }
      //   (b) { mmi, someVersion, someVocab.owl}

      // if parts[1] starts with a digit or is LATEST_VERSION_INDICATOR, take that part as the version:
      if ( parts[1].length() > 0
      && ( Character.isDigit(parts[1].charAt(0))
           || parts[1].equals(LATEST_VERSION_INDICATOR) )
      ) {
        // case (b):
        _version = parts[1];
        _topic = parts[2];
      }
      else {
        // case (a)
        _topic = parts[1];
        _term = parts[2];
      }
    }
   
    String _authority = parts[0];
       
    // remove any extension from _authority, _topic and _term, but remember them to assign this.extension below
   
    Set<String> extensions = new HashSet<String>();
   
    String _authorityExt = "";
    int dotIdx = _authority.lastIndexOf('.');
    if ( dotIdx >= 0) {
      _authorityExt = _authority.substring(dotIdx).toLowerCase();
      _authority = _authority.substring(0, dotIdx);
      extensions.add(_authorityExt);
    }

    String _topicExt = "";
    dotIdx = _topic.lastIndexOf('.');
    if ( dotIdx >= 0) {
      _topicExt = _topic.substring(dotIdx).toLowerCase();
      _topic = _topic.substring(0, dotIdx);
      extensions.add(_topicExt);
    }
   
    String _termExt = "";
    dotIdx = _term.lastIndexOf('.');
    if ( dotIdx >= 0) {
      _termExt = _term.substring(dotIdx).toLowerCase();
      _term = _term.substring(0, dotIdx);
      extensions.add(_termExt);
    }
   
   
    if ( extensions.size() > 1 ) {
      // there are different extensions:
      throw new URISyntaxException(fullRequestedUri, "Explicit extensions given but different: " +extensions);
    }

    ////////////////////////////////////////////////////////////////////////////////
    // now, assign to my final fields and do remaining checks:
   
    authority =  _authority;
   
    version = _version;
    topic =   _topic;
    term =    _term;
   
    extension = extensions.size() == 1 ? extensions.iterator().next() : "";
   
   
    if ( authority.length() == 0 ) {
      throw new URISyntaxException(fullRequestedUri, "Missing authority in URI");
    }
    if ( authority.startsWith("-") ) {
      throw new URISyntaxException(fullRequestedUri, "Authority cannot start with hyphen");
    }
    if ( Character.isDigit(authority.charAt(0)) ) {
      throw new URISyntaxException(fullRequestedUri, "Authority cannot start with digit");
    }
    if ( ! allowUntilAuthority && topic.length() == 0 ) {
      throw new URISyntaxException(fullRequestedUri, "Missing topic in URI");
    }
    if ( topic.length() > 0 && Character.isDigit(topic.charAt(0)) ) {
      throw new URISyntaxException(fullRequestedUri, "Topic cannot start with digit");
    }
   
    // check version, if given:
    if ( version != null ) {
      checkVersion(version);
View Full Code Here

   *
   * @throws URISyntaxException if version is not null and contains a slash.
   */
  public MmiUri copyWithVersionNoCheck(String version) throws URISyntaxException {
    if ( version != null && version.indexOf('/') >= 0 ) {
      throw new URISyntaxException(version, "version contains a slash");
    }
    return new MmiUri(untilRoot, authority, version, topic, term, extension);
  }
View Full Code Here

   *
   * @throws URISyntaxException if newExtension is null or contains a slash.
   */
  public MmiUri copyWithExtension(String newExtension) throws URISyntaxException {
    if ( newExtension == null || newExtension.indexOf('/') >= 0 ) {
      throw new URISyntaxException(newExtension, "newExtension is null or contains a slash");
    }
    return new MmiUri(untilRoot, authority, version, topic, term, newExtension);
  }
View Full Code Here

    if (curBase == null || curBase.equals("")) {

      // We require an absolute URI.
      if (!newBaseUri.isAbsolute()) {
        throw new URISyntaxException(
          newBase, "No xml:base established--need an absolute URI.");
      }

      return newBase;
    }
View Full Code Here

                    }
                }
            }
            return rc;
        } catch (UnsupportedEncodingException e) {
            throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
        }
    }
View Full Code Here

    private static void parseComposite(URI uri, CompositeData rc, String ssp) throws URISyntaxException {
        String componentString;
        String params;

        if (!checkParenthesis(ssp)) {
            throw new URISyntaxException(uri.toString(), "Not a matching number of '(' and ')' parenthesis");
        }

        int p;
        int intialParen = ssp.indexOf("(");
        if (intialParen == 0) {
View Full Code Here

                return rc.toString();
            } else {
                return "";
            }
        } catch (UnsupportedEncodingException e) {
            throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
        }
    }
View Full Code Here

        try {
            URI uri = new URI(source);
            if (uri.getScheme() != null
                    && !uri.getScheme().toLowerCase(Locale.US)
                            .equals(getRepositoryScheme().toLowerCase(Locale.US))) {
                throw new URISyntaxException(source, "Wrong scheme in URI. Expected "
                        + getRepositoryScheme() + " as scheme!");
            }
            if (uri.getHost() == null && getHost() == null) {
                throw new URISyntaxException(source, "Missing host in URI or in resolver");
            }
            if (uri.getPath() == null) {
                throw new URISyntaxException(source, "Missing path in URI");
            }
            // if (uri.getUserInfo() == null && getUser() == null) {
            // throw new URISyntaxException(source, "Missing username in URI or in resolver");
            // }
            return uri;
View Full Code Here

TOP

Related Classes of java.net.URISyntaxException

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.