java.lang.Object
com.aspose.words.RevisionType
public class RevisionType
- extends java.lang.Object
Utility class containing constants.
Specifies the type of change being tracked in Revision.
Example:
Shows how to check if a document has revisions.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Normal editing of the document does not count as a revision
builder.write("This does not count as a revision. ");
Assert.assertFalse(doc.hasRevisions());
// In order for our edits to count as revisions, we need to declare an author and start tracking them
doc.startTrackRevisions("John Doe", new Date());
builder.write("This is revision #1. ");
// This flag corresponds to the "Track Changes" option being turned on in Microsoft Word, to track the editing manually
// done there and not the programmatic changes we are about to do here
Assert.assertFalse(doc.getTrackRevisions());
// As well as nodes in the document, revisions get referenced in this collection
Assert.assertTrue(doc.hasRevisions());
Assert.assertEquals(doc.getRevisions().getCount(), 1);
Revision revision = doc.getRevisions().get(0);
Assert.assertEquals(revision.getAuthor(), "John Doe");
Assert.assertEquals(revision.getParentNode().getText(), "This is revision #1. ");
Assert.assertEquals(revision.getRevisionType(), RevisionType.INSERTION);
Assert.assertEquals(DocumentHelper.getDateWithoutTimeUsingFormat(revision.getDateTime()), DocumentHelper.getDateWithoutTimeUsingFormat(new Date()));
Assert.assertEquals(revision.getGroup(), doc.getRevisions().getGroups().get(0));
// Deleting content also counts as a revision
// The most recent revisions are put at the start of the collection
doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).remove();
Assert.assertEquals(doc.getRevisions().get(0).getRevisionType(), RevisionType.DELETION);
Assert.assertEquals(doc.getRevisions().getCount(), 2);
// Insert revisions are treated as document text by the GetText() method before they are accepted,
// since they are still nodes with text and are in the body
Assert.assertEquals(doc.getText().trim(), "This does not count as a revision. This is revision #1.");
// Accepting the deletion revision will assimilate it into the paragraph text and remove it from the collection
doc.getRevisions().get(0).accept();
Assert.assertEquals(doc.getRevisions().getCount(), 1);
// Once the delete revision is accepted, the nodes that it concerns are removed and their text will not show up here
Assert.assertEquals(doc.getText().trim(), "This is revision #1.");
// The second insertion revision is now at index 0, which we can reject to ignore and discard it
doc.getRevisions().get(0).reject();
Assert.assertEquals(doc.getRevisions().getCount(), 0);
Assert.assertEquals(doc.getText().trim(), "");
Field Summary |
static final int | INSERTION = 0 | |
New content was inserted in the document.
|
static final int | DELETION = 1 | |
Content was removed from the document.
|
static final int | FORMAT_CHANGE = 2 | |
Change of formatting was applied to the parent node.
|
static final int | STYLE_DEFINITION_CHANGE = 3 | |
Change of formatting was applied to the parent style.
|
static final int | MOVING = 4 | |
Content was moved in the document.
|
INSERTION = 0 | |
public static final int INSERTION |
-
New content was inserted in the document.
DELETION = 1 | |
public static final int DELETION |
-
Content was removed from the document.
FORMAT_CHANGE = 2 | |
public static final int FORMAT_CHANGE |
-
Change of formatting was applied to the parent node.
STYLE_DEFINITION_CHANGE = 3 | |
public static final int STYLE_DEFINITION_CHANGE |
-
Change of formatting was applied to the parent style.
MOVING = 4 | |
public static final int MOVING |
-
Content was moved in the document.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.