Resources Module

Provides file access for workspace and file system resources. Methods accepting location objects can deal with String, URI, IFile and File instances.

Constants

Constant Description
APPEND Access modifier for append mode (4).
READ Access modifier for read mode (1).
WRITE Access modifier for write mode (2).

Method Overview

Method Description
closeFile() Close a file.
copyFile() Copies a file from location to targetLocation.
createFile() Create a new file in the workspace or the file system.
createFolder() Create a new folder in the workspace or the file system.
createProblemMarker() Create a problem marker on a file resource.
createProject() Create a new workspace project.
deleteFile() Delete a file from the workspace or local file system.
deleteFolder() Delete a folder from the workspace or local file system.
deleteProject() Delete a project from the workspace.
fileExists() Verifies that a specific file exists.
findFiles() Return files matching a certain pattern.
getFile() Get a workspace or file system file.
getProject() Get a project instance.
getWorkspace() Get the workspace root.
linkProject() Links a project into the current workspace.
openFile() Opens a file from the workspace or the file system.
readFile() Read data from a file.
readLine() Read a single line from a file.
readStream() Read from an InputStream into a string.
refreshResource() Refresh a given resource and all its child elements.
showFileSelectionDialog() Opens a file dialog.
showFolderSelectionDialog() Opens a dialog box which allows the user to select a container (project or folder).
writeFile() Write data to a file.
writeLine() Write a line of data to a file.

Methods

closeFile

void closeFile(org.eclipse.ease.modules.platform.IFileHandle handle)

Close a file. Releases system resources bound by an open file.

Parameter Type Description
handle org.eclipse.ease.modules.platform.IFileHandle handle to be closed

copyFile

void copyFile(java.lang.Object sourceLocation, java.lang.Object targetLocation)

Copies a file from location to targetLocation.

Parameter Type Description
sourceLocation java.lang.Object
targetLocation java.lang.Object file location, file handle or file instance

createFile

java.lang.Object createFile(java.lang.Object location)

Create a new file in the workspace or the file system.

Parameter Type Description
location java.lang.Object file location

Returns:java.lang.Object ... IFile, File or null in case of error

createFolder

java.lang.Object createFolder(java.lang.Object location)

Create a new folder in the workspace or the file system.

Parameter Type Description
location java.lang.Object folder location

Returns:java.lang.Object ... IFolder, File or null in case of error

createProblemMarker

void createProblemMarker(java.lang.String severity, java.lang.Object location, int lineNumber, java.lang.String message, [java.lang.String type], [boolean permanent])

Create a problem marker on a file resource.

Parameter Type Description
severity java.lang.String one of error/warning/info
location java.lang.Object file resource to create marker for
lineNumber int line number to set marker on
message java.lang.String message to be added to the marker
type java.lang.String marker type to create, needs to match an existing type
Optional: defaults to <"org.eclipse.core.resources.problemmarker">.
permanent boolean true for permanent markers, false for temporary markers
Optional: defaults to <true>.

createProject

org.eclipse.core.resources.IProject createProject(java.lang.String name)

Create a new workspace project. Will create a new project if it now already exists. If creation fails, null is returned.

Parameter Type Description
name java.lang.String name or project to create

Returns:org.eclipse.core.resources.IProject ... null or project

deleteFile

void deleteFile(java.lang.Object source)

Delete a file from the workspace or local file system.

Parameter Type Description
source java.lang.Object file to be deleted

deleteFolder

void deleteFolder(java.lang.Object source)

Delete a folder from the workspace or local file system.

Parameter Type Description
source java.lang.Object folder to be deleted

deleteProject

void deleteProject(java.lang.Object source)

Delete a project from the workspace.

Parameter Type Description
source java.lang.Object project to be deleted

fileExists

boolean fileExists(java.lang.Object location)

Verifies that a specific file exists.

Parameter Type Description
location java.lang.Object file location to verify

Returns:boolean ... true if file exists

findFiles

java.lang.Object findFiles(java.lang.String pattern, [java.lang.Object rootFolder], [boolean recursive])

Return files matching a certain pattern.

Parameter Type Description
pattern java.lang.String search pattern: use * and ? as wildcards. If the pattern starts with '^' then a regular expression can be used.
rootFolder java.lang.Object root folder to start your search from. null for workspace root
Optional: defaults to <null>.
recursive boolean searches subfolders when set to true
Optional: defaults to <true>.

Returns:java.lang.Object ... An array of all matching files

getFile

java.lang.Object getFile(java.lang.String location, [boolean exists])

Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If exists is false this method also returns files that do not exist yet. If true only existing instances are returned.

Parameter Type Description
location java.lang.String file location/path to resolve
exists boolean whether the resolved file needs to exist
Optional: defaults to <true>.

