Project prefix

This section introduces what is and how to handle project prefix.

Background

In BTT tooling, the following resources are supported to be chosen from another project:

At time of generating JSP from XUI, value of a widget attribute need to be generated into runtime value properly. The following mapping rules handle multi-project for widget attributes specially:

When a resource is selected from another project, BTT will add project prefix to the resource reference information. In this case, resource reference information will be in the format of [project prefix]:[resource reference identity]. In order to avoid massive modification when a common or global project is renamed, BTT uses project map key instead of project name as project prefix.

Project map key

The common or global projects information is defined in btt configuration file as “remoteProjectURL” kColl of local project. For each entry, the “id” field is the project name, the “description” field is the project map key and the “value” field is access information at runtime. The following is a sample of map key definition:

APIs to handle project prefix

For an extended widget, if its attribute refers resource in another project, the widget implementation needs to handle project prefix to locate the resource. BTT provides two APIs for technical developers to handle project prefix.

IProject FilePathUtil.getProjecByResourceID(String resourceID, IProject activeProject)

The API returns project which resource locates according to resourceID, if resourceID does not contain project prefix, the activeProject will be returned. If the project map key is not defined in BTT configuration file, “IllegalArgumentException” exception will be thrown.

String FilePathUtil.getValueByResourceID(String resourceID)

The API returns resource without project prefix.

Example

The following sample code demonstrates how to retrieve icon file from global project.

try{
IProject imageProject = FilePathUtil.getProjecByResourceID(imageLocation,EditorUtils.getActiveProject())
String imageRelativeLocation = FilePathUtil.getValueByResourceID(imageLocation);
IFile imageFile = imageProject.getFile(imageRelativeLocation);
}
catch(IllegalArgumentException ie){
 // handle map key is not defined exception

}

The following sample code demonstrates how to retrieve NLS definition from global project.

try{
	IProject selectedProject = FilePathUtil.getProjecByResourceID(nlsLocation,EditorUtils.getActiveProject())
	String nlsTextField = getValueByResourceID(nlsLocation);
	String nlsValue = NLSUtils.getPropertiesValue(nlsTextField,selectedProject);
}
catch(IllegalArgumentException ie){
 // handle map key is not defined exception
}