public final class Diff extends Object
Comparison of revisions must have been enabled in the initial
document using DiffSupport.addSerialNumbers(com.xmlmind.xml.doc.Document)
(or DiffSupport.addRevisions(com.xmlmind.xml.doc.Document)
).
Constructor and Description |
---|
Diff()
Constructs an object allowing to two revisions of
the same initial document.
|
Modifier and Type | Method and Description |
---|---|
static String |
canDiff(Document origDoc,
Document revDoc)
Returns a
null string if specified documents
can be compared for changes. |
void |
diff(Document origDoc,
Document revDoc,
List<Change> changes)
Compares specified document for changes.
|
static boolean |
hasPreserveSpace(DocumentType docType,
Element element)
Helper: returns
true if specied element has
or inherits xml:space="preserve";
returns false otherwise. |
static void |
printChanges(PrintStream out,
List<Change> changes,
boolean detailed)
Writes on specified output stream specified list of changes.
|
public Diff()
This object is not designed to be reused several times.
public static String canDiff(Document origDoc, Document revDoc)
null
string if specified documents
can be compared for changes. Returns a non-null
string
--an error message--if specified documents cannot be compared
for changes.public void diff(Document origDoc, Document revDoc, List<Change> changes) throws DiffException
origDoc
- the original documentrevDoc
- a revised copy of the original documentchanges
- detected changes, if any, are appended to this list
(after first clearing it)DiffException
- if, for any reason, an error occurs during
the execution of this method.
Note that this method first starts by invoking canDiff(com.xmlmind.xml.doc.Document, com.xmlmind.xml.doc.Document)
and will throw an exception if canDiff(com.xmlmind.xml.doc.Document, com.xmlmind.xml.doc.Document)
returns
an error message.
public static boolean hasPreserveSpace(DocumentType docType, Element element)
true
if specied element has
or inherits xml:space="preserve";
returns false
otherwise.docType
- the type of the document containing element;
may be null
element
- the element to be testedtrue
specified element is space preserving;
false
otherwisepublic static void printChanges(PrintStream out, List<Change> changes, boolean detailed)
This function may be used when testing or debugging. It also may be used to implement a command-line diff utility.