java.lang.Object
com.aspose.words.RevisionGroupCollection
public class RevisionGroupCollection
You do not create instances of this class directly. Use the Example: Example:
Document doc = new Document(getMyDir() + "Document.Revisions.docx");
System.out.println(MessageFormat.format("Revision groups count: {0}\n", doc.getRevisions().getGroups().getCount()));
// Get info about all of revisions in document
for (RevisionGroup group : doc.getRevisions().getGroups()) {
System.out.println(MessageFormat.format("Revision author: {0}; Revision type: {1} \nRevision text: {2}", group.getAuthor(),
group.getRevisionType(), group.getRevisionType()));
}
Document doc = new Document(getMyDir() + "Document.Revisions.docx");
// Get revision group by index.
RevisionGroup revisionGroup = doc.getRevisions().getGroups().get(1);
// Get info about specific revision groups sorted by RevisionType
for (RevisionGroup revision : doc.getRevisions().getGroups()) {
if (revision.getRevisionType() == RevisionType.INSERTION) {
System.out.println(MessageFormat.format("Revision type: {0},\nRevision author: {1},\nRevision text: {2}.\n",
revision.getRevisionType(), revision.getAuthor(), revision.getText()));
}
}
| Property Getters/Setters Summary | ||
|---|---|---|
int | getCount() | |
| Returns the number of revision groups in the collection. | ||
RevisionGroup | get(int index) | |
| Returns a revision group at the specified index. | ||
| Method Summary | ||
|---|---|---|
java.util.Iterator<RevisionGroup> | iterator() | |
| Returns an enumerator object. | ||
| Property Getters/Setters Detail |
|---|
getCount | |
public int getCount() | |
Example:
Shows how to get info about a set of revisions in document.
Document doc = new Document(getMyDir() + "Document.Revisions.docx");
System.out.println(MessageFormat.format("Revision groups count: {0}\n", doc.getRevisions().getGroups().getCount()));
// Get info about all of revisions in document
for (RevisionGroup group : doc.getRevisions().getGroups()) {
System.out.println(MessageFormat.format("Revision author: {0}; Revision type: {1} \nRevision text: {2}", group.getAuthor(),
group.getRevisionType(), group.getRevisionType()));
}get | |
public RevisionGroup get(int index) | |
Example:
Shows how to get a set of revisions in document.
Document doc = new Document(getMyDir() + "Document.Revisions.docx");
// Get revision group by index.
RevisionGroup revisionGroup = doc.getRevisions().getGroups().get(1);
// Get info about specific revision groups sorted by RevisionType
for (RevisionGroup revision : doc.getRevisions().getGroups()) {
if (revision.getRevisionType() == RevisionType.INSERTION) {
System.out.println(MessageFormat.format("Revision type: {0},\nRevision author: {1},\nRevision text: {2}.\n",
revision.getRevisionType(), revision.getAuthor(), revision.getText()));
}
}| Method Detail |
|---|
iterator | |
public java.util.Iterator<RevisionGroup> iterator() | |
Example:
Shows how to look through a document's revisions.
// Open a document that contains revisions and get its revision collection
Document doc = new Document(getMyDir() + "Document.Revisions.docx");
RevisionCollection revisions = doc.getRevisions();
// This collection itself has a collection of revision groups, which are merged sequences of adjacent revisions
System.out.println(MessageFormat.format("{0} revision groups:", revisions.getGroups().getCount()));
// We can iterate over the collection of groups and access the text that the revision concerns
Iterator<RevisionGroup> e = revisions.getGroups().iterator();
while (e.hasNext()) {
RevisionGroup currentRevisionGroup = e.next();
System.out.println(MessageFormat.format("\tGroup type \"{0}\", ", currentRevisionGroup.getRevisionType()) +
MessageFormat.format("author: {0}, contents: [{1}]", currentRevisionGroup.getAuthor(), currentRevisionGroup.getText().trim()));
}
// The collection of revisions is considerably larger than the condensed form we printed above,
// depending on how many Runs the text has been segmented into during editing in Microsoft Word,
// since each Run affected by a revision gets its own Revision object
System.out.println(MessageFormat.format("\n{0} revisions:", revisions.getCount()));
Iterator<Revision> e1 = revisions.iterator();
while (e1.hasNext()) {
Revision currentRevision = e1.next();
// A StyleDefinitionChange strictly affects styles and not document nodes, so in this case the ParentStyle
// attribute will always be used, while the ParentNode will always be null
// Since all other changes affect nodes, ParentNode will conversely be in use and ParentStyle will be null
if (currentRevision.getRevisionType() == RevisionType.STYLE_DEFINITION_CHANGE) {
System.out.println(MessageFormat.format("\tRevision type \"{0}\", ", currentRevision.getRevisionType()) +
MessageFormat.format("author: {0}, style: [{1}]", currentRevision.getAuthor(), currentRevision.getParentStyle().getName()));
} else {
System.out.println(MessageFormat.format("\tRevision type \"{0}\", ", currentRevision.getRevisionType()) +
MessageFormat.format("author: {0}, contents: [{1}]", currentRevision.getAuthor(), currentRevision.getParentNode().getText().trim()));
}
}
// While the collection of revision groups provides a clearer overview of all revisions that took place in the document,
// the changes must be accepted/rejected by the revisions themselves, the RevisionCollection, or the document
// In this case we will reject all revisions via the collection, reverting the document to its original form, which we will then save
revisions.rejectAll();
Assert.assertEquals(revisions.getCount(), 0);
doc.save(getArtifactsDir() + "Document.RevisionCollection.docx");