Skip to content

Commit

Permalink
dbeaver/pro#2795 Editors for objects under a path with special symbol…
Browse files Browse the repository at this point in the history
…s don't get restored (#29993)

* dbeaver/pro#2795 Editors for objects under a path with special symbols
don't get restored

Fix path of restored node

* dbeaver/pro#2795 Editors for objects under a path with special symbols
don't get restored

Fix path of restored node

* dbeaver/pro#2795 Extracted to upper method

* Merge branch 'dbeaver/pro#2795-editor-restore-path' of
git@github.com:dbeaver/dbeaver.git into
dbeaver/pro#2795-editor-restore-path

* dbeaver/pro#2795-editor-restore-path - normalize - to - denormalize

* dbeaver/pro#2795-editor-restore-path Minor

* dbeaver/pro#2795-editor-restore-path Remane method

* dbeaver/pro#2795-editor-restore-path decode from any Ascii code to
string

* dbeaver/pro#2795 Check before decode

* dbeaver/pro#2795 Illigal argument of "%"

* dbeaver/pro#2795 Fixed encoding/ decoding of path segment

* dbeaver/pro#2795 Fixed encoding/ decoding of path segment

* dbeaver/pro#2795 Removed constant

* Merge branch 'dbeaver/pro#2795-editor-restore-path' of
git@github.com:dbeaver/dbeaver.git into
dbeaver/pro#2795-editor-restore-path

* dbeaver/pro#2795 - Unrelated changes
  • Loading branch information
serjiokov committed May 13, 2024
1 parent 9127baa commit 1457abe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ public String getNodeItemPath() {
if (pathName.length() > 0) {
pathName.insert(0, '/');
}
pathName.insert(0, node.getNodeDisplayName().replace("/", DBNModel.SLASH_ESCAPE_TOKEN));
pathName.insert(0, DBNUtils.encodeNodePath(node.getNodeDisplayName()));
}
return pathName.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static DBNNode legacyFindNodeByPath(

final List<String> pathItems = nodePath.pathItems;
for (int i = firstItem, itemsSize = pathItems.size(); i < itemsSize; i++) {
String item = pathItems.get(i).replace(DBNModel.SLASH_ESCAPE_TOKEN, "/");
String item = pathItems.get(i);
if (nodePath.type == DBNNode.NodePathType.ext && curNode instanceof DBNProject pn) {
// Trigger project to load extra nodes
pn.getExtraNode(DBNFileSystems.class);
Expand Down Expand Up @@ -173,7 +173,7 @@ private static DBNNode legacyFindNodeByPath(
}

if (!pathItems.isEmpty()) {
String lastItemName = pathItems.get(pathItems.size() - 1).replace(DBNModel.SLASH_ESCAPE_TOKEN, "/");
String lastItemName = pathItems.get(pathItems.size() - 1);
if (!nodeMatchesPath(nodePath, curNode, lastItemName)) {
// Tail node doesn't match tail node from the desired path
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
* (e.g. TreeViewer sometimes update only first TreeItem corresponding to model certain model object).
*/
public class DBNModel implements IResourceChangeListener {
public static final String SLASH_ESCAPE_TOKEN = "%2F";

private static final Log log = Log.getLog(DBNModel.class);

Expand Down Expand Up @@ -271,7 +270,9 @@ private static NodePath getNodePath(@NotNull String path) {
break;
}
}
return new NodePath(nodeType, CommonUtils.splitString(path, '/'));
final List<String> items = CommonUtils.splitString(path, '/');
items.replaceAll(DBNUtils::decodeNodePath);
return new NodePath(nodeType, items);
}

@Nullable
Expand Down Expand Up @@ -327,7 +328,8 @@ public DBNNode getNodeByPath(
log.debug("Project node not found");
return null;
}
final NodePath nodePath = getNodePath(path);
NodePath nodePath = getNodePath(path);

if (nodePath.legacyFormat) {
return DBNLegacyUtils.legacyGetNodeByPath(monitor, projectNode, nodePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public final String getNodeUri() {
if (!pathBuilder.isEmpty()) {
pathBuilder.insert(0, '/');
}
String nodeId = currentNode.getNodeId().replace("/", DBNModel.SLASH_ESCAPE_TOKEN);
String nodeId = DBNUtils.encodeNodePath(currentNode.getNodeId());
if (currentNode instanceof DBNResource && currentNode.getParentNode() instanceof DBNProject) {
//FIXME: remove after migration to the real resource root node
nodeId = DBNResource.FAKE_RESOURCE_ROOT_NODE + "/" + nodeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,24 @@ public boolean has(String name) {
};
}

/**
* The method decode symbols('%2F','%25')
*
* @param nodePath - path
* @return - node path object
*/
public static String decodeNodePath(@NotNull String nodePath) {
return nodePath.replace("%2F", "/").replace("%25", "%");
}

/**
* The method encode symbols('/','%')
*
* @param path - path
* @return - string path segment
*/
public static String encodeNodePath(@NotNull String path) {
return path.replace("%", "%25").replace("/", "%2F");
}

}

0 comments on commit 1457abe

Please sign in to comment.