Package java.net

Examples of java.net.URISyntaxException


          URI uri = new URI(url);
          String host = uri.getHost();

          if (host == null || host.equals(""))
            throw new URISyntaxException(url, "Unable to gather host or no host found");

          // Gather the domain object
          InternetDomainName domainObj = InternetDomainName.from(host);

          // Output the TLD
View Full Code Here


                    // fall through on purpose
                case 1:
                    element.setSymbolicName(parts[0]);
                    break;
                default:
                    throw new URISyntaxException(base.toString(),
                        "Unexpected number of parts: " + parts.length);
            }
            try
            {
                ResolutionConfig config = new ResolutionConfig(
View Full Code Here

     * @see #RAW_TOKEN_END
     */
    public static Map<String, Object> parseQuery(String uri, boolean useRaw) throws URISyntaxException {
        // must check for trailing & as the uri.split("&") will ignore those
        if (uri != null && uri.endsWith("&")) {
            throw new URISyntaxException(uri, "Invalid uri syntax: Trailing & marker found. "
                    + "Check the uri and remove the trailing & marker.");
        }

        if (ObjectHelper.isEmpty(uri)) {
            // return an empty map
            return new LinkedHashMap<String, Object>(0);
        }

        // need to parse the uri query parameters manually as we cannot rely on splitting by &,
        // as & can be used in a parameter value as well.

        try {
            // use a linked map so the parameters is in the same order
            Map<String, Object> rc = new LinkedHashMap<String, Object>();

            boolean isKey = true;
            boolean isValue = false;
            boolean isRaw = false;
            StringBuilder key = new StringBuilder();
            StringBuilder value = new StringBuilder();

            // parse the uri parameters char by char
            for (int i = 0; i < uri.length(); i++) {
                // current char
                char ch = uri.charAt(i);
                // look ahead of the next char
                char next;
                if (i <= uri.length() - 2) {
                    next = uri.charAt(i + 1);
                } else {
                    next = '\u0000';
                }

                // are we a raw value
                isRaw = value.toString().startsWith(RAW_TOKEN_START);

                // if we are in raw mode, then we keep adding until we hit the end marker
                if (isRaw) {
                    if (isKey) {
                        key.append(ch);
                    } else if (isValue) {
                        value.append(ch);
                    }

                    // we only end the raw marker if its )& or at the end of the value

                    boolean end = ch == RAW_TOKEN_END.charAt(0) && (next == '&' || next == '\u0000');
                    if (end) {
                        // raw value end, so add that as a parameter, and reset flags
                        addParameter(key.toString(), value.toString(), rc, useRaw || isRaw);
                        key.setLength(0);
                        value.setLength(0);
                        isKey = true;
                        isValue = false;
                        isRaw = false;
                        // skip to next as we are in raw mode and have already added the value
                        i++;
                    }
                    continue;
                }

                // if its a key and there is a = sign then the key ends and we are in value mode
                if (isKey && ch == '=') {
                    isKey = false;
                    isValue = true;
                    isRaw = false;
                    continue;
                }

                // the & denote parameter is ended
                if (ch == '&') {
                    // parameter is ended, as we hit & separator
                    addParameter(key.toString(), value.toString(), rc, useRaw || isRaw);
                    key.setLength(0);
                    value.setLength(0);
                    isKey = true;
                    isValue = false;
                    isRaw = false;
                    continue;
                }

                // regular char so add it to the key or value
                if (isKey) {
                    key.append(ch);
                } else if (isValue) {
                    value.append(ch);
                }
            }

            // any left over parameters, then add that
            if (key.length() > 0) {
                addParameter(key.toString(), value.toString(), rc, useRaw || isRaw);
            }

            return rc;

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

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

    private DocumentSource createHTTPDocumentSource(WebResponder responder, String uri, boolean report)
    throws IOException {
        try {
            if (!isValidURI(uri)) {
                throw new URISyntaxException(uri, "@@@");
            }
            return createHTTPDocumentSource(responder.getRunner().getHTTPClient(), uri);
        } catch (URISyntaxException ex) {
            responder.sendError(400, "Invalid input URI " + uri, report);
            return null;
View Full Code Here

      String scheme = uri.getScheme();
      if (uri.getScheme() == null)
         scheme = JCR_SCHEME;
      if (!scheme.equals(JCR_SCHEME))
         throw new URISyntaxException(scheme, "Only 'jcr' scheme is acceptable!");

      userInfo = uri.getUserInfo();

      repository = uri.getHost();

      workspace = parseWorkpace(uri);

      String fragment = uri.getFragment();
      if (fragment != null)
      {
         if (fragment.startsWith("/"))
            this.path = fragment;
         else
            this.id = new Identifier(uri.getFragment());
      }
      else
         throw new URISyntaxException(fragment, "Neither Path nor Identifier defined!");

   }
View Full Code Here

      String scheme = uri.getScheme();
      if (uri.getScheme() == null)
         scheme = JCR_SCHEME;
      if (!scheme.equals(JCR_SCHEME))
         throw new URISyntaxException(scheme, "Only 'jcr' scheme is acceptable!");

      userInfo = uri.getUserInfo();

      repository = uri.getHost();
      if (repository == null)
         repository = defaultRepository;

      workspace = parseWorkpace(uri);
      if (workspace == null || workspace.length() == 0)
         workspace = defaultWorkspace;

      String fragment = uri.getFragment();
      if (fragment != null)
      {
         if (fragment.startsWith("/"))
            this.path = fragment;
         else
            this.id = new Identifier(uri.getFragment());
      }
      else
         throw new URISyntaxException(fragment, "Neither Path nor Identifier defined!");

   }
View Full Code Here

   {
      if (id != null)
         return new URI(JCR_SCHEME, userInfo, repository, -1, '/' + workspace, null, id.getString());
      else if (path != null)
         return new URI(JCR_SCHEME, userInfo, repository, -1, '/' + workspace, null, path);
      throw new URISyntaxException("", "Path or Idenfifier is not defined!");
   }
View Full Code Here

      URI _uRI = fileURL.toURI();
      File _file = new File(_uRI);
      sourceRoot = _file;
    } catch (final Throwable _t) {
      if (_t instanceof URISyntaxException) {
        final URISyntaxException e = (URISyntaxException)_t;
        throw new IOException(e);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
View Full Code Here

     * 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 module name. 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) {
            moduleName = uri.substring(protocolIndex, atIndex);
        }
        else if (slashIndex != -1) {
            moduleName = 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

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.