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 theStrings 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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTLcyFileWorkspaceCodec(ILcyLucyEnv aLucyEnv, TLcyWorkspaceManager aWorkspaceManager) Creates a newTLcyFileWorkspaceCodec. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecodeWorkspace(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().voidencodeWorkspace(String aDestinationName) Encodes the workspace.booleanReturns true if relative paths that start with .. are allowed.final booleanReturnstruewhen this codec saves a screenshot of the map next to the workspace file when saving a workspace.booleanReturns true if relative paths are used.voidsetAllowUpRelativePaths(boolean aAllowUpRelativePaths) Sets if relative paths that start with .. are allowed.final voidsetSaveScreenshot(boolean aSaveScreenshot) Sets whether this codec should save a screenshot of the map next to the workspace file when saving a workspace.voidsetUseRelativePaths(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, setOutputStreamFactoryMethods 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:ALcyWorkspaceCodecReturns 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:
canDecodeWorkspacein classTLcyBlobWorkspaceCodec- Parameters:
aSourceName- The source name to checkaReasonsSFCT- A side-effect parameter to which this method may add reasons on why it returnedtrueorfalse- Returns:
trueif the given source name can be decoded,falseotherwise
-
encodeWorkspace
public void encodeWorkspace(String aDestinationName) throws IOException, TLcyWorkspaceAbortedException Description copied from class:ALcyWorkspaceCodecEncodes the workspace. This method must never be invoked by user code, insteadTLcyWorkspaceManager.encodeWorkspace(String)must be used. Encoding the workspace means all registeredALcyWorkspaceCodecDelegates will be asked to encode their part. When aALcyWorkspaceCodecDelegateis 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:
encodeWorkspacein 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()Returnstruewhen this codec saves a screenshot of the map next to the workspace file when saving a workspace.- Returns:
truewhen 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-truewhen 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. Ifnullis provided,nullis returned.- Overrides:
encodePathin 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. Ifnullis provided,nullis returned.- Overrides:
decodePathin classALcyWorkspaceCodec- Parameters:
aPath- The path to resolve.- Returns:
- The resolved path.
- See Also:
-