class Util {

    public static String namespaceToJavaPackage(String namespace) {
        URI uri;
        try {
            uri = new URI(namespace);
        } catch (URISyntaxException e) {
            Util.LOGGER.debug(e.getMessage(), e);
            return "uri.invalid";
        }
        StringBuilder sb = new StringBuilder();

        String host = uri.getHost();
        if (host != null) {
            Util.addReversed(sb, host, "\\.");
        }

        String path = uri.getPath();
        if (!path.equals("")) {
            if (path.startsWith("/")) {
                // remove first slash
                path = path.substring(1);
            }

            // and then handle the string
            Util.addAsIs(sb, path, "/");
        }

        // remove the final dot
        sb.replace(sb.length() - 1, sb.length(), "");

        return Util.cleanName(sb.toString());
    }

}