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("/")) { path = path.substring(1); } Util.addAsIs(sb, path, "/"); } sb.replace(sb.length() - 1, sb.length(), ""); return Util.cleanName(sb.toString()); }  static String URLdecode(String s); static String URLencode(String s); static String URLencode(QName qname); static String DoubleURLencode(String s); static String DoubleURLencode(QName qname); static boolean isRelativeURI(String uri); static String getPathInsideRepo(GenericId id); static Class<? extends DefinitionsChildId> getComponentIdClassForTExtensibleElements(Class<? extends TExtensibleElements> clazz); @SuppressWarnings("unchecked") static Class<? extends DefinitionsChildId> getComponentIdClass(String idClassName); @SuppressWarnings("unchecked") static Class<? extends GenericId> getGenericIdClassForType(String typeIdType); static String getUrlPath(GenericId id); static String getUrlPath(String pathInsideRepo); static String getUrlPath(RepositoryFileReference ref); static String getURLpathFragmentForCollection(Class<? extends TExtensibleElements> c); static String getEverythingBetweenTheLastDotAndBeforeId(Class<? extends GenericId> cls); static String getTypeForElementId(Class<? extends ToscaElementId> idClass); static String getTypeForComponentId(Class<? extends DefinitionsChildId> idClass); static String getRootPathFragment(Class<? extends DefinitionsChildId> idClass); static String getFolderName(Class<? extends DefinitionsChildId> idClass); static String qname2hrefWithName(String repositoryUiUrl, Class<? extends TExtensibleElements> element, QName qname, String name); static String qname2href(@NonNull String repositoryUiUrl, @NonNull Class<? extends TExtensibleElements> element, @Nullable QName qname, @Nullable String name); static String qname2href(String repositoryUiUrl, Class<? extends TExtensibleElements> element, QName qname); static String renderMinInstances(Integer minInstances); static String renderMaxInstances(String maxInstances); static JAXBElement<T> getJAXBElement(Class<T> clazz, T obj); static String getXMLAsString(Class<T> clazz, T obj); static String getXMLAsString(Element el); static boolean instanceSupportsNameAttribute(Class<? extends DefinitionsChildId> idClass); static String getLastURIPart(String loc); static String makeCSSName(String namespace, String localName); static String makeCSSName(QName qname); static SortedMap<String, SortedSet<String>> convertQNameListToNamespaceToLocalNameList(List<QName> list); static String namespaceToJavaPackage(String namespace); static String makeNCName(String text); static Path determineAndCreateRepositoryPath(); static void createCsarOutputPath(String csarOutputPath); static final String FORBIDDEN_CHARACTER_REPLACEMENT; static final String slashEncoded; }
@Test public void testNamespaceToJavaPackageURLWithNoHost() { assertEquals("plainNCname", Util.namespaceToJavaPackage("plainNCname")); }
@Test public void testNamespaceToJavaPackageFullURL() { assertEquals("org.example.www.tosca.nodetypes", Util.namespaceToJavaPackage("http: }
@Test public void testNamespaceToJavaPackageURLWithHostOnly() { assertEquals("org.example.www", Util.namespaceToJavaPackage("http: }
@Test public void testNamespaceToJavaPackageURLWithHostOnlyAndNoFinalSlash() { assertEquals("org.example.www", Util.namespaceToJavaPackage("http: }