public class TLcyFileWorkspaceCodec extends TLcyBlobWorkspaceCodec
Extension of TLcyBlobWorkspaceCodec
that can save and load workspaces
to/from the file system.
This workspace codec assumes that all String
instances passed to it (for example
in the encodeWorkspace
and decodeWorkspace
methods) represent file paths.
If you want to customize the codec to save to other persistent storage like for example a database,
you need to extend from TLcyBlobWorkspaceCodec
instead of from this class.
Since this class knows the workspaces are encoded and decoded to/from the file system, it provides the following optimizations:
decodePath(String)
and encodePath(String)
are implemented to
interpret the String
s as file names, and to encode/resolve as much paths as
possible as relative paths.
This allows the workspace file, together with the needed data files, to be copied to another location on disk.
Those data files could for example be the files that were loading by the user.
The methods setUseRelativePaths(boolean)
and setAllowUpRelativePaths(boolean)
allow to find tune this behavior.
setSaveScreenshot(boolean)
).
The Lucy file chooser picks up such images when selecting the workspace file, and shows a preview of the image in the file chooser.
This allows users to get a preview of the data contained in the workspace without actually loading it.
Modifier and Type | Field and Description |
---|---|
static String |
FILE_EXTENSION
A suggested file extension for workspaces.
|
Constructor and Description |
---|
TLcyFileWorkspaceCodec(ILcyLucyEnv aLucyEnv,
TLcyWorkspaceManager aWorkspaceManager)
Creates a new
TLcyFileWorkspaceCodec . |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeWorkspace(String aSourceName,
List<String> aReasonsSFCT)
Returns true if the given source name can be decoded, false otherwise.
|
String |
decodePath(String aPath)
Resolves relative paths as relative to the workspace file name.
|
String |
encodePath(String aPath)
Encodes aPath as a relative path depending on
isUseRelativePaths() . |
void |
encodeWorkspace(String aDestinationName)
Encodes the workspace.
|
boolean |
isAllowUpRelativePaths()
Returns true if relative paths that start with .. are allowed.
|
boolean |
isSaveScreenshot()
Returns
true when this codec saves a screenshot of the map next to the workspace file when saving a workspace. |
boolean |
isUseRelativePaths()
Returns true if relative paths are used.
|
void |
setAllowUpRelativePaths(boolean aAllowUpRelativePaths)
Sets if relative paths that start with .. are allowed.
|
void |
setSaveScreenshot(boolean aSaveScreenshot)
Sets whether this codec should save a screenshot of the map next to the workspace file when saving a workspace.
|
void |
setUseRelativePaths(boolean aUseRelativePaths)
Sets whether relative paths are used or not.
|
canDecodeWorkspace, canEncodeWorkspace, decodeWorkspace, decodeWorkspaceDelegateCodecIDs, getInputStreamFactory, getOutputStreamFactory, retrieveInputStream, retrieveOutputStream, setInputStreamFactory, setOutputStreamFactory
addPropertyChangeListener, addPropertyChangeListener, canEncodeReference, canEncodeReference, checkApplicationHeader, createApplicationHeader, decodeFromInputStream, decodeReference, encodeObject, encodeReference, encodeReference, firePropertyChange, flushWorkspaceStorageName, getLogListener, getParentComponent, getStatusListener, getWorkspaceManager, getWorkspaceStorageName, removePropertyChangeListener, removePropertyChangeListener, setLogListener, setParentComponent, setStatusListener
public static final String FILE_EXTENSION
public TLcyFileWorkspaceCodec(ILcyLucyEnv aLucyEnv, TLcyWorkspaceManager aWorkspaceManager)
TLcyFileWorkspaceCodec
.aLucyEnv
- The lucy environment.aWorkspaceManager
- The workspace manager.public boolean canDecodeWorkspace(String aSourceName, List<String> aReasonsSFCT)
ALcyWorkspaceCodec
Returns true if the given source name can be decoded, false otherwise.
The second argument of the method is a list of strings which can be used to pass
a description to the caller of this method.
For example when a workspace cannot be decoded for a certain reason,
a description of that reason can be added to the list of strings.
canDecodeWorkspace
in class TLcyBlobWorkspaceCodec
aSourceName
- The source name to checkaReasonsSFCT
- A side-effect parameter to which this method may add reasons on why it returned true
or false
true
if the given source name can be decoded, false
otherwisepublic void encodeWorkspace(String aDestinationName) throws IOException, TLcyWorkspaceAbortedException
ALcyWorkspaceCodec
TLcyWorkspaceManager.encodeWorkspace(String)
must be used.
Encoding the workspace means all registered ALcyWorkspaceCodecDelegate
s will be asked to encode their part. When a
ALcyWorkspaceCodecDelegate
is encoding its part, it might need to store an object
reference (e.g. a reference to an ILcdGXYLayer). It can do so using ALcyWorkspaceCodec.encodeReference(Object)
.
This method must only be used if ALcyWorkspaceCodec.canEncodeWorkspace(String)
for the same
aDestinationName returns true.encodeWorkspace
in class TLcyBlobWorkspaceCodec
aDestinationName
- The destination name of the workspace. It is up to subclasses to
interpret this string, e.g. as a file name.IOException
- In case of fatal IO failure.TLcyWorkspaceAbortedException
- In case the operation is aborted, e.g. because the user canceled
it.public boolean isUseRelativePaths()
setUseRelativePaths(boolean)
public void setUseRelativePaths(boolean aUseRelativePaths)
encodePath(String)
will encode
a path as a path relative to the workspace file name. Other file names are left untouched.
If false, file names are left untouched. See also setAllowUpRelativePaths(boolean)
.aUseRelativePaths
- True to use relative paths, false otherwise.public boolean isAllowUpRelativePaths()
isUseRelativePaths()
returns true.setAllowUpRelativePaths(boolean)
public void setAllowUpRelativePaths(boolean aAllowUpRelativePaths)
isUseRelativePaths()
returns true.aAllowUpRelativePaths
- True to use relative paths always, false to only use
relative paths that point 'below' the workspace file.isAllowUpRelativePaths()
public final boolean isSaveScreenshot()
true
when this codec saves a screenshot of the map next to the workspace file when saving a workspace.true
when this codec saves a screenshot of the map next to the workspace file when saving a workspace.public final void setSaveScreenshot(boolean aSaveScreenshot)
aSaveScreenshot
- true
when a screenshot of the map should be saved next to the workspace file.public String encodePath(String aPath)
isUseRelativePaths()
. If true, this
method will encode aPath as a path relative to the workspace file name if the given path is in
the same directory as the workspace file or below it. If isAllowUpRelativePaths()
returns true, also relative paths above the directory of the workspace file are allowed.
Other file names are left untouched. If null
is provided, null
is returned.encodePath
in class ALcyWorkspaceCodec
aPath
- The path to encode.public String decodePath(String aPath)
null
is provided, null
is returned.decodePath
in class ALcyWorkspaceCodec
aPath
- The path to resolve.encodePath(String)