Class TLcyFileWorkspaceCodec
- All Implemented Interfaces:
ILcdInputStreamFactoryCapable
,ILcdOutputStreamFactoryCapable
,ILcdPropertyChangeSource
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:
-
The methods
decodePath(String)
andencodePath(String)
are implemented to interpret theString
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 methodssetUseRelativePaths(boolean)
andsetAllowUpRelativePaths(boolean)
allow to find tune this behavior. - When overwriting an existing workspace, the codec will take a back-up of the existing workspace first. When workspace encoding fails, the back-up will be restored. When workspace encoding is successful, the back-up will be removed. This avoids that you end up with corrupt workspaces when something goes wrong during workspace encoding.
-
A screenshot of the current active GXY or Lightspeed map is saved next to the workspace file (see
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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTLcyFileWorkspaceCodec
(ILcyLucyEnv aLucyEnv, TLcyWorkspaceManager aWorkspaceManager) Creates a newTLcyFileWorkspaceCodec
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeWorkspace
(String aSourceName, List<String> aReasonsSFCT) Returns true if the given source name can be decoded, false otherwise.decodePath
(String aPath) Resolves relative paths as relative to the workspace file name.encodePath
(String aPath) Encodes aPath as a relative path depending onisUseRelativePaths()
.void
encodeWorkspace
(String aDestinationName) Encodes the workspace.boolean
Returns true if relative paths that start with .. are allowed.final boolean
Returnstrue
when this codec saves a screenshot of the map next to the workspace file when saving a workspace.boolean
Returns true if relative paths are used.void
setAllowUpRelativePaths
(boolean aAllowUpRelativePaths) Sets if relative paths that start with .. are allowed.final 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.Methods inherited from class com.luciad.lucy.workspace.TLcyBlobWorkspaceCodec
canDecodeWorkspace, canEncodeWorkspace, decodeWorkspace, decodeWorkspaceDelegateCodecIDs, getInputStreamFactory, getOutputStreamFactory, retrieveInputStream, retrieveOutputStream, setInputStreamFactory, setOutputStreamFactory
Methods inherited from class com.luciad.lucy.workspace.ALcyWorkspaceCodec
addPropertyChangeListener, addPropertyChangeListener, canEncodeReference, canEncodeReference, checkApplicationHeader, createApplicationHeader, decodeFromInputStream, decodeReference, encodeObject, encodeReference, encodeReference, firePropertyChange, flushWorkspaceStorageName, getLogListener, getParentComponent, getStatusListener, getWorkspaceManager, getWorkspaceStorageName, removePropertyChangeListener, removePropertyChangeListener, setLogListener, setParentComponent, setStatusListener
-
Field Details
-
FILE_EXTENSION
A suggested file extension for workspaces. It is not mandatory to use this extension.- See Also:
-
-
Constructor Details
-
TLcyFileWorkspaceCodec
Creates a newTLcyFileWorkspaceCodec
.- Parameters:
aLucyEnv
- The lucy environment.aWorkspaceManager
- The workspace manager.
-
-
Method Details
-
canDecodeWorkspace
Description copied from class: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.- Overrides:
canDecodeWorkspace
in classTLcyBlobWorkspaceCodec
- Parameters:
aSourceName
- The source name to checkaReasonsSFCT
- A side-effect parameter to which this method may add reasons on why it returnedtrue
orfalse
- Returns:
true
if the given source name can be decoded,false
otherwise
-
encodeWorkspace
public void encodeWorkspace(String aDestinationName) throws IOException, TLcyWorkspaceAbortedException Description copied from class:ALcyWorkspaceCodec
Encodes the workspace. This method must never be invoked by user code, insteadTLcyWorkspaceManager.encodeWorkspace(String)
must be used. Encoding the workspace means all registeredALcyWorkspaceCodecDelegate
s will be asked to encode their part. When aALcyWorkspaceCodecDelegate
is encoding its part, it might need to store an object reference (e.g. a reference to an ILcdGXYLayer). It can do so usingALcyWorkspaceCodec.encodeReference(Object)
. This method must only be used ifALcyWorkspaceCodec.canEncodeWorkspace(String)
for the same aDestinationName returns true.- Overrides:
encodeWorkspace
in classTLcyBlobWorkspaceCodec
- Parameters:
aDestinationName
- The destination name of the workspace. It is up to subclasses to interpret this string, e.g. as a file name.- Throws:
IOException
- In case of fatal IO failure.TLcyWorkspaceAbortedException
- In case the operation is aborted, e.g. because the user canceled it.
-
isUseRelativePaths
public boolean isUseRelativePaths()Returns true if relative paths are used. The default is true.- Returns:
- True if relative paths are used.
- See Also:
-
setUseRelativePaths
public void setUseRelativePaths(boolean aUseRelativePaths) Sets whether relative paths are used or not. If true,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 alsosetAllowUpRelativePaths(boolean)
.- Parameters:
aUseRelativePaths
- True to use relative paths, false otherwise.
-
isAllowUpRelativePaths
public boolean isAllowUpRelativePaths()Returns true if relative paths that start with .. are allowed. The default is false. This property is only applicable ifisUseRelativePaths()
returns true.- Returns:
- true if relative paths that start with .. are allowed.
- See Also:
-
setAllowUpRelativePaths
public void setAllowUpRelativePaths(boolean aAllowUpRelativePaths) Sets if relative paths that start with .. are allowed. If false only relative paths are used for files that are 'below' the workspace file. If set to true, relative paths will always be used, regardless if they are 'below' the workspace file or not. This property is only applicable ifisUseRelativePaths()
returns true.- Parameters:
aAllowUpRelativePaths
- True to use relative paths always, false to only use relative paths that point 'below' the workspace file.- See Also:
-
isSaveScreenshot
public final boolean isSaveScreenshot()Returnstrue
when this codec saves a screenshot of the map next to the workspace file when saving a workspace.- Returns:
true
when this codec saves a screenshot of the map next to the workspace file when saving a workspace.- Since:
- 2017.1
-
setSaveScreenshot
public final void setSaveScreenshot(boolean aSaveScreenshot) Sets whether this codec should save a screenshot of the map next to the workspace file when saving a workspace. Images next to a file are shown by the standard Lucy file chooser when selecting the file. This allows the user to see a preview of the workspace without actually loading the workspace.- Parameters:
aSaveScreenshot
-true
when a screenshot of the map should be saved next to the workspace file.- Since:
- 2017.1
-
encodePath
Encodes aPath as a relative path depending onisUseRelativePaths()
. 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. IfisAllowUpRelativePaths()
returns true, also relative paths above the directory of the workspace file are allowed. Other file names are left untouched. Ifnull
is provided,null
is returned.- Overrides:
encodePath
in classALcyWorkspaceCodec
- Parameters:
aPath
- The path to encode.- Returns:
- The (relative) path.
-
decodePath
Resolves relative paths as relative to the workspace file name. Other paths are left untouched. Ifnull
is provided,null
is returned.- Overrides:
decodePath
in classALcyWorkspaceCodec
- Parameters:
aPath
- The path to resolve.- Returns:
- The resolved path.
- See Also:
-