Skip to main content

Accessing Resources in a Plug-in and the Workspace

Before you can use the Sabre Red 360 API to access resources, you must define an Activator class in your plug-in by extending the com.sabre.edge.platform.core.common.plugin.base.AbstractEdgeBasePlugin class.

Next, review one of the following topics to access the resources that you want, and then add the Java code to your plug-in:

Accessing Images in Your Plug-in

This topic describes two ways to access images. You can choose either way.

  • Add the following line of code to your Java source file to return an instance of the class . The image is associated with the icon sample_icon.png, which is located in the icons directory in your plug-in.

Image image = Activator.getDefault().getImage("icons/sample_icon.png");

In the preceding example, Activator is the name of the Activator class in the plug-in.
  • Call the getImageDescriptor() method from your Java code to obtain an instance of the class org.eclipse.jface.resource.ImageDescriptor . This class is associated with the specified image. It can create an image on demand. (For more details, see the Eclipse documentation.) This method is from AbstractEdgeBasePlugin .

ImageDescriptor imageDescriptor = Activator.getDefault().getImageDescriptor("icons/sample_icon.png");

Accessing Other Resources in Your Plug-in

To access resources that are not images in your plug-in, call getResourceAsStream() from your Java code.

The com.sabre.edge.platform.core.common.plugin.base.AbstractEdgeBasePlugin class provides the getResourceAsStream() method. This method returns an input stream that is associated with the resource file inside the plug-in. The following code sample demonstrates how to load properties from a file using this method.

public Properties getProperties(String filename) throws IOException {
      Properties properties = new Properties();
      InputStream inputStream = Activator.getDefault().getResourceAsStream(filename);
      if(inputStream != null) {
      return properties;


Accessing Files from the Workspace Directory

The methods in this topic enable you to access the path and a specific file in the workspace directory.

Obtaining the File Path in the Workspace

Add the following line of code to your Java source file. This code retrieves an object of the File class that represents a directory in the workspace of the com.sabre.redapp.example.resources plug-in.

File dir = Activator.getDefault().getDataDirectory("com.sabre.redapp.example.resources");

Obtaining a Specific File in the Workspace Directory

To access a specific file in the workspace directory, use the getDataFile() method in your Java source file. The following line of code retrieves an object of the File class. The File class represents a file or directory with the name store.dat, and the plug-in ID com.sabre.redapp.example.resources that is located in the workspace.

File file = Activator.getDefault().getDataFile("com.sabre.redapp.example.resources", "store.dat");

The getDataFile() method does not guarantee the existence of a return File object. To verify that a return File object exists, call the exists() method on this object.