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.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
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.
      engine.login("admin""admin");
 
 
//      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()) {
          workflows.add(it.next().getFlowChart());
        }
      finally {
        it.close();
      }
 
 
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      EngineHelper.makeXmlFromFlowCharts(workflows, bos, true);
      bos.close();
      String workflowXml = bos.toString();
 
 
//    Use Java libraries for the XML comparison
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      dbf.setCoalescing(true);
      dbf.setIgnoringElementContentWhitespace(true);
      dbf.setIgnoringComments(true);
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc1 = db.parse(new File("/path/to/myworkflow.ffc"));
      doc1.normalizeDocument();
      Document doc2 = db.parse(new ByteArrayInputStream(workflowXml.getBytes()));
      doc2.normalizeDocument();
 
 
      System.out.println(doc1.isEqualNode(doc2));
    finally {
      engine.logout();
    }
  }
}
 
 
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.