Replies: 1 comment
-
It looks like the only correct way to resolve the uri string is:
The My suggestion for changing this class would be the following implementation - including the comments ;-) /**
* Resolves to a source File instance from a GModelState to load a model. Can be
* called from the method <code>SourceModelStorage.loadSourceModel</code>.
*
* @param modelState
* @return a File Instance - or null
* @throws NullPointerException
* If the sourceUri resolves to <code>null</code>
*/
public static File getSourceFile(final GModelState modelState) {
String filePath = MapUtil.getValue(modelState.getClientOptions(), "sourceUri").orElse(null);
// strip the file:// prefix
filePath = filePath.replace(FILE_PREFIX, "");
return new File(filePath);
}
/**
* Resolves to a target File instance from a SaveModelAction and the GModelState
* to save a model. Can be called from the method
* <code>SourceModelStorage.loadSourceModel</code>.
*
* @param modelState
* @return a File Instance - or null
* @throws NullPointerException
* If the sourceUri resolves to <code>null</code>
*/
public static File getTargetFile(final GModelState modelState, final SaveModelAction action) {
// first take the origin sourceUri from the current modelState
String filePath = MapUtil.getValue(modelState.getClientOptions(), "sourceUri").orElse(null);
// test if we have a new optional fileUri....
String newFileURI = action.getFileUri().orElse(null);
if (newFileURI != null && !newFileURI.isEmpty()) {
// we got a new URI which means we have a 'saveAs' situation!
filePath = newFileURI;
}
// strip the optional file:// prefix
filePath = filePath.replace(FILE_PREFIX, "");
return new File(filePath);
} Note: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
During implementing my own SourceModelStorage in run into a strange (or even funny) problem with the
sourceUri
parameter provided in the SaveModelAction.On a linux system the provided URI may be something like this:
It is a String but it looks like a URI so I converted it into an URI object:
This works fine, but users under Windows may have URIs like this
And this String cant be converted easily into a URI without throwing a
java.net.URISyntaxException: Illegal character
because of the spaces.I wonder how you are usually threat this file/uri string?
Another special case seems to be if the user calls 'Save As..." in VS-Code. In this case the new Location is available in the Action object param FileURI:
But now it does NOT start with the 'file://' prefix
I think I can handle this in my code but I wonder if
SoureUri
andfileUri
are good names for the params because the params are not URL encoded. I am not sure if you can follow my thoughts of if I am totally wrong here (trying to solve the problem since several hours now.. ;-)Beta Was this translation helpful? Give feedback.
All reactions