예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * 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();
   }
 }
예제 #3
0
  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");
  }
예제 #4
0
 /**
  * Method to set custom UI media types.
  *
  * @param customUIMediaTypes the custom UI media types.
  */
 public void setCustomUIMediaTypes(String customUIMediaTypes) {
   RegistryContext.getBaseInstance().customUIMediaTypes = customUIMediaTypes;
 }
예제 #5
0
 /**
  * Method to obtain custom UI media types.
  *
  * @return the custom UI media types.
  */
 public String getCustomUIMediaTypes() {
   return RegistryContext.getBaseInstance().customUIMediaTypes;
 }
예제 #6
0
 /**
  * Method to set collection media types.
  *
  * @param collectionMediaTypes the collection media types.
  */
 public void setCollectionMediaTypes(String collectionMediaTypes) {
   RegistryContext.getBaseInstance().collectionMediaTypes = collectionMediaTypes;
 }
예제 #7
0
 /**
  * Method to obtain collection media types.
  *
  * @return the collection media types.
  */
 public String getCollectionMediaTypes() {
   return RegistryContext.getBaseInstance().collectionMediaTypes;
 }
예제 #8
0
 /**
  * Method to set resource media types.
  *
  * @param resourceMediaTypes the resource media types.
  */
 public void setResourceMediaTypes(String resourceMediaTypes) {
   RegistryContext.getBaseInstance().resourceMediaTypes = resourceMediaTypes;
 }
예제 #9
0
 /**
  * Method to obtain resource media types.
  *
  * @return the resource media types.
  */
 public String getResourceMediaTypes() {
   return RegistryContext.getBaseInstance().resourceMediaTypes;
 }