/** * Method to obtain the media type of a given resource. * * @param resourceName the name of the resource. * @return the media type. * @throws RegistryException if the operation failed. */ public static String getMediaType(String resourceName) throws RegistryException { if (resourceName == null || resourceName.indexOf('.') == -1 || resourceName.indexOf('.') + 1 >= resourceName.length()) { return null; } String extension = resourceName.substring(resourceName.lastIndexOf('.') + 1).toLowerCase(); String mediaTypes = getResourceMediaTypeMappings(RegistryContext.getBaseInstance()); if (mediaTypes == null) { // We don't treat this as an error, since some collections and resources would be // created even before the media types have been stored into the registry, and have // been initialized. return null; } extension += ":"; if (mediaTypes.contains(extension)) { String temp = mediaTypes.substring(mediaTypes.indexOf(extension) + extension.length()); if (temp.indexOf(',') == -1) { return temp; } else { return temp.substring(0, temp.indexOf(',')); } } return null; }
/** * Method to obtain the collection media types. * * @param registryContext the registry context. * @return a String of collection media types, in the format name:type,name:type,... * @throws RegistryException if the operation failed. */ public static String getCollectionMediaTypeMappings(RegistryContext registryContext) throws RegistryException { if (registryContext == null) { return RegistryContext.getBaseInstance().getCollectionMediaTypes(); } else { return registryContext.getCollectionMediaTypes(); } }
public void setUp() throws RegistryException { if (System.getProperty("carbon.home") == null) { File file = new File("src/test/resources/carbon-home"); if (file.exists()) { System.setProperty("carbon.home", file.getAbsolutePath()); } } // The line below is responsible for initializing the cache. CarbonContext.getCurrentContext(); String carbonHome = System.getProperty("carbon.home"); System.out.println("carbon home " + carbonHome); String carbonXMLPath = carbonHome + File.separator + "repository" + File.separator + "conf" + File.separator + "carbon.xml"; RegistryConfiguration regConfig = new RegistryConfiguration(carbonXMLPath); RegistryCoreServiceComponent.setRegistryConfig(regConfig); RealmService realmService = new InMemoryRealmService(); InputStream is; try { is = this.getClass().getClassLoader().getResourceAsStream("registry.xml"); } catch (Exception e) { is = null; } ctx = RegistryContext.getBaseInstance(is, realmService); // RegistryConfigurationProcessor.populateRegistryConfig(is, ctx); ctx.setSetup(true); ctx.selectDBConfig("h2-db"); }
/** * Method to set custom UI media types. * * @param customUIMediaTypes the custom UI media types. */ public void setCustomUIMediaTypes(String customUIMediaTypes) { RegistryContext.getBaseInstance().customUIMediaTypes = customUIMediaTypes; }
/** * Method to obtain custom UI media types. * * @return the custom UI media types. */ public String getCustomUIMediaTypes() { return RegistryContext.getBaseInstance().customUIMediaTypes; }
/** * Method to set collection media types. * * @param collectionMediaTypes the collection media types. */ public void setCollectionMediaTypes(String collectionMediaTypes) { RegistryContext.getBaseInstance().collectionMediaTypes = collectionMediaTypes; }
/** * Method to obtain collection media types. * * @return the collection media types. */ public String getCollectionMediaTypes() { return RegistryContext.getBaseInstance().collectionMediaTypes; }
/** * Method to set resource media types. * * @param resourceMediaTypes the resource media types. */ public void setResourceMediaTypes(String resourceMediaTypes) { RegistryContext.getBaseInstance().resourceMediaTypes = resourceMediaTypes; }
/** * Method to obtain resource media types. * * @return the resource media types. */ public String getResourceMediaTypes() { return RegistryContext.getBaseInstance().resourceMediaTypes; }