|
@@ -13,8 +13,7 @@ import org.graphstream.stream.file.FileSinkGraphML;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
|
|
|
|
|
|
-
|
|
|
|
-public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
|
|
|
|
+public class MyFileSinkGraphML extends FileSinkGraphML {
|
|
public boolean isWritingMultigraph = false;
|
|
public boolean isWritingMultigraph = false;
|
|
|
|
|
|
private void print(String format, Object... args) throws IOException {
|
|
private void print(String format, Object... args) throws IOException {
|
|
@@ -22,7 +21,7 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void exportGraph(Graph g){
|
|
|
|
|
|
+ protected void exportGraph(Graph g) {
|
|
try {
|
|
try {
|
|
int attribute = 0;
|
|
int attribute = 0;
|
|
HashMap<String, String> nodeAttributes = new HashMap<String, String>();
|
|
HashMap<String, String> nodeAttributes = new HashMap<String, String>();
|
|
@@ -54,15 +53,15 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
|
|
|
|
graphAttributes.put(j, gId);
|
|
graphAttributes.put(j, gId);
|
|
|
|
|
|
- print("\t<key id=\"%s\" for=\"graph\" attr.name=\"%s\" attr.type=\"%s\"/>\n",
|
|
|
|
- gId, escapeXmlString(j), gType);
|
|
|
|
|
|
+ print("\t<key id=\"%s\" for=\"graph\" attr.name=\"%s\" attr.type=\"%s\"/>\n", gId,
|
|
|
|
+ escapeXmlString(j), gType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (Node n : g.getEachNode()) {
|
|
for (Node n : g.getEachNode()) {
|
|
for (String k : n.getAttributeKeySet()) {
|
|
for (String k : n.getAttributeKeySet()) {
|
|
- //AttributeFiltering
|
|
|
|
- if(k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")){
|
|
|
|
|
|
+ // AttributeFiltering
|
|
|
|
+ if (k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
@@ -70,8 +69,8 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
|
|
&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
|
|
&& !(c == Float.class) && !(c == Double.class)) {
|
|
&& !(c == Float.class) && !(c == Double.class)) {
|
|
Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
|
|
Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
|
|
- + "(Attribute: " + k + ", Value: " + n.getAttribute(k) + ", from Node: " + n + ", Type: "
|
|
|
|
- + c + ") ", 2);
|
|
|
|
|
|
+ + "(Attribute: " + k + ", Value: " + n.getAttribute(k) + ", from Node: " + n
|
|
|
|
+ + ", Type: " + c + ") ", 2);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -99,16 +98,16 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
|
|
|
|
nodeAttributes.put(k, id);
|
|
nodeAttributes.put(k, id);
|
|
|
|
|
|
- print("\t<key id=\"%s\" for=\"node\" attr.name=\"%s\" attr.type=\"%s\"/>\n",
|
|
|
|
- id, escapeXmlString(k), type);
|
|
|
|
|
|
+ print("\t<key id=\"%s\" for=\"node\" attr.name=\"%s\" attr.type=\"%s\"/>\n", id,
|
|
|
|
+ escapeXmlString(k), type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (Edge n : g.getEachEdge()) {
|
|
for (Edge n : g.getEachEdge()) {
|
|
for (String k : n.getAttributeKeySet()) {
|
|
for (String k : n.getAttributeKeySet()) {
|
|
- //AttributeFiltering
|
|
|
|
- if(k.equals("ui.j2dsk")){
|
|
|
|
|
|
+ // AttributeFiltering
|
|
|
|
+ if (k.equals("ui.j2dsk")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
@@ -116,10 +115,10 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
|
|
&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
|
|
&& !(c == Float.class) && !(c == Double.class)) {
|
|
&& !(c == Float.class) && !(c == Double.class)) {
|
|
Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
|
|
Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
|
|
- + "(Attribute: " + k + ", Value: " + n.getAttribute(k) + ", from Edge: " + n + ", Type: "
|
|
|
|
- + c + ") ", 2);
|
|
|
|
|
|
+ + "(Attribute: " + k + ", Value: " + n.getAttribute(k) + ", from Edge: " + n
|
|
|
|
+ + ", Type: " + c + ") ", 2);
|
|
continue;
|
|
continue;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
if (!edgeAttributes.containsKey(k)) {
|
|
if (!edgeAttributes.containsKey(k)) {
|
|
Object value = n.getAttribute(k);
|
|
Object value = n.getAttribute(k);
|
|
@@ -144,22 +143,22 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
type = "string";
|
|
type = "string";
|
|
|
|
|
|
edgeAttributes.put(k, id);
|
|
edgeAttributes.put(k, id);
|
|
- print("\t<key id=\"%s\" for=\"edge\" attr.name=\"%s\" attr.type=\"%s\"/>\n",
|
|
|
|
- id, escapeXmlString(k), type);
|
|
|
|
|
|
+ print("\t<key id=\"%s\" for=\"edge\" attr.name=\"%s\" attr.type=\"%s\"/>\n", id,
|
|
|
|
+ escapeXmlString(k), type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
print("\t<graph id=\"%s\" edgedefault=\"undirected\">\n", escapeXmlString(g.getId()));
|
|
print("\t<graph id=\"%s\" edgedefault=\"undirected\">\n", escapeXmlString(g.getId()));
|
|
for (String k : g.getAttributeKeySet()) {
|
|
for (String k : g.getAttributeKeySet()) {
|
|
- print("\t\t\t<data key=\"%s\">%s</data>\n", graphAttributes
|
|
|
|
- .get(k), escapeXmlString(g.getAttribute(k).toString()));
|
|
|
|
|
|
+ print("\t\t\t<data key=\"%s\">%s</data>\n", graphAttributes.get(k),
|
|
|
|
+ escapeXmlString(g.getAttribute(k).toString()));
|
|
}
|
|
}
|
|
|
|
|
|
for (Node n : g.getEachNode()) {
|
|
for (Node n : g.getEachNode()) {
|
|
print("\t\t<node id=\"%s\">\n", n.getId());
|
|
print("\t\t<node id=\"%s\">\n", n.getId());
|
|
for (String k : n.getAttributeKeySet()) {
|
|
for (String k : n.getAttributeKeySet()) {
|
|
- if(k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")){
|
|
|
|
|
|
+ if (k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
Class<? extends Object> c = n.getAttribute(k).getClass();
|
|
@@ -169,18 +168,16 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- print("\t\t\t<data key=\"%s\">%s</data>\n", nodeAttributes
|
|
|
|
- .get(k), escapeXmlString(n.getAttribute(k).toString()));
|
|
|
|
|
|
+ print("\t\t\t<data key=\"%s\">%s</data>\n", nodeAttributes.get(k),
|
|
|
|
+ escapeXmlString(n.getAttribute(k).toString()));
|
|
}
|
|
}
|
|
print("\t\t</node>\n");
|
|
print("\t\t</node>\n");
|
|
}
|
|
}
|
|
for (Edge e : g.getEachEdge()) {
|
|
for (Edge e : g.getEachEdge()) {
|
|
- print(
|
|
|
|
- "\t\t<edge id=\"%s\" source=\"%s\" target=\"%s\" directed=\"%s\">\n",
|
|
|
|
- e.getId(), e.getSourceNode().getId(), e.getTargetNode()
|
|
|
|
- .getId(), e.isDirected());
|
|
|
|
|
|
+ print("\t\t<edge id=\"%s\" source=\"%s\" target=\"%s\" directed=\"%s\">\n", e.getId(),
|
|
|
|
+ e.getSourceNode().getId(), e.getTargetNode().getId(), e.isDirected());
|
|
for (String k : e.getAttributeKeySet()) {
|
|
for (String k : e.getAttributeKeySet()) {
|
|
- if(k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")){
|
|
|
|
|
|
+ if (k.equals("ui.j2dsk") || k.equals("ui.class") || k.equals("ui.pie-values")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
Class<? extends Object> c = e.getAttribute(k).getClass();
|
|
Class<? extends Object> c = e.getAttribute(k).getClass();
|
|
@@ -190,8 +187,8 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- print("\t\t\t<data key=\"%s\">%s</data>\n", edgeAttributes
|
|
|
|
- .get(k), escapeXmlString(e.getAttribute(k).toString()));
|
|
|
|
|
|
+ print("\t\t\t<data key=\"%s\">%s</data>\n", edgeAttributes.get(k),
|
|
|
|
+ escapeXmlString(e.getAttribute(k).toString()));
|
|
}
|
|
}
|
|
print("\t\t</edge>\n");
|
|
print("\t\t</edge>\n");
|
|
}
|
|
}
|
|
@@ -201,36 +198,32 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static String escapeXmlString(String s){
|
|
|
|
- //why do you make me do this graphstream???
|
|
|
|
- return s
|
|
|
|
- .replace("&", "&")
|
|
|
|
- .replace("<", "<")
|
|
|
|
- .replace(">", ">")
|
|
|
|
- .replace("\"", """)
|
|
|
|
- .replace("'", "'");
|
|
|
|
|
|
+ private static String escapeXmlString(String s) {
|
|
|
|
+ // why do you make me do this graphstream???
|
|
|
|
+ return s.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """).replace("'",
|
|
|
|
+ "'");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @param graphs
|
|
* @param graphs
|
|
*/
|
|
*/
|
|
- public void exportGraphs(LinkedList<MyGraph> graphs, String fileName){
|
|
|
|
|
|
+ public void exportGraphs(LinkedList<MyGraph> graphs, String fileName) {
|
|
Iterator<MyGraph> graphIter = graphs.iterator();
|
|
Iterator<MyGraph> graphIter = graphs.iterator();
|
|
- while(graphIter.hasNext()){
|
|
|
|
- if(graphIter.next().isComposite()){
|
|
|
|
|
|
+ while (graphIter.hasNext()) {
|
|
|
|
+ if (graphIter.next().isComposite()) {
|
|
graphIter.remove();
|
|
graphIter.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
begin(fileName);
|
|
begin(fileName);
|
|
isWritingMultigraph = true;
|
|
isWritingMultigraph = true;
|
|
- for(MyGraph g : graphs){
|
|
|
|
|
|
+ for (MyGraph g : graphs) {
|
|
exportGraph(g);
|
|
exportGraph(g);
|
|
}
|
|
}
|
|
isWritingMultigraph = false;
|
|
isWritingMultigraph = false;
|
|
end();
|
|
end();
|
|
- } catch(IOException e){
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|