X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frepresentation%2FTransferableGraphUtils.java;h=f2321dce9515b2819af7c51ddc146f324c5b4b1a;hb=414dd6f06a51268cbbf7bc8c1b1ae0a1e3d71f89;hp=10637ad65caf0d861d52e3d1adfffdee66d5f2ca;hpb=befd1d92fb37c9b95ea0b1262385199d9e78380d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java index 10637ad65..f2321dce9 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java @@ -70,7 +70,7 @@ public class TransferableGraphUtils { if("http:/".equals(uri)) return identity; String[] tokens = uri.substring("http://".length()).split("/"); for(String token : tokens) { - identity = findExternalWithNameAndParent(tg, identity.resource, token); + identity = findExternalWithNameAndParent(tg, identity.resource, URIStringUtils.unescape(token)); if (identity == null) { return null; } @@ -78,7 +78,51 @@ public class TransferableGraphUtils { return identity; } - + + /** + * Provided a tg and a resource uri, returns the identity of the tg if the uri_ matches the tg exactly + * @param tg + * @param uri_ + * @return + */ + public static Identity getIdentity2(TransferableGraph1 tg, String uri_) { + Collection identities = TransferableGraphUtils.getRoots(tg); + for (Identity i : identities) { + Identity id = getIdentity2(tg, uri_, i); + if (id != null) { + return id; + } + } + return null; + } + + /** + * + * @param tg + * @param uri_ + * @param id + * @return + */ + public static Identity getIdentity2(TransferableGraph1 tg, String uri_, Identity id) { + String uri = TransferableGraphUtils.getURI(tg, id.resource); + + if (uri_.equals(uri)) { + return id; + } + + if (uri_.startsWith(uri)) { + Collection childIdentitiesOfRoot = TransferableGraphUtils.getChildren2(tg, id); + for (Identity i2 : childIdentitiesOfRoot) { + Identity id2 = getIdentity2(tg, uri_, i2); + if (id2 != null) { + return id2; + } + } + } + + return null; + } + public static Identity getIdentity(TransferableGraph1 tg, int resource) { for(Identity id : tg.identities) { if(id.resource == resource) return id; @@ -301,14 +345,14 @@ public class TransferableGraphUtils { if(definition instanceof External) { External def = (External)definition; if(def.parent == -1) return "http:/"; - else return getURI(identities, def.parent) + "/" + def.name; + else return getURI(identities, def.parent) + "/" + URIStringUtils.escape(def.name); } else if(definition instanceof Root) { Root def = (Root)definition; if(def.name.isEmpty()) return "http:/"; return def.name; } else if (definition instanceof Internal) { Internal def = (Internal)definition; - return getURI(identities, def.parent) + "/" + def.name; + return getURI(identities, def.parent) + "/" + URIStringUtils.escape(def.name); } else { return ""; }