]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java
Make prettyPrintTG available via SCL from Simantics/DB-module
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / representation / TransferableGraphUtils.java
index 4646116dc37d784255466ad55f1914e94c545596..a7b92c8d015727880d256a9c17494bed54b70ce9 100644 (file)
@@ -8,6 +8,7 @@ import java.util.TreeMap;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.util.URIStringUtils;
 
 import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.TIntObjectMap;
@@ -70,6 +71,9 @@ public class TransferableGraphUtils {
                String[] tokens = uri.substring("http://".length()).split("/");
                for(String token : tokens) {
                        identity = findExternalWithNameAndParent(tg, identity.resource, token);
+                       if (identity == null) {
+                           return null;
+                       }
                }
                return identity;
                
@@ -266,5 +270,27 @@ public class TransferableGraphUtils {
                }
                return "<internal reference " + id + ">:";
        }
+       
+       public static String getTrueURI(int resourceCount, TIntObjectMap<Identity> identities, int id) {
+               Identity identity = identities.get(id);
+               if(identity != null) {
+                       IdentityDefinition definition = identity.definition;
+                       if(definition instanceof External) {
+                               External def = (External)definition;
+                               if(def.parent == -1) return "http:/";
+                               else return getTrueURI(resourceCount, 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 getTrueURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+                       } else {
+                               return "";
+                       }
+               }
+               return "<internal reference " + id + ">:";
+       }
 
 }