org.foray.xml
Class FOrayXDiff

java.lang.Object
  extended by org.foray.xml.FOrayXDiff

public class FOrayXDiff
extends Object

This class reads two or more XML streams and finds the first difference (if any) between them. This is not intended to be a general-purpose XML diff and compare tool. It is suitable in situations where some tranformation (like a pretty-print) has taken place and we wish to make sure that no significant changes were made to the document.


Field Summary
static byte STATUS_COMMAND_LINE_ERROR
          Command-line status constant indicating that the command line itself was not properly formed.
static byte STATUS_DIFFERENCE_FOUND
          Command-line status constant indicating that a substantive difference between the two inputs was detected.
static byte STATUS_MALFORMED_URL
          Command-line status constant indicating a malformed URL.
static byte STATUS_PARSING_ERROR
          Command-line status constant indicating a parsing error.
static byte STATUS_SUCCESS
          Command-line status constant indicating success.
 
Constructor Summary
FOrayXDiff(InputStream[] streams, String catalog)
          Constructor accepting InputStreams to compare.
FOrayXDiff(URL[] urls, String catalog)
          Constructor accepting URLs to compare.
 
Method Summary
 boolean equivalent()
          Compares the XML streams passed or implicitly passed in the constructor, and returns true if the streams are equivalent, false if there is one or more differences.
static String getEventDescription(int event)
          Returns an event description matching the parsed event.
 org.apache.commons.logging.Log getLogger()
          Returns the logger.
static void main(String[] args)
          Command-line interface for FOrayXDiff.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_SUCCESS

public static final byte STATUS_SUCCESS
Command-line status constant indicating success.

See Also:
Constant Field Values

STATUS_COMMAND_LINE_ERROR

public static final byte STATUS_COMMAND_LINE_ERROR
Command-line status constant indicating that the command line itself was not properly formed.

See Also:
Constant Field Values

STATUS_MALFORMED_URL

public static final byte STATUS_MALFORMED_URL
Command-line status constant indicating a malformed URL.

See Also:
Constant Field Values

STATUS_PARSING_ERROR

public static final byte STATUS_PARSING_ERROR
Command-line status constant indicating a parsing error.

See Also:
Constant Field Values

STATUS_DIFFERENCE_FOUND

public static final byte STATUS_DIFFERENCE_FOUND
Command-line status constant indicating that a substantive difference between the two inputs was detected.

See Also:
Constant Field Values
Constructor Detail

FOrayXDiff

public FOrayXDiff(URL[] urls,
                  String catalog)
           throws IOException,
                  XMLStreamException
Constructor accepting URLs to compare.

Parameters:
urls - An array of URLs to be compared.
catalog - The location of a catalog file that should be used to find the DTD for this document.
Throws:
IOException - For errors opening the files.
XMLStreamException - For errors parsing the files.
See Also:
For a constructor that takes any {@link InputStream}.

FOrayXDiff

public FOrayXDiff(InputStream[] streams,
                  String catalog)
           throws XMLStreamException
Constructor accepting InputStreams to compare.

Parameters:
streams - An array of InputStreams to be compared.
catalog - The location of a catalog file that should be used to find the DTD for this document.
Throws:
XMLStreamException - For errors during the diff.
See Also:
For a constructor that takes {@link URL}s.
Method Detail

equivalent

public boolean equivalent()
                   throws IOException,
                          XMLStreamException
Compares the XML streams passed or implicitly passed in the constructor, and returns true if the streams are equivalent, false if there is one or more differences.

Returns:
True if the streams are equivalent, false if there is one or more differences.
Throws:
IOException - For errors reading the documents.
XMLStreamException - For errors pulling events from the documents.

getEventDescription

public static String getEventDescription(int event)
Returns an event description matching the parsed event.

Parameters:
event - The parsed event.
Returns:
The description of event.

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger.

Returns:
The logger.

main

public static void main(String[] args)
Command-line interface for FOrayXDiff.

Design Note: We use files instead of URLs here to more easily integrate with desktop tools such as XML editors, which typically know how to pass parameters for local files, but not how to convert them to URLs. If URLs are needed, additional flags probably need to be added to the command-line interface to designate that.

Return status is one of:

Parameters:
args - The following are valid command-line arguments:
  • -c,--catalog <arg> path to the catalog file (optional)
  • -f,--files <arg> paths to the files to be compared (required, minimum 2)


Copyright © 2017. All rights reserved.