Get the *.asr File from a given IResource

Support questions relating to the actifsource Template Editor

Get the *.asr File from a given IResource

Postby meierd » Thu Jan 24, 2013 2:57 pm

How is it possible to identify inside of a JavaFunction the corresponding *.asr file of the eclipse workspace for a any given IResource. Something like:

Code: Select all
    public java.lang.String ResourceFilePath(final ch.actifsource.core.javamodel.IResource resource) {
      /* Begin Protected Region [[78244c52-2641-11e1-94ec-dfbbf5e511e0]] */
          return XXXX (... File URL String to IResource)
      /* End Protected Region   [[78244c52-2641-11e1-94ec-dfbbf5e511e0]] */
    }


Result should somethin like:

file:/C:/Documents%20and%20Settings/dmei/workspace-aat1/ch.test/asrc/ch/test/presets/f0199fb0-7cc8-11e1-9889-37e1c30ea0b9.asr

Thanks
meierd
 
Posts: 11
Joined: Thu Oct 13, 2011 3:58 pm
Location: Switzerland

Re: Get the *.asr File from a given IResource

Postby Heiko Böttger » Fri Jan 25, 2013 8:24 am

At the moment there is no simple api for doing this in an eclipse independent way. The actifsource Plugins using the ProjectUtil#findFileFor-Methods to get an eclipse IFile. However there is a better way to archive this:

Knowing that an actifsource package lives in a scope (=project) and a package contains the information about the asrc-folder location and it's fullname, there is a relativly new method on the actifsource package returning it's folder.
Since all actifsource root resource stored directly in the package folder you can easily concat the folderURL and the fileName. For creating the filename use the static helper method ResouceStore.createResourceFileName. However this helper always assumes that the resource passed is a root resource, this means you need to handle the case of aggregated resources by yourself. In the following snippet we always return the url of the root resource:

Code: Select all

public java.lang.String ResourceFilePath(final ch.actifsource.core.javamodel.IResource resource) {
     URL url  = resource.getPackage().toFolder().getUrl();
      if (url == null) throw new GenerationException("resource with unsupported folder type");
      INode rootResource = Select.rootResource(resource.getReadJobExecutor(), resource.getResource());
      String fileName = ResourceStore.createResourceFileName((Resource) rootResource);
      return URLUtil.append(url, fileName).toExternalForm();
}


Be aware that the returned url from the folder may not be a file-url or the folder might not support getting an url at all. For example if the resource comes from an eclipse bundle such as ch.actifsource.core you will get an bundle url. The code above assumes the resource is available as a file.

Best regards
Heiko Böttger
Heiko Böttger
 
Posts: 21
Joined: Fri Aug 06, 2010 7:27 am


Return to Template Editor

Who is online

Users browsing this forum: No registered users and 1 guest

cron