Comparing Workflow XML Between the File System and Repository

If you have a workflow 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.*;
import flux.repository.RepositoryAdministrator;
import flux.repository.RepositoryIterator;
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 CompareWorkflowXML {
  public static void main(String[] args) throws NotBoundException, EngineException, IOException, ParserConfigurationException, SAXException {
    Factory factory = Factory.makeInstance();
//    Look up the engine at the given host, port, and SSL setting
    Engine engine = Factory.makeInstance().lookupEngine("localhost"7250true);
    try {
//      Edit this to use a valid login for your engine.
//      If security is not enabled, comment out the line below, as well as the
//      try / finally block and the logout line.
//      Get the workflow from the repository
      RepositoryAdministrator repoAdmin = engine.getRepositoryAdministrator();
      List<FlowChart> workflows = new ArrayList<FlowChart>();
      RepositoryIterator it = repoAdmin.get("/myworkflow"); 
      try {
        while (it.hasNext()) {
      finally {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      EngineHelper.makeXmlFromFlowCharts(workflows, bos, true);
      String workflowXml = 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/myworkflow.ffc"));
      Document doc2 = db.parse(new ByteArrayInputStream(workflowXml.getBytes()));
    finally {
Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.