Ejemplo n.º 1
0
  private void writeGraph(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
    xmlWriter.writeStartElement(GRAPH);
    xmlWriter.writeAttribute(
        GRAPH_DEFAULT_EDGETYPE,
        graph instanceof DirectedGraph
            ? "directed"
            : graph instanceof UndirectedGraph ? "undirected" : "mixed");

    if (exportDynamic) {
      if (!Double.isInfinite(visibleInterval.getLow())) {
        String intervalLow = formatTime(visibleInterval.getLow());
        xmlWriter.writeAttribute(GRAPH_START, intervalLow);
      }
      if (!Double.isInfinite(visibleInterval.getHigh())) {
        String intervalHigh = formatTime(visibleInterval.getHigh());
        xmlWriter.writeAttribute(GRAPH_END, intervalHigh);
      }
      String timeFormat =
          dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE) ? "date" : "double";
      xmlWriter.writeAttribute(GRAPH_TIMEFORMAT, timeFormat);
    }
    xmlWriter.writeAttribute(GRAPH_MODE, exportDynamic ? "dynamic" : "static");

    writeAttributes(xmlWriter, attributeModel.getNodeTable());
    writeAttributes(xmlWriter, attributeModel.getEdgeTable());
    writeNodes(xmlWriter, graph);
    writeEdges(xmlWriter, graph);

    xmlWriter.writeEndElement();
  }
Ejemplo n.º 2
0
 private String formatTime(double time) {
   if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE)) {
     String t = DynamicUtilities.getXMLDateStringFromDouble(time);
     if (t.endsWith("T00:00:00.000")) {
       t = t.substring(0, t.length() - 13);
     }
     return t;
   } else {
     return Double.toString(time);
   }
 }
Ejemplo n.º 3
0
  public boolean execute() {
    attributeModel = workspace.getLookup().lookup(AttributeModel.class);
    graphModel = workspace.getLookup().lookup(GraphModel.class);
    HierarchicalGraph graph = null;
    if (exportVisible) {
      graph = graphModel.getHierarchicalGraphVisible();
    } else {
      graph = graphModel.getHierarchicalGraph();
    }
    Progress.start(progress);
    graph.readLock();

    // Options
    if (normalize) {
      calculateMinMax(graph);
    }

    // Calculate progress units count
    int max = 0;
    if (exportHierarchy) {
      for (Node n : graph.getNodesTree()) {
        max++;
      }
      for (Edge e : graph.getEdgesTree()) {
        max++;
      }
    } else {
      max = graph.getNodeCount();
      for (Edge e : graph.getEdgesAndMetaEdges()) {
        max++;
      }
    }
    Progress.switchToDeterminate(progress, max);

    try {
      XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
      outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);

      XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
      xmlWriter = new IndentingXMLStreamWriter(xmlWriter);

      xmlWriter.writeStartDocument("UTF-8", "1.0");
      xmlWriter.setPrefix("", GEXF_NAMESPACE);
      xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
      xmlWriter.writeNamespace("", GEXF_NAMESPACE);
      xmlWriter.writeAttribute(GEXF_VERSION, "1.1");

      if (exportColors || exportPosition || exportSize) {
        xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
      }
      xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);

      if (exportDynamic) {
        DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
        dynamicModel = dynamicController != null ? dynamicController.getModel(workspace) : null;
        visibleInterval =
            dynamicModel == null
                ? null
                : exportVisible
                    ? dynamicModel.getVisibleInterval()
                    : new TimeInterval(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
      }

      writeMeta(xmlWriter);
      writeGraph(xmlWriter, graph);

      xmlWriter.writeEndElement();
      xmlWriter.writeEndDocument();
      xmlWriter.close();

    } catch (Exception e) {
      graph.readUnlockAll();
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RuntimeException(e);
    }

    graph.readUnlock();

    Progress.finish(progress);
    return !cancel;
  }