public String getGraphXML(String name, String key) {
StringBuffer sb = new StringBuffer();
Set vertices = _myGraph.getVertices();
Set edges = _myGraph.getEdges();
Vertex v = null;
Edge e = null;
Coordinates coord = null;
Boolean hidden = null;
Object tmp = null;
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
sb.append("<mapdefinition>\n");
// The config
sb.append("<config>\n");
sb.append("<view>" + name + "</view>\n");
double scale = getVV(key).getLayoutTransformer().getScale();
double ltranslateX = getVV(key).getLayoutTransformer().getTranslateX();
double ltranslateY = getVV(key).getLayoutTransformer().getTranslateY();
double vtranslateX = getVV(key).getViewTransformer().getTranslateX();
double vtranslateY = getVV(key).getViewTransformer().getTranslateY();
if (scale == 1.0) {
scale = getVV(key).getViewTransformer().getScale();
}
sb.append("<layouttranslatex>" + ltranslateX + "</layouttranslatex>\n");
sb.append("<layouttranslatey>" + ltranslateY + "</layouttranslatey>\n");
sb.append("<viewtranslatex>" + vtranslateX + "</viewtranslatex>\n");
sb.append("<viewtranslatey>" + vtranslateY + "</viewtranslatey>\n");
sb.append("<scale>" + scale + "</scale>\n");
String title = getBackgroundTitle(key);
if (title != null && title.length() > 0) {
sb.append("<backgroundtitle>" + title + "</backgroundtitle>\n");
}
String bgImage = getBackground(key);
if (bgImage != null && bgImage.length() > 0)
sb.append("<backgroundimage>"+ bgImage +"</backgroundimage>\n");
sb.append("</config>\n");
// The hosts
if (!vertices.isEmpty()) {
sb.append("<hosts>\n");
for (Object o: vertices) {
if (o != null && o instanceof Vertex) {
v = (Vertex)o;
coord = getLayout(key).getCoordinates(v);
hidden = (Boolean)v.getUserDatum(userdatumkey+key);
sb.append("<host");
if (hidden != null && hidden.booleanValue()) {
sb.append(" hidden=\"true\"");
} if (isLocked(v, key)) {
sb.append(" locked=\"true\"");
}
sb.append(">\n");
sb.append("<name>" + getLabel(v) + "</name>\n");
sb.append("<coords>" + coord.getX() + "," + coord.getY() + "</coords>\n");
tmp = v.getUserDatum("labelLocation");
if (tmp != null && tmp instanceof Location) {
sb.append("<label_location>" + ((Location)tmp).toString() + "</label_location>\n");
tmp = null;
}
sb.append("</host>\n");
}
}
sb.append("</hosts>\n");
}
// The Edges
boolean exportedge = false;
if (!edges.isEmpty()) {
sb.append("<edges>\n");
for (Object o: edges) {
exportedge = false;
if (o != null && o instanceof Edge) {
e = (Edge)o;
if (getEdgeColor(e) != null) {
exportedge = true;
}
if (!isVisible(e, key)) {
exportedge = true;
}
if (exportedge) {
sb.append("<edge"+ (!isVisible(e, key)?" hidden=\"true\"":"") + ">\n");
sb.append("<first>"+ getLabel((Vertex)e.getEndpoints().getFirst()) + "</first>\n");
sb.append("<second>"+ getLabel((Vertex)e.getEndpoints().getSecond()) + "</second>\n");
if (getEdgeColor(e) != null) {
sb.append("<color>#" + Integer.toString(getEdgeColor(e).getRGB() & 0xFFFFFF, 16).toUpperCase() + "</color>\n");
}
sb.append("</edge>\n");
}