Returns:java.lang.Object ... resolved IFile or File instance

Example:getFile("workspace://my project/some folder/file.txt")
... to get the file.txt resource from the workspace

Example:getFile("project://some folder/file.txt")
... to get the file.txt resource as a project relative path

getProject

org.eclipse.core.resources.IProject getProject(java.lang.String name)

Get a project instance.

Parameter Type Description
name java.lang.String project name

Returns:org.eclipse.core.resources.IProject ... project or null

getWorkspace

org.eclipse.core.resources.IWorkspaceRoot getWorkspace()

Get the workspace root.

Returns:org.eclipse.core.resources.IWorkspaceRoot ... workspace root

linkProject

boolean linkProject(java.lang.String location)

Links a project into the current workspace. Does not copy resources to the workspace.

Parameter Type Description
location java.lang.String location of project (needs to contain .project file)

Returns:boolean ... link result

openFile

org.eclipse.ease.modules.platform.IFileHandle openFile(java.lang.Object location, [int mode])

Opens a file from the workspace or the file system. If the file does not exist and we open it for writing, the file is created automatically.

Parameter Type Description
location java.lang.Object file location
mode int one of READ, WRITE, APPEND
Optional: defaults to <1>.

Returns:org.eclipse.ease.modules.platform.IFileHandle ... file handle instance to be used for file modification commands

readFile

java.lang.String readFile(java.lang.Object location, [int bytes])

Read data from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.

Parameter Type Description
location java.lang.Object file location, file handle or file instance
bytes int amount of bytes to read (-1 for whole file)
Optional: defaults to <-1>.

Returns:java.lang.String ... file data or null if EOF is reached

readLine

java.lang.String readLine(java.lang.Object location)

Read a single line from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.

Parameter Type Description
location java.lang.Object file location, file handle or file instance

Returns:java.lang.String ... line of text or null if EOF is reached

readStream

java.lang.String readStream(java.io.InputStream input)

Read from an InputStream into a string. Consumes an InputStream and stores all available data in a string. Usually a stream is only readable once.

Parameter Type Description
input java.io.InputStream input stream to read from

Returns:java.lang.String ... string content of stream.

refreshResource

void refreshResource(org.eclipse.core.resources.IResource resource)

Refresh a given resource and all its child elements.

Parameter Type Description
resource org.eclipse.core.resources.IResource IFile, IFolder, IProject or workspace root to update

Example:updateResource(getProject("my project"))
... to update the project and all its subfolders

showFileSelectionDialog

java.lang.String showFileSelectionDialog([java.lang.Object rootFolder], [int type], [java.lang.String title], [java.lang.String message])

Opens a file dialog. Depending on the rootFolder a workspace dialog or a file system dialog will be used. If the folder cannot be located, the workspace root folder is used by default. When type is set to WRITE or APPEND a save dialog will be shown instead of the default open dialog.

Parameter Type Description
rootFolder java.lang.Object root folder path to use
Optional: defaults to <null>.
type int dialog type to use (WRITE/ APPEND for save dialog, other for open dialog)
Optional: defaults to <0>.
title java.lang.String dialog title
Optional: defaults to <null>.
message java.lang.String dialog message
Optional: defaults to <null>.

Returns:java.lang.String ... full path to selected file

showFolderSelectionDialog

java.lang.String showFolderSelectionDialog([java.lang.Object rootFolder], [java.lang.String title], [java.lang.String message])

Opens a dialog box which allows the user to select a container (project or folder). Workspace paths will always display the workspace as root object.

Parameter Type Description
rootFolder java.lang.Object root folder to display: for workspace paths this will set the default selection
Optional: defaults to <null>.
title java.lang.String dialog title
Optional: defaults to <null>.
message java.lang.String dialog message
Optional: defaults to <null>.

Returns:java.lang.String ... path to selected folder

writeFile

org.eclipse.ease.modules.platform.IFileHandle writeFile(java.lang.Object location, java.lang.Object data, [int mode])

Write data to a file. When not using an IFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created. After the write operation the file remains open. It needs to be closed explicitly using the closeFile() command

Parameter Type Description
location java.lang.Object file location
data java.lang.Object data to be written
mode int write mode (WRITE/APPEND)
Optional: defaults to <2>.

Returns:org.eclipse.ease.modules.platform.IFileHandle ... file handle to continue write operations

writeLine

org.eclipse.ease.modules.platform.IFileHandle writeLine(java.lang.Object location, java.lang.String data, [int mode])

Write a line of data to a file. When not using an IFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created.

Parameter Type Description
location java.lang.Object file location
data java.lang.String data to be written
mode int write mode (WRITE/APPEND)
Optional: defaults to <2>.

Returns:org.eclipse.ease.modules.platform.IFileHandle ... file handle to continue write operations