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.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 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()) { flowCharts.add(it.next().getFlowChart()); } } finally { it.close(); } // Convert the flow chart to XML XmlEngineHelper xmlHelper = XmlFactory.makeInstance().makeXmlEngineHelper(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); xmlHelper.makeXmlFromFlowCharts(flowCharts, bos, true ); bos.close(); String flowChartXml = 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/myflowchart.ffc" )); doc1.normalizeDocument(); Document doc2 = db.parse( new ByteArrayInputStream(flowChartXml.getBytes())); doc2.normalizeDocument(); System.out.println(doc1.isEqualNode(doc2)); } } |
Comments
Please sign in to leave a comment.