Comparing Flow Chart XML Between the File System and Repository

If you have a flow chart in the repository and an .ffc file on the file system, and you would like to compare the XML contents to see if they are equal, you can use the following Java code:

You will need to be sure that the file flow-charts-5-0.dtd is located in the Java working directory in order to use the code below.

import flux.Engine;
import flux.EngineException;
import flux.Factory;
import flux.FlowChart;
import flux.repository.RepositoryAdministrator;
import flux.repository.RepositoryIterator;
import flux.xml.XmlEngineHelper;
import flux.xml.XmlFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.rmi.NotBoundException;
import java.util.ArrayList;
import java.util.List;
public class CompareFlowChartXML {
  public static void main(String[] args) throws NotBoundException, EngineException, IOException, ParserConfigurationException, SAXException {
    Factory factory = Factory.makeInstance();
//    Look up the engine, this code assumes an unsecured engine running at the
//    default location
    Engine engine = factory.lookupRmiEngine("localhost"1099"Flux");
//    Get the flow chart from the repository
    RepositoryAdministrator repoAdmin = engine.getRepositoryAdministrator();
    List<FlowChart> flowCharts = new ArrayList<FlowChart>();
    RepositoryIterator it = repoAdmin.get("/myflowchart");
    try {
      while (it.hasNext()) {
    finally {
//    Convert the flow chart to XML
    XmlEngineHelper xmlHelper = XmlFactory.makeInstance().makeXmlEngineHelper();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    xmlHelper.makeXmlFromFlowCharts(flowCharts, bos, true);
    String flowChartXml = bos.toString();
//    Use Java libraries for the XML comparison
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc1 = db.parse(new File("/path/to/myflowchart.ffc"));
    Document doc2 = db.parse(new ByteArrayInputStream(flowChartXml.getBytes()));
Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.